| 40 | import io.mola.galimatias.URL; |
| 41 | |
| 42 | public class CSSHandler implements CssContentHandler, CssErrorHandler |
| 43 | { |
| 44 | final ValidationContext context; |
| 45 | final Report report; |
| 46 | final EPUBVersion version; |
| 47 | final Mode mode; |
| 48 | int startingLineNumber = 0; // append to line info from css parser |
| 49 | int startingColumnNumber = 0; |
| 50 | static final CharMatcher SPACE_AND_QUOTES = CharMatcher.anyOf(" \t\n\r\f\"'").precomputed(); |
| 51 | |
| 52 | // map to store parsed URLs |
| 53 | Map<String, URL> parsedURLs = new HashMap<>(); |
| 54 | final URLChecker urlChecker; |
| 55 | |
| 56 | // vars for font-face info |
| 57 | String fontFamily; |
| 58 | String fontStyle; |
| 59 | String fontWeight; |
| 60 | String fontURI; |
| 61 | boolean inFontFace = false; |
| 62 | boolean hasFontFaceDeclarations = false; |
| 63 | boolean inKeyFrames = false; |
| 64 | CssAtRule atRule = null; |
| 65 | |
| 66 | // properties the must be declared on the related OPF item |
| 67 | final Set<ITEM_PROPERTIES> detectedProperties = EnumSet.noneOf(ITEM_PROPERTIES.class); |
| 68 | |
| 69 | public CSSHandler(ValidationContext context, Mode mode) |
| 70 | { |
| 71 | this.context = context; |
| 72 | this.report = context.report; |
| 73 | this.version = context.version; |
| 74 | this.mode = mode; |
| 75 | this.urlChecker = new URLChecker(context); |
| 76 | } |
| 77 | |
| 78 | private EPUBLocation getCorrectedEPUBLocation(int lineNumber, int columnNumber, String details) |
| 79 | { |
| 80 | lineNumber = correctedLineNumber(lineNumber); |
| 81 | columnNumber = correctedColumnNumber(lineNumber, columnNumber); |
| 82 | return EPUBLocation.of(context).at(lineNumber, columnNumber).context(details); |
| 83 | } |
| 84 | |
| 85 | private EPUBLocation getCorrectedEPUBLocation(CssConstruct construct) |
| 86 | { |
| 87 | int line = correctedLineNumber(construct.getLocation().getLine()); |
| 88 | int col = correctedColumnNumber(line, construct.getLocation().getColumn()); |
| 89 | return EPUBLocation.of(context).at(line, col).context(construct.toCssString()); |
| 90 | } |
| 91 | |
| 92 | private int correctedLineNumber(int lineNumber) |
| 93 | { |
| 94 | return startingLineNumber + lineNumber; |
| 95 | } |
| 96 | |
| 97 | private int correctedColumnNumber(int lineNumber, int columnNumber) |
| 98 | { |
| 99 | if (lineNumber != 0) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…