Java Code Examples for javax.xml.stream.XMLStreamReader#getNamespaceCount()

The following examples show how to use javax.xml.stream.XMLStreamReader#getNamespaceCount() . 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: StreamReaderBufferCreator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void storeElement(XMLStreamReader reader) {
    storeQualifiedName(T_ELEMENT_LN,
            reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());

    if (reader.getNamespaceCount() > 0) {
        storeNamespaceAttributes(reader);
    }

    if (reader.getAttributeCount() > 0) {
        storeAttributes(reader);
    }
}
 
Example 2
Source File: XMLStreamReaderUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 3
Source File: EdmParser.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
private void extractNamespaces(final XMLStreamReader reader) throws EntityProviderException {
  int namespaceCount = reader.getNamespaceCount();
  for (int i = 0; i < namespaceCount; i++) {
    String namespacePrefix = reader.getNamespacePrefix(i);
    String namespaceUri = reader.getNamespaceURI(i);
    if (namespacePrefix == null || isDefaultNamespace(namespacePrefix)) {
      namespacePrefix = Edm.PREFIX_EDM;
    }
    xmlNamespaceMap.put(namespacePrefix, namespaceUri);
  }
}
 
Example 4
Source File: StAXEventAllocatorBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void addNamespaces(StartElementEvent event,XMLStreamReader streamReader){
    Namespace namespace = null;
    for(int i=0; i<streamReader.getNamespaceCount(); i++){
        namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
                            streamReader.getNamespaceURI(i));
        event.addNamespace(namespace);
    }
}
 
Example 5
Source File: XMLStreamReaderUtil.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 6
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addCurrentNamespaceDecls(XMLStreamReader xmlReader, Map<String, String> bodyNsMap) {
    for (int i = 0; i < xmlReader.getNamespaceCount(); i++) {
        String nsuri = xmlReader.getNamespaceURI(i);
        if ("".equals(nsuri)) {
            bodyNsMap.remove("");
        } else {
            bodyNsMap.put(xmlReader.getNamespacePrefix(i), nsuri);
        }
    }
}
 
Example 7
Source File: StAXEventAllocatorBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void addNamespaces(StartElementEvent event,XMLStreamReader streamReader){
    Namespace namespace = null;
    for(int i=0; i<streamReader.getNamespaceCount(); i++){
        namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
                            streamReader.getNamespaceURI(i));
        event.addNamespace(namespace);
    }
}
 
