Top Fields Constructors Methods
org.codehaus.jettison.badgerfish

public Class BadgerFishXMLStreamReader

extends AbstractXMLStreamReader
Class Inheritance
Imports
javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLStreamException, org.codehaus.jettison.AbstractXMLStreamReader, .Node, org.codehaus.jettison.json.JSONArray, .JSONException, .JSONObject, org.codehaus.jettison.util.FastStack

Field Summary

Modifier and TypeField and Description
private static final BadgerFishConvention
private String
private FastStack
Inherited from org.codehaus.jettison.AbstractXMLStreamReader:
eventnode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements javax.xml.stream.XMLStreamReader.close.

Frees any resources associated with this Reader.
public String
getAttributeType(int
the position of the attribute
arg0
)

Overrides org.codehaus.jettison.AbstractXMLStreamReader.getAttributeType.

Implements javax.xml.stream.XMLStreamReader.getAttributeType.

Returns the XML type of the attribute at the provided index
public String
getCharacterEncodingScheme()

Overrides org.codehaus.jettison.AbstractXMLStreamReader.getCharacterEncodingScheme.

Implements javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Returns the character encoding declared on the xml declaration Returns null if none was declared
public String
getElementText()

Implements javax.xml.stream.XMLStreamReader.getElementText.

Reads the content of a text-only element, an exception is thrown if this is not a text-only element.
public NamespaceContext
getNamespaceContext()

Implements javax.xml.stream.XMLStreamReader.getNamespaceContext.

Returns a read only namespace context for the current position.
public String
getText()

Implements javax.xml.stream.XMLStreamReader.getText.

Returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD.
public int
next()

Implements javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks.
private void
private void
processKey(String nextKey, Object newObj)

Inherited from org.codehaus.jettison.AbstractXMLStreamReader:
getAttributeCountgetAttributeLocalNamegetAttributeNamegetAttributeNamespacegetAttributePrefixgetAttributeValuegetAttributeValuegetEncodinggetEventTypegetLocalNamegetLocationgetNamegetNamespaceCountgetNamespacePrefixgetNamespaceURIgetNamespaceURIgetNamespaceURIgetPIDatagetPITargetgetPrefixgetPropertygetTextCharactersgetTextCharactersgetTextLengthgetTextStartgetVersionhasNamehasNexthasTextisAttributeSpecifiedisCharactersisEndElementisStandaloneisStartElementisWhiteSpacenextTagrequirestandaloneSet

Field Detail

CONVENTIONback to summary
private static final BadgerFishConvention CONVENTION
currentTextback to summary
private String currentText
nodesback to summary
private FastStack nodes

Constructor Detail

BadgerFishXMLStreamReaderback to summary
public BadgerFishXMLStreamReader(JSONObject obj) throws JSONException, XMLStreamException

Method Detail

closeback to summary
public void close() throws XMLStreamException

Implements javax.xml.stream.XMLStreamReader.close.

Doc from javax.xml.stream.XMLStreamReader.close.

Frees any resources associated with this Reader. This method does not close the underlying input source.

Exceptions
XMLStreamException:
if there are errors freeing associated resources
getAttributeTypeback to summary
public String getAttributeType(int arg0)

Overrides org.codehaus.jettison.AbstractXMLStreamReader.getAttributeType.

Implements javax.xml.stream.XMLStreamReader.getAttributeType.

Doc from javax.xml.stream.XMLStreamReader.getAttributeType.

Returns the XML type of the attribute at the provided index

Parameters
arg0:int

the position of the attribute

Returns:String

the XML type of the attribute

getCharacterEncodingSchemeback to summary
public String getCharacterEncodingScheme()

Overrides org.codehaus.jettison.AbstractXMLStreamReader.getCharacterEncodingScheme.

Implements javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Doc from javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Returns the character encoding declared on the xml declaration Returns null if none was declared

Returns:String

the encoding declared in the document or null

getElementTextback to summary
public String getElementText() throws XMLStreamException

Implements javax.xml.stream.XMLStreamReader.getElementText.

Doc from javax.xml.stream.XMLStreamReader.getElementText.

Reads the content of a text-only element, an exception is thrown if this is not a text-only element. Regardless of value of javax.xml.stream.isCoalescing this method always returns coalesced content.
Precondition: the current event is START_ELEMENT.
Postcondition: the current event is the corresponding END_ELEMENT.
The method does the following (implementations are free to optimized but must do equivalent processing):

if(getEventType() != XMLStreamConstants.START_ELEMENT) {
    throw new XMLStreamException(
    "parser must be on START_ELEMENT to read next text", getLocation());
}

int eventType = next();
StringBuffer content = new StringBuffer();
while(eventType != XMLStreamConstants.END_ELEMENT) {
    if(eventType == XMLStreamConstants.CHARACTERS
       || eventType == XMLStreamConstants.CDATA
       || eventType == XMLStreamConstants.SPACE
       || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
          buf.append(getText());
    } else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
              || eventType == XMLStreamConstants.COMMENT) {
        // skipping
    } else if(eventType == XMLStreamConstants.END_DOCUMENT) {
        throw new XMLStreamException(
        "unexpected end of document when reading element text content", this);
    } else if(eventType == XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException(
        "element text content may not contain START_ELEMENT", getLocation());
    } else {
        throw new XMLStreamException(
        "Unexpected event type "+eventType, getLocation());
    }
    eventType = next();
}
return buf.toString();
Returns:String

the content of a text-only element

Exceptions
XMLStreamException:
if the current event is not a START_ELEMENT or if a non text element is encountered
getNamespaceContextback to summary
public NamespaceContext getNamespaceContext()

Implements javax.xml.stream.XMLStreamReader.getNamespaceContext.

Doc from javax.xml.stream.XMLStreamReader.getNamespaceContext.

Returns a read only namespace context for the current position. The context is transient and only valid until a call to next() changes the state of the reader.

Returns:NamespaceContext

return a namespace context

getTextback to summary
public String getText()

Implements javax.xml.stream.XMLStreamReader.getText.

Doc from javax.xml.stream.XMLStreamReader.getText.

Returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved, any character data will be reported as CHARACTERS events.

Returns:String

the current text or null

nextback to summary
public int next() throws XMLStreamException

Implements javax.xml.stream.XMLStreamReader.next.

Doc from javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks. If the property javax.xml.stream.isCoalescing is set to true element content must be coalesced and only one CHARACTERS event must be returned for contiguous element content or CDATA Sections. By default entity references must be expanded and reported transparently to the application. An exception will be thrown if an entity reference cannot be expanded. If element content is empty (i.e. content is "") then no CHARACTERS event will be reported.

Given the following XML:
<foo><!--description-->content text<![CDATA[<greeting>Hello>/greeting>]]>other content>/foo>
The behavior of calling next() when being on foo will be:
1- the comment (COMMENT)
2- then the characters section (CHARACTERS)
3- then the CDATA section (another CHARACTERS)
4- then the next characters section (another CHARACTERS)
5- then the END_ELEMENT

Note

empty element (such as <tag/>) will be reported with two separate events: START_ELEMENT, END_ELEMENT - This preserves parsing equivalency of empty element to <tag></tag>.

Returns:int

the integer code corresponding to the current parse event

Exceptions
XMLStreamException:
if there is an error processing the underlying XML source
processElementback to summary
private void processElement() throws XMLStreamException
processKeyback to summary
private void processKey(String nextKey, Object newObj) throws JSONException, XMLStreamException