org.apache.xerces.xni.XMLAttributes Java Examples

The following examples show how to use org.apache.xerces.xni.XMLAttributes. 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
/**
 * {@inheritDoc}
 */
@Override
public void ignoredStartElement(final QName elem, final XMLAttributes attrs, final Augmentations augs) {
    // when multiple body elements are encountered, the attributes of the discarded
    // elements are used when not previously defined
    if (body_ != null && "body".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes(body_, attrs);
    }
    if (body_ != null && "html".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes((DomElement) body_.getParentNode(), attrs);
    }
}
 
Example #3
Source File: OpenID4JavaDOMParser.java    From openid4java with Apache License 2.0 5 votes vote down vote up
public void ignoredStartElement(QName element, XMLAttributes attrs, Augmentations augs)
{
    if (element.rawname.equals("HEAD")
            && this.fCurrentNode instanceof HTMLHtmlElement)
    {
        this.ignoredHeadStartElement = true;
    }
}
 
Example #4
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoked for a start element. If the element is a <script>, overrides the normal behavior to begin collecting
 * the script text.
 */
public void startElement( QName element, XMLAttributes attrs, Augmentations augs ) throws XNIException {
    if (!isSupportedScript( element, attrs )) {
        super.startElement( element, attrs, augs );
    } else {
        _activeScriptBlock = new StringBuffer();
        _scriptLanguage = getScriptLanguage( attrs );
        String srcAttribute = attrs.getValue( "src" );
        if (srcAttribute != null) _activeScriptBlock.append( _scriptHandler.getIncludedScript( srcAttribute ) );
    }
}
 
Example #5
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called to signal an empty element. This simply synthesizes a
 * startElement followed by an endElement event.
 */
@Override
public void emptyElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
  this.startElement(element, attributes, augs);
  this.endElement(element, augs, true);
}
 
Example #6
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** Empty element. */
public void emptyElement(final QName element, XMLAttributes attrs, Augmentations augs)
    throws XNIException {
	startElement(element, attrs, augs);
    // browser ignore the closing indication for non empty tags like <form .../> but not for unknown element
    final HTMLElements.Element elem = getElement(element);
    if (elem.isEmpty() || elem.code == HTMLElements.UNKNOWN) {
    	endElement(element, augs);
    }
}
 
Example #7
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/**
 * Forces an element start, taking care to set the information to allow startElement to "see" that's
 * the element has been forced.
 * @return <code>true</code> if creation could be done (TABLE's creation for instance can't be forced)
 */
private boolean forceStartElement(final QName elem, XMLAttributes attrs, final Augmentations augs)
throws XNIException {
	
	forcedStartElement_ = true;
	startElement(elem, attrs, augs);
	
	return fElementStack.top > 0 && elem.equals(fElementStack.peek().qname);
}
 
Example #8
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 #9
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void ignoredStartElement(final QName elem, final XMLAttributes attrs, final Augmentations augs) {
    // when multiple body elements are encountered, the attributes of the discarded
    // elements are used when not previously defined
    if (body_ != null && "body".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes(body_, attrs);
    }
    if (body_ != null && "html".equalsIgnoreCase(elem.localpart) && attrs != null) {
        copyAttributes((DomElement) body_.getParentNode(), attrs);
    }
}
 
Example #10
Source File: HTMLParser.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void startElement(final QName element, final XMLAttributes attributes, final Augmentations augs)
    throws XNIException {
    // augs might change so we store only the interesting part
    lastTagWasSynthesized_ = isSynthesized(augs);
    super.startElement(element, attributes, augs);
}
 
Example #11
Source File: XMLModelSchemaValidator.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
	if (rootElement) {
		// on the document element, we associate the XML Schema declared in <?xml-model
		// processing instruction
		String defaultNamespace = attributes.getValue(XMLNS_ATTR);
		if (StringUtils.isEmpty(defaultNamespace)) {
			// XML doesn't define a xmlns attribute in the root element -> same support than
			// xsi:noNamespaceSchemaLocation. Ex:
			/**
			 * <?xml-model href="http://www.docbook.org/xml/5.0/xsd/docbook.xsd"?> <book>
			 **/
			String noNamespaceSchemaLocation = href;
			XMLSchemaLoader.processExternalHints(null, noNamespaceSchemaLocation, fLocationPairs, errorReporter);
		} else {
			// XML defines a xmlns attribute in the root element -> same support than
			// xsi:schemaLocation. Ex:
			/**
			 * <?xml-model href="http://www.docbook.org/xml/5.0/xsd/docbook.xsd"?>
			 * <book xmlns="http://docbook.org/ns/docbook">
			 **/
			String schemaLocation = new StringBuilder(defaultNamespace).append(' ').append(href).toString();
			XMLSchemaLoader.processExternalHints(schemaLocation, null, fLocationPairs, errorReporter);
		}
		rootElement = false;
	}
	super.startElement(element, attributes, augs);
}
 
Example #12
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.emptyElement(element, attributes, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.emptyElement(element, attributes, augs);
	}
}
 
Example #13
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.setLocator(locator);
			validator.startElement(element, attributes, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.startElement(element, attributes, augs);
	}
}
 
Example #14
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 #15
Source File: HtmlUnitNekoDOMBuilder.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void startElement(final QName element, final XMLAttributes attributes, final Augmentations augs)
    throws XNIException {
    // augs might change so we store only the interesting part
    lastTagWasSynthesized_ = isSynthesized(augs);
    super.startElement(element, attributes, augs);
}
 
Example #16
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 4 votes vote down vote up
/** Call document handler start element. */
protected final void callStartElement(QName element, XMLAttributes attrs,
                                      Augmentations augs) 
    throws XNIException {
    fDocumentHandler.startElement(element, attrs, augs);
}
 
Example #17
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 4 votes vote down vote up
/** Returns a set of empty attributes. */
protected final XMLAttributes emptyAttributes() {
    fEmptyAttrs.removeAllAttributes();
    return fEmptyAttrs;
}
 
Example #18
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 4 votes vote down vote up
/**
 * Notifies the tagBalancingListener (if any) of an ignored start element
 */
   private void notifyDiscardedStartElement(final QName elem, final XMLAttributes attrs,
   		final Augmentations augs) {
   	if (tagBalancingListener != null)
   		tagBalancingListener.ignoredStartElement(elem, attrs, augs);
}
 
Example #19
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);

}
 
Example #20
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private boolean isSupportedScript( QName element, XMLAttributes attrs ) {
    if (!element.rawname.equalsIgnoreCase( "script" ) || attrs == null) return false;
    String value = getScriptLanguage( attrs );
    return _scriptHandler.supportsScriptLanguage( value );
}
 
Example #21
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String getScriptLanguage( XMLAttributes attrs ) {
    return attrs == null ? null : attrs.getValue( "language" );
}
 
Example #22
Source File: ScriptFilter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void emptyElement( QName element, XMLAttributes attrs, Augmentations augs ) throws XNIException {
    if (!isSupportedScript( element, attrs )) {
        super.emptyElement(element, attrs, augs);
    }
}