@Override protected NodeData createDataInstance() { return CSSFactory.createNodeData(); }
/** * This is the same as {@link CSSFactory#getUsedStyles(Document, String, URL, MediaSpec)} with * the possibility of specifying a custom network processor. * * @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 * @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) { return getUsedStyles(doc, encoding, base, media, getNetworkProcessor()); }
/** * Returns the registered DeclarationTransformer * * @return DeclarationTransformer instance */ public static final DeclarationTransformer getDeclarationTransformer() { if (dt == null) { try { @SuppressWarnings("unchecked") Class<? extends DeclarationTransformerImpl> clazz = (Class<? extends DeclarationTransformerImpl>) Class .forName(DEFAULT_DECLARATION_TRANSFORMER); Method m = clazz.getMethod("getInstance"); registerDeclarationTransformer((DeclarationTransformerImpl) m.invoke(null)); log.debug("Retrived {} as default DeclarationTransformer implementation.", DEFAULT_DECLARATION_TRANSFORMER); } catch (Exception e) { log.error("Unable to get DeclarationTransformer from default", e); throw new RuntimeException( "No DeclarationTransformer implementation registered!"); } } return dt; }
URL base, MediaSpec media, boolean useInheritance, final MatchCondition matchCond) { return assignDOM(doc, encoding, getNetworkProcessor(), base, media, useInheritance, matchCond);
/** * Creates an empty block style definition. * @return */ protected NodeData createBlockStyle() { NodeData ret = CSSFactory.createNodeData(); TermFactory tf = CSSFactory.getTermFactory(); ret.push(createDeclaration("display", tf.createIdent("block"))); return ret; }
stylesheet = brailleParserFactory.append(sheet, network, null, SourceType.URL, stylesheet, sheet); CSSFactory.registerCSSParserFactory(brailleParserFactory); stylesheet = CSSFactory.getUsedStyles(document, null, baseURL, new MediaSpec(medium), network, stylesheet); CSSFactory.registerDeclarationTransformer(brailleDeclarationTransformer); CSSFactory.registerSupportedCSS(brailleCSS); style.styleMap = new Analyzer(stylesheet).evaluateDOM(document, medium, false); style.pageRules = new HashMap<String,Map<String,RulePage>>(); { for (URL sheet : defaultSheets) { CSSFactory.registerRuleFactory(printRuleFactory); stylesheet = printParserFactory.append(sheet, network, null, SourceType.URL, stylesheet, sheet); } CSSFactory.registerCSSParserFactory(printParserFactory); CSSFactory.registerRuleFactory(printRuleFactory); stylesheet = CSSFactory.getUsedStyles(document, null, baseURL, new MediaSpec(medium), network, stylesheet); CSSFactory.registerDeclarationTransformer(printDeclarationTransformer); CSSFactory.registerSupportedCSS(printCSS); style.styleMap = new Analyzer(stylesheet).evaluateDOM(document, medium, false); } else {
/** * 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; }
/** * 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); }
@Deprecated public static final StyleMap assignDOM(Document doc, URL base, String media, boolean useInheritance) { return assignDOM(doc, null, base, media, useInheritance); }
@Deprecated public static final StyleSheet getUsedStyles(Document doc, URL base, String media) { return getUsedStyles(doc, null, base, media); }
/** * Assigns the default values to all the properties. * @param properties * @param values */ public void assignDefaults(Map<String, CSSProperty> properties, Map<String, Term<?>> values) { SupportedCSS css = CSSFactory.getSupportedCSS(); for (String name : names) { CSSProperty dp = css.getDefaultProperty(name); if (dp != null) properties.put(name, dp); Term<?> dv = css.getDefaultValue(name); if (dv != null) values.put(name, dv); } }
/** * Returns registered RuleFactory * * @return RuleFactory instance */ public static final RuleFactory getRuleFactory() { if (rf == null) { try { @SuppressWarnings("unchecked") Class<? extends RuleFactory> clazz = (Class<? extends RuleFactory>) Class .forName(DEFAULT_RULE_FACTORY); Method m = clazz.getMethod("getInstance"); registerRuleFactory((RuleFactory) m.invoke(null)); log.debug("Retrived {} as default RuleFactory implementation.", DEFAULT_RULE_FACTORY); } catch (Exception e) { log.error("Unable to get RuleFactory from default", e); throw new RuntimeException( "No RuleFactory implementation registered!"); } } return rf; }
/** * Returns registered SupportedCSS * * @return SupportedCSS instance */ public static final SupportedCSS getSupportedCSS() { if (css == null) { try { @SuppressWarnings("unchecked") Class<? extends SupportedCSS> clazz = (Class<? extends SupportedCSS>) Class .forName(DEFAULT_SUPPORTED_CSS); Method m = clazz.getMethod("getInstance"); registerSupportedCSS((SupportedCSS) m.invoke(null)); log.debug( "Retrived {} as default SupportedCSS implementation.", DEFAULT_SUPPORTED_CSS); } catch (Exception e) { log.error("Unable to get SupportedCSS from default", e); throw new RuntimeException( "No SupportedCSS implementation registered!"); } } return css; }
/** * Parses file into StyleSheet. Internally transforms file to URL * @param fileName Name of file * @param encoding Encoding used to parse input * @return Parsed style sheet * @throws CSSException In case that parsing error occurs * @throws IOException If file is not found or not readable */ public static final StyleSheet parse(String fileName, String encoding) throws CSSException, IOException { try { File f = new File(fileName); URL url = f.toURI().toURL(); return parse(url, encoding); } catch (MalformedURLException e) { String message = "Unable to construct URL from fileName: " + fileName; log.error(message); throw new FileNotFoundException(message); } }
if (CSSFactory.getImplyPixelLength() || ((TermInteger) term).getValue() == 0) { //0 is always allowed with no units
/** * 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); }
protected NodeData createLineStyle(float x1, float y1, float x2, float y2) { HtmlDivLine line = new HtmlDivLine(x1, y1, x2, y2); String bside = line.getBorderSide(); NodeData ret = CSSFactory.createNodeData(); TermFactory tf = CSSFactory.getTermFactory(); ret.push(createDeclaration("position", tf.createIdent("absolute"))); ret.push(createDeclaration("position", tf.createIdent("absolute"))); ret.push(createDeclaration("left", tf.createLength(line.getLeft(), unit))); ret.push(createDeclaration("top", tf.createLength(line.getTop(), unit))); ret.push(createDeclaration("width", tf.createLength(line.getWidth(), unit))); ret.push(createDeclaration("height", tf.createLength((float) line.getHeight(), unit))); ret.push(createDeclaration(bside + "-width", tf.createLength(line.getLineStrokeWidth(), unit))); ret.push(createDeclaration(bside + "-style", tf.createIdent("solid"))); String color = colorString(getGraphicsState().getStrokingColor()); ret.push(createDeclaration(bside + "-color", tf.createColor(color))); if (line.getAngleDegrees() != 0) { TermFunction rotate = tf.createFunction(); rotate.setFunctionName("rotate").add(tf.createAngle(String.valueOf(line.getAngleDegrees()), Unit.deg, 1)); ret.push(createDeclaration("transform", rotate)); } return ret; }
@Deprecated public static final StyleMap assignDOM(Document doc, URL base, String media, boolean useInheritance) { return assignDOM(doc, null, base, media, useInheritance); }
@Deprecated public static final StyleSheet getUsedStyles(Document doc, URL base, String media) { return getUsedStyles(doc, null, base, media); }
/** * Assigns the default values to all the properties. * @param properties * @param values */ public void assignDefaults(Map<String, CSSProperty> properties, Map<String, Term<?>> values) { SupportedCSS css = CSSFactory.getSupportedCSS(); for (String name : names) { CSSProperty dp = css.getDefaultProperty(name); if (dp != null) properties.put(name, dp); Term<?> dv = css.getDefaultValue(name); if (dv != null) values.put(name, dv); } }