Package org.xhtmlrenderer.css.parser

Examples of org.xhtmlrenderer.css.parser.PropertyValue


public class QuotesPropertyBuilder extends AbstractPropertyBuilder {

    public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) {
        if (values.size() == 1) {
            PropertyValue value = (PropertyValue)values.get(0);
            if (value.getCssValueType() == CSSValue.CSS_INHERIT) {
                return Collections.EMPTY_LIST;
            } else if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                IdentValue ident = checkIdent(CSSName.QUOTES, value);
                if (ident == IdentValue.NONE) {
                    return Collections.singletonList(
                            new PropertyDeclaration(CSSName.QUOTES, value, important, origin));
                }
            }
        }
       
        if (values.size() % 2 == 1) {
            throw new CSSParseException(
                    "Mismatched quotes " + values, -1);
        }
       
        List resultValues = new ArrayList();
        for (Iterator i = values.iterator(); i.hasNext(); ) {
            PropertyValue value = (PropertyValue)i.next();
           
            if (value.getOperator() != null) {
                throw new CSSParseException(
                        "Found unexpected operator, " + value.getOperator().getExternalName(), -1);
            }
           
            short type = value.getPrimitiveType();
            if (type == CSSPrimitiveValue.CSS_STRING) {
                resultValues.add(value.getStringValue());
            } else if (type == CSSPrimitiveValue.CSS_URI) {
                throw new CSSParseException(
                        "URI is not allowed here", -1);
            } else if (value.getPropertyValueType() == PropertyValue.VALUE_TYPE_FUNCTION) {
                throw new CSSParseException(
                        "Function " + value.getFunction().getName() + " is not allowed here", -1);
            } else if (type == CSSPrimitiveValue.CSS_IDENT) {
                throw new CSSParseException(
                        "Identifier is not a valid value for the quotes property", -1);
            } else {
                throw new CSSParseException(
                        value.getCssText() + " is not a value value for the quotes property", -1);
            }
        }
       
        if (resultValues.size() > 0) {
            return Collections.singletonList(
                    new PropertyDeclaration(CSSName.QUOTES, new PropertyValue(resultValues), important, origin));
        } else {
            return Collections.EMPTY_LIST;
        }
    }
View Full Code Here


            _font.families = valueByName(CSSName.FONT_FAMILY).asStringArray();

            FSDerivedValue fontSize = valueByName(CSSName.FONT_SIZE);
            if (fontSize instanceof IdentValue) {
                PropertyValue replacement;
                IdentValue resolved = resolveAbsoluteFontSize();
                if (resolved != null) {
                    replacement = FontSizeHelper.resolveAbsoluteFontSize(resolved, _font.families);
                } else {
                    replacement = FontSizeHelper.getDefaultRelativeFontSize((IdentValue) fontSize);
                }
                _font.size = LengthValue.calcFloatProportionalValue(
                        this, CSSName.FONT_SIZE, replacement.getCssText(),
                        replacement.getFloatValue(), replacement.getPrimitiveType(), 0, ctx);
            } else {
                _font.size = getFloatPropertyProportionalTo(CSSName.FONT_SIZE, 0, ctx);
            }

            _font.fontWeight = getIdent(CSSName.FONT_WEIGHT);
View Full Code Here

public class ContentPropertyBuilder extends AbstractPropertyBuilder {

    public List buildDeclarations(
            CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) {
        if (values.size() == 1) {
            PropertyValue value = (PropertyValue)values.get(0);
            if (value.getCssValueType() == CSSValue.CSS_INHERIT) {
                return Collections.EMPTY_LIST;
            } else if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                IdentValue ident = checkIdent(CSSName.CONTENT, value);
                if (ident == IdentValue.NONE || ident == IdentValue.NORMAL) {
                    return Collections.singletonList(
                            new PropertyDeclaration(CSSName.CONTENT, value, important, origin));
                }
            }
        }
       
