Method from org.xml.sax.helpers.ParserAdapter Detail: |
public void characters(char[] ch,
int start,
int length) throws SAXException {
if (contentHandler != null) {
contentHandler.characters(ch, start, length);
}
}
Adapter implementation method; do not call.
Adapt a SAX1 characters event. |
public void endDocument() throws SAXException {
if (contentHandler != null) {
contentHandler.endDocument();
}
}
Adapter implementation method; do not call.
Adapt a SAX1 end document event. |
public void endElement(String qName) throws SAXException {
// 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();
}
Adapter implementation method; do not call.
Adapt a SAX1 end element event. |
public ContentHandler getContentHandler() {
return contentHandler;
}
Return the current content handler. |
public DTDHandler getDTDHandler() {
return dtdHandler;
}
Return the current DTD handler. |
public EntityResolver getEntityResolver() {
return entityResolver;
}
Return the current entity resolver. |
public ErrorHandler getErrorHandler() {
return errorHandler;
}
Return the current error handler. |
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
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 Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
throw new SAXNotRecognizedException("Property: " + name);
}
|
public void ignorableWhitespace(char[] ch,
int start,
int length) throws SAXException {
if (contentHandler != null) {
contentHandler.ignorableWhitespace(ch, start, length);
}
}
Adapter implementation method; do not call.
Adapt a SAX1 ignorable whitespace event. |
public void parse(String systemId) throws IOException, SAXException {
parse(new InputSource(systemId));
}
|
public void parse(InputSource input) throws IOException, SAXException {
if (parsing) {
throw new SAXException("Parser is already in use");
}
setupParser();
parsing = true;
try {
parser.parse(input);
} finally {
parsing = false;
}
parsing = false;
}
|
public void processingInstruction(String target,
String data) throws SAXException {
if (contentHandler != null) {
contentHandler.processingInstruction(target, data);
}
}
Adapter implementation method; do not call.
Adapt a SAX1 processing instruction event. |
void reportError(String message) throws SAXException {
if (errorHandler != null)
errorHandler.error(makeException(message));
}
Report a non-fatal error. |
public void setContentHandler(ContentHandler handler) {
contentHandler = handler;
}
|
public void setDTDHandler(DTDHandler handler) {
dtdHandler = handler;
}
|
public void setDocumentLocator(Locator locator) {
this.locator = locator;
if (contentHandler != null) {
contentHandler.setDocumentLocator(locator);
}
}
Adapter implementation method; do not call.
Adapt a SAX1 document locator event. |
public void setEntityResolver(EntityResolver resolver) {
entityResolver = resolver;
}
|
public void setErrorHandler(ErrorHandler handler) {
errorHandler = handler;
}
|
public void setFeature(String name,
boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
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(String name,
Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
throw new SAXNotRecognizedException("Property: " + name);
}
|
public void startDocument() throws SAXException {
if (contentHandler != null) {
contentHandler.startDocument();
}
}
Adapter implementation method; do not call.
Adapt a SAX1 start document event. |
public void startElement(String qName,
AttributeList qAtts) throws SAXException {
// 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);
}
}
Adapter implementation method; do not call.
Adapt a SAX1 startElement event.
If necessary, perform Namespace processing. |