Methods Summary |
---|
public boolean | canReuse()This function tells if this instances is available for reuse.
One must call reset() and setInputSource() to be able to reuse
this instance.
if(DEBUG){
System.out.println("fReuse = " + fReuse);
System.out.println("fEventType = " + getEventTypeString(fEventType) );
}
//when parsing begins, fReuse is set to false
//fReuse is set to 'true' when application calls close()
return fReuse;
|
public void | close()Frees any resources associated with this Reader. This method does not close the underlying input source.
//xxx: Check what this function is intended to do.
//reset();
fReuse = true ;
|
public javax.xml.namespace.QName | convertXNIQNametoJavaxQName(com.sun.org.apache.xerces.internal.xni.QName qname)
//xxx: prefix definition ?
if(qname.prefix == null){
return new javax.xml.namespace.QName(qname.uri, qname.localpart) ;
} else{
return new javax.xml.namespace.QName(qname.uri, qname.localpart, qname.prefix) ;
}
|
public int | getAttributeCount()Returns the count of attributes on this START_ELEMENT,
this method is only valid on a START_ELEMENT or ATTRIBUTE. This
count excludes namespace definitions. Attribute indices are
zero-based.
//xxx: recognize SAX properties namespace, namespace-prefix to get XML Namespace declarations
//does length includes namespace declarations ?
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getLength() ;
} else{
throw new java.lang.IllegalStateException( "Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeCount()") ;
}
|
public java.lang.String | getAttributeLocalName(int index)
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getLocalName(index) ;
} else{
throw new java.lang.IllegalStateException() ;
}
|
public javax.xml.namespace.QName | getAttributeName(int index)Returns the localName of the attribute at the provided
index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return convertXNIQNametoJavaxQName(fScanner.getAttributeIterator().getQualifiedName(index)) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeName()") ;
}
|
public java.lang.String | getAttributeNamespace(int index)Returns the namespace of the attribute at the provided
index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getURI(index);
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeNamespace()") ;
}
|
public java.lang.String | getAttributePrefix(int index)Returns the prefix of this attribute at the
provided index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getPrefix(index);
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributePrefix()") ;
}
|
public javax.xml.namespace.QName | getAttributeQName(int index)Returns the qname of the attribute at the provided index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
// create new object at runtime..
String localName = fScanner.getAttributeIterator().getLocalName(index) ;
String uri = fScanner.getAttributeIterator().getURI(index) ;
return new javax.xml.namespace.QName(uri, localName) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeQName()") ;
}
|
public java.lang.String | getAttributeType(int index)Returns the XML type of the attribute at the provided
index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getType(index) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeType()") ;
}
|
public java.lang.String | getAttributeValue(int index)Returns the value of the attribute at the
index
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getValue(index) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()") ;
}
|
public java.lang.String | getAttributeValue(java.lang.String namespaceURI, java.lang.String localName)
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getValue(namespaceURI, localName) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()") ;
}
|
public java.lang.String | getCharacterEncodingScheme()Returns the character encoding declared on the xml declaration Returns null if none was declared
return fScanner.getCharacterEncodingScheme();
|
public int | getColumnNumber()
return fEntityScanner.getColumnNumber();
|
public java.lang.String | getElementText()Reads the content of a text-only element. Precondition:
the current event is START_ELEMENT. Postcondition:
The current event is the corresponding END_ELEMENT.
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) {
content.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");
} else if(eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"elementGetText() function expects text only elment but START_ELEMENT was encountered.", getLocation());
} else {
throw new XMLStreamException(
"Unexpected event type "+ eventType, getLocation());
}
eventType = next();
}
return content.toString();
|
public java.lang.String | getEncoding()Return input encoding if known or null if unknown.
return fEntityScanner.getEncoding();
|
protected java.util.List | getEntityDecls()
if(fEventType == XMLStreamConstants.DTD){
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
Hashtable ht = entityStore.getDeclaredEntities();
ArrayList list = null;
if(ht != null){
EntityDeclarationImpl decl = null;
list = new ArrayList(ht.size());
Enumeration enu = ht.keys();
while(enu.hasMoreElements()){
String key = (String)enu.nextElement();
Entity en = (Entity)ht.get(key);
decl = new EntityDeclarationImpl();
decl.setEntityName(key);
if(en.isExternal()){
decl.setXMLResourceIdentifier(((Entity.ExternalEntity)en).entityLocation);
decl.setNotationName(((Entity.ExternalEntity)en).notation);
}
else
decl.setEntityReplacementText(((Entity.InternalEntity)en).text);
list.add(decl);
}
}
return list;
}
return null;
|
public int | getEventType()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.
return fEventType ;
|
static final java.lang.String | getEventTypeString(int eventType)
switch (eventType){
case XMLEvent.START_ELEMENT:
return "START_ELEMENT";
case XMLEvent.END_ELEMENT:
return "END_ELEMENT";
case XMLEvent.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLEvent.CHARACTERS:
return "CHARACTERS";
case XMLEvent.COMMENT:
return "COMMENT";
case XMLEvent.START_DOCUMENT:
return "START_DOCUMENT";
case XMLEvent.END_DOCUMENT:
return "END_DOCUMENT";
case XMLEvent.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLEvent.ATTRIBUTE:
return "ATTRIBUTE";
case XMLEvent.DTD:
return "DTD";
case XMLEvent.CDATA:
return "CDATA";
case XMLEvent.SPACE:
return "SPACE";
}
return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType);
|
public int | getLineNumber()
return fEntityScanner.getLineNumber() ;
|
public java.lang.String | getLocalName()For START_ELEMENT or END_ELEMENT returns the (local) name of the current element. For ENTITY_REF it returns entity name. For
PROCESSING_INSTRUCTION it returns the target. The current event must be START_ELEMENT or END_ELEMENT, PROCESSING_INSTRUCTION, or
ENTITY_REF, otherwise null is returned.
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
//xxx check whats the value of fCurrentElement
return fScanner.getElementQName().localpart ;
}
else if(fEventType == XMLEvent.PROCESSING_INSTRUCTION){
return fScanner.getPITarget();
}
else if(fEventType == XMLEvent.ENTITY_REFERENCE){
return fScanner.getEntityName();
}
return null;
|
public javax.xml.stream.Location | getLocation()Return the current location of the processor.
If the Location is unknown the processor should return
an implementation of Location that returns -1 for the
location and null for the publicId and systemId.
The location information is only valid until next() is
called.
return new Location() {
public String getLocationURI(){
return fEntityScanner.getExpandedSystemId();
}
public int getCharacterOffset(){
return fEntityScanner.getCharacterOffset();
}
public int getColumnNumber() {
return fEntityScanner.getColumnNumber();
}
public int getLineNumber(){
return fEntityScanner.getLineNumber();
}
public String getPublicId(){
return fEntityScanner.getPublicId();
}
public String getSystemId(){
return fEntityScanner.getExpandedSystemId();
}
public String toString(){
StringBuffer sbuffer = new StringBuffer() ;
sbuffer.append("Line number = " + getLineNumber());
sbuffer.append("\n") ;
sbuffer.append("Column number = " + getColumnNumber());
sbuffer.append("\n") ;
sbuffer.append("System Id = " + getSystemId());
sbuffer.append("\n") ;
sbuffer.append("Public Id = " + getPublicId());
sbuffer.append("\n") ;
sbuffer.append("Location Uri= " + getLocationURI());
sbuffer.append("\n") ;
sbuffer.append("CharacterOffset = " + getCharacterOffset());
sbuffer.append("\n") ;
return sbuffer.toString();
}
} ;
|
public javax.xml.namespace.QName | getName()Returns a QName for the current START_ELEMENT or END_ELEMENT event
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT)
return convertXNIQNametoJavaxQName(fScanner.getElementQName());
else
throw new java.lang.IllegalArgumentException("Illegal to call getName() "+
"when event type is "+ getEventTypeString(fEventType) + "."
+ " Valid states are " + getEventTypeString(XMLEvent.START_ELEMENT) + ", "
+ getEventTypeString(XMLEvent.END_ELEMENT));
|
public javax.xml.namespace.NamespaceContext | 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.
return fNamespaceContextWrapper ;
|
public int | getNamespaceCount()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.
//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()." );
}
|
public java.lang.String | getNamespacePrefix(int index)Returns the prefix for the namespace declared at the
index. Returns null if this is the default namespace
declaration
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()." );
}
|
public java.lang.String | getNamespaceURI()
//doesn't take care of Attribute as separte event
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
return fScanner.getElementQName().uri ;
}
return null ;
|
public java.lang.String | getNamespaceURI(int index)Returns the uri for the namespace declared at the
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()." );
}
|
public java.lang.String | getNamespaceURI(java.lang.String prefix)Return the uri for the given prefix.
The uri returned depends on the current state of the processor.
NOTE:The 'xml' prefix is bound as defined in
Namespaces in XML
specification to "http://www.w3.org/XML/1998/namespace".
NOTE: The 'xmlns' prefix must be resolved to following namespace
http://www.w3.org/2000/xmlns/
//first add the string to symbol table.. since internally identity comparisons are done.
return fScanner.getNamespaceContext().getURI(fSymbolTable.addSymbol(prefix)) ;
|
protected java.util.List | getNotationDecls()
if(fEventType == XMLStreamConstants.DTD){
if(fScanner.fDTDScanner == null) return null;
DTDGrammar grammar = ((XMLDTDScannerImpl)(fScanner.fDTDScanner)).getGrammar();
if(grammar == null) return null;
List notations = grammar.getNotationDecls();
Iterator it = notations.iterator();
ArrayList list = new ArrayList();
while(it.hasNext()){
XMLNotationDecl ni = (XMLNotationDecl)it.next();
if(ni!= null){
list.add(new NotationDeclarationImpl(ni));
}
}
return list;
}
return null;
|
public java.lang.String | getPIData()Get the data section of a processing instruction
if( fEventType == XMLEvent.PROCESSING_INSTRUCTION){
return fScanner.getPIData().toString();
}
else throw new java.lang.IllegalStateException("Current state of the parser is " + getEventTypeString(fEventType) +
" But Expected state is " + XMLEvent.PROCESSING_INSTRUCTION ) ;
|
public java.lang.String | getPITarget()Get the target of a processing instruction
if( fEventType == XMLEvent.PROCESSING_INSTRUCTION){
return fScanner.getPITarget();
}
else throw new java.lang.IllegalStateException("Current state of the parser is " + getEventTypeString(fEventType) +
" But Expected state is " + XMLEvent.PROCESSING_INSTRUCTION ) ;
|
public java.lang.String | getPrefix()
//doesn't take care of Attribute as separte event
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
return fScanner.getElementQName().prefix ;
}
return null ;
|
public java.lang.Object | getProperty(java.lang.String name)Get the value of a feature/property from the underlying implementation
if(name == null) throw new java.lang.IllegalArgumentException() ;
if (fPropertyManager != null ){
if(name.equals(fPropertyManager.STAX_NOTATIONS)){
return getNotationDecls();
}else if(name.equals(fPropertyManager.STAX_ENTITIES)){
return getEntityDecls();
}else
return fPropertyManager.getProperty(name);
}
return null;
|
protected com.sun.org.apache.xerces.internal.impl.PropertyManager | getPropertyManager()
return fPropertyManager ;
|
public com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl | getScanner()
System.out.println("returning scanner");
return fScanner;
|
public java.lang.String | 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,
or the String value of the DTD
if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE){
//this requires creation of new string
//fEventType == XMLEvent.ENTITY_REFERENCE
return fScanner.getCharacterData().toString() ;
} else if(fEventType == XMLEvent.ENTITY_REFERENCE){
String name = fScanner.getEntityName();
if(name != null){
if(fScanner.foundBuiltInRefs)
return fScanner.getCharacterData().toString();
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
Hashtable ht = entityStore.getDeclaredEntities();
Entity en = (Entity)ht.get(name);
if(en == null)
return null;
if(en.isExternal())
return ((Entity.ExternalEntity)en).entityLocation.getExpandedSystemId();
else
return ((Entity.InternalEntity)en).text;
}else
return null;
}
else if(fEventType == XMLEvent.DTD){
if(fDTDDecl != null){
return fDTDDecl;
}
XMLStringBuffer tmpBuffer = fScanner.getDTDDecl();
fDTDDecl = tmpBuffer.toString();
return fDTDDecl;
} else{
throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
+ " is not among the states" + getEventTypeString(XMLEvent.CHARACTERS) + ", "
+ getEventTypeString(XMLEvent.COMMENT) + ", "
+ getEventTypeString(XMLEvent.CDATA) + ", "
+ getEventTypeString(XMLEvent.SPACE) + ", "
+ getEventTypeString(XMLEvent.ENTITY_REFERENCE) + ", "
+ getEventTypeString(XMLEvent.DTD) + " valid for getText() " ) ;
}
|
public char[] | getTextCharacters()
if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE){
return fScanner.getCharacterData().ch;
} else{
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType)
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , "
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA)
+ " , " + getEventTypeString(XMLEvent.SPACE) +" valid for getTextCharacters() " ) ;
}
|
public int | getTextCharacters(int sourceStart, char[] target, int targetStart, int length)Gets the the text associated with a CHARACTERS, SPACE or CDATA event.
Text starting a "sourceStart" is copied into "destination" starting at "targetStart".
Up to "length" characters are copied. The number of characters actually copied is returned.
The "sourceStart" argument must be greater or equal to 0 and less than or equal to
the number of characters associated with the event. Usually, one requests text starting at a "sourceStart" of 0.
If the number of characters actually copied is less than the "length", then there is no more text.
Otherwise, subsequent calls need to be made until all text has been retrieved. For example:
int length = 1024;
char[] myBuffer = new char[ length ];
for ( int sourceStart = 0 ; ; sourceStart += length )
{
int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length );
if (nCopied < length)
break;
}
XMLStreamException may be thrown if there are any XML errors in the underlying source.
The "targetStart" argument must be greater than or equal to 0 and less than the length of "target",
Length must be greater than 0 and "targetStart + length" must be less than or equal to length of "target".
if(target == null){
throw new NullPointerException("target char array can't be null") ;
}
if(targetStart < 0 || length < 0 || sourceStart < 0 || targetStart >= target.length ||
(targetStart + length ) > target.length) {
throw new IndexOutOfBoundsException();
}
//getTextStart() + sourceStart should not be greater than the lenght of number of characters
//present
int copiedLength = 0;
//int presentDataLen = getTextLength() - (getTextStart()+sourceStart);
int available = getTextLength() - sourceStart;
if(available < 0){
throw new IndexOutOfBoundsException("sourceStart is greater than" +
"number of characters associated with this event");
}
if(available < length){
copiedLength = available;
} else{
copiedLength = length;
}
System.arraycopy(getTextCharacters(), getTextStart() + sourceStart , target, targetStart, copiedLength);
return copiedLength;
|
public int | getTextLength()
if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE){
return fScanner.getCharacterData().length;
} else{
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType)
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , "
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA)
+ " , " + getEventTypeString(XMLEvent.SPACE) +" valid for getTextLength() " ) ;
}
|
public int | getTextStart()
if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE){
return fScanner.getCharacterData().offset;
} else{
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType)
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , "
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA)
+ " , " + getEventTypeString(XMLEvent.SPACE) +" valid for getTextStart() " ) ;
}
|
public java.lang.String | getValue()
if(fEventType == XMLEvent.PROCESSING_INSTRUCTION){
return fScanner.getPIData().toString();
} else if(fEventType == XMLEvent.COMMENT){
return fScanner.getComment();
} else if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
return fScanner.getElementQName().localpart ;
} else if(fEventType == XMLEvent.CHARACTERS){
return fScanner.getCharacterData().toString();
}
return null;
|
public java.lang.String | getVersion()Get the XML language version of the current document being parsed
return fEntityScanner.getXMLVersion();
|
public boolean | hasAttributes()
return fScanner.getAttributeIterator().getLength() > 0 ? true : false ;
|
public boolean | hasName()this Funtion returns true if the current event has name
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT
|| fEventType == XMLEvent.ENTITY_REFERENCE || fEventType == XMLEvent.PROCESSING_INSTRUCTION) {
return true;
} else {
return false;
}
|
public boolean | hasNext()
//we can check in scanners if the scanner state is not set to
//terminating, we still have more events.
return fEventType != XMLEvent.END_DOCUMENT;
|
public boolean | hasText()Return true if the current event has text, false otherwise
The following events have text:
CHARACTERS,DTD ,ENTITY_REFERENCE, COMMENT
if(DEBUG) pr("XMLReaderImpl#EVENT TYPE = " + fEventType ) ;
if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CDATA) {
return fScanner.getCharacterData().length > 0 ? true : false;
} else if(fEventType == XMLEvent.ENTITY_REFERENCE) {
String name = fScanner.getEntityName();
if(name != null){
if(fScanner.foundBuiltInRefs)
return true;
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
Hashtable ht = entityStore.getDeclaredEntities();
Entity en =(Entity)ht.get(name);
if(en == null)
return false;
if(en.isExternal()){
return ((Entity.ExternalEntity)en).entityLocation.getExpandedSystemId() != null ? true : false;
} else{
return ((Entity.InternalEntity)en).text != null ? true : false ;
}
}else
return false;
} else {
if(fEventType == XMLEvent.DTD)
return fScanner.fSeenDoctypeDecl;
}
return false;
|
public boolean | hasValue()
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT
|| fEventType == XMLEvent.ENTITY_REFERENCE || fEventType == XMLEvent.PROCESSING_INSTRUCTION
|| fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CHARACTERS) {
return true;
} else {
return false;
}
|
void | init(com.sun.org.apache.xerces.internal.impl.PropertyManager propertyManager)
fPropertyManager = propertyManager;
//set Stax internal properties -- Note that these instances are being created in XMLReaderImpl.
//1.SymbolTable
//2.XMLMessageFormatter
//3.XMLEntityManager
//4. call reset()
//1.
propertyManager.setProperty(SYMBOL_TABLE, fSymbolTable ) ;
//2.
propertyManager.setProperty(ERROR_REPORTER, fErrorReporter ) ;
//3.
propertyManager.setProperty(ENTITY_MANAGER, fEntityManager);
//4.
reset();
|
public boolean | isAttributeSpecified(int index)Returns a boolean which indicates if this
attribute was created by default
//check that current state should be either START_ELEMENT or ATTRIBUTE
if( (fEventType == XMLEvent.START_ELEMENT) || (fEventType == XMLEvent.ATTRIBUTE)){
return fScanner.getAttributeIterator().isSpecified(index) ;
} else{
throw new IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for isAttributeSpecified()") ;
}
|
public boolean | isCharacters()Returns true if the cursor points to a character data event
return fEventType == XMLEvent.CHARACTERS ;
|
public boolean | isEndElement()
return fEventType == XMLEvent.END_ELEMENT;
|
public boolean | isStandalone()
return fScanner.isStandAlone();
|
public boolean | isStartElement()
return fEventType == XMLEvent.START_ELEMENT;
|
public boolean | isWhiteSpace()Returns true if the cursor points to a character data event that consists of all whitespace
Application calling this method needs to cache the value and avoid calling this method again
for the same event.
if(isCharacters() || (fEventType == XMLStreamConstants.CDATA)){
char [] ch = this.getTextCharacters();
final int start = this.getTextStart();
final int end = start + this.getTextLength();
for (int i = start; i < end; i++){
if(!XMLChar.isSpace(ch[i])){
return false;
}
}
return true;
}
return false;
|
public int | next()
try {
fEventType = fScanner.next();
if (versionStr == null) {
versionStr = getVersion();
}
if (fEventType == XMLStreamConstants.START_DOCUMENT
&& versionStr != null
&& versionStr.equals("1.1")) {
switchToXML11Scanner();
}
return fEventType;
} catch (IOException ex) {
// if this error occured trying to resolve the external DTD subset
// and IS_VALIDATING == false, then this is not an XML error
if (fScanner.fScannerState == fScanner.SCANNER_STATE_DTD_EXTERNAL) {
Boolean isValidating = (Boolean) fPropertyManager.getProperty(
XMLInputFactory.IS_VALIDATING);
if (isValidating != null
&& !isValidating.booleanValue()) {
// ignore the error, set scanner to known state
fEventType = XMLEvent.DTD;
fScanner.setScannerState(fScanner.SCANNER_STATE_PROLOG);
fScanner.setDriver(fScanner.fPrologDriver);
if (fDTDDecl == null
|| fDTDDecl.length() == 0) {
fDTDDecl = "<!-- "
+ "Exception scanning External DTD Subset. "
+ "True contents of DTD cannot be determined. "
+ "Processing will continue as XMLInputFactory.IS_VALIDATING == false."
+ " -->";
}
return XMLEvent.DTD;
}
}
// else real error
throw new XMLStreamException(ex.getMessage(), getLocation(), ex);
} catch (XNIException ex) {
throw new XMLStreamException(
ex.getMessage(),
getLocation(),
ex.getException());
}
|
public int | nextTag()Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION)
until a START_ELEMENT or
END_ELEMENT is reached. If other than space characters are
encountered, an exception is thrown. This method should
be used when processing element-only content because
the parser is not able to recognize ignorable whitespace if
then DTD is missing or not interpreted.
int eventType = next();
while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
// skip whitespace
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
) {
eventType = next();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException(
"found: " + getEventTypeString(eventType)
+ ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
+ " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
getLocation());
}
return eventType;
|
static void | pr(java.lang.String str)
System.out.println(str) ;
|
public void | require(int type, java.lang.String namespaceURI, java.lang.String localName)Test if the current event is of the given type and if the namespace and name match the current namespace and name of the current event.
If the namespaceURI is null it is not checked for equality, if the localName is null it is not checked for equality.
if( type != fEventType)
throw new XMLStreamException("Event type " + getEventTypeString(type) + " specified did " +
"not match with current parser event " + getEventTypeString(fEventType));
if( namespaceURI != null && !namespaceURI.equals(getNamespaceURI()) )
throw new XMLStreamException("Namespace URI " + namespaceURI +" specified did not match " +
"with current namespace URI");
if(localName != null && !localName.equals(getLocalName()))
throw new XMLStreamException("LocalName " + localName +" specified did not match with " +
"current local name");
return;
|
public void | reset()Resets this instance so that this instance is ready for reuse.
fReuse = true;
fEventType = 0 ;
//reset entity manager
fEntityManager.reset(fPropertyManager);
//reset the scanner
fScanner.reset(fPropertyManager);
//REVISIT:this is too ugly -- we are getting XMLEntityManager and XMLEntityReader from
//property manager, it should be only XMLEntityManager
fDTDDecl = null;
fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner() ;
//default value for this property is true. However, this should be false when using XMLEventReader... Ugh..
//because XMLEventReader should not have defined state.
fReaderInDefinedState = ((Boolean)fPropertyManager.getProperty(READER_IN_DEFINED_STATE)).booleanValue();
fBindNamespaces = ((Boolean)fPropertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
versionStr = null;
|
public void | setInputSource(com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource inputSource)
//once setInputSource() is called this instance is busy parsing the inputsource supplied
//this instances is free for reuse if parser has reached END_DOCUMENT state or application has
//called close()
fReuse = false;
try{
fScanner.setInputSource(inputSource) ;
//XMLStreamReader should be in defined state
if(fReaderInDefinedState){
fEventType = fScanner.next();
if (versionStr == null)
versionStr = getVersion();
if (fEventType == XMLStreamConstants.START_DOCUMENT && versionStr != null && versionStr.equals("1.1")){
switchToXML11Scanner();
}
}
}catch(java.io.IOException ex){
throw new XMLStreamException(ex);
}
|
protected void | setPropertyManager(com.sun.org.apache.xerces.internal.impl.PropertyManager propertyManager)
fPropertyManager = propertyManager ;
//REVISIT: we were supplying hashmap ealier
fScanner.setProperty("stax-properties",propertyManager);
fScanner.setPropertyManager(propertyManager) ;
|
public boolean | standaloneSet()Checks if standalone was set in the document
//xxx: it requires if the standalone was set in the document ? This is different that if the document
// is standalone
return fScanner.isStandAlone() ;
|
private void | switchToXML11Scanner()
int oldEntityDepth = fScanner.fEntityDepth;
com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext = fScanner.fNamespaceContext;
fScanner = new XML11NSDocumentScannerImpl();
//get the new scanner state to old scanner's previous state
fScanner.reset(fPropertyManager);
fScanner.setPropertyManager(fPropertyManager);
fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner() ;
fEntityManager.fCurrentEntity.mayReadChunks = true;
fScanner.setScannerState(XMLEvent.START_DOCUMENT);
fScanner.fEntityDepth = oldEntityDepth;
fScanner.fNamespaceContext = oldNamespaceContext;
fEventType = fScanner.next();
|