        List resultValues = new ArrayList();
        for (Iterator i = values.iterator(); i.hasNext(); ) {
            PropertyValue value = (PropertyValue)i.next();
           
            if (value.getOperator() != null) {
                throw new CSSParseException(
                        "Found unexpected operator, " + value.getOperator().getExternalName(), -1);
            }
           
            short type = value.getPrimitiveType();
            if (type == CSSPrimitiveValue.CSS_URI) {
                continue;
            } else if (type == CSSPrimitiveValue.CSS_STRING) {
                resultValues.add(value);
            } else if (value.getPropertyValueType() == PropertyValue.VALUE_TYPE_FUNCTION) {
                if (! isFunctionAllowed(value.getFunction())) {
                    throw new CSSParseException(
                            "Function " + value.getFunction().getName() + " is not allowed here", -1);
                }
                resultValues.add(value);
            } else if (type == CSSPrimitiveValue.CSS_IDENT) {
                IdentValue ident = checkIdent(CSSName.CONTENT, value);
                if (ident == IdentValue.OPEN_QUOTE || ident == IdentValue.CLOSE_QUOTE ||
                        ident == IdentValue.NO_CLOSE_QUOTE || ident == IdentValue.NO_OPEN_QUOTE) {
                    resultValues.add(value);
                } else {
                    throw new CSSParseException(
                            "Identifier " + ident + " is not a valid value for the content property", -1);
                }
            } else {
                throw new CSSParseException(
                        value.getCssText() + " is not a value value for the content property", -1);
            }
        }
       
        if (resultValues.size() > 0) {
            return Collections.singletonList(
                    new PropertyDeclaration(CSSName.CONTENT, new PropertyValue(resultValues), important, origin));
        } else {
            return Collections.EMPTY_LIST;
        }
    }
View Full Code Here

    public String getRunningName() {
        FunctionValue value = (FunctionValue)valueByName(CSSName.POSITION);
        FSFunction function = value.getFunction();

        PropertyValue param = (PropertyValue)function.getParameters().get(0);

        return param.getStringValue();
    }
View Full Code Here

  public BorderRadiusCorner() {
  }
  public BorderRadiusCorner(CSSName fromVal, CalculatedStyle style, CssContext ctx) {
    FSDerivedValue value = style.valueByName(fromVal);
    PropertyValue first = null, second = null;
    if(value instanceof ListValue) {
      ListValue lValues = (ListValue)value;
      first = (PropertyValue)lValues.getValues().get(0);
      if(lValues.getValues().size() > 1)
        second = (PropertyValue)lValues.getValues().get(1);
View Full Code Here

   
    // XXX returns a PropertyValue of type VALUE_TYPE_LIST, but the List contains
    // CounterData objects and not PropertyValue objects
    public List buildDeclarations(CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) {
        if (values.size() == 1) {
            PropertyValue value = (PropertyValue)values.get(0);
           
            checkInheritAllowed(value, inheritAllowed);
           
            if (value.getCssValueType() == CSSValue.CSS_INHERIT) {
                return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin));
            } else if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                if (value.getCssText().equals("none")) {
                    return Collections.singletonList(new PropertyDeclaration(cssName, value, important, origin));
                } else {
                    CounterData data = new CounterData(
                            value.getStringValue(),
                            getDefaultValue());
                   
                    return Collections.singletonList(
                            new PropertyDeclaration(cssName, new PropertyValue(
                                    Collections.singletonList(data)), important, origin));
                }
            }
           
            throw new CSSParseException("The syntax of the " + cssName + " property is invalid", -1);
        } else {
            List result = new ArrayList();
            for (int i = 0; i < values.size(); i++) {
                PropertyValue value = (PropertyValue)values.get(i);
               
                if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                    String name = value.getStringValue();
                    int cValue = getDefaultValue();
                   
                    if (i < values.size() - 1) {
                        PropertyValue next = (PropertyValue)values.get(i+1);
                        if (next.getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER) {
                            checkNumberIsInteger(cssName, next);
                           
                            cValue = (int)next.getFloatValue();
                        }
                       
                        i++;
                    }
                    result.add(new CounterData(name, cValue));
                } else {
                    throw new CSSParseException("The syntax of the " + cssName + " property is invalid", -1);
                }
            }
           
            return Collections.singletonList(
                    new PropertyDeclaration(cssName, new PropertyValue(result), important, origin));
        }
    }
