Add interfaces for constructing a filter with a particular CatalogManager
git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec123dbb6d
commit
4f7be003f3
@ -104,9 +104,11 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
public boolean validating = false;
|
||||
|
||||
/** The underlying catalog */
|
||||
private static Catalog staticCatalog = null;
|
||||
private Catalog catalog = null;
|
||||
|
||||
/** The catalog manager */
|
||||
private CatalogManager catalogManager = CatalogManager.getStaticManager();
|
||||
|
||||
/** Constructor */
|
||||
public CatalogResolver() {
|
||||
initializeCatalogs(false);
|
||||
@ -117,44 +119,15 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
initializeCatalogs(privateCatalog);
|
||||
}
|
||||
|
||||
/** Constructor */
|
||||
public CatalogResolver(CatalogManager manager) {
|
||||
catalogManager = manager;
|
||||
initializeCatalogs(!catalogManager.getUseStaticCatalog());
|
||||
}
|
||||
|
||||
/** Initialize catalog */
|
||||
private void initializeCatalogs(boolean privateCatalog) {
|
||||
catalog = staticCatalog;
|
||||
|
||||
if (privateCatalog || catalog == null) {
|
||||
try {
|
||||
String catalogClassName = CatalogManager.catalogClassName();
|
||||
if (catalogClassName == null) {
|
||||
catalog = new Catalog();
|
||||
} else {
|
||||
try {
|
||||
catalog = (Catalog) Class.forName(catalogClassName).newInstance();
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
Debug.message(1,"Catalog class named '"
|
||||
+ catalogClassName
|
||||
+ "' could not be found. Using default.");
|
||||
catalog = new Catalog();
|
||||
} catch (ClassCastException cnfe) {
|
||||
Debug.message(1,"Class named '"
|
||||
+ catalogClassName
|
||||
+ "' is not a Catalog. Using default.");
|
||||
catalog = new Catalog();
|
||||
}
|
||||
}
|
||||
|
||||
catalog.setupReaders();
|
||||
|
||||
if (!privateCatalog) {
|
||||
catalog.loadSystemCatalogs();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!privateCatalog && catalog != null && CatalogManager.staticCatalog()) {
|
||||
staticCatalog = catalog;
|
||||
}
|
||||
catalog = catalogManager.getCatalog();
|
||||
}
|
||||
|
||||
/** Return the underlying catalog */
|
||||
@ -186,7 +159,7 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
String resolved = null;
|
||||
|
||||
if (catalog == null) {
|
||||
Debug.message(1, "Catalog resolution attempted with null catalog; ignored");
|
||||
catalogManager.debug.message(1, "Catalog resolution attempted with null catalog; ignored");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -194,11 +167,11 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
try {
|
||||
resolved = catalog.resolveSystem(systemId);
|
||||
} catch (MalformedURLException me) {
|
||||
Debug.message(1, "Malformed URL exception trying to resolve",
|
||||
catalogManager.debug.message(1, "Malformed URL exception trying to resolve",
|
||||
publicId);
|
||||
resolved = null;
|
||||
} catch (IOException ie) {
|
||||
Debug.message(1, "I/O exception trying to resolve", publicId);
|
||||
catalogManager.debug.message(1, "I/O exception trying to resolve", publicId);
|
||||
resolved = null;
|
||||
}
|
||||
}
|
||||
@ -208,18 +181,18 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
try {
|
||||
resolved = catalog.resolvePublic(publicId, systemId);
|
||||
} catch (MalformedURLException me) {
|
||||
Debug.message(1, "Malformed URL exception trying to resolve",
|
||||
catalogManager.debug.message(1, "Malformed URL exception trying to resolve",
|
||||
publicId);
|
||||
} catch (IOException ie) {
|
||||
Debug.message(1, "I/O exception trying to resolve", publicId);
|
||||
catalogManager.debug.message(1, "I/O exception trying to resolve", publicId);
|
||||
}
|
||||
}
|
||||
|
||||
if (resolved != null) {
|
||||
Debug.message(2, "Resolved public", publicId, resolved);
|
||||
catalogManager.debug.message(2, "Resolved public", publicId, resolved);
|
||||
}
|
||||
} else {
|
||||
Debug.message(2, "Resolved system", systemId, resolved);
|
||||
catalogManager.debug.message(2, "Resolved system", systemId, resolved);
|
||||
}
|
||||
|
||||
return resolved;
|
||||
@ -277,7 +250,7 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
|
||||
return iSource;
|
||||
} catch (Exception e) {
|
||||
Debug.message(1, "Failed to create InputSource", resolved);
|
||||
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -332,7 +305,7 @@ public class CatalogResolver implements EntityResolver, URIResolver {
|
||||
}
|
||||
|
||||
// if (!href.equals(result)) {
|
||||
Debug.message(2, "Resolved URI", href, result);
|
||||
catalogManager.debug.message(2, "Resolved URI", href, result);
|
||||
// }
|
||||
|
||||
SAXSource source = new SAXSource();
|
||||
|
||||
@ -117,8 +117,11 @@ public class ResolvingParser
|
||||
/** The underlying DTDHandler */
|
||||
private DTDHandler dtdHandler = null;
|
||||
|
||||
/** The manager for the underlying resolver */
|
||||
private CatalogManager catalogManager = CatalogManager.getStaticManager();
|
||||
|
||||
/** The underlying catalog resolver */
|
||||
private CatalogResolver catalogResolver = new CatalogResolver();
|
||||
private CatalogResolver catalogResolver = null;
|
||||
|
||||
/** A separate resolver for oasis-xml-pi catalogs */
|
||||
private CatalogResolver piCatalogResolver = null;
|
||||
@ -134,6 +137,19 @@ public class ResolvingParser
|
||||
|
||||
/** Constructor */
|
||||
public ResolvingParser() {
|
||||
initParser();
|
||||
}
|
||||
|
||||
/** Constructor */
|
||||
public ResolvingParser(CatalogManager manager) {
|
||||
catalogManager = manager;
|
||||
initParser();
|
||||
}
|
||||
|
||||
/** Initialize the parser */
|
||||
private void initParser() {
|
||||
catalogResolver = new CatalogResolver(catalogManager);
|
||||
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(namespaceAware);
|
||||
spf.setValidating(validating);
|
||||
@ -293,12 +309,12 @@ public class ResolvingParser
|
||||
}
|
||||
|
||||
if (allowXMLCatalogPI) {
|
||||
if (CatalogManager.allowOasisXMLCatalogPI()) {
|
||||
Debug.message(4,"oasis-xml-catalog PI", pidata);
|
||||
if (catalogManager.allowOasisXMLCatalogPI()) {
|
||||
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
|
||||
|
||||
if (catalog != null) {
|
||||
try {
|
||||
Debug.message(4,"oasis-xml-catalog", catalog.toString());
|
||||
catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString());
|
||||
oasisXMLCatalogPI = true;
|
||||
|
||||
if (piCatalogResolver == null) {
|
||||
@ -307,17 +323,17 @@ public class ResolvingParser
|
||||
|
||||
piCatalogResolver.getCatalog().parseCatalog(catalog.toString());
|
||||
} catch (Exception e) {
|
||||
Debug.message(3, "Exception parsing oasis-xml-catalog: "
|
||||
catalogManager.debug.message(3, "Exception parsing oasis-xml-catalog: "
|
||||
+ catalog.toString());
|
||||
}
|
||||
} else {
|
||||
Debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
|
||||
catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
|
||||
}
|
||||
} else {
|
||||
Debug.message(4,"PI oasis-xml-catalog ignored: " + pidata);
|
||||
catalogManager.debug.message(4,"PI oasis-xml-catalog ignored: " + pidata);
|
||||
}
|
||||
} else {
|
||||
Debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: "
|
||||
catalogManager.debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: "
|
||||
+ pidata);
|
||||
}
|
||||
} else {
|
||||
@ -406,7 +422,7 @@ public class ResolvingParser
|
||||
|
||||
return iSource;
|
||||
} catch (Exception e) {
|
||||
Debug.message(1, "Failed to create InputSource", resolved);
|
||||
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -96,8 +96,11 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
|
||||
*/
|
||||
public static boolean suppressExplanation = false;
|
||||
|
||||
/** The manager for the underlying resolver */
|
||||
private CatalogManager catalogManager = CatalogManager.getStaticManager();
|
||||
|
||||
/** The underlying catalog resolver */
|
||||
private CatalogResolver catalogResolver = new CatalogResolver();
|
||||
private CatalogResolver catalogResolver = null;
|
||||
|
||||
/** A separate resolver for oasis-xml-pi catalogs */
|
||||
private CatalogResolver piCatalogResolver = null;
|
||||
@ -114,11 +117,27 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
|
||||
/** Construct an empty XML Filter with no parent */
|
||||
public ResolvingXMLFilter() {
|
||||
super();
|
||||
catalogResolver = new CatalogResolver(catalogManager);
|
||||
}
|
||||
|
||||
/** Construct an XML filter with the specified parent */
|
||||
public ResolvingXMLFilter(XMLReader parent) {
|
||||
super(parent);
|
||||
catalogResolver = new CatalogResolver(catalogManager);
|
||||
}
|
||||
|
||||
/** Construct an XML filter with the specified parent */
|
||||
public ResolvingXMLFilter(CatalogManager manager) {
|
||||
super();
|
||||
catalogManager = manager;
|
||||
catalogResolver = new CatalogResolver(catalogManager);
|
||||
}
|
||||
|
||||
/** Construct an XML filter with the specified parent */
|
||||
public ResolvingXMLFilter(XMLReader parent, CatalogManager manager) {
|
||||
super(parent);
|
||||
catalogManager = manager;
|
||||
catalogResolver = new CatalogResolver(catalogManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +235,7 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
|
||||
|
||||
return iSource;
|
||||
} catch (Exception e) {
|
||||
Debug.message(1, "Failed to create InputSource", resolved);
|
||||
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@ -297,12 +316,12 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
|
||||
}
|
||||
|
||||
if (allowXMLCatalogPI) {
|
||||
if (CatalogManager.allowOasisXMLCatalogPI()) {
|
||||
Debug.message(4,"oasis-xml-catalog PI", pidata);
|
||||
if (catalogManager.allowOasisXMLCatalogPI()) {
|
||||
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
|
||||
|
||||
if (catalog != null) {
|
||||
try {
|
||||
Debug.message(4,"oasis-xml-catalog", catalog.toString());
|
||||
catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString());
|
||||
oasisXMLCatalogPI = true;
|
||||
|
||||
if (piCatalogResolver == null) {
|
||||
@ -311,17 +330,17 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
|
||||
|
||||
piCatalogResolver.getCatalog().parseCatalog(catalog.toString());
|
||||
} catch (Exception e) {
|
||||
Debug.message(3, "Exception parsing oasis-xml-catalog: "
|
||||
catalogManager.debug.message(3, "Exception parsing oasis-xml-catalog: "
|
||||
+ catalog.toString());
|
||||
}
|
||||
} else {
|
||||
Debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
|
||||
catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
|
||||
}
|
||||
} else {
|
||||
Debug.message(4,"PI oasis-xml-catalog ignored: " + pidata);
|
||||
catalogManager.debug.message(4,"PI oasis-xml-catalog ignored: " + pidata);
|
||||
}
|
||||
} else {
|
||||
Debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: "
|
||||
catalogManager.debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: "
|
||||
+ pidata);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -91,7 +91,7 @@ public class ResolvingXMLReader extends ResolvingXMLFilter {
|
||||
*
|
||||
* <p>In order to do its job, a ResolvingXMLReader must in fact be
|
||||
* a filter. So the only difference between this code and the filter
|
||||
* code is that a zero-argument constructor builds a new reader.</p>
|
||||
* code is that the constructor builds a new reader.</p>
|
||||
*/
|
||||
public ResolvingXMLReader() {
|
||||
super();
|
||||
@ -103,5 +103,23 @@ public class ResolvingXMLReader extends ResolvingXMLFilter {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Construct a new reader from the JAXP factory</p>
|
||||
*
|
||||
* <p>In order to do its job, a ResolvingXMLReader must in fact be
|
||||
* a filter. So the only difference between this code and the filter
|
||||
* code is that the constructor builds a new reader.</p>
|
||||
*/
|
||||
public ResolvingXMLReader(CatalogManager manager) {
|
||||
super(manager);
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
try {
|
||||
SAXParser parser = spf.newSAXParser();
|
||||
setParent(parser.getXMLReader());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user