Methods Summary |
---|
public void | characters(char[] ch, int start, int length)Adapter implementation method; do not call.
Adapt a SAX1 characters event.
if (contentHandler != null) {
contentHandler.characters(ch, start, length);
}
|
private void | checkNotParsing(java.lang.String type, java.lang.String name)Throw an exception if we are parsing.
Use this method to detect illegal feature or
property changes.
if (parsing) {
throw new SAXNotSupportedException("Cannot change " +
type + ' " +
name + " while parsing");
}
|
public void | endDocument()Adapter implementation method; do not call.
Adapt a SAX1 end document event.
if (contentHandler != null) {
contentHandler.endDocument();
}
|
public void | endElement(java.lang.String qName)Adapter implementation method; do not call.
Adapt a SAX1 end element event.
// If we're not doing Namespace
// processing, dispatch this quickly.
if (!namespaces) {
if (contentHandler != null) {
contentHandler.endElement("", "", qName.intern());
}
return;
}
// Split the name.
String names[] = processName(qName, false, false);
if (contentHandler != null) {
contentHandler.endElement(names[0], names[1], names[2]);
Enumeration prefixes = nsSupport.getDeclaredPrefixes();
while (prefixes.hasMoreElements()) {
String prefix = (String)prefixes.nextElement();
contentHandler.endPrefixMapping(prefix);
}
}
nsSupport.popContext();
|
public org.xml.sax.ContentHandler | getContentHandler()Return the current content handler.
return contentHandler;
|
public org.xml.sax.DTDHandler | getDTDHandler()Return the current DTD handler.
return dtdHandler;
|
public org.xml.sax.EntityResolver | getEntityResolver()Return the current entity resolver.
return entityResolver;
|
public org.xml.sax.ErrorHandler | getErrorHandler()Return the current error handler.
return errorHandler;
|
public boolean | getFeature(java.lang.String name)Check a parser feature flag.
The only features recognized are namespaces and
namespace-prefixes.
if (name.equals(NAMESPACES)) {
return namespaces;
} else if (name.equals(NAMESPACE_PREFIXES)) {
return prefixes;
} else if (name.equals(XMLNS_URIs)) {
return uris;
} else {
throw new SAXNotRecognizedException("Feature: " + name);
}
|
public java.lang.Object | getProperty(java.lang.String name)Get a parser property.
No properties are currently recognized.
throw new SAXNotRecognizedException("Property: " + name);
|
public void | ignorableWhitespace(char[] ch, int start, int length)Adapter implementation method; do not call.
Adapt a SAX1 ignorable whitespace event.
if (contentHandler != null) {
contentHandler.ignorableWhitespace(ch, start, length);
}
|
private org.xml.sax.SAXParseException | makeException(java.lang.String message)Construct an exception for the current context.
if (locator != null) {
return new SAXParseException(message, locator);
} else {
return new SAXParseException(message, null, null, -1, -1);
}
|
public void | parse(java.lang.String systemId)Parse an XML document.
parse(new InputSource(systemId));
|
public void | parse(org.xml.sax.InputSource input)Parse an XML document.
if (parsing) {
throw new SAXException("Parser is already in use");
}
setupParser();
parsing = true;
try {
parser.parse(input);
} finally {
parsing = false;
}
parsing = false;
|
private java.lang.String[] | processName(java.lang.String qName, boolean isAttribute, boolean useException)Process a qualified (prefixed) name.
If the name has an undeclared prefix, use only the qname
and make an ErrorHandler.error callback in case the app is
interested.
String parts[] = nsSupport.processName(qName, nameParts,
isAttribute);
if (parts == null) {
if (useException)
throw makeException("Undeclared prefix: " + qName);
reportError("Undeclared prefix: " + qName);
parts = new String[3];
parts[0] = parts[1] = "";
parts[2] = qName.intern();
}
return parts;
|
public void | processingInstruction(java.lang.String target, java.lang.String data)Adapter implementation method; do not call.
Adapt a SAX1 processing instruction event.
if (contentHandler != null) {
contentHandler.processingInstruction(target, data);
}
|
void | reportError(java.lang.String message)Report a non-fatal error.
if (errorHandler != null)
errorHandler.error(makeException(message));
|
public void | setContentHandler(org.xml.sax.ContentHandler handler)Set the content handler.
contentHandler = handler;
|
public void | setDTDHandler(org.xml.sax.DTDHandler handler)Set the DTD handler.
dtdHandler = handler;
|
public void | setDocumentLocator(org.xml.sax.Locator locator)Adapter implementation method; do not call.
Adapt a SAX1 document locator event.
this.locator = locator;
if (contentHandler != null) {
contentHandler.setDocumentLocator(locator);
}
|
public void | setEntityResolver(org.xml.sax.EntityResolver resolver)Set the entity resolver.
entityResolver = resolver;
|
public void | setErrorHandler(org.xml.sax.ErrorHandler handler)Set the error handler.
errorHandler = handler;
|
public void | setFeature(java.lang.String name, boolean value)Set a feature flag for the parser.
The only features recognized are namespaces and
namespace-prefixes.
if (name.equals(NAMESPACES)) {
checkNotParsing("feature", name);
namespaces = value;
if (!namespaces && !prefixes) {
prefixes = true;
}
} else if (name.equals(NAMESPACE_PREFIXES)) {
checkNotParsing("feature", name);
prefixes = value;
if (!prefixes && !namespaces) {
namespaces = true;
}
} else if (name.equals(XMLNS_URIs)) {
checkNotParsing("feature", name);
uris = value;
} else {
throw new SAXNotRecognizedException("Feature: " + name);
}
|
public void | setProperty(java.lang.String name, java.lang.Object value)Set a parser property.
No properties are currently recognized.
throw new SAXNotRecognizedException("Property: " + name);
|
private void | setup(org.xml.sax.Parser parser)Internal setup method.
if (parser == null) {
throw new
NullPointerException("Parser argument must not be null");
}
this.parser = parser;
atts = new AttributesImpl();
nsSupport = new NamespaceSupport();
attAdapter = new AttributeListAdapter();
|
private void | setupParser()Initialize the parser before each run.
// catch an illegal "nonsense" state.
if (!prefixes && !namespaces)
throw new IllegalStateException ();
nsSupport.reset();
if (uris)
nsSupport.setNamespaceDeclUris (true);
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
if (dtdHandler != null) {
parser.setDTDHandler(dtdHandler);
}
if (errorHandler != null) {
parser.setErrorHandler(errorHandler);
}
parser.setDocumentHandler(this);
locator = null;
|
public void | startDocument()Adapter implementation method; do not call.
Adapt a SAX1 start document event.
if (contentHandler != null) {
contentHandler.startDocument();
}
|
public void | startElement(java.lang.String qName, org.xml.sax.AttributeList qAtts)Adapter implementation method; do not call.
Adapt a SAX1 startElement event.
If necessary, perform Namespace processing.
// These are exceptions from the
// first pass; they should be
// ignored if there's a second pass,
// but reported otherwise.
Vector exceptions = null;
// If we're not doing Namespace
// processing, dispatch this quickly.
if (!namespaces) {
if (contentHandler != null) {
attAdapter.setAttributeList(qAtts);
contentHandler.startElement("", "", qName.intern(),
attAdapter);
}
return;
}
// OK, we're doing Namespace processing.
nsSupport.pushContext();
int length = qAtts.getLength();
// First pass: handle NS decls
for (int i = 0; i < length; i++) {
String attQName = qAtts.getName(i);
if (!attQName.startsWith("xmlns"))
continue;
// Could be a declaration...
String prefix;
int n = attQName.indexOf(':");
// xmlns=...
if (n == -1 && attQName.length () == 5) {
prefix = "";
} else if (n != 5) {
// XML namespaces spec doesn't discuss "xmlnsf:oo"
// (and similarly named) attributes ... at most, warn
continue;
} else // xmlns:foo=...
prefix = attQName.substring(n+1);
String value = qAtts.getValue(i);
if (!nsSupport.declarePrefix(prefix, value)) {
reportError("Illegal Namespace prefix: " + prefix);
continue;
}
if (contentHandler != null)
contentHandler.startPrefixMapping(prefix, value);
}
// Second pass: copy all relevant
// attributes into the SAX2 AttributeList
// using updated prefix bindings
atts.clear();
for (int i = 0; i < length; i++) {
String attQName = qAtts.getName(i);
String type = qAtts.getType(i);
String value = qAtts.getValue(i);
// Declaration?
if (attQName.startsWith("xmlns")) {
String prefix;
int n = attQName.indexOf(':");
if (n == -1 && attQName.length () == 5) {
prefix = "";
} else if (n != 5) {
// XML namespaces spec doesn't discuss "xmlnsf:oo"
// (and similarly named) attributes ... ignore
prefix = null;
} else {
prefix = attQName.substring(6);
}
// Yes, decl: report or prune
if (prefix != null) {
if (prefixes) {
if (uris)
// note funky case: localname can be null
// when declaring the default prefix, and
// yet the uri isn't null.
atts.addAttribute (nsSupport.XMLNS, prefix,
attQName.intern(), type, value);
else
atts.addAttribute ("", "",
attQName.intern(), type, value);
}
continue;
}
}
// Not a declaration -- report
try {
String attName[] = processName(attQName, true, true);
atts.addAttribute(attName[0], attName[1], attName[2],
type, value);
} catch (SAXException e) {
if (exceptions == null)
exceptions = new Vector();
exceptions.addElement(e);
atts.addAttribute("", attQName, attQName, type, value);
}
}
// now handle the deferred exception reports
if (exceptions != null && errorHandler != null) {
for (int i = 0; i < exceptions.size(); i++)
errorHandler.error((SAXParseException)
(exceptions.elementAt(i)));
}
// OK, finally report the event.
if (contentHandler != null) {
String name[] = processName(qName, false, false);
contentHandler.startElement(name[0], name[1], name[2], atts);
}
|