Package net.htmlparser.jericho

Examples of net.htmlparser.jericho.Attribute


   
    int index = 1;
    HashMap<String, String> diagramList = new HashMap<String, String>();
    for(Element element : source.getAllElements("pre")) {
      StartTag tag = element.getStartTag();
      Attribute classAttr = tag.getAttributes().get("class");
      if(classAttr != null
          && classAttr.hasValue()
          && classAttr.getValue().equals(TAG_CLASS)) {
       
        String baseFilename = imageBaseFilename;
       
        String URL;
        Attribute nameAttr = tag.getAttributes().get("id");
        if(nameAttr != null
            && nameAttr.hasValue()) {
          baseFilename = makeFilenameFromTagName(nameAttr.getValue());
          URL = imageDirName + "/" + baseFilename + ".png";
        } else {
          URL = imageDirName + "/" + baseFilename + "_" + index + ".png";
          index++;
        }
View Full Code Here


     *            The HTMLAnchorElement.
     * @param source
     * @return Result or null if no error occurred.
     */
    protected Result validateLink(Element node, Source source) throws DOMException {
        final Attribute href = node.getAttributes().get("href");
        if (href == null) {
            return null;
        }

        // Criteria 6.1
        String linkValue = node.getTextExtractor().toString();
        if (StringUtils.isBlank(linkValue) && !node.getChildElements().isEmpty()) {
            linkValue = node.getChildElements().get(0).toString();
        }
        linkValue = linkValue != null ? text2XMLEntityRef(
                StringUtils.stripToEmpty(linkValue)) : "";
        final int length = linkValue.length();
        if (length > 80) {
            Result ve = new Result(bundle.getFormatted(
                    "org.jahia.services.htmlvalidator.WAIValidator.6.1",
                    "Link value should not be longer than 80 characters. Length = " + length,
                    new Object[]{linkValue, Integer.toString(length)}), node.toString(), node.toString(), bundle.get(
                    "org.jahia.services.htmlvalidator.WAIValidator.6.1.example", ""));
            setPosition(node, source, ve);
            return ve;
        }

        // Criteria 6.3
        final Attribute title = node.getAttributes().get("title");
        if (title == null) {
            Result ve = new Result(
                    bundle.getFormatted("org.jahia.services.htmlvalidator.WAIValidator.6.3",
                            "Missing 'title' attribute for 'hyperlink' element",
                            new Object[]{linkValue}), node.toString(), node.toString(), bundle.get(
                    "org.jahia.services.htmlvalidator.WAIValidator.6.3.example", ""));
            setPosition(node, source, ve);
            return ve;
        }

        // Criteria 6.3 bis
        if (title != null) {
            final String titleValue = text2XMLEntityRef(title.getValue());
            final int length2 = titleValue.length();
            if (length2 > 80) {
                Result ve = new Result(bundle.getFormatted(
                        "org.jahia.services.htmlvalidator.WAIValidator.6.3.2",
                        "Attribute 'title' should not be longer than 80 characters. Length = "
View Full Code Here

     *            The HTMLImageElement.
     * @param source
     * @return Result or null if no error occurred.
     */
    protected Result validateImage(final Element node, Source source) {
        final Attribute src = node.getAttributes().get("src");
        final String srcText;

        if (src == null) {
            srcText = "n/a";
        } else {
            srcText = src.getValue();
        }

        String width = node.getAttributeValue("width");
        String height = node.getAttributeValue("height");

        int widthValue = -1;
        int heightValue = -1;
        if (width != null && width.length() > 0 && height != null && height.length() > 0) {
            try {
                widthValue = Integer.parseInt(width);
                heightValue = Integer.parseInt(height);
            } catch (NumberFormatException nfe) {
                // Ignore
            }
        }
        if (widthValue == -1 || heightValue == -1) {
            // try out style attribute
            String style = node.getAttributeValue("style");
            if (style != null && style.length() > 0) {
                style = style.toLowerCase();
                if (style.contains("height:") && style.contains("width:")) {
                    height = StringUtils.substringBetween(style, "height:", "px");
                    width = StringUtils.substringBetween(style, "width:", "px");
                    if (width != null && width.length() > 0 && height != null
                            && height.length() > 0) {
                        try {
                            widthValue = Integer.parseInt(width.trim());
                            heightValue = Integer.parseInt(height.trim());
                        } catch (NumberFormatException nfe) {
                            // Ignore
                        }
                    }
                }
            }
        }

        // Criteria 1.1
        final Attribute alt = node.getAttributes().get("alt");
        if (alt == null) {
            Result ve = new Result(bundle.getFormatted(
                    "org.jahia.services.htmlvalidator.WAIValidator.1.1",
                    "Missing 'alt' attribute for image " + srcText, new Object[]{srcText}),
                    node.toString(), node.toString(), bundle.get(
                    "org.jahia.services.htmlvalidator.WAIValidator.1.1.example", ""));
            setPosition(node, source, ve);
            return ve;
        }

        final String altValue = text2XMLEntityRef(alt.getValue());
        final int length = altValue.length();

        if (length == 0) {
            Result ve = new Result(
                    bundle.getFormatted("org.jahia.services.htmlvalidator.WAIValidator.1.1.1",
View Full Code Here

     */
    protected Result validateAreaShape(final Element node, Source source) {
        logger.debug("validateAreaShape");

        // Criteria 1.1
        final Attribute shape = node.getAttributes().get("shape");
        if (shape != null) {
            final String shapeValue = shape.getValue();
            final Attribute alt = node.getAttributes().get("alt");
            if (alt == null) {
                Result ve = new Result(bundle.getFormatted(
                        "org.jahia.services.htmlvalidator.WAIValidator.1.1.2",
                        "Missing 'alt' attribute for 'area' element", new Object[]{shapeValue}),
                        getContextForArea(node, source), node.toString(), bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.1.1.2.example", ""));
                setPosition(node, source, ve);
                return ve;
            }

            final String altValue = text2XMLEntityRef(alt.getValue());
            final int length = altValue.length();
            if (length == 0) {
                Result ve = new Result(bundle.getFormatted(
                        "org.jahia.services.htmlvalidator.WAIValidator.1.1.3",
                        "'alt' attribute for 'area' element " + shapeValue + " is empty",
View Full Code Here

                setPosition(node, source, ve);
                errors.add(ve);
                return errors;
            }

            final Attribute scope = element.getAttributes().get("scope");
            final Attribute id = element.getAttributes().get("id");

            if ((scope == null && id == null) || (scope != null && id != null)) {
                final Result ve = new Result(
                        bundle.get("org.jahia.services.htmlvalidator.WAIValidator.5.3.2",
                                "'th' elements should have an attribute 'scope', set to 'col', OR an 'id' attribute"),
                                node.toString(), node.toString(), bundle.get(
                                "org.jahia.services.htmlvalidator.WAIValidator.5.3.2.example", ""));
                setPosition(node, source, ve);
                errors.add(ve);
                return errors;
            }

            if (id == null) {
                if (!"col".equals(scope.getValue().toLowerCase())) {
                    final Result ve = new Result(
                            bundle.get("org.jahia.services.htmlvalidator.WAIValidator.5.3.3",
                                    "The 'th' elements of the first row of the table should have a 'col' scope"),
                                    node.toString(), node.toString(), bundle.get(
                                    "org.jahia.services.htmlvalidator.WAIValidator.5.3.3.example",
                                    ""));
                    setPosition(node, source, ve);
                    errors.add(ve);
                    return errors;
                }
                scopes++;

            } else {
                ids.add(id.getValue());
            }
        }

        if (scopes > 0 && !ids.isEmpty()) {
            final Result ve = new Result(
View Full Code Here

            }

            if (StringUtils.isNotEmpty(styleSheetContent)) {
                sb.setLength(0);
                sb.append("<style");
                Attribute typeAttribute = attributes.get("type");
                if (typeAttribute != null) {
                    sb.append(' ').append(typeAttribute);
                }
                if (rewriteUrlsInCss) {
                    String baseUrl = HttpClientService.isAbsoluteUrl(href) ? href : serverUrl + href;
View Full Code Here

                                final Set<String> ids, final List<Result> errors, int level, Source source) {

        // Criteria 5.4
        if (HTMLElementName.TD.equals(node.getName().toLowerCase())) {

            final Attribute header = node.getAttributes().get("headers");
            if (header == null) {
                final Result ve = new Result(bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.5.4",
                        "Missing 'headers' attribute for 'td' element"), node
                        .getParentElement().getParentElement().toString(), node
                        .getParentElement().getParentElement().toString(), bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.5.4.example", ""));
                setPosition(node, source, ve);
                errors.add(ve);

            } else {
                final String value = header.getValue();
                for (String token : value.split("\\s+")) {
                    headers.add(token);
                }
            }
        } else if (HTMLElementName.TH.equals(node.getName().toLowerCase())) {
            final Attribute id = node.getAttributes().get("id");
            if (id != null) {
                ids.add(id.getValue());
            }
        }

        for (Element element : node.getChildElements()) {
            if (processNode(element, errors, level, source)) {
View Full Code Here

    private void processForm(final Element node, final Set<String> fors, final Set<String> ids,
                             final List<Result> errors, int level, Source source) {

        // Criteria 11.1
        if (HTMLElementName.LABEL.equals(node.getName())) {
            final Attribute forAttr = node.getAttributes().get("for");
            if (forAttr == null) {
                final Result ve = new Result(bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.11.1",
                        "Missing 'for' attribute for 'label' element"),
                        node.toString(), node.toString(), bundle.get(
                                "org.jahia.services.htmlvalidator.WAIValidator.11.1.example", ""));
                setPosition(node, source, ve);
                errors.add(ve);

            } else {
                fors.add(forAttr.getValue());
            }

        } else if (HTMLElementName.INPUT.equals(node.getName())) {
            if ("text".equalsIgnoreCase(node.getAttributeValue("type"))) {
                final Attribute idAttr = node.getAttributes().get("id");
                if (idAttr == null) {
                    final Result ve = new Result(bundle.get(
                            "org.jahia.services.htmlvalidator.WAIValidator.11.1.2",
                            "Missing 'id' attribute for 'input' element"), node.toString(), node.toString(),
                            bundle.get("org.jahia.services.htmlvalidator.WAIValidator.11.2.example", ""));
                    setPosition(node, source, ve);
                    errors.add(ve);

                } else {
                    ids.add(idAttr.getValue());
                }
            }
        }

        for (Element element : node.getChildElements()) {
View Full Code Here

    protected void processFrameset(final Element node, final Set<String> noframes,
                                   final List<Result> errors, int level, Source source) {
        if (HTMLElementName.FRAME.equals(node.getName().toLowerCase())) {
            logger.debug("validateFrame");
            // Criteria 2.1
            final Attribute name = node.getAttributes().get("name");
            if (name == null) {
                Result ve = new Result(bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.2.1",
                        "Missing 'name' attribute for 'frame' element"), node.toString(),
                        node.toString(), bundle.get(
                        "org.jahia.services.htmlvalidator.WAIValidator.2.1.example", ""));
                setPosition(node, source, ve);
                errors.add(ve);
            } else {

                // Criteria 2.1 (Remarque)
                final String nameValue = text2XMLEntityRef(name.getValue());
                if (nameValue.indexOf(' ') > -1) {
                    Result ve = new Result(bundle.getFormatted(
                            "org.jahia.services.htmlvalidator.WAIValidator.2.1.2",
                            "Attribute 'name' cannot contain any white space",
                            new Object[]{nameValue}), node.toString(), node.toString(), bundle.get(
                            "org.jahia.services.htmlvalidator.WAIValidator.2.1.2.example", ""));
                    setPosition(node, source, ve);
                    errors.add(ve);
                } else {
                    // Criteria 2.5
                    final Attribute title = node.getAttributes().get("title");
                    if (title == null) {
                        Result ve = new Result(bundle.getFormatted(
                                "org.jahia.services.htmlvalidator.WAIValidator.2.5",
                                "Missing 'title' attribute for 'frame' element",
                                new Object[]{nameValue}), node.toString(), node.toString(), bundle
                                .get("org.jahia.services.htmlvalidator.WAIValidator.2.5.example",
                                        ""));
                        setPosition(node, source, ve);
                        errors.add(ve);
                    }
                }

                // Criteria 2.10
                final Attribute scrolling = node.getAttributes().get("scrolling");
                if (scrolling != null && "no".equals(scrolling.getValue().toLowerCase())) {
                    Result ve = new Result(bundle.getFormatted(
                            "org.jahia.services.htmlvalidator.WAIValidator.2.10",
                            "Scrolling should be set to at least 'auto' for frame " + nameValue,
                            new Object[]{nameValue}), node.toString(), node.toString(), bundle.get(
                            "org.jahia.services.htmlvalidator.WAIValidator.2.10.example", ""));
View Full Code Here

        for (Map.Entry<String, Set<String>> tag : attributesToVisit.entrySet()) {
            List<StartTag> tags = source.getAllStartTags(tag.getKey());
            for (StartTag startTag : tags) {
                final Attributes attributes = startTag.getAttributes();
                for (String attrName : tag.getValue()) {
                    Attribute attribute = attributes.get(attrName);
                    if (attribute != null) {
                        String originalValue = attribute.getValue();
                        String value = originalValue;
                        for (HtmlTagAttributeVisitor visitor : visitors) {
                            value = visitor.visit(value, context, resource);
                        }
                        if (originalValue != value && originalValue != null && !originalValue.equals(value)) {
                            document.replace(attribute.getValueSegment(), value);
                        }
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of net.htmlparser.jericho.Attribute

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.