Java Code Examples for javax.xml.stream.events.XMLEvent#NAMESPACE

The following examples show how to use javax.xml.stream.events.XMLEvent#NAMESPACE . 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: XMLStreamReaderImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the uri for the namespace declared at the index.
 *
 * @param index the position of the namespace declaration
 * @return returns the namespace uri
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT
 * or NAMESPACE
 */
public String getNamespaceURI(int index) {
    if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT
            || fEventType == XMLEvent.NAMESPACE) {
        //namespaceContext is dynamic object.
        return fScanner.getNamespaceContext().getURI(fScanner.getNamespaceContext()
                .getDeclaredPrefixAt(index));
    } else {
        throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
                + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
                + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                + getEventTypeString(XMLEvent.NAMESPACE)
                + " valid for getNamespaceURI().");
    }

}
 
Example 2
Source File: XMLStreamReaderImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
 * this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
 * an END_ELEMENT the count is of the namespaces that are about to go
 * out of scope.  This is the equivalent of the information reported
 * by SAX callback for an end element event.
 * @return returns the number of namespace declarations on this specific element
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public int getNamespaceCount() {
    //namespaceContext is dynamic object.
    //REVISIT: check if it specifies all conditions mentioned in the javadoc
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        return fScanner.getNamespaceContext().getDeclaredPrefixCount() ;
    } else{
        throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceCount()." );
    }
}
 
Example 3
Source File: XMLStreamReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
 * this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
 * an END_ELEMENT the count is of the namespaces that are about to go
 * out of scope.  This is the equivalent of the information reported
 * by SAX callback for an end element event.
 * @return returns the number of namespace declarations on this specific element
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public int getNamespaceCount() {
    //namespaceContext is dynamic object.
    //REVISIT: check if it specifies all conditions mentioned in the javadoc
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        return fScanner.getNamespaceContext().getDeclaredPrefixCount() ;
    } else{
        throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceCount()." );
    }
}
 
Example 4
Source File: XMLStreamReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the prefix for the namespace declared at the
 * index.  Returns null if this is the default namespace
 * declaration
 *
 * @param index the position of the namespace declaration
 * @return returns the namespace prefix
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public String getNamespacePrefix(int index) {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        //namespaceContext is dynamic object.
        String prefix = fScanner.getNamespaceContext().getDeclaredPrefixAt(index) ;
        return prefix.equals("") ? null : prefix ;
    }
    else{
        throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespacePrefix()." );
    }
}
 
Example 5
Source File: XMLStreamReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the uri for the namespace declared at the
 * index.
 *
 * @param index the position of the namespace declaration
 * @return returns the namespace uri
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public String getNamespaceURI(int index) {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        //namespaceContext is dynamic object.
        return fScanner.getNamespaceContext().getURI(fScanner.getNamespaceContext().getDeclaredPrefixAt(index));
    }
    else{
        throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceURI()." );
    }

}
 
Example 6
Source File: XMLStreamReaderImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the count of namespaces declared on this START_ELEMENT or
 * END_ELEMENT, this method is only valid on a START_ELEMENT, END_ELEMENT or
 * NAMESPACE. On an END_ELEMENT the count is of the namespaces that are
 * about to go out of scope. This is the equivalent of the information
 * reported by SAX callback for an end element event.
 *
 * @return returns the number of namespace declarations on this specific
 * element
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT
 * or NAMESPACE
 */
public int getNamespaceCount() {
    //namespaceContext is dynamic object.
    //REVISIT: check if it specifies all conditions mentioned in the javadoc
    if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT
            || fEventType == XMLEvent.NAMESPACE) {
        return fScanner.getNamespaceContext().getDeclaredPrefixCount();
    } else {
        throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType)
                + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
                + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                + getEventTypeString(XMLEvent.NAMESPACE)
                + " valid for getNamespaceCount().");
    }
}
 
Example 7
Source File: XMLStreamReaderImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the prefix for the namespace declared at the
 * index.  Returns null if this is the default namespace
 * declaration
 *
 * @param index the position of the namespace declaration
 * @return returns the namespace prefix
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public String getNamespacePrefix(int index) {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        //namespaceContext is dynamic object.
        String prefix = fScanner.getNamespaceContext().getDeclaredPrefixAt(index) ;
        return prefix.equals("") ? null : prefix ;
    }
    else{
        throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespacePrefix()." );
    }
}
 
Example 8
Source File: XMLStreamReaderImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
 * this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
 * an END_ELEMENT the count is of the namespaces that are about to go
 * out of scope.  This is the equivalent of the information reported
 * by SAX callback for an end element event.
 * @return returns the number of namespace declarations on this specific element
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public int getNamespaceCount() {
    //namespaceContext is dynamic object.
    //REVISIT: check if it specifies all conditions mentioned in the javadoc
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        return fScanner.getNamespaceContext().getDeclaredPrefixCount() ;
    } else{
        throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceCount()." );
    }
}
 
