Package org.xhtmlrenderer.css.parser

Examples of org.xhtmlrenderer.css.parser.CSSParseException


                    return new NthChildCondition(0, Integer.parseInt(number));
                } catch (NumberFormatException e) {
                    Matcher m = pattern.matcher(number);

                    if (!m.matches()) {
                        throw new CSSParseException("Invalid nth-child selector: " + number, -1);
                    } else {
                        int a = m.group(2).equals("") ? 1 : Integer.parseInt(m.group(2));
                        int b = (m.group(5) == null) ? 0 : Integer.parseInt(m.group(5));
                        if ("-".equals(m.group(1))) {
                            a *= -1;
View Full Code Here


        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) {
View Full Code Here

                            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

    }
   
    private void checkNumberIsInteger(CSSName cssName, CSSPrimitiveValue value) {
        if ((int)value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) !=
                    Math.round(value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER))) {
            throw new CSSParseException("The value " + value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) + " in " +
                    cssName + " must be an integer", -1);
        }
    }
View Full Code Here

            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) {
View Full Code Here

                if (ident == IdentValue.NORMAL) { // skip to avoid double set false positives
                    continue;
                }
                if (PrimitivePropertyBuilders.FONT_STYLES.get(ident.FS_ID)) {
                    if (fontStyle != null) {
                        throw new CSSParseException("font-style cannot be set twice", -1);
                    }
                    fontStyle = new PropertyDeclaration(CSSName.FONT_STYLE, value, important, origin);
                } else if (PrimitivePropertyBuilders.FONT_VARIANTS.get(ident.FS_ID)) {
                    if (fontVariant != null) {
                        throw new CSSParseException("font-variant cannot be set twice", -1);
                    }
                    fontVariant = new PropertyDeclaration(CSSName.FONT_VARIANT, value, important, origin);
                } else if (PrimitivePropertyBuilders.FONT_WEIGHTS.get(ident.FS_ID)) {
                    if (fontWeight != null) {
                        throw new CSSParseException("font-weight cannot be set twice", -1);
                    }
                    fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, value, important, origin);
                } else {
                    keepGoing = true;
                    break;
                }
            } else if (type == CSSPrimitiveValue.CSS_NUMBER && value.getFloatValue() > 0) {
                if (fontWeight != null) {
                    throw new CSSParseException("font-weight cannot be set twice", -1);
                }
               
                IdentValue weight = Conversions.getNumericFontWeight(value.getFloatValue());
                if (weight == null) {
                    throw new CSSParseException(value + " is not a valid font weight", -1);
                }
               
                PropertyValue replacement = new PropertyValue(
                        CSSPrimitiveValue.CSS_IDENT, weight.toString(), weight.toString());
                replacement.setIdentValue(weight);
               
                fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, replacement, important, origin);
            } else {
                keepGoing = true;
                break;
            }
        }
       
        if (keepGoing) {
            i.previous();
            PropertyValue value = (PropertyValue)i.next();
           
            if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                String lowerCase = value.getStringValue().toLowerCase();
                value = new PropertyValue(CSSPrimitiveValue.CSS_IDENT, lowerCase, lowerCase);
            }
           
            PropertyBuilder fontSizeBuilder = CSSName.getPropertyBuilder(CSSName.FONT_SIZE);
            List l = fontSizeBuilder.buildDeclarations(
                    CSSName.FONT_SIZE, Collections.singletonList(value), origin, important);
           
            fontSize = (PropertyDeclaration)l.get(0);
           
            if (i.hasNext()) {
                value = (PropertyValue)i.next();
                if (value.getOperator() == Token.TK_VIRGULE) {
                    PropertyBuilder lineHeightBuilder = CSSName.getPropertyBuilder(CSSName.LINE_HEIGHT);
                    l = lineHeightBuilder.buildDeclarations(
                            CSSName.LINE_HEIGHT, Collections.singletonList(value), origin, important);
                    lineHeight = (PropertyDeclaration)l.get(0);
                } else {
                    i.previous();
                }
            }
           
            if (i.hasNext()) {
                List families = new ArrayList();
                while (i.hasNext()) {
                    families.add(i.next());
                }
                PropertyBuilder fontFamilyBuilder = CSSName.getPropertyBuilder(CSSName.FONT_FAMILY);
                l = fontFamilyBuilder.buildDeclarations(
                        CSSName.FONT_FAMILY, families, origin, important);
                fontFamily = (PropertyDeclaration)l.get(0);
            }
        }
       
        if (fontStyle == null) {
            fontStyle = new PropertyDeclaration(
                    CSSName.FONT_STYLE, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontVariant == null) {
            fontVariant = new PropertyDeclaration(
                    CSSName.FONT_VARIANT, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontWeight == null) {
            fontWeight = new PropertyDeclaration(
                    CSSName.FONT_WEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);
        }
       
        if (fontSize == null) {
            throw new CSSParseException("A font-size value is required", -1);
        }
       
        if (lineHeight == null) {
            lineHeight = new PropertyDeclaration(
                    CSSName.LINE_HEIGHT, new PropertyValue(IdentValue.NORMAL), important, origin);
View Full Code Here

                    checkInheritAllowed(value, false);
                    boolean matched = false;
                    CSSPrimitiveValue borderWidth = convertToBorderWidth(value);
                    if (borderWidth != null) {
                        if (haveBorderWidth) {
                            throw new CSSParseException("A border width cannot be set twice", -1);
                        }
                        haveBorderWidth = true;
                        matched = true;
                        addAll(result, props[0], borderWidth, origin, important);
                    }
                   
                    if (isBorderStyle(value)) {
                        if (haveBorderStyle) {
                            throw new CSSParseException("A border style cannot be set twice", -1);
                        }
                        haveBorderStyle = true;
                        matched = true;
                        addAll(result, props[1], value, origin, important);
                    }
                   
                    CSSPrimitiveValue borderColor = convertToBorderColor(value);
                    if (borderColor != null) {
                        if (haveBorderColor) {
                            throw new CSSParseException("A border color cannot be set twice", -1);
                        }
                        haveBorderColor = true;
                        matched = true;
                        addAll(result, props[2], borderColor, origin, important);
                    }
                   
                    if (! matched) {
                        throw new CSSParseException(value.getCssText() + " is not a border width, style, or color", -1);
                    }
                }
               
                if (! haveBorderWidth) {
                    addAll(result, props[0], new PropertyValue(IdentValue.FS_INITIAL_VALUE), origin, important);
View Full Code Here

       
        if (values.size() == 1) {
            PropertyValue value = (PropertyValue)values.get(0);
            checkLengthType(cssName, value);
            if (value.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            horizontalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_HORIZONTAL, value, important, origin);
            verticalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_VERTICAL, value, important, origin);           
        } else { /* values.size() == 2 */
            PropertyValue horizontal = (PropertyValue)values.get(0);
            checkLengthType(cssName, horizontal);
            if (horizontal.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            horizontalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_HORIZONTAL, horizontal, important, origin);
           
            PropertyValue vertical = (PropertyValue)values.get(1);
            checkLengthType(cssName, vertical);
            if (vertical.getFloatValue() < 0.0f) {
                throw new CSSParseException("border-spacing may not be negative", -1);
            }
            verticalSpacing = new PropertyDeclaration(
                    CSSName.FS_BORDER_SPACING_VERTICAL, vertical, important, origin);           
        }
       
View Full Code Here

                        listStyleImage = new PropertyDeclaration(
                                CSSName.LIST_STYLE_IMAGE, value, important, origin);
                    }
                } else if (PrimitivePropertyBuilders.LIST_STYLE_POSITIONS.get(ident.FS_ID)) {
                    if (listStylePosition != null) {
                        throw new CSSParseException("A list-style-position value cannot be set twice", -1);
                    }
                   
                    listStylePosition = new PropertyDeclaration(
                            CSSName.LIST_STYLE_POSITION, value, important, origin);
                } else if (PrimitivePropertyBuilders.LIST_STYLE_TYPES.get(ident.FS_ID)) {
                    if (listStyleType != null) {
                        throw new CSSParseException("A list-style-type value cannot be set twice", -1);
                    }
                   
                    listStyleType = new PropertyDeclaration(
                            CSSName.LIST_STYLE_TYPE, value, important, origin);
                }
            } else if (type == CSSPrimitiveValue.CSS_URI) {
                if (listStyleImage != null) {
                    throw new CSSParseException("A list-style-image value cannot be set twice", -1);
                }
               
                listStyleImage = new PropertyDeclaration(
                        CSSName.LIST_STYLE_IMAGE, value, important, origin);
            }
View Full Code Here

        }

        private void checkIdentPosition(CSSName cssName, IdentValue firstIdent, IdentValue secondIdent) {
            if (firstIdent == IdentValue.TOP || firstIdent == IdentValue.BOTTOM ||
                    secondIdent == IdentValue.LEFT || secondIdent == IdentValue.RIGHT) {
                throw new CSSParseException("Invalid combination of keywords in " + cssName, -1);
            }
        }
View Full Code Here

TOP

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

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.