/** * Creates a new instance of PropertyDeclaration from an {@link * CSSPrimitiveValue} instance. * * @param cssName * @param value The CSSValue to wrap * @param imp True if property was declared important! and false if * not. * @param orig int constant from {@link Stylesheet} for the origin of * the property declaration, that is, the origin of the style sheet * where it was declared. See {@link StylesheetInfo#USER_AGENT}, {@link * StylesheetInfo#USER}, and {@link StylesheetInfo#AUTHOR}. */ public PropertyDeclaration(CSSName cssName, org.w3c.dom.css.CSSPrimitiveValue value, boolean imp, int orig) { this.propName = cssName.toString(); this.cssName = cssName; this.cssPrimitiveValue = value; this.important = imp; this.origin = orig; }
/** * Adds a feature to the Property attribute of the CSSName class * * @param propName The feature to be added to the Property attribute * @param type * @param initialValue * @param inherit * @return Returns */ private final static synchronized CSSName addProperty( String propName, Object type, String initialValue, Object inherit, boolean implemented, PropertyBuilder builder ) { CSSName cssName = new CSSName( propName, initialValue, (inherit == INHERITS), type, implemented, builder); ALL_PROPERTY_NAMES.put(propName, cssName); if (type == PRIMITIVE) { ALL_PRIMITIVE_PROPERTY_NAMES.put(propName, cssName); } return cssName; }
private static synchronized CSSName addProperty( String propName, Object type, String initialValue, Object inherit, PropertyBuilder builder ) { return addProperty(propName, type, initialValue, inherit, true, builder); }
private String genStyleKey() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < _derivedValuesById.length; i++) { CSSName name = CSSName.getByID(i); FSDerivedValue val = _derivedValuesById[i]; if (val != null) { sb.append(name.toString()); } else { sb.append("(no prop assigned in this pos)"); } sb.append("|\n"); } return sb.toString(); }
if (! needInitialValue && CSSName.propertyInherits(cssName) && _parent != null String initialValue = CSSName.initialValue(cssName); if (initialValue == null) { throw new XRRuntimeException("Property '" + cssName + "' has no initial values assigned. " + CSSName ref = CSSName.getByPropertyName(initialValue.substring(1)); val = valueByName(ref); } else { val = CSSName.initialDerivedValue(cssName);
private boolean checkCSSName(CSSName cssName, String propertyName) { if (cssName == null) { _errorHandler.error( _URI, propertyName + " is an unrecognized CSS property at line " + getCurrentLine() + ". Ignoring declaration."); return false; } if (! CSSName.isImplemented(cssName)) { _errorHandler.error( _URI, propertyName + " is not implemented at line " + getCurrentLine() + ". Ignoring declaration."); return false; } PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); if (builder == null) { _errorHandler.error( _URI, "(bug) No property builder defined for " + propertyName + " at line " + getCurrentLine() + ". Ignoring declaration."); return false; } return true; }
if (t == Token.TK_IDENT) { String propertyName = property(); CSSName cssName = CSSName.getByPropertyName(propertyName); PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); ruleset.addAllProperties(builder.buildDeclarations( cssName, values, ruleset.getOrigin(), important, !inFontFace));
String fallback = CSSName.initialValue(cssName); if (fallback.startsWith("=")) fallback = CSSName.initialValue(CSSName.getByPropertyName(fallback.substring(1))); val = getColorHex(fallback);
public PropertyValue parsePropertyValue(CSSName cssName, int origin, String expr) { _URI = cssName + " property value"; try { reset(new StringReader(expr)); List values = expr( cssName == CSSName.FONT_FAMILY || cssName == CSSName.FONT_SHORTHAND || cssName == CSSName.FS_PDF_FONT_ENCODING); PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); List props; try { props = builder.buildDeclarations(cssName, values, origin, false); } catch (CSSParseException e) { e.setLine(getCurrentLine()); throw e; } if (props.size() != 1) { throw new CSSParseException( "Builder created " + props.size() + "properties, expected 1", getCurrentLine()); } PropertyDeclaration decl = (PropertyDeclaration)props.get(0); return (PropertyValue)decl.getValue(); } catch (IOException e) { // "Shouldn't" happen throw new RuntimeException(e.getMessage(), e); } catch (CSSParseException e) { error(e, "property value", false); return null; } }
/** * Default constructor; as the instance is immutable after use, don't use * this for class instantiation externally. */ protected CalculatedStyle() { _derivedValuesById = new FSDerivedValue[CSSName.countCSSPrimitiveNames()]; }
/** * Returns a Map keyed by CSS property names (e.g. 'border-width'), and the * assigned value as a SAC CSSValue instance. The properties should have * been matched to the element when the Context was established for this * StyleReference on the Document to which the Element belongs. See {@link * org.xhtmlrenderer.swing.BasicPanel#setDocument(Document, java.net.URL)} * for an example of how to establish a StyleReference and associate to a * Document. * * @param e The DOM Element for which to find properties * @return Map of CSS property names to CSSValue instance assigned to it. */ public java.util.Map getCascadedPropertiesMap(Element e) { CascadedStyle cs = _matcher.getCascadedStyle(e, false);//this is only for debug, I think java.util.LinkedHashMap props = new java.util.LinkedHashMap(); for (java.util.Iterator i = cs.getCascadedPropertyDeclarations(); i.hasNext();) { PropertyDeclaration pd = (PropertyDeclaration) i.next(); String propName = pd.getPropertyName(); CSSName cssName = CSSName.getByPropertyName(propName); props.put(propName, cs.propertyByName(cssName).getValue()); } return props; }
if (! needInitialValue && CSSName.propertyInherits(cssName) && _parent != null String initialValue = CSSName.initialValue(cssName); if (initialValue == null) { throw new XRRuntimeException("Property '" + cssName + "' has no initial values assigned. " + CSSName ref = CSSName.getByPropertyName(initialValue.substring(1)); val = valueByName(ref); } else { val = CSSName.initialDerivedValue(cssName);
private String genStyleKey() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < _derivedValuesById.length; i++) { CSSName name = CSSName.getByID(i); FSDerivedValue val = _derivedValuesById[i]; if (val != null) { sb.append(name.toString()); } else { sb.append("(no prop assigned in this pos)"); } sb.append("|\n"); } return sb.toString(); }
private boolean checkCSSName(CSSName cssName, String propertyName) { if (cssName == null) { _errorHandler.error( _URI, propertyName + " is an unrecognized CSS property at line " + getCurrentLine() + ". Ignoring declaration."); return false; } if (! CSSName.isImplemented(cssName)) { _errorHandler.error( _URI, propertyName + " is not implemented at line " + getCurrentLine() + ". Ignoring declaration."); return false; } PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); if (builder == null) { _errorHandler.error( _URI, "(bug) No property builder defined for " + propertyName + " at line " + getCurrentLine() + ". Ignoring declaration."); return false; } return true; }
if (t == Token.TK_IDENT) { String propertyName = property(); CSSName cssName = CSSName.getByPropertyName(propertyName); PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); ruleset.addAllProperties(builder.buildDeclarations( cssName, values, ruleset.getOrigin(), important, !inFontFace));
String fallback = CSSName.initialValue(cssName); if (fallback.startsWith("=")) fallback = CSSName.initialValue(CSSName.getByPropertyName(fallback.substring(1))); val = getColorHex(fallback);
public PropertyValue parsePropertyValue(CSSName cssName, int origin, String expr) { _URI = cssName + " property value"; try { reset(new StringReader(expr)); List values = expr( cssName == CSSName.FONT_FAMILY || cssName == CSSName.FONT_SHORTHAND || cssName == CSSName.FS_PDF_FONT_ENCODING); PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); List props; try { props = builder.buildDeclarations(cssName, values, origin, false); } catch (CSSParseException e) { e.setLine(getCurrentLine()); throw e; } if (props.size() != 1) { throw new CSSParseException( "Builder created " + props.size() + "properties, expected 1", getCurrentLine()); } PropertyDeclaration decl = (PropertyDeclaration)props.get(0); return (PropertyValue)decl.getValue(); } catch (IOException e) { // "Shouldn't" happen throw new RuntimeException(e.getMessage(), e); } catch (CSSParseException e) { error(e, "property value", false); return null; } }
/** * Default constructor; as the instance is immutable after use, don't use * this for class instantiation externally. */ protected CalculatedStyle() { _derivedValuesById = new FSDerivedValue[CSSName.countCSSPrimitiveNames()]; }
/** * Returns a Map keyed by CSS property names (e.g. 'border-width'), and the * assigned value as a SAC CSSValue instance. The properties should have * been matched to the element when the Context was established for this * StyleReference on the Document to which the Element belongs. See {@link * org.xhtmlrenderer.swing.BasicPanel#setDocument(Document, java.net.URL)} * for an example of how to establish a StyleReference and associate to a * Document. * * @param e The DOM Element for which to find properties * @return Map of CSS property names to CSSValue instance assigned to it. */ public java.util.Map getCascadedPropertiesMap(Element e) { CascadedStyle cs = _matcher.getCascadedStyle(e, false);//this is only for debug, I think java.util.LinkedHashMap props = new java.util.LinkedHashMap(); for (java.util.Iterator i = cs.getCascadedPropertyDeclarations(); i.hasNext();) { PropertyDeclaration pd = (PropertyDeclaration) i.next(); String propName = pd.getPropertyName(); CSSName cssName = CSSName.getByPropertyName(propName); props.put(propName, cs.propertyByName(cssName).getValue()); } return props; }
/** * Creates a new instance of PropertyDeclaration from an {@link * CSSPrimitiveValue} instance. * * @param cssName * @param value The CSSValue to wrap * @param imp True if property was declared important! and false if * not. * @param orig int constant from {@link Stylesheet} for the origin of * the property declaration, that is, the origin of the style sheet * where it was declared. See {@link StylesheetInfo#USER_AGENT}, {@link * StylesheetInfo#USER}, and {@link StylesheetInfo#AUTHOR}. */ public PropertyDeclaration(CSSName cssName, org.w3c.dom.css.CSSPrimitiveValue value, boolean imp, int orig) { this.propName = cssName.toString(); this.cssName = cssName; this.cssPrimitiveValue = value; this.important = imp; this.origin = orig; }