Java Code Examples for org.apache.xerces.xni.XMLAttributes#getLength()

The following examples show how to use org.apache.xerces.xni.XMLAttributes#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an element information object.
 * <p>
 * <strong>Note:</strong>
 * This constructor makes a copy of the element information.
 *
 * @param element The element qualified name.
 * @param attributes The element attributes.
 */
public Info(HTMLElements.Element element,
            QName qname, XMLAttributes attributes) {
    this.element = element;
    this.qname = new QName(qname);
    if (attributes != null) {
        int length = attributes.getLength();
        if (length > 0) {
            QName aqname = new QName();
            XMLAttributes newattrs = new XMLAttributesImpl();
            for (int i = 0; i < length; i++) {
                attributes.getName(i, aqname);
                String type = attributes.getType(i);
                String value = attributes.getValue(i);
                String nonNormalizedValue = attributes.getNonNormalizedValue(i);
                boolean specified = attributes.isSpecified(i);
                newattrs.addAttribute(aqname, type, value);
                newattrs.setNonNormalizedValue(i, nonNormalizedValue);
                newattrs.setSpecified(i, specified);
            }
            this.attributes = newattrs;
        }
    }
}
 
Example 2
Source File: HtmlUnitNekoDOMBuilder.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private static void copyAttributes(final DomElement to, final XMLAttributes attrs) {
    final int length = attrs.getLength();
    for (int i = 0; i < length; i++) {
        final String attrName = attrs.getLocalName(i).toLowerCase(Locale.ROOT);
        if (to.getAttributes().getNamedItem(attrName) == null) {
            to.setAttribute(attrName, attrs.getValue(i));
            if (attrName.startsWith("on") && to.getPage().getWebClient().isJavaScriptEngineEnabled()
                    && to.getScriptableObject() instanceof HTMLBodyElement) {
                final HTMLBodyElement jsBody = to.getScriptableObject();
                jsBody.createEventHandlerFromAttribute(attrName, attrs.getValue(i));
            }
        }
    }
}
 
Example 3
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
private static void copyAttributes(final DomElement to, final XMLAttributes attrs) {
    final int length = attrs.getLength();
    for (int i = 0; i < length; i++) {
        final String attrName = attrs.getLocalName(i).toLowerCase(Locale.ROOT);
        if (to.getAttributes().getNamedItem(attrName) == null) {
            to.setAttribute(attrName, attrs.getValue(i));
            if (attrName.startsWith("on") && to.getScriptableObject() instanceof HTMLBodyElement) {
                final HTMLBodyElement jsBody = (HTMLBodyElement) to.getScriptableObject();
                jsBody.createEventHandlerFromAttribute(attrName, attrs.getValue(i));
            }
        }
    }
}
 
Example 4
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Called when the parser encounters the start of an HTML element.
 * Empty elements also trigger this method, followed immediately by an
 * {@link #endElement}.
 */
@Override
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
  // deal with any outstanding character content
  charactersAction();

  if(DEBUG_ELEMENTS) {
    Out.println("startElement: " + element.localpart);
  }
  // Fire the status listener if the elements processed exceded the
  // rate
  if(0 == (++elements % ELEMENTS_RATE))
    fireStatusChangedEvent("Processed elements : " + elements);

  // Start of ignorable tag
  if(ignorableTags.contains(element.localpart)) {
    ignorableTagLevels++;
    if(DEBUG_ELEMENTS) {
      Out.println("  ignorable tag: levels = " + ignorableTagLevels);
    }
  } // if

  // Construct a feature map from the attributes list
  FeatureMap fm = Factory.newFeatureMap();

  // Take all the attributes an put them into the feature map
  for(int i = 0; i < attributes.getLength(); i++) {
    if(DEBUG_ELEMENTS) {
      Out.println("  attribute: " + attributes.getLocalName(i) + " = "
              + attributes.getValue(i));
    }
    fm.put(attributes.getLocalName(i), attributes.getValue(i));
  }

  // Just analize the tag and add some\n chars and spaces to the
  // tmpDocContent.The reason behind is that we need to have a
  // readable form
  // for the final document.
  customizeAppearanceOfDocumentWithStartTag(element.localpart);

  // create the start index of the annotation
  Long startIndex = new Long(tmpDocContent.length());

  // initialy the start index is equal with the End index
  CustomObject obj = new CustomObject(element.localpart, fm, startIndex,
          startIndex);

  // put it into the stack
  stack.push(obj);

}