public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); }
private final int _initStartElement() throws XMLStreamException { _nextAttributeIndex = 0; _attributeCount = _xmlReader.getAttributeCount(); _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); return (_currentState = XML_START_ELEMENT); }
public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); }
public XmlTokenStream(XMLStreamReader xmlReader, Object sourceRef, int formatFeatures) { _sourceReference = sourceRef; // Let's ensure we point to START_ELEMENT... if (xmlReader.getEventType() != XMLStreamConstants.START_ELEMENT) { throw new IllegalArgumentException("Invalid XMLStreamReader passed: should be pointing to START_ELEMENT (" +XMLStreamConstants.START_ELEMENT+"), instead got "+xmlReader.getEventType()); } _xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader); _currentState = XML_START_ELEMENT; _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = _xmlReader.getAttributeCount(); _formatFeatures = formatFeatures; }
/** * Method for accessing namespace URI of the START_ELEMENT this * cursor points to. * * @return Namespace URI of currently pointed-to START_ELEMENT, * if it has one; "" if none * * @throws XMLStreamException if cursor does not point to START_ELEMENT */ public String getNsUri() throws XMLStreamException { if (!readerAccessible()) { throw _notAccessible("getNsUri"); } String uri = _streamReader.getNamespaceURI(); // some impls may return null instead, let's convert return (uri == null) ? "" : uri; }
/** * Method for accessing namespace URI of the START_ELEMENT this * cursor points to. * * @return Namespace URI of currently pointed-to START_ELEMENT, * if it has one; "" if none * * @throws XMLStreamException if cursor does not point to START_ELEMENT */ public String getNsUri() throws XMLStreamException { if (!readerAccessible()) { throw _notAccessible("getNsUri"); } String uri = _streamReader.getNamespaceURI(); // some impls may return null instead, let's convert return (uri == null) ? "" : uri; }
public void writeStartElement(XMLStreamReader2 reader, XMLStreamWriter2 writer) throws XMLStreamException { String uri = reader.getNamespaceURI(); String prefix = reader.getPrefix(); String local = reader.getLocalName(); writer.writeStartElement(prefix, local, uri); // Write out the namespaces for (int i = 0; i < reader.getNamespaceCount(); i++) { String nsURI = reader.getNamespaceURI(i); String nsPrefix = reader.getNamespacePrefix(i); writer.writeNamespace(nsPrefix, nsURI); } }
_namespaceURI = _xmlReader.getNamespaceURI(); if (_currentWrapper != null) { _currentWrapper = _currentWrapper.getParent();
_namespaceURI = _xmlReader.getNamespaceURI(); if (_currentWrapper != null) { _currentWrapper = _currentWrapper.getParent();
protected String convertToString() throws XMLStreamException { // only applicable to cases where START_OBJECT was induced by attributes if (_currentState != XML_ATTRIBUTE_NAME || _nextAttributeIndex != 0) { return null; } String text = _collectUntilTag(); // 23-Dec-2015, tatu: Used to require text not to be null, but as per // [dataformat-xml#167], empty tag does count if (_xmlReader.getEventType() == XMLStreamReader.END_ELEMENT) { if (text == null) { text = ""; } if (_currentWrapper != null) { _currentWrapper = _currentWrapper.getParent(); } // just for diagnostics, reset to element name (from first attribute name) _localName = _xmlReader.getLocalName(); _namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = 0; _currentState = XML_TEXT; _textValue = text; return text; } // Anything to do in failed case? Roll back whatever we found or.. ? return null; }
case XMLStreamConstants.END_ELEMENT: ln = _streamReader.getLocalName(); uri = _streamReader.getNamespaceURI(); break;
case XMLStreamConstants.END_ELEMENT: ln = _streamReader.getLocalName(); uri = _streamReader.getNamespaceURI(); break;
/** * Method cursor calls when it needs to track element state information; * if so, it calls this method to take a snapshot of the element. *<p> * Note caller already suppresses calls so that this method is only * called when information needs to be preserved. Further, previous * element is only passed if such linkage is to be preserved (reason * for not always doing it is the increased memory usage). *<p> * Finally, note that this method does NOT implement * {@link ElementInfoFactory}, as its signature does not include the * cursor argument, as that's passed as this pointer already. */ protected SMElementInfo constructElementInfo(SMElementInfo parent, SMElementInfo prevSibling) throws XMLStreamException { if (mElemInfoFactory != null) { return mElemInfoFactory.constructElementInfo(this, parent, prevSibling); } XMLStreamReader2 sr = _streamReader; return new DefaultElementInfo(parent, prevSibling, sr.getPrefix(), sr.getNamespaceURI(), sr.getLocalName(), _nodeCount-1, _elemCount-1, getParentCount()); }
/** * Method cursor calls when it needs to track element state information; * if so, it calls this method to take a snapshot of the element. *<p> * Note caller already suppresses calls so that this method is only * called when information needs to be preserved. Further, previous * element is only passed if such linkage is to be preserved (reason * for not always doing it is the increased memory usage). *<p> * Finally, note that this method does NOT implement * {@link ElementInfoFactory}, as its signature does not include the * cursor argument, as that's passed as this pointer already. */ protected SMElementInfo constructElementInfo(SMElementInfo parent, SMElementInfo prevSibling) throws XMLStreamException { if (mElemInfoFactory != null) { return mElemInfoFactory.constructElementInfo(this, parent, prevSibling); } XMLStreamReader2 sr = _streamReader; return new DefaultElementInfo(parent, prevSibling, sr.getPrefix(), sr.getNamespaceURI(), sr.getLocalName(), _nodeCount-1, _elemCount-1, getParentCount()); }
_namespaceURI = _xmlReader.getNamespaceURI(); _attributeCount = 0; _currentState = XML_TEXT;
newElem = doc.createElementNS(sr.getNamespaceURI(), qname); } else { // if non-ns-aware, things are simpler: newElem = doc.createElement(ln); qname = recycler.getQualified("xmlns", prefix); newElem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, qname, sr.getNamespaceURI(i));
newElem = doc.createElementNS(sr.getNamespaceURI(), qname); } else { // if non-ns-aware, things are simpler: newElem = doc.createElement(ln); qname = recycler.getQualified("xmlns", prefix); newElem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, qname, sr.getNamespaceURI(i));
private final int _initStartElement() throws XMLStreamException final String ns = _xmlReader.getNamespaceURI(); final String localName = _xmlReader.getLocalName(); _attributeCount = _xmlReader.getAttributeCount();
private final int _initStartElement() throws XMLStreamException final String ns = _xmlReader.getNamespaceURI(); final String localName = _xmlReader.getLocalName(); _attributeCount = _xmlReader.getAttributeCount();