Package nu.validator.htmlparser.impl

Examples of nu.validator.htmlparser.impl.HtmlAttributes


    boolean isEndTag = CajaTreeBuilder.isEndTag(start.text);
    String tagName = start.text.substring(isEndTag ? 2 : 1);
    boolean isHtml = checkName(tagName);
    if (isHtml) { tagName = Strings.lower(tagName); }

    HtmlAttributes htmlAttrs = new HtmlAttributes(AttributeName.HTML);
    boolean hasXmlns = false;
    List<Attr> attrs = Lists.newArrayList();
    if (!attrStubs.isEmpty()) {
      for (AttrStub as : attrStubs) {
        String qname = as.nameTok.text;
        Attr attrNode;
        boolean isAttrHtml;
        try {
          String name;
          if ("xmlns".equals(qname)) {
            if (!Namespaces.HTML_NAMESPACE_URI.equals(as.value)) {
              // We do not allow overriding of the default namespace when
              // parsing HTML.
              mq.addMessage(
                  MessageType.CANNOT_OVERRIDE_DEFAULT_NAMESPACE_IN_HTML,
                  as.nameTok.pos);
            } else {
              hasXmlns = true;
            }
            continue;
          } else {
            isAttrHtml = isHtml && checkName(qname);
            if (isAttrHtml) {
              name = Strings.lower(qname);
              attrNode = maybeCreateAttributeNs(Namespaces.HTML_NAMESPACE_URI,
                                                name, as);
              if (attrNode == null) {
                // Ignore this attribute.
                continue;
              }
            } else {
              name = AttributeNameFixup.fixupNameFromQname(qname);
              attrNode = maybeCreateAttribute(name, as);
              if (attrNode == null) {
                // Ignore this attribute.
                continue;
              }
            }
          }
          attrNode.setValue(as.value);
          if (needsDebugData) {
            Nodes.setFilePositionFor(attrNode, as.nameTok.pos);
            Nodes.setFilePositionForValue(attrNode, as.valueTok.pos);
            Nodes.setRawValue(attrNode, as.valueTok.text);
          }
          attrs.add(attrNode);
          try {
            htmlAttrs.addAttribute(
                AttributeName.nameByString(name),
                as.value, XmlViolationPolicy.ALLOW);
          } catch (SAXException ex) {
            if (CajaTreeBuilder.DEBUG) { ex.printStackTrace(); }
          }
View Full Code Here


        return newElt;
    }

    @Override
    protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException {
        HtmlAttributes existingAttrs = (HtmlAttributes) element.getAttributes();
        existingAttrs.merge(attributes);
    }
View Full Code Here

        return newElt;
    }

    @Override
    protected void addAttributesToElement(Element element, HtmlAttributes attributes) throws SAXException {
        HtmlAttributes existingAttrs = (HtmlAttributes) element.getAttributes();
        existingAttrs.merge(attributes);
    }
View Full Code Here

    boolean isEndTag = CajaTreeBuilder.isEndTag(start.text);
    String tagName = start.text.substring(isEndTag ? 2 : 1);
    boolean isHtml = checkName(tagName);
    if (isHtml) { tagName = Strings.lower(tagName); }

    HtmlAttributes htmlAttrs = new HtmlAttributes(AttributeName.HTML);
    boolean hasXmlns = false;
    List<Attr> attrs = Lists.newArrayList();
    if (!attrStubs.isEmpty()) {
      for (AttrStub as : attrStubs) {
        String qname = as.nameTok.text;
        Attr attrNode;
        boolean isAttrHtml;
        try {
          String name;
          if ("xmlns".equals(qname)) {
            if (!Namespaces.HTML_NAMESPACE_URI.equals(as.value)) {
              // We do not allow overriding of the default namespace when
              // parsing HTML.
              mq.addMessage(
                  MessageType.CANNOT_OVERRIDE_DEFAULT_NAMESPACE_IN_HTML,
                  as.nameTok.pos);
            } else {
              hasXmlns = true;
            }
            continue;
          } else {
            isAttrHtml = isHtml && checkName(qname);
            if (isAttrHtml) {
              name = Strings.lower(qname);
              attrNode = maybeCreateAttributeNs(Namespaces.HTML_NAMESPACE_URI,
                                                name, as);
              if (attrNode == null) {
                // Ignore this attribute.
                continue;
              }
            } else {
              name = AttributeNameFixup.fixupNameFromQname(qname);
              attrNode = maybeCreateAttribute(name, as);
              if (attrNode == null) {
                // Ignore this attribute.
                continue;
              }
            }
          }
          attrNode.setValue(as.value);
          if (needsDebugData) {
            Nodes.setFilePositionFor(attrNode, as.nameTok.pos);
            Nodes.setFilePositionForValue(attrNode, as.valueTok.pos);
            Nodes.setRawValue(attrNode, as.valueTok.text);
          }
          attrs.add(attrNode);
          try {
            htmlAttrs.addAttribute(
                AttributeName.nameByString(name),
                as.value, XmlViolationPolicy.ALLOW);
          } catch (SAXException ex) {
            if (CajaTreeBuilder.DEBUG) { ex.printStackTrace(); }
          }
View Full Code Here

TOP

Related Classes of nu.validator.htmlparser.impl.HtmlAttributes

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.