Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.daisy.pipeline.css.impl;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.URIResolver;
import com.google.common.collect.Iterables;
import cz.vutbr.web.css.CSSProperty.CounterIncrement;
import cz.vutbr.web.css.CSSProperty.CounterReset;
import cz.vutbr.web.css.CSSProperty.CounterSet;
import cz.vutbr.web.css.NodeData;
import cz.vutbr.web.css.RuleFactory;
import cz.vutbr.web.css.Selector.PseudoElement;
import cz.vutbr.web.css.SupportedCSS;
import cz.vutbr.web.css.Term;
import cz.vutbr.web.css.TermFunction;
import cz.vutbr.web.css.TermIdent;
import cz.vutbr.web.css.TermList;
import cz.vutbr.web.css.TermPair;
import cz.vutbr.web.css.TermString;
import cz.vutbr.web.csskit.antlr.CSSParserFactory;
import cz.vutbr.web.csskit.RuleFactoryImpl;
import cz.vutbr.web.domassign.DeclarationTransformer;
import cz.vutbr.web.domassign.StyleMap;
import org.daisy.braille.css.BrailleCSSDeclarationTransformer;
import org.daisy.braille.css.BrailleCSSParserFactory;
import org.daisy.braille.css.BrailleCSSProperty.Content;
import org.daisy.braille.css.BrailleCSSProperty.Display;
import org.daisy.braille.css.BrailleCSSProperty.ListStyleType;
import org.daisy.braille.css.RuleCounterStyle;
import org.daisy.braille.css.SupportedBrailleCSS;
import org.daisy.common.stax.BaseURIAwareXMLStreamWriter;
import org.daisy.common.stax.XMLStreamWriterHelper;
import org.daisy.common.transform.XMLTransformer;
import org.daisy.pipeline.css.CounterStyle;
import org.daisy.pipeline.css.CssCascader;
import org.daisy.pipeline.css.CssPreProcessor;
import org.daisy.pipeline.css.CssSerializer;
import org.daisy.pipeline.css.JStyleParserCssCascader;
import org.daisy.pipeline.css.Medium;
import org.daisy.pipeline.css.XsltProcessor;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* For now this cascader handles only 'print' and 'screen' media without support for counters
* ({@code (-counter-support: none)}). It will generate marker contents by evaluating marker contents, based
* on {@code ::marker} pseudo-element rules, 'list-style-type', 'counter-reset', 'counter-set' and
* 'counter-increment' properties and {@code @counter-style} rules, according to CSS Lists and Counters Module Level
* 3. The marker contents are inserted as text nodes.
*
* For now all other styles are ignored and no attributes are added.
*/
@Component(
name = "DefaultCssCascader",
service = { CssCascader.class }
)
public class DefaultCssCascader implements CssCascader {
public boolean supportsMedium(Medium medium) {
switch (medium.getType()) {
case PRINT:
case SCREEN:
return "none".equals(medium.getCustomFeatures().get("counter-support"));
default:
return false;
}
}
public XMLTransformer newInstance(Medium medium,
String userStylesheet,
URIResolver uriResolver,
CssPreProcessor preProcessor,
XsltProcessor xsltProcessor,
QName attributeName,
boolean multipleAttrs) {
if (!supportsMedium(medium))
throw new IllegalArgumentException("medium not supported: " + medium);
return new Transformer(uriResolver, preProcessor, xsltProcessor, userStylesheet, medium,
attributeName, multipleAttrs);
}
// using braille-css because @counter-style is not supported by jStyleParser
private static final CSSParserFactory parserFactory = new BrailleCSSParserFactory();
private static final RuleFactory ruleFactory = RuleFactoryImpl.getInstance();
private static final SupportedCSS supportedCSS = new SupportedBrailleCSS(false, true); // FIXME: support "list-style" shorthand
private static final DeclarationTransformer declarationTransformer
= new BrailleCSSDeclarationTransformer(supportedCSS);
/*
* We can make use of JStyleParserCssCascader for the evaluation of marker contents because to
* compute the value we only need to know about preceding and ancestor nodes, which is a
* condition that is fulfilled because of how traverse() is called.
*/
private static class Transformer extends JStyleParserCssCascader {
private Map namedCounterStyles = null;
private LinkedList listCounterStyle = new LinkedList<>();
private LinkedList