Example 9
Source File: XMLStreamReaderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the uri for the namespace declared at the
 * index.
 *
 * @param index the position of the namespace declaration
 * @return returns the namespace uri
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public String getNamespaceURI(int index) {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        //namespaceContext is dynamic object.
        return fScanner.getNamespaceContext().getURI(fScanner.getNamespaceContext().getDeclaredPrefixAt(index));
    }
    else{
        throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceURI()." );
    }

}
 
Example 10
Source File: XMLStreamReaderImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
 * this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
 * an END_ELEMENT the count is of the namespaces that are about to go
 * out of scope.  This is the equivalent of the information reported
 * by SAX callback for an end element event.
 * @return returns the number of namespace declarations on this specific element
 * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
 */
public int getNamespaceCount() {
    //namespaceContext is dynamic object.
    //REVISIT: check if it specifies all conditions mentioned in the javadoc
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
        return fScanner.getNamespaceContext().getDeclaredPrefixCount() ;
    } else{
        throw new IllegalStateException("Current event state is " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
         + ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
                 + getEventTypeString(XMLEvent.NAMESPACE)
         + " valid for getNamespaceCount()." );
    }
}
 
Example 11
Source File: DummyEvent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** A utility function to check if this event is a Namespace.
 * @see Namespace
 */
public boolean isNamespace() {
    return fEventType == XMLEvent.NAMESPACE;
}
 
Example 12
Source File: DummyEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/** A utility function to check if this event is a Namespace.
 * @see Namespace
 */
public boolean isNamespace() {
    return fEventType == XMLEvent.NAMESPACE;
}
 
Example 13
Source File: DummyEvent.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** A utility function to check if this event is a Namespace.
 * @see Namespace
 */
public boolean isNamespace() {
    return fEventType == XMLEvent.NAMESPACE;
}
 
Example 14
Source File: NamespaceImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public int getEventType(){
    return XMLEvent.NAMESPACE;
}
 
Example 15
Source File: NamespaceImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public int getEventType(){
    return XMLEvent.NAMESPACE;
}
 
Example 16
Source File: DummyEvent.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/** A utility function to check if this event is a Namespace.
 * @see Namespace
 */
public boolean isNamespace() {
    return fEventType == XMLEvent.NAMESPACE;
}
 
Example 17
Source File: NamespaceImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public int getEventType(){
    return XMLEvent.NAMESPACE;
}
 
Example 18
Source File: NamespaceImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public int getEventType(){
    return XMLEvent.NAMESPACE;
}
 
Example 19
Source File: DummyEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/** A utility function to check if this event is a Namespace.
 * @see Namespace
 */
public boolean isNamespace() {
    return fEventType == XMLEvent.NAMESPACE;
}
 
Example 20
Source File: XmlUtils.java    From entity-fishing with Apache License 2.0 2 votes vote down vote up
/**
 * Compares two {@link XMLEvent} instances. This method delegates actual
 * matching to the appropriate overloaded method.
 * 
 * @param a
 *            The first event.
 * @param b
 *            The second event.
 * @return <code>true</code> if the events match, <code>false</code>
 *         otherwise.
 */
public static boolean eventsMatch(XMLEvent a, XMLEvent b) {

	if (a == b) {

		return true;

	} else if (a == null || b == null) {

		return false;

	} else if (a.getEventType() == b.getEventType()) {

		switch (a.getEventType()) {

		case XMLEvent.START_ELEMENT:
			return eventsMatch(a.asStartElement(), b.asStartElement());

		case XMLEvent.END_ELEMENT:
			return eventsMatch(a.asEndElement(), b.asEndElement());

		case XMLEvent.CDATA:
		case XMLEvent.SPACE:
		case XMLEvent.CHARACTERS:
			return eventsMatch(a.asCharacters(), b.asCharacters());

		case XMLEvent.COMMENT:
			return eventsMatch((Comment) a, (Comment) b);

		case XMLEvent.ENTITY_REFERENCE:
			return eventsMatch((EntityReference) a, (EntityReference) b);

		case XMLEvent.ATTRIBUTE:
			return eventsMatch((Attribute) a, (Attribute) b);

		case XMLEvent.NAMESPACE:
			return eventsMatch((Namespace) a, (Namespace) b);

		case XMLEvent.START_DOCUMENT:
			return eventsMatch((StartDocument) a, (StartDocument) b);

		case XMLEvent.END_DOCUMENT:
			return eventsMatch((EndDocument) a, (EndDocument) b);

		case XMLEvent.PROCESSING_INSTRUCTION:
			return eventsMatch((ProcessingInstruction) a, (ProcessingInstruction) b);

		case XMLEvent.DTD:
			return eventsMatch((DTD) a, (DTD) b);

		case XMLEvent.ENTITY_DECLARATION:
			return eventsMatch((EntityDeclaration) a, (EntityDeclaration) b);

		case XMLEvent.NOTATION_DECLARATION:
			return eventsMatch((NotationDeclaration) a, (NotationDeclaration) b);

		}

	}

	return false;

}