Fields Summary |
---|
public static boolean | namespaceAwareMake the parser Namespace aware? |
public static boolean | validatingMake the parser validating? |
public static boolean | suppressExplanationSuppress explanatory message? |
private SAXParser | saxParserThe underlying parser. |
private Parser | parserThe underlying reader. |
private DocumentHandler | documentHandlerThe underlying DocumentHandler. |
private DTDHandler | dtdHandlerThe underlying DTDHandler. |
private com.sun.org.apache.xml.internal.resolver.CatalogManager | catalogManagerThe manager for the underlying resolver. |
private CatalogResolver | catalogResolverThe underlying catalog resolver. |
private CatalogResolver | piCatalogResolverA separate resolver for oasis-xml-pi catalogs. |
private boolean | allowXMLCatalogPIAre we in the prolog? Is an oasis-xml-catalog PI valid now? |
private boolean | oasisXMLCatalogPIHas an oasis-xml-catalog PI been seen? |
private URL | baseURLThe base URI of the input document, if known. |
Methods Summary |
---|
public void | characters(char[] ch, int start, int length)SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.characters(ch,start,length);
}
|
public void | endDocument()SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.endDocument();
}
|
public void | endElement(java.lang.String name)SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.endElement(name);
}
|
private void | explain(java.lang.String systemId)Provide one possible explanation for an InternalError.
if (!suppressExplanation) {
System.out.println("Parser probably encountered bad URI in " + systemId);
System.out.println("For example, replace '/some/uri' with 'file:/some/uri'.");
}
|
public com.sun.org.apache.xml.internal.resolver.Catalog | getCatalog()Return the Catalog being used.
return catalogResolver.getCatalog();
|
public void | ignorableWhitespace(char[] ch, int start, int length)SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.ignorableWhitespace(ch,start,length);
}
|
private void | initParser()Initialize the parser.
catalogResolver = new CatalogResolver(catalogManager);
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(namespaceAware);
spf.setValidating(validating);
try {
saxParser = spf.newSAXParser();
parser = saxParser.getParser();
documentHandler = null;
dtdHandler = null;
} catch (Exception ex) {
ex.printStackTrace();
}
|
public void | notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)SAX DTDHandler API.
allowXMLCatalogPI = false;
if (dtdHandler != null) {
dtdHandler.notationDecl(name,publicId,systemId);
}
|
public void | parse(org.xml.sax.InputSource input)SAX Parser API.
Note that the JAXP 1.1ea2 parser crashes with an InternalError if
it encounters a system identifier that appears to be a relative URI
that begins with a slash. For example, the declaration:
<!DOCTYPE book SYSTEM "/path/to/dtd/on/my/system/docbookx.dtd">
would cause such an error. As a convenience, this method catches
that error and prints an explanation. (Unfortunately, it's not possible
to identify the particular system identifier that causes the problem.)
The underlying error is forwarded after printing the explanatory
message. The message is only every printed once and if
suppressExplanation is set to false before
parsing, it will never be printed.
setupParse(input.getSystemId());
try {
parser.parse(input);
} catch (InternalError ie) {
explain(input.getSystemId());
throw ie;
}
|
public void | parse(java.lang.String systemId)SAX Parser API.
setupParse(systemId);
try {
parser.parse(systemId);
} catch (InternalError ie) {
explain(systemId);
throw ie;
}
|
public void | processingInstruction(java.lang.String target, java.lang.String pidata)SAX DocumentHandler API.
if (target.equals("oasis-xml-catalog")) {
URL catalog = null;
String data = pidata;
int pos = data.indexOf("catalog=");
if (pos >= 0) {
data = data.substring(pos+8);
if (data.length() > 1) {
String quote = data.substring(0,1);
data = data.substring(1);
pos = data.indexOf(quote);
if (pos >= 0) {
data = data.substring(0, pos);
try {
if (baseURL != null) {
catalog = new URL(baseURL, data);
} else {
catalog = new URL(data);
}
} catch (MalformedURLException mue) {
// nevermind
}
}
}
}
if (allowXMLCatalogPI) {
if (catalogManager.getAllowOasisXMLCatalogPI()) {
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
if (catalog != null) {
try {
catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString());
oasisXMLCatalogPI = true;
if (piCatalogResolver == null) {
piCatalogResolver = new CatalogResolver(true);
}
piCatalogResolver.getCatalog().parseCatalog(catalog.toString());
} catch (Exception e) {
catalogManager.debug.message(3, "Exception parsing oasis-xml-catalog: "
+ catalog.toString());
}
} else {
catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
}
} else {
catalogManager.debug.message(4,"PI oasis-xml-catalog ignored: " + pidata);
}
} else {
catalogManager.debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: "
+ pidata);
}
} else {
if (documentHandler != null) {
documentHandler.processingInstruction(target, pidata);
}
}
|
public org.xml.sax.InputSource | resolveEntity(java.lang.String publicId, java.lang.String systemId)Implements the resolveEntity method
for the SAX interface, using an underlying CatalogResolver
to do the real work.
allowXMLCatalogPI = false;
String resolved = catalogResolver.getResolvedEntity(publicId, systemId);
if (resolved == null && piCatalogResolver != null) {
resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
}
if (resolved != null) {
try {
InputSource iSource = new InputSource(resolved);
iSource.setPublicId(publicId);
// Ideally this method would not attempt to open the
// InputStream, but there is a bug (in Xerces, at least)
// that causes the parser to mistakenly open the wrong
// system identifier if the returned InputSource does
// not have a byteStream.
//
// It could be argued that we still shouldn't do this here,
// but since the purpose of calling the entityResolver is
// almost certainly to open the input stream, it seems to
// do little harm.
//
URL url = new URL(resolved);
InputStream iStream = url.openStream();
iSource.setByteStream(iStream);
return iSource;
} catch (Exception e) {
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
return null;
}
} else {
return null;
}
|
public void | setDTDHandler(org.xml.sax.DTDHandler handler)SAX Parser API.
dtdHandler = handler;
|
public void | setDocumentHandler(org.xml.sax.DocumentHandler handler)SAX Parser API.
documentHandler = handler;
|
public void | setDocumentLocator(org.xml.sax.Locator locator)SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.setDocumentLocator(locator);
}
|
public void | setEntityResolver(org.xml.sax.EntityResolver resolver)SAX Parser API.
The purpose of this class is to implement an entity resolver.
Attempting to set a different one is pointless (and ignored).
// nop
|
public void | setErrorHandler(org.xml.sax.ErrorHandler handler)SAX Parser API.
parser.setErrorHandler(handler);
|
public void | setLocale(java.util.Locale locale)SAX Parser API.
parser.setLocale(locale);
|
private void | setupParse(java.lang.String systemId)Setup for parsing.
allowXMLCatalogPI = true;
parser.setEntityResolver(this);
parser.setDocumentHandler(this);
parser.setDTDHandler(this);
URL cwd = null;
try {
cwd = FileURL.makeURL("basename");
} catch (MalformedURLException mue) {
cwd = null;
}
try {
baseURL = new URL(systemId);
} catch (MalformedURLException mue) {
if (cwd != null) {
try {
baseURL = new URL(cwd, systemId);
} catch (MalformedURLException mue2) {
// give up
baseURL = null;
}
} else {
// give up
baseURL = null;
}
}
|
public void | startDocument()SAX DocumentHandler API.
if (documentHandler != null) {
documentHandler.startDocument();
}
|
public void | startElement(java.lang.String name, org.xml.sax.AttributeList atts)SAX DocumentHandler API.
allowXMLCatalogPI = false;
if (documentHandler != null) {
documentHandler.startElement(name,atts);
}
|
public void | unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)SAX DTDHandler API.
allowXMLCatalogPI = false;
if (dtdHandler != null) {
dtdHandler.unparsedEntityDecl (name, publicId, systemId, notationName);
}
|