View Full Code Here

    /**
     * Creates a <code>CascadedStyle</code>, setting the display property to
     * to the value of the <code>display</code> parameter. 
     */
    public static CascadedStyle createAnonymousStyle(IdentValue display) {
        CSSPrimitiveValue val = new PropertyValue(display);
       
        List props = Collections.singletonList(
                new PropertyDeclaration(CSSName.DISPLAY, val, true, StylesheetInfo.USER));
       
        return new CascadedStyle(props.iterator());
View Full Code Here

     * {@link #createLayoutStyle(PropertyDeclaration[])} or
     * {@link #createLayoutStyle(CascadedStyle, PropertyDeclaration[])}
     */
    public static PropertyDeclaration createLayoutPropertyDeclaration(
            CSSName cssName, IdentValue display) {
        CSSPrimitiveValue val = new PropertyValue(display);
        // Urk... kind of ugly, but we really want this value to be used
        return new PropertyDeclaration(cssName, val, true, StylesheetInfo.USER);
    }
View Full Code Here

        PropertyDeclaration backgroundRepeat = null;
        PropertyDeclaration backgroundAttachment =  null;
        PropertyDeclaration backgroundPosition = null;
       
        for (int i = 0; i < values.size(); i++) {
            PropertyValue value = (PropertyValue)values.get(i);
            checkInheritAllowed(value, false);
           
            boolean processingBackgroundPosition = false;
            short type = value.getPrimitiveType();
            if (type == CSSPrimitiveValue.CSS_IDENT) {
                FSRGBColor color = Conversions.getColor(value.getStringValue());
                if (color != null) {
                    if (backgroundColor != null) {
                        throw new CSSParseException("A background-color value cannot be set twice", -1);
                    }
                   
                    backgroundColor = new PropertyDeclaration(
                            CSSName.BACKGROUND_COLOR,
                            new PropertyValue(color),
                            important, origin);
                    continue;
                }
               
                IdentValue ident = checkIdent(CSSName.BACKGROUND_SHORTHAND, value);
               
                if (PrimitivePropertyBuilders.BACKGROUND_REPEATS.get(ident.FS_ID)) {
                    if (backgroundRepeat != null) {
                        throw new CSSParseException("A background-repeat value cannot be set twice", -1);
                    }
                   
                    backgroundRepeat = new PropertyDeclaration(
                            CSSName.BACKGROUND_REPEAT, value, important, origin);
                }
               
                if (PrimitivePropertyBuilders.BACKGROUND_ATTACHMENTS.get(ident.FS_ID)) {
                    if (backgroundAttachment != null) {
                        throw new CSSParseException("A background-attachment value cannot be set twice", -1);
                    }
                   
                    backgroundAttachment = new PropertyDeclaration(
                            CSSName.BACKGROUND_ATTACHMENT, value, important, origin);
                }
               
                if (ident == IdentValue.TRANSPARENT) {
                    if (backgroundColor != null) {
                        throw new CSSParseException("A background-color value cannot be set twice", -1);
                    }
                   
                    backgroundColor = new PropertyDeclaration(
                            CSSName.BACKGROUND_COLOR, value, important, origin);
                }
               
                if (ident == IdentValue.NONE) {
                    if (backgroundImage != null) {
                        throw new CSSParseException("A background-image value cannot be set twice", -1);
                    }
                   
                    backgroundImage = new PropertyDeclaration(
                            CSSName.BACKGROUND_IMAGE, value, important, origin);
                }
               
                if (PrimitivePropertyBuilders.BACKGROUND_POSITIONS.get(ident.FS_ID)) {
                    processingBackgroundPosition = true;
                }
            } else if (type == CSSPrimitiveValue.CSS_RGBCOLOR) {
                if (backgroundColor != null) {
                    throw new CSSParseException("A background-color value cannot be set twice", -1);
                }
               
                backgroundColor = new PropertyDeclaration(
                        CSSName.BACKGROUND_COLOR, value, important, origin);
            } else if (type == CSSPrimitiveValue.CSS_URI) {
                if (backgroundImage != null) {
                    throw new CSSParseException("A background-image value cannot be set twice", -1);
                }
               
                backgroundImage = new PropertyDeclaration(
                        CSSName.BACKGROUND_IMAGE, value, important, origin);
            }
           
            if (processingBackgroundPosition || isLength(value) || type == CSSPrimitiveValue.CSS_PERCENTAGE) {
                if (backgroundPosition != null) {
                    throw new CSSParseException("A background-position value cannot be set twice", -1);
                }
               
                List v = new ArrayList(2);
                v.add(value);
                if (i < values.size() - 1) {
                    PropertyValue next = (PropertyValue)values.get(i+1);
                    if (isAppliesToBackgroundPosition(next)) {
                        v.add(next);
                        i++;
                    }
                }
               
                PropertyBuilder builder = CSSName.getPropertyBuilder(CSSName.BACKGROUND_POSITION);
                backgroundPosition = (PropertyDeclaration)builder.buildDeclarations(
                        CSSName.BACKGROUND_POSITION, v, origin, important).get(0);
            }
        }
       
        if (backgroundColor == null) {
            backgroundColor = new PropertyDeclaration(
                    CSSName.BACKGROUND_COLOR, new PropertyValue(IdentValue.TRANSPARENT), important, origin);
        }
       
        if (backgroundImage == null) {
            backgroundImage = new PropertyDeclaration(
                    CSSName.BACKGROUND_IMAGE, new PropertyValue(IdentValue.NONE), important, origin);
        }
       
        if (backgroundRepeat == null) {
            backgroundRepeat = new PropertyDeclaration(
                    CSSName.BACKGROUND_REPEAT, new PropertyValue(IdentValue.REPEAT), important, origin);
        }
       
        if (backgroundAttachment == null) {
            backgroundAttachment = new PropertyDeclaration(
                    CSSName.BACKGROUND_ATTACHMENT, new PropertyValue(IdentValue.SCROLL), important, origin);
           
        }
       
        if (backgroundPosition == null) {
            List v = new ArrayList(2);
            v.add(new PropertyValue(CSSPrimitiveValue.CSS_PERCENTAGE, 0.0f, "0%"));
            v.add(new PropertyValue(CSSPrimitiveValue.CSS_PERCENTAGE, 0.0f, "0%"));
            backgroundPosition = new PropertyDeclaration(
                    CSSName.BACKGROUND_POSITION, new PropertyValue(v), important, origin);
        }
       
        result = new ArrayList(5);
        result.add(backgroundColor);
        result.add(backgroundImage);
View Full Code Here

        }
       
        all.add(CascadedStyle.createLayoutPropertyDeclaration(CSSName.DISPLAY, IdentValue.TABLE_CELL));
        all.add(new PropertyDeclaration(
                    CSSName.VERTICAL_ALIGN,
                    new PropertyValue(marginBox.getInitialVerticalAlign()),
                    false,
                    StylesheetInfo.USER_AGENT));
        all.add(new PropertyDeclaration(
                CSSName.TEXT_ALIGN,
                new PropertyValue(marginBox.getInitialTextAlign()),
                false,
                StylesheetInfo.USER_AGENT));       
                       
       
        return new CascadedStyle(all.iterator());
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.css.parser.PropertyValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.