Java Code Examples for javax.xml.stream.XMLStreamReader#getNamespaceURI()
The following examples show how to use
javax.xml.stream.XMLStreamReader#getNamespaceURI() .
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: XMLSupport.java From FHIR with Apache License 2.0 | 6 votes |
private static void writeStartElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { String prefix = reader.getPrefix(); String namespaceURI = reader.getNamespaceURI(); String localName = reader.getLocalName(); if (namespaceURI != null) { if (prefix != null) { writer.writeStartElement(prefix, localName, namespaceURI); } else { writer.setDefaultNamespace(namespaceURI); writer.writeStartElement(namespaceURI, localName); } } else { writer.writeStartElement(localName); } writeNamespaces(reader, writer); writeAttributes(reader, writer); }
Example 2
Source File: DomReader.java From cosmo with Apache License 2.0 | 6 votes |
private static Element readElement(Document d, XMLStreamReader reader) throws XMLStreamException { Element e = null; String local = reader.getLocalName(); String ns = reader.getNamespaceURI(); if (ns != null && !ns.equals("")) { String prefix = reader.getPrefix(); String qualified = prefix != null && !prefix.isEmpty() ? prefix + ":" + local : local; e = d.createElementNS(ns, qualified); } else { e = d.createElement(local); } for (int i = 0; i < reader.getAttributeCount(); i++) { Attr a = readAttribute(i, d, reader); if (a.getNamespaceURI() != null) { e.setAttributeNodeNS(a); } else { e.setAttributeNode(a); } } return e; }
Example 3
Source File: ReadHeadersInterceptor.java From cxf with Apache License 2.0 | 6 votes |
public static SoapVersion readVersion(XMLStreamReader xmlReader, SoapMessage message) { String ns = xmlReader.getNamespaceURI(); String lcname = xmlReader.getLocalName(); if (ns == null || "".equals(ns)) { throw new SoapFault(new Message("NO_NAMESPACE", LOG, lcname), Soap11.getInstance().getVersionMismatch()); } SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns); if (soapVersion == null) { throw new SoapFault(new Message("INVALID_VERSION", LOG, ns, lcname), Soap11.getInstance().getVersionMismatch()); } if (!"Envelope".equals(lcname)) { throw new SoapFault(new Message("INVALID_ENVELOPE", LOG, lcname), soapVersion.getSender()); } message.setVersion(soapVersion); return soapVersion; }
Example 4
Source File: XmlFormatter.java From hop with Apache License 2.0 | 5 votes |
public StartElementBuffer( XMLStreamReader rd ) { prefix = rd.getPrefix(); namespace = rd.getNamespaceURI(); localName = rd.getLocalName(); for ( int i = 0; i < rd.getAttributeCount(); i++ ) { attrBuffer.add( new AttrBuffer( rd, i ) ); } }
Example 5
Source File: XmlFeedDeserializer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Maps all all found namespaces of current xml tag into a map. * * @param reader xml reader with current position at a xml tag * @return map with all found namespaces of current xml tag */ private Map<String, String> extractNamespacesFromTag(final XMLStreamReader reader) { // 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 6
Source File: EdmParser.java From cloud-odata-java with Apache License 2.0 | 5 votes |
private AnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException { AnnotationElement aElement = new AnnotationElement(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>(); aElement.setName(reader.getLocalName()); String elementNamespace = reader.getNamespaceURI(); if (!Edm.NAMESPACE_EDM_2008_09.equals(elementNamespace)) { aElement.setPrefix(reader.getPrefix()); aElement.setNamespace(elementNamespace); } for (int i = 0; i < reader.getAttributeCount(); i++) { AnnotationAttribute annotationAttribute = new AnnotationAttribute(); annotationAttribute.setText(reader.getAttributeValue(i)); annotationAttribute.setName(reader.getAttributeLocalName(i)); annotationAttribute.setPrefix(reader.getAttributePrefix(i)); String namespace = reader.getAttributeNamespace(i); if (namespace != null && !isDefaultNamespace(namespace)) { annotationAttribute.setNamespace(namespace); } annotationAttributes.add(annotationAttribute); } aElement.setAttributes(annotationAttributes); while (reader.hasNext() && !(reader.isEndElement() && aElement.getName() != null && aElement.getName().equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { annotationElements.add(readAnnotationElement(reader)); } else if (reader.isCharacters()) { aElement.setText(reader.getText()); } } if (!annotationElements.isEmpty()) { aElement.setChildElements(annotationElements); } return aElement; }
Example 7
Source File: XmlMetadataConsumer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
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 8
Source File: XmlEntryConsumer.java From cloud-odata-java with Apache License 2.0 | 5 votes |
private void extractNamespacesFromTag(final XMLStreamReader reader) throws EntityProviderException { // collect namespaces 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); } }
Example 9
Source File: XMLStreamReaderUtil.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void verifyTag(XMLStreamReader reader, String namespaceURI, String localName) { if (!localName.equals(reader.getLocalName()) || !namespaceURI.equals(reader.getNamespaceURI())) { throw new XMLStreamReaderException( "xmlreader.unexpectedState.tag", "{" + namespaceURI + "}" + localName, "{" + reader.getNamespaceURI() + "}" + reader.getLocalName()); } }
Example 10
Source File: NodeParser.java From galleon with Apache License 2.0 | 5 votes |
private ElementNode createNodeWithAttributesAndNs(XMLStreamReader reader, ElementNode parent) { String namespace = reader.getNamespaceURI() != null && reader.getNamespaceURI().length() > 0 ? reader.getNamespaceURI() : namespaceURI; ElementNode childNode = new ElementNode(parent, reader.getLocalName(), namespace); int count = reader.getAttributeCount(); for (int i = 0 ; i < count ; i++) { String name = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); childNode.addAttribute(name, createAttributeValue(value)); } return childNode; }
Example 11
Source File: XMLStreamReaderUtil.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 12
Source File: StreamSOAPCodec.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static final Message decode(SOAPVersion soapVersion, XMLStreamReader reader, @NotNull AttachmentSet attachmentSet) { // Move to soap:Envelope and verify if(reader.getEventType()!=XMLStreamConstants.START_ELEMENT) XMLStreamReaderUtil.nextElementContent(reader); XMLStreamReaderUtil.verifyReaderState(reader,XMLStreamConstants.START_ELEMENT); if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) { throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI()); } XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE); return new StreamMessage(soapVersion, reader, attachmentSet); }
Example 13
Source File: XmlMetadataDeserializer.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private EdmAnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException { EdmAnnotationElementImpl elementImpl = new EdmAnnotationElementImpl(); List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>(); List<EdmAnnotationAttribute> annotationAttributes = new ArrayList<EdmAnnotationAttribute>(); elementImpl.setName(reader.getLocalName()); String elementNamespace = reader.getNamespaceURI(); if (!edmNamespaces.contains(elementNamespace)) { elementImpl.setPrefix(reader.getPrefix()); elementImpl.setNamespace(elementNamespace); } for (int i = 0; i < reader.getAttributeCount(); i++) { EdmAnnotationAttributeImpl annotationAttribute = new EdmAnnotationAttributeImpl(); annotationAttribute.setText(reader.getAttributeValue(i)); annotationAttribute.setName(reader.getAttributeLocalName(i)); annotationAttribute.setPrefix(reader.getAttributePrefix(i)); String namespace = reader.getAttributeNamespace(i); if (namespace != null && !isDefaultNamespace(namespace)) { annotationAttribute.setNamespace(namespace); } annotationAttributes.add(annotationAttribute); } if (!annotationAttributes.isEmpty()) { elementImpl.setAttributes(annotationAttributes); } boolean justRead = false; if (reader.hasNext()) { reader.next(); justRead = true; } while (justRead && !(reader.isEndElement() && elementImpl.getName() != null && elementImpl.getName().equals(reader.getLocalName()))) { justRead = false; if (reader.isStartElement()) { annotationElements.add(readAnnotationElement(reader)); if (reader.hasNext()) { reader.next(); justRead = true; } } else if (reader.isCharacters()) { String elementText = ""; do { justRead = false; elementText = elementText + reader.getText(); if (reader.hasNext()) { reader.next(); justRead = true; } } while (justRead && reader.isCharacters()); elementImpl.setText(elementText); } } if (!annotationElements.isEmpty()) { elementImpl.setChildElements(annotationElements); } return elementImpl; }
Example 14
Source File: XmlMetadataConsumer.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private AnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException { AnnotationElement aElement = new AnnotationElement(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>(); aElement.setName(reader.getLocalName()); String elementNamespace = reader.getNamespaceURI(); if (!edmNamespaces.contains(elementNamespace)) { aElement.setPrefix(reader.getPrefix()); aElement.setNamespace(elementNamespace); } for (int i = 0; i < reader.getAttributeCount(); i++) { AnnotationAttribute annotationAttribute = new AnnotationAttribute(); annotationAttribute.setText(reader.getAttributeValue(i)); annotationAttribute.setName(reader.getAttributeLocalName(i)); annotationAttribute.setPrefix(reader.getAttributePrefix(i)); String namespace = reader.getAttributeNamespace(i); if (namespace != null && !isDefaultNamespace(namespace)) { annotationAttribute.setNamespace(namespace); } annotationAttributes.add(annotationAttribute); } if (!annotationAttributes.isEmpty()) { aElement.setAttributes(annotationAttributes); } boolean justRead = false; if (reader.hasNext()) { reader.next(); justRead = true; } while (justRead && !(reader.isEndElement() && aElement.getName() != null && aElement.getName().equals(reader.getLocalName()))) { justRead = false; if (reader.isStartElement()) { annotationElements.add(readAnnotationElement(reader)); if (reader.hasNext()) { reader.next(); justRead = true; } } else if (reader.isCharacters()) { String elementText = ""; do { justRead = false; elementText = elementText + reader.getText(); if (reader.hasNext()) { reader.next(); justRead = true; } } while (justRead && reader.isCharacters()); aElement.setText(elementText); } } if (!annotationElements.isEmpty()) { aElement.setChildElements(annotationElements); } return aElement; }
Example 15
Source File: StreamHeader.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Creates a {@link StreamHeader}. * * @param reader * The parser that points to the start tag of the header. * By the end of this method, the parser will point at * the end tag of this element. */ protected StreamHeader(XMLStreamReader reader) throws XMLStreamException { _localName = reader.getLocalName(); _namespaceURI = reader.getNamespaceURI(); attributes = processHeaderAttributes(reader); // cache the body _mark = XMLStreamBuffer.createNewBufferFromXMLStreamReader(reader); }
Example 16
Source File: XmlEntryConsumer.java From cloud-odata-java with Apache License 2.0 | 3 votes |
/** * Checks if property of currently read tag in {@link XMLStreamReader} is defined in * <code>edm properties namespace</code> {@value Edm#NAMESPACE_D_2007_08}. * * If no namespace uri definition is found for namespace prefix of property (<code>tag</code>) an exception is thrown. * * @param reader {@link XMLStreamReader} with position at to checked tag * @return <code>true</code> if property is in <code>edm properties namespace</code>, otherwise <code>false</code>. * @throws EntityProviderException If no namespace uri definition is found for namespace prefix of property (<code>tag</code>). */ private boolean isEdmNamespaceProperty(final XMLStreamReader reader) throws EntityProviderException { final String nsUri = reader.getNamespaceURI(); if (nsUri == null) { throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(reader.getLocalName())); } else { return Edm.NAMESPACE_D_2007_08.equals(nsUri); } }
Example 17
Source File: XmlEntryConsumer.java From olingo-odata2 with Apache License 2.0 | 3 votes |
/** * Checks if property of currently read tag in {@link XMLStreamReader} is defined in * <code>edm properties namespace</code> {@value Edm#NAMESPACE_D_2007_08}. * * If no namespace uri definition is found for namespace prefix of property (<code>tag</code>) an exception is thrown. * * @param reader {@link XMLStreamReader} with position at to checked tag * @return <code>true</code> if property is in <code>edm properties namespace</code>, otherwise <code>false</code>. * @throws EntityProviderException If no namespace uri definition is found for namespace prefix of property * (<code>tag</code>). */ private boolean isEdmNamespaceProperty(final XMLStreamReader reader) throws EntityProviderException { final String nsUri = reader.getNamespaceURI(); if (nsUri == null) { throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(reader.getLocalName())); } else { return Edm.NAMESPACE_D_2007_08.equals(nsUri); } }
Example 18
Source File: XmlEntryDeserializer.java From olingo-odata2 with Apache License 2.0 | 3 votes |
/** * Checks if property of currently read tag in {@link XMLStreamReader} is defined in * <code>edm properties namespace</code> {@value Edm#NAMESPACE_D_2007_08}. * * If no namespace uri definition is found for namespace prefix of property (<code>tag</code>) an exception is thrown. * * @param reader {@link XMLStreamReader} with position at to checked tag * @return <code>true</code> if property is in <code>edm properties namespace</code>, otherwise <code>false</code>. * @throws EntityProviderException If no namespace uri definition is found for namespace prefix of property * (<code>tag</code>). */ private boolean isEdmNamespaceProperty(final XMLStreamReader reader) throws EntityProviderException { final String nsUri = reader.getNamespaceURI(); if (nsUri == null) { throw new EntityProviderException(EntityProviderException.INVALID_NAMESPACE.addContent(reader.getLocalName())); } else { return Edm.NAMESPACE_D_2007_08.equals(nsUri); } }
Example 19
Source File: StreamHeader.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Creates a {@link StreamHeader}. * * @param reader * The parser that points to the start tag of the header. * By the end of this method, the parser will point at * the end tag of this element. */ protected StreamHeader(XMLStreamReader reader) throws XMLStreamException { _localName = reader.getLocalName(); _namespaceURI = reader.getNamespaceURI(); attributes = processHeaderAttributes(reader); // cache the body _mark = XMLStreamBuffer.createNewBufferFromXMLStreamReader(reader); }
Example 20
Source File: StreamHeader.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Creates a {@link StreamHeader}. * * @param reader * The parser that points to the start tag of the header. * By the end of this method, the parser will point at * the end tag of this element. */ protected StreamHeader(XMLStreamReader reader) throws XMLStreamException { _localName = reader.getLocalName(); _namespaceURI = reader.getNamespaceURI(); attributes = processHeaderAttributes(reader); // cache the body _mark = XMLStreamBuffer.createNewBufferFromXMLStreamReader(reader); }