Methods Summary |
---|
public int | getColumnNumber() return pp.getColumnNumber();
|
public org.xml.sax.ContentHandler | getContentHandler() return contentHandler;
|
public org.xml.sax.DTDHandler | getDTDHandler() return null;
|
public org.xml.sax.EntityResolver | getEntityResolver() return null;
|
public org.xml.sax.ErrorHandler | getErrorHandler() return errorHandler;
|
public boolean | getFeature(java.lang.String name)
if(NAMESPACES_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
} else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES);
} else if(VALIDATION_FEATURE.equals(name)) {
return pp.getFeature(XmlPullParser.FEATURE_VALIDATION);
// } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) {
// return false; //TODO
// } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) {
// return false; //TODO
} else {
return pp.getFeature(name);
//throw new SAXNotRecognizedException("unrecognized feature "+name);
}
|
public int | getIndex(java.lang.String qName)
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeName(i).equals(qName))
{
return i;
}
}
return -1;
|
public int | getIndex(java.lang.String uri, java.lang.String localName)
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeNamespace(i).equals(uri)
&& pp.getAttributeName(i).equals(localName))
{
return i;
}
}
return -1;
|
public int | getLength() return pp.getAttributeCount();
|
public int | getLineNumber() return pp.getLineNumber();
|
public java.lang.String | getLocalName(int index) return pp.getAttributeName(index);
|
public java.lang.Object | getProperty(java.lang.String name)
if(DECLARATION_HANDLER_PROPERTY.equals(name)) {
return null;
} else if(LEXICAL_HANDLER_PROPERTY.equals(name)) {
return null;
} else {
return pp.getProperty(name);
//throw new SAXNotRecognizedException("not recognized get property "+name);
}
|
public java.lang.String | getPublicId() return null;
|
public java.lang.String | getQName(int index)
final String prefix = pp.getAttributePrefix(index);
if(prefix != null) {
return prefix+':"+pp.getAttributeName(index);
} else {
return pp.getAttributeName(index);
}
|
public java.lang.String | getSystemId() return systemId;
|
public java.lang.String | getType(java.lang.String uri, java.lang.String localName)
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeNamespace(i).equals(uri)
&& pp.getAttributeName(i).equals(localName))
{
return pp.getAttributeType(i);
}
}
return null;
|
public java.lang.String | getType(java.lang.String qName)
for (int i = 0; i < pp.getAttributeCount(); i++)
{
if(pp.getAttributeName(i).equals(qName))
{
return pp.getAttributeType(i);
}
}
return null;
|
public java.lang.String | getType(int index) return pp.getAttributeType(index);
|
public java.lang.String | getURI(int index) return pp.getAttributeNamespace(index);
|
public java.lang.String | getValue(java.lang.String uri, java.lang.String localName)
return pp.getAttributeValue(uri, localName);
|
public java.lang.String | getValue(java.lang.String qName)
return pp.getAttributeValue(null, qName);
|
public java.lang.String | getValue(int index) return pp.getAttributeValue(index);
|
public void | parse(org.xml.sax.InputSource source)
systemId = source.getSystemId();
contentHandler.setDocumentLocator(this);
final Reader reader = source.getCharacterStream();
try {
if (reader == null) {
InputStream stream = source.getByteStream();
final String encoding = source.getEncoding();
if (stream == null) {
systemId = source.getSystemId();
if(systemId == null) {
SAXParseException saxException = new SAXParseException(
"null source systemId" , this);
errorHandler.fatalError(saxException);
return;
}
// NOTE: replace with Connection to run in J2ME environment
try {
final URL url = new URL(systemId);
stream = url.openStream();
} catch (MalformedURLException nue) {
try {
stream = new FileInputStream(systemId);
} catch (FileNotFoundException fnfe) {
final SAXParseException saxException = new SAXParseException(
"could not open file with systemId "+systemId, this, fnfe);
errorHandler.fatalError(saxException);
return;
}
}
}
pp.setInput(stream, encoding);
} else {
pp.setInput(reader);
}
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException(
"parsing initialization error: "+ex, this, ex);
//if(DEBUG) ex.printStackTrace();
errorHandler.fatalError(saxException);
return;
}
// start parsing - move to first start tag
try {
contentHandler.startDocument();
// get first event
pp.next();
// it should be start tag...
if(pp.getEventType() != XmlPullParser.START_TAG) {
final SAXParseException saxException = new SAXParseException(
"expected start tag not"+pp.getPositionDescription(), this);
//throw saxException;
errorHandler.fatalError(saxException);
return;
}
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException(
"parsing initialization error: "+ex, this, ex);
//ex.printStackTrace();
errorHandler.fatalError(saxException);
return;
}
// now real parsing can start!
parseSubTree(pp);
// and finished ...
contentHandler.endDocument();
|
public void | parse(java.lang.String systemId)
parse(new InputSource(systemId));
|
public void | parseSubTree(org.xmlpull.v1.XmlPullParser pp)
this.pp = pp;
final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES);
try {
if(pp.getEventType() != XmlPullParser.START_TAG) {
throw new SAXException(
"start tag must be read before skiping subtree"+pp.getPositionDescription());
}
final int[] holderForStartAndLength = new int[2];
final StringBuffer rawName = new StringBuffer(16);
String prefix = null;
String name = null;
int level = pp.getDepth() - 1;
int type = XmlPullParser.START_TAG;
LOOP:
do {
switch(type) {
case XmlPullParser.START_TAG:
if(namespaceAware) {
final int depth = pp.getDepth() - 1;
final int countPrev =
(level > depth) ? pp.getNamespaceCount(depth) : 0;
//int countPrev = pp.getNamespaceCount(pp.getDepth() - 1);
final int count = pp.getNamespaceCount(depth + 1);
for (int i = countPrev; i < count; i++)
{
contentHandler.startPrefixMapping(
pp.getNamespacePrefix(i),
pp.getNamespaceUri(i)
);
}
name = pp.getName();
prefix = pp.getPrefix();
if(prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':");
rawName.append(name);
}
startElement(pp.getNamespace(),
name,
// TODO Fixed this. Was "not equals".
prefix == null ? name : rawName.toString());
} else {
startElement(pp.getNamespace(),
pp.getName(),
pp.getName());
}
//++level;
break;
case XmlPullParser.TEXT:
final char[] chars = pp.getTextCharacters(holderForStartAndLength);
contentHandler.characters(chars,
holderForStartAndLength[0], //start
holderForStartAndLength[1] //len
);
break;
case XmlPullParser.END_TAG:
//--level;
if(namespaceAware) {
name = pp.getName();
prefix = pp.getPrefix();
if(prefix != null) {
rawName.setLength(0);
rawName.append(prefix);
rawName.append(':");
rawName.append(name);
}
contentHandler.endElement(pp.getNamespace(),
name,
prefix != null ? name : rawName.toString()
);
// when entering show prefixes for all levels!!!!
final int depth = pp.getDepth();
final int countPrev =
(level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0;
int count = pp.getNamespaceCount(pp.getDepth() - 1);
// undeclare them in reverse order
for (int i = count - 1; i >= countPrev; i--)
{
contentHandler.endPrefixMapping(
pp.getNamespacePrefix(i)
);
}
} else {
contentHandler.endElement(pp.getNamespace(),
pp.getName(),
pp.getName()
);
}
break;
case XmlPullParser.END_DOCUMENT:
break LOOP;
}
type = pp.next();
} while(pp.getDepth() > level);
} catch (XmlPullParserException ex) {
final SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex);
ex.printStackTrace();
errorHandler.fatalError(saxException);
}
|
public void | setContentHandler(org.xml.sax.ContentHandler handler)
this.contentHandler = handler;
|
public void | setDTDHandler(org.xml.sax.DTDHandler handler)
|
public void | setEntityResolver(org.xml.sax.EntityResolver resolver)
|
public void | setErrorHandler(org.xml.sax.ErrorHandler handler)
this.errorHandler = handler;
|
public void | setFeature(java.lang.String name, boolean value)
try {
if(NAMESPACES_FEATURE.equals(name)) {
pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, value);
} else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) {
if(pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES) != value) {
pp.setFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, value);
}
} else if(VALIDATION_FEATURE.equals(name)) {
pp.setFeature(XmlPullParser.FEATURE_VALIDATION, value);
// } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) {
// // can ignore as validation must be false ...
// // if(true == value) {
// // throw new SAXNotSupportedException("schema validation is not supported");
// // }
// } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) {
// if(true == value) {
// throw new SAXNotSupportedException("dynamic validation is not supported");
// }
} else {
pp.setFeature(name, value);
//throw new SAXNotRecognizedException("unrecognized feature "+name);
}
} catch(XmlPullParserException ex) {
// throw new SAXNotSupportedException("problem with setting feature "+name+": "+ex);
}
|
public void | setProperty(java.lang.String name, java.lang.Object value)
//
if(DECLARATION_HANDLER_PROPERTY.equals(name)) {
throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value);
} else if(LEXICAL_HANDLER_PROPERTY.equals(name)) {
throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value);
} else {
try {
pp.setProperty(name, value);
} catch(XmlPullParserException ex) {
throw new SAXNotSupportedException("not supported set property "+name+": "+ ex);
}
//throw new SAXNotRecognizedException("not recognized set property "+name);
}
|
protected void | startElement(java.lang.String namespace, java.lang.String localName, java.lang.String qName)Calls {@link ContentHandler#startElement(String, String, String, Attributes) startElement}
on the ContentHandler with this driver object as the
{@link Attributes} implementation. In default implementation
{@link Attributes} object is valid only during this method call and may not
be stored. Sub-classes can overwrite this method to cache attributes.
contentHandler.startElement(namespace, localName, qName, this);
|