cz.vutbr.web.css.RuleBlock Java Examples
The following examples show how to use
cz.vutbr.web.css.RuleBlock.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Override public RuleBlock<?> prepareRuleKeyframes(List<KeyframeBlock> rules, String name) { if (rules == null || rules.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Empty RuleKeyframes was ommited"); } return null; } if (name == null || name.isEmpty()) { if (log.isDebugEnabled()) { log.debug("RuleKeyframes with no name was ommited"); } return null; } // create media at position of mark RuleKeyframes rk = rf.createKeyframes(); rk.replaceAll(rules); rk.setName(name); log.info("Create @keyframes as with:\n{}", rk); return (RuleBlock<?>) rk; }
Example #2
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static List<RuleBlock<?>> getAtRuleBlocks(StyleSheet styles, StylesEmbeddingOptions options) { List<RuleBlock<?>> rules = new ArrayList<>(); if (styles != null) { for (RuleBlock<?> ruleBlock : styles) { if (ruleBlock instanceof RuleMedia) { RuleMedia block = (RuleMedia) ruleBlock; for (RuleSet set : block) { set.forEach(HtmlUtils::resolveUris); } resolveMediaType(block.getMediaQueries(), options.getMediaType()); rules.add(block); } else if (ruleBlock instanceof RuleFontFace) { rules.add(ruleBlock); } } } return rules; }
Example #3
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
/** * Extract all the media queries from a {@code styles} stylesheet, resolve relative URIs (if any) in a CSS rules. * @param styles a stylesheet to process. * @return a list of entities that represent media queries. */ private static List<RuleMedia> getMediaQueries(StyleSheet styles) { List<RuleMedia> rules = new ArrayList<>(); if (styles != null) { for (RuleBlock<?> ruleBlock : styles) { if (ruleBlock instanceof RuleMedia) { RuleMedia block = (RuleMedia) ruleBlock; for (RuleSet set : block) { set.forEach(HtmlUtils::resolveUris); } rules.add(block); } } } return rules; }
Example #4
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static void appendStyleTag(StringBuilder builder, List<RuleBlock<?>> rules, DeclarationMap styleMap, Element element, StylesEmbeddingOptions options) { if (!rules.isEmpty()) { builder.append("<style"); appendAttributes(builder, styleMap, element, options); builder.append('>'); if (options.isPrettyPrint()) { builder.append('\n'); } for (RuleBlock<?> rule : rules) { builder.append(rule.toString()); } builder.append("</style>"); if (options.isPrettyPrint()) { builder.append('\n'); } } }
Example #5
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static void appendStyleTag(StringBuilder builder, List<RuleBlock<?>> rules, StylesEmbeddingOptions options) { if (!rules.isEmpty()) { builder.append("<style type=\"text/css\">"); if (options.isPrettyPrint()) { builder.append('\n'); } for (RuleBlock<?> rule : rules) { builder.append(rule.toString()); } builder.append("</style>"); if (options.isPrettyPrint()) { builder.append('\n'); } } }
Example #6
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Override public RuleBlock<?> prepareRulePage(List<Declaration> declarations, List<RuleMargin> marginRules, String name, Selector.PseudoPage pseudo) { if ((declarations == null || declarations.isEmpty()) && (marginRules == null || marginRules.isEmpty())) { if (log.isDebugEnabled()) { 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; }
Example #7
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
public RuleBlock<?> prepareRuleMedia(List<RuleSet> rules, List<MediaQuery> media) { if (rules == null || rules.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Empty RuleMedia was ommited"); } return null; } // create media at position of mark RuleMedia rm = rf.createMedia(); rm.replaceAll(rules); if (media != null && !media.isEmpty()) rm.setMediaQueries(media); log.info("Create @media as with:\n{}", rm); return (RuleBlock<?>) rm; }
Example #8
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private static List<RuleBlock<?>> getAtRuleBlocks(URL source, StylesEmbeddingOptions options) { try { return getAtRuleBlocks(CSSFactory.parse(source, options.getEncodingName()), options); } catch (IOException | CSSException e) { logger.error("Remote style sheets parsing failed", e); } return Collections.emptyList(); }
Example #9
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public RuleBlock<?> prepareInlineRuleSet(List<Declaration> dlist, List<Selector.SelectorPart> pseudos) { if(dlist==null || dlist.isEmpty()) { if (log.isDebugEnabled()) { 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 inline ruleset as with:\n{}", rs); return (RuleBlock<?>) rs; }
Example #10
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
public RuleBlock<?> prepareRuleFontFace(List<Declaration> decl) { if (decl == null || decl.isEmpty()) { if (log.isDebugEnabled()) { 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; }
Example #11
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
public RuleBlock<?> prepareRuleViewport(List<Declaration> decl) { if (decl == null || decl.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Empty Viewport was ommited"); } return null; } RuleViewport rp = rf.createViewport(); rp.replaceAll(decl); log.info("Create @viewport as {}th with:\n{}", rp); return (RuleBlock<?>) rp; }
Example #12
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
public RuleBlock<?> prepareRuleSet(List<CombinedSelector> cslist, List<Declaration> dlist, boolean wrap, List<MediaQuery> media) { // check emptiness if ((cslist == null || cslist.isEmpty()) || (dlist == null || dlist.isEmpty())) { if (log.isDebugEnabled()) { log.debug("Empty RuleSet was ommited"); } return null; } // create rule set RuleSet rs = rf.createSet(); rs.setSelectors(cslist); rs.replaceAll(dlist); log.info("Created RuleSet as with:\n{}", rs); // wrap if (wrap) { // swap numbers, so RuleMedia is created before RuleSet RuleMedia rm = rf.createMedia(); if (log.isDebugEnabled()) { log.debug("Wrapping RuleSet {} into RuleMedia: {}", rs, media); } rm.unlock(); rm.add(rs); rm.setMediaQueries(media); // return wrapped block return (RuleBlock<?>) rm; } // return classic rule set return (RuleBlock<?>) rs; }
Example #13
Source File: DOMAnalyzer.java From CSSBox with GNU Lesser General Public License v3.0 | 5 votes |
private void scanLocalFonts() { for (StyleSheet sheet : styles) { for (RuleBlock<?> block : sheet.asList()) { if (block instanceof RuleFontFace) { processFontFaceRule((RuleFontFace) block); } } } }
Example #14
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private static List<RuleBlock<?>> getAtRuleBlocks(String css, StylesEmbeddingOptions options) { try { return getAtRuleBlocks(CSSFactory.parseString(css, options.getBaseUrl()), options); } catch (IOException | CSSException e) { logger.error("Style sheets parsing failed", e); } return Collections.emptyList(); }
Example #15
Source File: StyleSheetImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean add(RuleBlock<?> o) { o.setStyleSheet(this); return super.add(o); }
Example #16
Source File: StyleSheetImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void add(int index, RuleBlock<?> element) { element.setStyleSheet(this); super.add(index, element); }
Example #17
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates base block of rules. Most usually, it will be RuleSet, but when * parser is inside of imported file with medium and wrap condition is {@code true}, then * RuleSet is wrapped by media into RuleMedia * @param cslist List of CombinedSelector for this rule block * @param dlist List of Declaration for this rule block * @param wrap Wrap condition, it {@code true}, rule set is wrapped into rule media * @param media List of medias used to wrap * @return Either RuleSet containing selectors and declarations, or RuleMedia, wrapped * version of RuleSet */ public RuleBlock<?> prepareRuleSet(List<CombinedSelector> cslist, List<Declaration> dlist, boolean wrap, List<MediaQuery> media);
Example #18
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates block of rules as result of parsing in-line declaration. * @param dlist List of Declaration * @param pseudos List of pseudo page identifiers * @return RuleSet */ public RuleBlock<?> prepareInlineRuleSet(List<Declaration> dlist, List<Selector.SelectorPart> pseudos);
Example #19
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates RuleMedia, block of rules with assigned medias. Uses mark to change priority of rules, * that is priority of this rule is set to mark * @param rules Rules encapsulated by this RuleMedia * @param media List of media assigned to rule * @return RuleMedia */ public RuleBlock<?> prepareRuleMedia(List<RuleSet> rules, List<MediaQuery> media);
Example #20
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates RulePage, block of rules associated with specific page * @param declarations List of declarations * @param marginRules List of margin rules * @param name Name of the page * @param pseudo Pseudo-class of the page * @return RulePage */ public RuleBlock<?> prepareRulePage(List<Declaration> declarations, List<RuleMargin> marginRules, String name, Selector.PseudoPage pseudo);
Example #21
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates RuleViewport, block of rules associated with the viewport. * @param decl List of declarations * @return RuleViewport */ public RuleBlock<?> prepareRuleViewport(List<Declaration> decl);
Example #22
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates RuleFontFace, block of rules associated with specific font * @param decl List of declarations * @return RuleFontFace */ public RuleBlock<?> prepareRuleFontFace(List<Declaration> decl);
Example #23
Source File: Preparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 2 votes |
/** * Creates RuleKeyframes, block of key frames with assigned name. * @param rules Rules encapsulated by this RuleKeyframes * @param name Keyframes name * @return RuleKeyframes */ public RuleBlock<?> prepareRuleKeyframes(List<KeyframeBlock> rules, String name);