public RuleMargin prepareRuleMargin(String area, List<Declaration> decl) { if ((decl == null || decl.isEmpty())) { log.debug("Empty RuleMargin was ommited"); return null; } RuleMargin rm = rf.createMargin(area); rm.replaceAll(decl); log.info("Create @" + area + " with:\n" + rm); return rm; }
public RuleBlock<?> prepareRulePage(List<Declaration> declarations, List<RuleMargin> marginRules, String name, String pseudo) { if ((declarations == null || declarations.isEmpty()) && (marginRules == null || marginRules.isEmpty())) { log.debug("Empty RulePage was ommited"); return null; } RulePage rp = rf.createPage(); if (declarations != null) for (Declaration d : declarations) rp.add(d); if (marginRules != null) for (RuleMargin m : marginRules) rp.add(m); rp.setName(name); rp.setPseudo(pseudo); log.info("Create @page as with:\n{}", rp); return (RuleBlock<?>) rp; }
public RuleBlock<?> prepareInlineRuleSet(List<Declaration> dlist, List<PseudoPage> pseudos) { if(dlist==null || dlist.isEmpty()) { log.debug("Empty RuleSet (inline) was ommited"); return null; } // create selector with element CombinedSelector cs = (CombinedSelector) rf.createCombinedSelector() .unlock(); Selector sel = (Selector) rf.createSelector().unlock(); sel.add(rf.createElementDOM(elem, inlinePriority)); if(pseudos!=null) sel.addAll(pseudos); cs.add(sel); RuleSet rs = rf.createSet(); rs.replaceAll(dlist); rs.setSelectors(Arrays.asList(cs)); log.info("Create @media as with:\n{}", rs); return (RuleBlock<?>) rs; }
/** * This is the same as {@link CSSFactory#getUsedStyles(Document, String, URL, MediaSpec, NetworkProcessor, Stylesheet)} * but a new StyleSheet is created instead of appending to one. * * @param doc * DOM tree * @param encoding * The default encoding used for the referenced style sheets * @param base * Base URL against which all files are searched * @param media * Selected media for style sheet * @param network * The network processor used for accessing the URL resources * @return the rules of all the style sheets used in the document including the inline styles */ public static final StyleSheet getUsedStyles(Document doc, String encoding, URL base, MediaSpec media, NetworkProcessor network) { StyleSheet style = (StyleSheet) getRuleFactory().createStyleSheet().unlock(); return getUsedStyles(doc, encoding, base, media, network, style); }
/** * selector * : (IDENT | ASTERISK) selpart* S* * | selpart+ S* * ; */ public Selector visitSelector(CSSParser.SelectorContext ctx) { if (ctxHasErrorNode(ctx)) { statement_stack.peek().invalid = true; return null; } selector_stack.push(new selector_scope()); cz.vutbr.web.css.Selector sel; logEnter("selector"); selector_stack.peek().s = sel = (cz.vutbr.web.css.Selector) rf.createSelector().unlock(); if (ctx.IDENT() != null || ctx.ASTERISK() != null) { cz.vutbr.web.css.Selector.ElementName en = rf.createElement(cz.vutbr.web.css.Selector.ElementName.WILDCARD); if (ctx.IDENT() != null) { en.setName(extractTextUnescaped(ctx.IDENT().getText())); } //log.debug("Adding element name: {}.", en.getName()); selector_stack.peek().s.add(en); } for (CSSParser.SelpartContext selpartctx : ctx.selpart()) { visitSelpart(selpartctx); } logLeave("selector"); selector_stack.pop(); return sel; }
ident = extractIdUnescaped(ctx.HASH().getText()); if (ident != null) { selector_stack.peek().s.add(rf.createID(ident)); } else { combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(rf.createClass(extractTextUnescaped(ctx.CLASSKEYWORD().getText()))); } else if (ctx.attribute() != null) { Selector.ElementAttribute ea = visitAttribute(ctx.attribute());
private static RulePage makePageRule(String name, String pseudo, List<RulePage> from) { RulePage pageRule = brailleRuleFactory.createPage().setName(name).setPseudo(pseudo); for (RulePage f : from) for (Rule<?> r : f) if (r instanceof Declaration) { Declaration d = (Declaration)r; String property = d.getProperty(); if (getDeclaration(pageRule, property) == null) pageRule.add(r); } else if (r instanceof RuleMargin) { RuleMargin m = (RuleMargin)r; String marginArea = m.getMarginArea(); RuleMargin marginRule = getRuleMargin(pageRule, marginArea); if (marginRule == null) { marginRule = brailleRuleFactory.createMargin(marginArea); pageRule.add(marginRule); marginRule.replaceAll(m); } else for (Declaration d : m) if (getDeclaration(marginRule, d.getProperty()) == null) marginRule.add(d); } return pageRule; }
/** * Creates a single property declaration. * @param property Property name. * @param term Property value. * @return The resulting declaration. */ protected Declaration createDeclaration(String property, Term<?> term) { Declaration d = CSSFactory.getRuleFactory().createDeclaration(); d.unlock(); d.setProperty(property); d.add(term); return d; }
return null; MediaExpression expr = rf.createMediaExpression(); Declaration decl; declaration_stack.push(new declaration_scope()); declaration_stack.peek().d = decl = rf.createDeclaration(); declaration_stack.peek().invalid = false;
public RuleBlock<?> prepareRuleFontFace(List<Declaration> decl) { if (decl == null || decl.isEmpty()) { log.debug("Empty RuleFontFace was ommited"); return null; } RuleFontFace rp = rf.createFontFace(); rp.replaceAll(decl); log.info("Create @font-face as with:\n{}", rp); return (RuleBlock<?>) rp; }
logEnter("combined_selector"); combined_selector_stack.push(new combined_selector_scope()); CombinedSelector combinedSelector = (CombinedSelector) rf.createCombinedSelector().unlock(); Selector.Combinator c; Selector s = visitSelector(ctx.selector(0));
elemAttr = rf.createAttribute(value, isStringValue, op, attributeName); } else { log.debug("Invalid attribute element in selector");
/** * Parses source of given type * * @param source Source, interpretation depends on {@code type} * @param type Type of source provided * @param inline InlineElement * @param inlinePriority True when the rule should have an 'inline' (greater) priority * @return Created StyleSheet * @throws IOException When problem with input stream occurs * @throws CSSException When unrecoverable exception during parsing occurs */ public StyleSheet parse(Object source, NetworkProcessor network, String encoding, SourceType type, Element inline, boolean inlinePriority, URL base) throws IOException, CSSException { StyleSheet sheet = (StyleSheet) CSSFactory.getRuleFactory() .createStyleSheet().unlock(); Preparator preparator = new SimplePreparator(inline, inlinePriority); return parseAndImport(source, network, encoding, type, sheet, preparator, base, null); }
/** * selector * : (IDENT | ASTERISK) selpart* S* * | selpart+ S* * ; */ public Selector visitSelector(CSSParser.SelectorContext ctx) { if (ctxHasErrorNode(ctx)) { statement_stack.peek().invalid = true; return null; } selector_stack.push(new selector_scope()); cz.vutbr.web.css.Selector sel; logEnter("selector"); selector_stack.peek().s = sel = (cz.vutbr.web.css.Selector) rf.createSelector().unlock(); if (ctx.IDENT() != null || ctx.ASTERISK() != null) { cz.vutbr.web.css.Selector.ElementName en = rf.createElement(cz.vutbr.web.css.Selector.ElementName.WILDCARD); if (ctx.IDENT() != null) { en.setName(extractTextUnescaped(ctx.IDENT().getText())); } //log.debug("Adding element name: {}.", en.getName()); selector_stack.peek().s.add(en); } for (CSSParser.SelpartContext selpartctx : ctx.selpart()) { visitSelpart(selpartctx); } logLeave("selector"); selector_stack.pop(); return sel; }
ident = extractIdUnescaped(ctx.HASH().getText()); if (ident != null) { selector_stack.peek().s.add(rf.createID(ident)); } else { combined_selector_stack.peek().invalid = true; selector_stack.peek().s.add(rf.createClass(extractTextUnescaped(ctx.CLASSKEYWORD().getText()))); } else if (ctx.attribute() != null) { Selector.ElementAttribute ea = visitAttribute(ctx.attribute());
Declaration decl; declaration_stack.push(new declaration_scope()); declaration_stack.peek().d = decl = rf.createDeclaration(); declaration_stack.peek().invalid = false;
return null; MediaExpression expr = rf.createMediaExpression(); Declaration decl; declaration_stack.push(new declaration_scope()); declaration_stack.peek().d = decl = rf.createDeclaration(); declaration_stack.peek().invalid = false;
public RuleBlock<?> prepareRuleFontFace(List<Declaration> decl) { if (decl == null || decl.isEmpty()) { log.debug("Empty RuleFontFace was ommited"); return null; } RuleFontFace rp = rf.createFontFace(); rp.replaceAll(decl); log.info("Create @font-face as with:\n{}", rp); return (RuleBlock<?>) rp; }
logEnter("combined_selector"); combined_selector_stack.push(new combined_selector_scope()); CombinedSelector combinedSelector = (CombinedSelector) rf.createCombinedSelector().unlock(); Selector.Combinator c; Selector s = visitSelector(ctx.selector(0));
elemAttr = rf.createAttribute(value, isStringValue, op, attributeName); } else { log.debug("Invalid attribute element in selector");