Example 8
Source File: StAXSchemaParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(XMLStreamReader reader) {
    fDeclaredPrefixes.clear();
    final int len = reader.getNamespaceCount();
    for (int i = 0; i < len; ++i) {
        String prefix = reader.getNamespacePrefix(i);
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
Example 9
Source File: XMLStreamReaderUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 10
Source File: StAXEventAllocatorBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void addNamespaces(EndElementEvent event,XMLStreamReader streamReader){
    Namespace namespace = null;
    for(int i=0; i<streamReader.getNamespaceCount(); i++){
        namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
                            streamReader.getNamespaceURI(i));
        event.addNamespace(namespace);
    }
}
 
Example 11
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void extractNamespaces(final XMLStreamReader reader) throws EntityProviderException {
  int namespaceCount = reader.getNamespaceCount();
  for (int i = 0; i < namespaceCount; i++) {
    String namespacePrefix = reader.getNamespacePrefix(i);
    String namespaceUri = reader.getNamespaceURI(i);
    if (namespacePrefix == null || isDefaultNamespace(namespacePrefix)) {
      namespacePrefix = Edm.PREFIX_EDM;
    }
    //Ignoring the duplicate tags, parent tag namespace takes precedence
    if (!xmlNamespaceMap.containsKey(namespacePrefix)) {
      xmlNamespaceMap.put(namespacePrefix, namespaceUri);
    }
  }
}
 
Example 12
Source File: StAXSchemaParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(XMLStreamReader reader) {
    fDeclaredPrefixes.clear();
    final int len = reader.getNamespaceCount();
    for (int i = 0; i < len; ++i) {
        String prefix = reader.getNamespacePrefix(i);
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
Example 13
Source File: StreamReaderBufferCreator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void storeElement(XMLStreamReader reader) {
    storeQualifiedName(T_ELEMENT_LN,
            reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());

    if (reader.getNamespaceCount() > 0) {
        storeNamespaceAttributes(reader);
    }

    if (reader.getAttributeCount() > 0) {
        storeAttributes(reader);
    }
}
 
Example 14
Source File: StAXSchemaParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(XMLStreamReader reader) {
    fDeclaredPrefixes.clear();
    final int len = reader.getNamespaceCount();
    for (int i = 0; i < len; ++i) {
        String prefix = reader.getNamespacePrefix(i);
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
Example 15
Source File: XmlFeedConsumer.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param reader
 * @return 
 * @throws EntityProviderException
 */
private Map<String, String> extractNamespacesFromTag(final XMLStreamReader reader) throws EntityProviderException {
  // collect namespaces
  Map<String, String> foundPrefix2NamespaceUri = new HashMap<String, String>();
  int namespaceCount = reader.getNamespaceCount();
  for (int i = 0; i < namespaceCount; i++) {
    String namespacePrefix = reader.getNamespacePrefix(i);
    String namespaceUri = reader.getNamespaceURI(i);

    foundPrefix2NamespaceUri.put(namespacePrefix, namespaceUri);
  }
  return foundPrefix2NamespaceUri;
}
 
Example 16
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Document process(XMLStreamReader reader) throws XMLStreamException {
    // number of elements read in
    int read = 0;
    int event = reader.getEventType();
    while (reader.hasNext()) {
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            read++;
            addEvent(eventFactory.createStartElement(new QName(reader.getNamespaceURI(), reader
                                                    .getLocalName(), reader.getPrefix()), null, null));
            for (int i = 0; i < reader.getNamespaceCount(); i++) {
                addEvent(eventFactory.createNamespace(reader.getNamespacePrefix(i),
                                                 reader.getNamespaceURI(i)));
            }
            for (int i = 0; i < reader.getAttributeCount(); i++) {
                addEvent(eventFactory.createAttribute(reader.getAttributePrefix(i),
                                                 reader.getAttributeNamespace(i),
                                                 reader.getAttributeLocalName(i),
                                                 reader.getAttributeValue(i)));
            }
            if (doc != null) {
                //go on parsing the stream directly till the end and stop generating events
                StaxUtils.readDocElements(doc, parent, reader, context);
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            if (read > 0) {
                addEvent(eventFactory.createEndElement(new QName(reader.getNamespaceURI(), reader
                                                      .getLocalName(), reader.getPrefix()), null));
            }
            read--;
            break;
        case XMLStreamConstants.CHARACTERS:
            String s = reader.getText();
            if (s != null) {
                addEvent(eventFactory.createCharacters(s));
            }
            break;
        case XMLStreamConstants.COMMENT:
            addEvent(eventFactory.createComment(reader.getText()));
            break;
        case XMLStreamConstants.CDATA:
            addEvent(eventFactory.createCData(reader.getText()));
            break;
        case XMLStreamConstants.START_DOCUMENT:
        case XMLStreamConstants.END_DOCUMENT:
        case XMLStreamConstants.ATTRIBUTE:
        case XMLStreamConstants.NAMESPACE:
            break;
        default:
            break;
        }
        event = reader.next();
    }

    return doc;
}
 
Example 17
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void storeNamespaceAttributes(XMLStreamReader reader) {
    int count = reader.getNamespaceCount();
    for (int i = 0; i < count; i++) {
        storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
}
 
Example 18
Source File: StreamReaderBufferCreator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void storeNamespaceAttributes(XMLStreamReader reader) {
    int count = reader.getNamespaceCount();
    for (int i = 0; i < count; i++) {
        storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
}
 
Example 19
Source File: StreamReaderBufferCreator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void storeNamespaceAttributes(XMLStreamReader reader) {
    int count = reader.getNamespaceCount();
    for (int i = 0; i < count; i++) {
        storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
}
 
Example 20
Source File: StreamReaderBufferCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private void storeNamespaceAttributes(XMLStreamReader reader) {
    int count = reader.getNamespaceCount();
    for (int i = 0; i < count; i++) {
        storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
}