You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2013/11/22 20:06:56 UTC
svn commit: r1544642 - in
/xerces/xml-commons/trunk/java/src/org/apache/xml/resolver:
CatalogManager.java readers/DOMCatalogReader.java
readers/SAXCatalogReader.java
Author: mrglavas
Date: Fri Nov 22 19:06:55 2013
New Revision: 1544642
URL: http://svn.apache.org/r1544642
Log:
Fix up source indentation.
Modified:
xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/CatalogManager.java
xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/DOMCatalogReader.java
xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java
Modified: xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/CatalogManager.java
URL: http://svn.apache.org/viewvc/xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/CatalogManager.java?rev=1544642&r1=1544641&r2=1544642&view=diff
==============================================================================
--- xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/CatalogManager.java (original)
+++ xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/CatalogManager.java Fri Nov 22 19:06:55 2013
@@ -119,724 +119,724 @@ import org.apache.xml.resolver.helpers.D
*/
public class CatalogManager {
- private static final String pFiles = "xml.catalog.files";
- private static final String pVerbosity = "xml.catalog.verbosity";
- private static final String pPrefer = "xml.catalog.prefer";
- private static final String pStatic = "xml.catalog.staticCatalog";
- private static final String pAllowPI = "xml.catalog.allowPI";
- private static final String pClassname = "xml.catalog.className";
- private static final String pIgnoreMissing = "xml.catalog.ignoreMissing";
+ private static final String pFiles = "xml.catalog.files";
+ private static final String pVerbosity = "xml.catalog.verbosity";
+ private static final String pPrefer = "xml.catalog.prefer";
+ private static final String pStatic = "xml.catalog.staticCatalog";
+ private static final String pAllowPI = "xml.catalog.allowPI";
+ private static final String pClassname = "xml.catalog.className";
+ private static final String pIgnoreMissing = "xml.catalog.ignoreMissing";
- /** A static CatalogManager instance for sharing */
- private static final CatalogManager staticManager = new CatalogManager();
+ /** A static CatalogManager instance for sharing */
+ private static final CatalogManager staticManager = new CatalogManager();
- /** The bootstrap resolver to use when loading XML Catalogs. */
- private BootstrapResolver bResolver = new BootstrapResolver();
+ /** The bootstrap resolver to use when loading XML Catalogs. */
+ private BootstrapResolver bResolver = new BootstrapResolver();
- /** Flag to ignore missing property files and/or properties */
- private boolean ignoreMissingProperties
+ /** Flag to ignore missing property files and/or properties */
+ private boolean ignoreMissingProperties
= (SecuritySupport.getSystemProperty(pIgnoreMissing) != null
- || SecuritySupport.getSystemProperty(pFiles) != null);
+ || SecuritySupport.getSystemProperty(pFiles) != null);
- /** Holds the resources after they are loaded from the file. */
- private ResourceBundle resources;
+ /** Holds the resources after they are loaded from the file. */
+ private ResourceBundle resources;
- /** The name of the CatalogManager properties file. */
- private String propertyFile = "CatalogManager.properties";
+ /** The name of the CatalogManager properties file. */
+ private String propertyFile = "CatalogManager.properties";
- /** The location of the propertyFile */
- private URL propertyFileURI = null;
-
- /** Default catalog files list. */
- private String defaultCatalogFiles = "./xcatalog";
-
- /** Current catalog files list. */
- private String catalogFiles = null;
-
- /** Did the catalogFiles come from the properties file? */
- private boolean fromPropertiesFile = false;
-
- /** Default verbosity level if there is no property setting for it. */
- private int defaultVerbosity = 1;
-
- /** Current verbosity level. */
- private Integer verbosity = null;
-
- /** Default preference setting. */
- private boolean defaultPreferPublic = true;
-
- /** Current preference setting. */
- private Boolean preferPublic = null;
-
- /** Default setting of the static catalog flag. */
- private boolean defaultUseStaticCatalog = true;
-
- /** Current setting of the static catalog flag. */
- private Boolean useStaticCatalog = null;
-
- /** The static catalog used by this manager. */
- private static volatile Catalog staticCatalog = null;
-
- /** Default setting of the oasisXMLCatalogPI flag. */
- private boolean defaultOasisXMLCatalogPI = true;
-
- /** Current setting of the oasisXMLCatalogPI flag. */
- private Boolean oasisXMLCatalogPI = null;
-
- /** Default setting of the relativeCatalogs flag. */
- private boolean defaultRelativeCatalogs = true;
-
- /** Current setting of the relativeCatalogs flag. */
- private Boolean relativeCatalogs = null;
-
- /** Current catalog class name. */
- private String catalogClassName = null;
-
- /** The manager's debug object. Used for printing debugging messages.
- *
- * <p>This field is public so that objects that have access to this
- * CatalogManager can use this debug object.</p>
- */
- public Debug debug = null;
-
- /** Constructor. */
- public CatalogManager() {
- debug = new Debug();
- queryVerbosityFromSysProp();
- // Make sure verbosity is set by xml.catalog.verbosity sysprop
- // setting, if defined.
- }
-
- /** Constructor that specifies an explicit property file. */
- public CatalogManager(String propertyFile) {
- this.propertyFile = propertyFile;
-
- debug = new Debug();
- queryVerbosityFromSysProp();
- // Make sure verbosity is set by xml.catalog.verbosity sysprop
- // setting, if defined.
- }
-
- /** Set the bootstrap resolver.*/
- public void setBootstrapResolver(BootstrapResolver resolver) {
- bResolver = resolver;
- }
-
- /** Get the bootstrap resolver.*/
- public BootstrapResolver getBootstrapResolver() {
- return bResolver;
- }
-
- /** Query system property for verbosity level. */
- private void queryVerbosityFromSysProp() {
- String verbStr = SecuritySupport.getSystemProperty(pVerbosity);
- if (verbStr != null) {
- try {
- int verb = Integer.parseInt(verbStr.trim());
- verbosity = new Integer(verb);
- debug.setDebug(verb);
- } catch (Exception e) {
- System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
- }
- }
- }
-
- /**
- * Load the properties from the propertyFile and build the
- * resources from it.
- */
- private synchronized void readProperties() {
- try {
- propertyFileURI = CatalogManager.class.getResource("/"+propertyFile);
- InputStream in =
- CatalogManager.class.getResourceAsStream("/"+propertyFile);
- if (in==null) {
- if (!ignoreMissingProperties) {
- System.err.println("Cannot find "+propertyFile);
- // there's no reason to give this warning more than once
- ignoreMissingProperties = true;
- }
- return;
- }
- resources = new PropertyResourceBundle(in);
- } catch (MissingResourceException mre) {
- if (!ignoreMissingProperties) {
- System.err.println("Cannot read "+propertyFile);
- }
- } catch (java.io.IOException e) {
- if (!ignoreMissingProperties) {
- System.err.println("Failure trying to read "+propertyFile);
- }
- }
-
- // This is a bit of a hack. After we've successfully read the properties,
- // use them to set the default debug level, if the user hasn't already set
- // the default debug level.
- if (verbosity == null) {
- try {
- String verbStr = resources.getString("verbosity");
- int verb = Integer.parseInt(verbStr.trim());
- debug.setDebug(verb);
- verbosity = new Integer(verb);
- } catch (Exception e) {
- // nop
- }
- }
- }
-
- /**
- * Allow access to the static CatalogManager
- */
- public static CatalogManager getStaticManager() {
- return staticManager;
- }
-
- /**
- * How are missing properties handled?
- *
- * <p>If true, missing or unreadable property files will
- * not be reported. Otherwise, a message will be sent to System.err.
- * </p>
- */
- public boolean getIgnoreMissingProperties() {
- return ignoreMissingProperties;
- }
-
- /**
- * How should missing properties be handled?
- *
- * <p>If ignore is true, missing or unreadable property files will
- * not be reported. Otherwise, a message will be sent to System.err.
- * </p>
- */
- public void setIgnoreMissingProperties(boolean ignore) {
- ignoreMissingProperties = ignore;
- }
-
- /**
- * How are missing properties handled?
- *
- * <p>If ignore is true, missing or unreadable property files will
- * not be reported. Otherwise, a message will be sent to System.err.
- * </p>
- *
- * @deprecated No longer static; use get/set methods.
- */
- public void ignoreMissingProperties(boolean ignore) {
- setIgnoreMissingProperties(ignore);
- }
-
- /**
- * Obtain the verbosity setting from the properties.
- *
- * @return The verbosity level from the propertyFile or the
- * defaultVerbosity.
- */
- private int queryVerbosity () {
- String defaultVerbStr = Integer.toString(defaultVerbosity);
-
- String verbStr = SecuritySupport.getSystemProperty(pVerbosity);
-
- if (verbStr == null) {
- if (resources==null) readProperties();
- if (resources != null) {
- try {
- verbStr = resources.getString("verbosity");
- } catch (MissingResourceException e) {
- verbStr = defaultVerbStr;
- }
- } else {
- verbStr = defaultVerbStr;
- }
- }
-
- int verb = defaultVerbosity;
-
- try {
- verb = Integer.parseInt(verbStr.trim());
- } catch (Exception e) {
- System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
- }
-
- // This is a bit of a hack. After we've successfully got the verbosity,
- // we have to use it to set the default debug level,
- // if the user hasn't already set the default debug level.
- if (verbosity == null) {
- debug.setDebug(verb);
- verbosity = new Integer(verb);
- }
-
- return verb;
- }
-
- /**
- * What is the current verbosity?
- */
- public int getVerbosity() {
- if (verbosity == null) {
- verbosity = new Integer(queryVerbosity());
- }
-
- return verbosity.intValue();
- }
-
- /**
- * Set the current verbosity.
- */
- public void setVerbosity (int verbosity) {
- this.verbosity = new Integer(verbosity);
- debug.setDebug(verbosity);
- }
-
- /**
- * What is the current verbosity?
- *
- * @deprecated No longer static; use get/set methods.
- */
- public int verbosity () {
- return getVerbosity();
- }
-
- /**
- * Obtain the relativeCatalogs setting from the properties.
- *
- * @return The relativeCatalogs setting from the propertyFile or the
- * defaultRelativeCatalogs.
- */
- private boolean queryRelativeCatalogs () {
- if (resources==null) readProperties();
-
- if (resources==null) return defaultRelativeCatalogs;
-
- try {
- String allow = resources.getString("relative-catalogs");
- return (allow.equalsIgnoreCase("true")
- || allow.equalsIgnoreCase("yes")
- || allow.equalsIgnoreCase("1"));
- } catch (MissingResourceException e) {
- return defaultRelativeCatalogs;
- }
- }
-
- /**
- * Get the relativeCatalogs setting.
- *
- * <p>This property is used when the catalogFiles property is
- * interrogated. If true, then relative catalog entry file names
- * are returned. If false, relative catalog entry file names are
- * made absolute with respect to the properties file before returning
- * them.</p>
- *
- * <p>This property <emph>only applies</emph> when the catalog files
- * come from a properties file. If they come from a system property or
- * the default list, they are never considered relative. (What would
- * they be relative to?)</p>
- *
- * <p>In the properties, a value of 'yes', 'true', or '1' is considered
- * true, anything else is false.</p>
- *
- * @return The relativeCatalogs setting from the propertyFile or the
- * defaultRelativeCatalogs.
- */
- public boolean getRelativeCatalogs () {
- if (relativeCatalogs == null) {
- relativeCatalogs = queryRelativeCatalogs() ? Boolean.TRUE : Boolean.FALSE;
- }
-
- return relativeCatalogs.booleanValue();
- }
-
- /**
- * Set the relativeCatalogs setting.
- *
- * @see #getRelativeCatalogs()
- */
- public void setRelativeCatalogs (boolean relative) {
- relativeCatalogs = relative ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Get the relativeCatalogs setting.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public boolean relativeCatalogs () {
- return getRelativeCatalogs();
- }
-
- /**
- * Obtain the list of catalog files from the properties.
- *
- * @return A semicolon delimited list of catlog file URIs
- */
- private String queryCatalogFiles () {
- String catalogList = SecuritySupport.getSystemProperty(pFiles);
- fromPropertiesFile = false;
-
- if (catalogList == null) {
- if (resources == null) readProperties();
- if (resources != null) {
- try {
- catalogList = resources.getString("catalogs");
- fromPropertiesFile = true;
- } catch (MissingResourceException e) {
- System.err.println(propertyFile + ": catalogs not found.");
- catalogList = null;
- }
- }
- }
-
- if (catalogList == null) {
- catalogList = defaultCatalogFiles;
- }
-
- return catalogList;
- }
-
- /**
- * Return the current list of catalog files.
- *
- * @return A vector of the catalog file names or null if no catalogs
- * are available in the properties.
- */
- public Vector getCatalogFiles() {
- if (catalogFiles == null) {
- catalogFiles = queryCatalogFiles();
- }
-
- StringTokenizer files = new StringTokenizer(catalogFiles, ";");
- Vector catalogs = new Vector();
- while (files.hasMoreTokens()) {
- String catalogFile = files.nextToken();
- URL absURI = null;
-
- if (fromPropertiesFile && !relativeCatalogs()) {
- try {
- absURI = new URL(propertyFileURI, catalogFile);
- catalogFile = absURI.toString();
- } catch (MalformedURLException mue) {
- absURI = null;
- }
- }
-
- catalogs.add(catalogFile);
- }
-
- return catalogs;
- }
-
- /**
- * Set the list of catalog files.
- */
- public void setCatalogFiles(String fileList) {
- catalogFiles = fileList;
- fromPropertiesFile = false;
- }
-
- /**
- * Return the current list of catalog files.
- *
- * @return A vector of the catalog file names or null if no catalogs
- * are available in the properties.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public Vector catalogFiles() {
- return getCatalogFiles();
- }
-
- /**
- * Obtain the preferPublic setting from the properties.
- *
- * <p>In the properties, a value of 'public' is true,
- * anything else is false.</p>
- *
- * @return True if prefer is public or the
- * defaultPreferSetting.
- */
- private boolean queryPreferPublic () {
- String prefer = SecuritySupport.getSystemProperty(pPrefer);
-
- if (prefer == null) {
- if (resources==null) readProperties();
- if (resources==null) return defaultPreferPublic;
- try {
- prefer = resources.getString("prefer");
- } catch (MissingResourceException e) {
- return defaultPreferPublic;
- }
- }
-
- if (prefer == null) {
- return defaultPreferPublic;
- }
-
- return (prefer.equalsIgnoreCase("public"));
- }
-
- /**
- * Return the current prefer public setting.
- *
- * @return True if public identifiers are preferred.
- */
- public boolean getPreferPublic () {
- if (preferPublic == null) {
- preferPublic = queryPreferPublic() ? Boolean.TRUE : Boolean.FALSE;
- }
- return preferPublic.booleanValue();
- }
-
- /**
- * Set the prefer public setting.
- */
- public void setPreferPublic (boolean preferPublic) {
- this.preferPublic = preferPublic ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Return the current prefer public setting.
- *
- * @return True if public identifiers are preferred.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public boolean preferPublic () {
- return getPreferPublic();
- }
-
- /**
- * Obtain the static-catalog setting from the properties.
- *
- * <p>In the properties, a value of 'yes', 'true', or '1' is considered
- * true, anything else is false.</p>
- *
- * @return The static-catalog setting from the propertyFile or the
- * defaultUseStaticCatalog.
- */
- private boolean queryUseStaticCatalog () {
- String staticCatalog = SecuritySupport.getSystemProperty(pStatic);
-
- if (staticCatalog == null) {
- if (resources==null) readProperties();
- if (resources==null) return defaultUseStaticCatalog;
- try {
- staticCatalog = resources.getString("static-catalog");
- } catch (MissingResourceException e) {
- return defaultUseStaticCatalog;
- }
- }
-
- if (staticCatalog == null) {
- return defaultUseStaticCatalog;
- }
-
- return (staticCatalog.equalsIgnoreCase("true")
- || staticCatalog.equalsIgnoreCase("yes")
- || staticCatalog.equalsIgnoreCase("1"));
- }
-
- /**
- * Get the current use static catalog setting.
- */
- public boolean getUseStaticCatalog() {
- if (useStaticCatalog == null) {
- useStaticCatalog = queryUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
- }
-
- return useStaticCatalog.booleanValue();
- }
-
- /**
- * Set the use static catalog setting.
- */
- public void setUseStaticCatalog(boolean useStatic) {
- useStaticCatalog = useStatic ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Get the current use static catalog setting.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public boolean staticCatalog() {
- return getUseStaticCatalog();
- }
-
- /**
- * Get a new catalog instance.
- *
- * This method always returns a new instance of the underlying catalog class.
- */
- public Catalog getPrivateCatalog() {
- Catalog catalog = staticCatalog;
-
- if (useStaticCatalog == null) {
- useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
- }
-
- if (catalog == null || !useStaticCatalog.booleanValue()) {
-
- try {
- String catalogClassName = getCatalogClassName();
-
- 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.setCatalogManager(this);
- catalog.setupReaders();
- catalog.loadSystemCatalogs();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- if (useStaticCatalog.booleanValue()) {
- staticCatalog = catalog;
- }
- }
-
- return catalog;
- }
-
- /**
- * Get a catalog instance.
- *
- * If this manager uses static catalogs, the same static catalog will
- * always be returned. Otherwise a new catalog will be returned.
- */
- public Catalog getCatalog() {
- Catalog catalog = staticCatalog;
-
- if (useStaticCatalog == null) {
- useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
- }
-
- if (catalog == null || !useStaticCatalog.booleanValue()) {
- catalog = getPrivateCatalog();
- if (useStaticCatalog.booleanValue()) {
- staticCatalog = catalog;
- }
- }
-
- return catalog;
- }
-
- /**
- * <p>Obtain the oasisXMLCatalogPI setting from the properties.</p>
- *
- * <p>In the properties, a value of 'yes', 'true', or '1' is considered
- * true, anything else is false.</p>
- *
- * @return The oasisXMLCatalogPI setting from the propertyFile or the
- * defaultOasisXMLCatalogPI.
- */
- public boolean queryAllowOasisXMLCatalogPI () {
- String allow = SecuritySupport.getSystemProperty(pAllowPI);
-
- if (allow == null) {
- if (resources==null) readProperties();
- if (resources==null) return defaultOasisXMLCatalogPI;
- try {
- allow = resources.getString("allow-oasis-xml-catalog-pi");
- } catch (MissingResourceException e) {
- return defaultOasisXMLCatalogPI;
- }
- }
-
- if (allow == null) {
- return defaultOasisXMLCatalogPI;
- }
-
- return (allow.equalsIgnoreCase("true")
- || allow.equalsIgnoreCase("yes")
- || allow.equalsIgnoreCase("1"));
- }
-
- /**
- * Get the current XML Catalog PI setting.
- */
- public boolean getAllowOasisXMLCatalogPI () {
- if (oasisXMLCatalogPI == null) {
- oasisXMLCatalogPI = queryAllowOasisXMLCatalogPI() ? Boolean.TRUE : Boolean.FALSE;
- }
-
- return oasisXMLCatalogPI.booleanValue();
- }
-
- /**
- * Set the XML Catalog PI setting
- */
- public void setAllowOasisXMLCatalogPI(boolean allowPI) {
- oasisXMLCatalogPI = allowPI ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Get the current XML Catalog PI setting.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public boolean allowOasisXMLCatalogPI() {
- return getAllowOasisXMLCatalogPI();
- }
-
- /**
- * Obtain the Catalog class name setting from the properties.
- *
- */
- public String queryCatalogClassName () {
- String className = SecuritySupport.getSystemProperty(pClassname);
-
- if (className == null) {
- if (resources==null) readProperties();
- if (resources==null) return null;
- try {
- return resources.getString("catalog-class-name");
- } catch (MissingResourceException e) {
- return null;
- }
- }
-
- return className;
- }
-
- /**
- * Get the current Catalog class name.
- */
- public String getCatalogClassName() {
- if (catalogClassName == null) {
- catalogClassName = queryCatalogClassName();
- }
-
- return catalogClassName;
- }
-
- /**
- * Set the Catalog class name.
- */
- public void setCatalogClassName(String className) {
- catalogClassName = className;
- }
-
- /**
- * Get the current Catalog class name.
- *
- * @deprecated No longer static; use get/set methods.
- */
- public String catalogClassName() {
- return getCatalogClassName();
- }
+ /** The location of the propertyFile */
+ private URL propertyFileURI = null;
+
+ /** Default catalog files list. */
+ private String defaultCatalogFiles = "./xcatalog";
+
+ /** Current catalog files list. */
+ private String catalogFiles = null;
+
+ /** Did the catalogFiles come from the properties file? */
+ private boolean fromPropertiesFile = false;
+
+ /** Default verbosity level if there is no property setting for it. */
+ private int defaultVerbosity = 1;
+
+ /** Current verbosity level. */
+ private Integer verbosity = null;
+
+ /** Default preference setting. */
+ private boolean defaultPreferPublic = true;
+
+ /** Current preference setting. */
+ private Boolean preferPublic = null;
+
+ /** Default setting of the static catalog flag. */
+ private boolean defaultUseStaticCatalog = true;
+
+ /** Current setting of the static catalog flag. */
+ private Boolean useStaticCatalog = null;
+
+ /** The static catalog used by this manager. */
+ private static volatile Catalog staticCatalog = null;
+
+ /** Default setting of the oasisXMLCatalogPI flag. */
+ private boolean defaultOasisXMLCatalogPI = true;
+
+ /** Current setting of the oasisXMLCatalogPI flag. */
+ private Boolean oasisXMLCatalogPI = null;
+
+ /** Default setting of the relativeCatalogs flag. */
+ private boolean defaultRelativeCatalogs = true;
+
+ /** Current setting of the relativeCatalogs flag. */
+ private Boolean relativeCatalogs = null;
+
+ /** Current catalog class name. */
+ private String catalogClassName = null;
+
+ /** The manager's debug object. Used for printing debugging messages.
+ *
+ * <p>This field is public so that objects that have access to this
+ * CatalogManager can use this debug object.</p>
+ */
+ public Debug debug = null;
+
+ /** Constructor. */
+ public CatalogManager() {
+ debug = new Debug();
+ queryVerbosityFromSysProp();
+ // Make sure verbosity is set by xml.catalog.verbosity sysprop
+ // setting, if defined.
+ }
+
+ /** Constructor that specifies an explicit property file. */
+ public CatalogManager(String propertyFile) {
+ this.propertyFile = propertyFile;
+
+ debug = new Debug();
+ queryVerbosityFromSysProp();
+ // Make sure verbosity is set by xml.catalog.verbosity sysprop
+ // setting, if defined.
+ }
+
+ /** Set the bootstrap resolver.*/
+ public void setBootstrapResolver(BootstrapResolver resolver) {
+ bResolver = resolver;
+ }
+
+ /** Get the bootstrap resolver.*/
+ public BootstrapResolver getBootstrapResolver() {
+ return bResolver;
+ }
+
+ /** Query system property for verbosity level. */
+ private void queryVerbosityFromSysProp() {
+ String verbStr = SecuritySupport.getSystemProperty(pVerbosity);
+ if (verbStr != null) {
+ try {
+ int verb = Integer.parseInt(verbStr.trim());
+ verbosity = new Integer(verb);
+ debug.setDebug(verb);
+ } catch (Exception e) {
+ System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
+ }
+ }
+ }
+
+ /**
+ * Load the properties from the propertyFile and build the
+ * resources from it.
+ */
+ private synchronized void readProperties() {
+ try {
+ propertyFileURI = CatalogManager.class.getResource("/"+propertyFile);
+ InputStream in =
+ CatalogManager.class.getResourceAsStream("/"+propertyFile);
+ if (in==null) {
+ if (!ignoreMissingProperties) {
+ System.err.println("Cannot find "+propertyFile);
+ // there's no reason to give this warning more than once
+ ignoreMissingProperties = true;
+ }
+ return;
+ }
+ resources = new PropertyResourceBundle(in);
+ } catch (MissingResourceException mre) {
+ if (!ignoreMissingProperties) {
+ System.err.println("Cannot read "+propertyFile);
+ }
+ } catch (java.io.IOException e) {
+ if (!ignoreMissingProperties) {
+ System.err.println("Failure trying to read "+propertyFile);
+ }
+ }
+
+ // This is a bit of a hack. After we've successfully read the properties,
+ // use them to set the default debug level, if the user hasn't already set
+ // the default debug level.
+ if (verbosity == null) {
+ try {
+ String verbStr = resources.getString("verbosity");
+ int verb = Integer.parseInt(verbStr.trim());
+ debug.setDebug(verb);
+ verbosity = new Integer(verb);
+ } catch (Exception e) {
+ // nop
+ }
+ }
+ }
+
+ /**
+ * Allow access to the static CatalogManager
+ */
+ public static CatalogManager getStaticManager() {
+ return staticManager;
+ }
+
+ /**
+ * How are missing properties handled?
+ *
+ * <p>If true, missing or unreadable property files will
+ * not be reported. Otherwise, a message will be sent to System.err.
+ * </p>
+ */
+ public boolean getIgnoreMissingProperties() {
+ return ignoreMissingProperties;
+ }
+
+ /**
+ * How should missing properties be handled?
+ *
+ * <p>If ignore is true, missing or unreadable property files will
+ * not be reported. Otherwise, a message will be sent to System.err.
+ * </p>
+ */
+ public void setIgnoreMissingProperties(boolean ignore) {
+ ignoreMissingProperties = ignore;
+ }
+
+ /**
+ * How are missing properties handled?
+ *
+ * <p>If ignore is true, missing or unreadable property files will
+ * not be reported. Otherwise, a message will be sent to System.err.
+ * </p>
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public void ignoreMissingProperties(boolean ignore) {
+ setIgnoreMissingProperties(ignore);
+ }
+
+ /**
+ * Obtain the verbosity setting from the properties.
+ *
+ * @return The verbosity level from the propertyFile or the
+ * defaultVerbosity.
+ */
+ private int queryVerbosity () {
+ String defaultVerbStr = Integer.toString(defaultVerbosity);
+
+ String verbStr = SecuritySupport.getSystemProperty(pVerbosity);
+
+ if (verbStr == null) {
+ if (resources==null) readProperties();
+ if (resources != null) {
+ try {
+ verbStr = resources.getString("verbosity");
+ } catch (MissingResourceException e) {
+ verbStr = defaultVerbStr;
+ }
+ } else {
+ verbStr = defaultVerbStr;
+ }
+ }
+
+ int verb = defaultVerbosity;
+
+ try {
+ verb = Integer.parseInt(verbStr.trim());
+ } catch (Exception e) {
+ System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
+ }
+
+ // This is a bit of a hack. After we've successfully got the verbosity,
+ // we have to use it to set the default debug level,
+ // if the user hasn't already set the default debug level.
+ if (verbosity == null) {
+ debug.setDebug(verb);
+ verbosity = new Integer(verb);
+ }
+
+ return verb;
+ }
+
+ /**
+ * What is the current verbosity?
+ */
+ public int getVerbosity() {
+ if (verbosity == null) {
+ verbosity = new Integer(queryVerbosity());
+ }
+
+ return verbosity.intValue();
+ }
+
+ /**
+ * Set the current verbosity.
+ */
+ public void setVerbosity (int verbosity) {
+ this.verbosity = new Integer(verbosity);
+ debug.setDebug(verbosity);
+ }
+
+ /**
+ * What is the current verbosity?
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public int verbosity () {
+ return getVerbosity();
+ }
+
+ /**
+ * Obtain the relativeCatalogs setting from the properties.
+ *
+ * @return The relativeCatalogs setting from the propertyFile or the
+ * defaultRelativeCatalogs.
+ */
+ private boolean queryRelativeCatalogs () {
+ if (resources==null) readProperties();
+
+ if (resources==null) return defaultRelativeCatalogs;
+
+ try {
+ String allow = resources.getString("relative-catalogs");
+ return (allow.equalsIgnoreCase("true")
+ || allow.equalsIgnoreCase("yes")
+ || allow.equalsIgnoreCase("1"));
+ } catch (MissingResourceException e) {
+ return defaultRelativeCatalogs;
+ }
+ }
+
+ /**
+ * Get the relativeCatalogs setting.
+ *
+ * <p>This property is used when the catalogFiles property is
+ * interrogated. If true, then relative catalog entry file names
+ * are returned. If false, relative catalog entry file names are
+ * made absolute with respect to the properties file before returning
+ * them.</p>
+ *
+ * <p>This property <emph>only applies</emph> when the catalog files
+ * come from a properties file. If they come from a system property or
+ * the default list, they are never considered relative. (What would
+ * they be relative to?)</p>
+ *
+ * <p>In the properties, a value of 'yes', 'true', or '1' is considered
+ * true, anything else is false.</p>
+ *
+ * @return The relativeCatalogs setting from the propertyFile or the
+ * defaultRelativeCatalogs.
+ */
+ public boolean getRelativeCatalogs () {
+ if (relativeCatalogs == null) {
+ relativeCatalogs = queryRelativeCatalogs() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ return relativeCatalogs.booleanValue();
+ }
+
+ /**
+ * Set the relativeCatalogs setting.
+ *
+ * @see #getRelativeCatalogs()
+ */
+ public void setRelativeCatalogs (boolean relative) {
+ relativeCatalogs = relative ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Get the relativeCatalogs setting.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public boolean relativeCatalogs () {
+ return getRelativeCatalogs();
+ }
+
+ /**
+ * Obtain the list of catalog files from the properties.
+ *
+ * @return A semicolon delimited list of catlog file URIs
+ */
+ private String queryCatalogFiles () {
+ String catalogList = SecuritySupport.getSystemProperty(pFiles);
+ fromPropertiesFile = false;
+
+ if (catalogList == null) {
+ if (resources == null) readProperties();
+ if (resources != null) {
+ try {
+ catalogList = resources.getString("catalogs");
+ fromPropertiesFile = true;
+ } catch (MissingResourceException e) {
+ System.err.println(propertyFile + ": catalogs not found.");
+ catalogList = null;
+ }
+ }
+ }
+
+ if (catalogList == null) {
+ catalogList = defaultCatalogFiles;
+ }
+
+ return catalogList;
+ }
+
+ /**
+ * Return the current list of catalog files.
+ *
+ * @return A vector of the catalog file names or null if no catalogs
+ * are available in the properties.
+ */
+ public Vector getCatalogFiles() {
+ if (catalogFiles == null) {
+ catalogFiles = queryCatalogFiles();
+ }
+
+ StringTokenizer files = new StringTokenizer(catalogFiles, ";");
+ Vector catalogs = new Vector();
+ while (files.hasMoreTokens()) {
+ String catalogFile = files.nextToken();
+ URL absURI = null;
+
+ if (fromPropertiesFile && !relativeCatalogs()) {
+ try {
+ absURI = new URL(propertyFileURI, catalogFile);
+ catalogFile = absURI.toString();
+ } catch (MalformedURLException mue) {
+ absURI = null;
+ }
+ }
+
+ catalogs.add(catalogFile);
+ }
+
+ return catalogs;
+ }
+
+ /**
+ * Set the list of catalog files.
+ */
+ public void setCatalogFiles(String fileList) {
+ catalogFiles = fileList;
+ fromPropertiesFile = false;
+ }
+
+ /**
+ * Return the current list of catalog files.
+ *
+ * @return A vector of the catalog file names or null if no catalogs
+ * are available in the properties.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public Vector catalogFiles() {
+ return getCatalogFiles();
+ }
+
+ /**
+ * Obtain the preferPublic setting from the properties.
+ *
+ * <p>In the properties, a value of 'public' is true,
+ * anything else is false.</p>
+ *
+ * @return True if prefer is public or the
+ * defaultPreferSetting.
+ */
+ private boolean queryPreferPublic () {
+ String prefer = SecuritySupport.getSystemProperty(pPrefer);
+
+ if (prefer == null) {
+ if (resources==null) readProperties();
+ if (resources==null) return defaultPreferPublic;
+ try {
+ prefer = resources.getString("prefer");
+ } catch (MissingResourceException e) {
+ return defaultPreferPublic;
+ }
+ }
+
+ if (prefer == null) {
+ return defaultPreferPublic;
+ }
+
+ return (prefer.equalsIgnoreCase("public"));
+ }
+
+ /**
+ * Return the current prefer public setting.
+ *
+ * @return True if public identifiers are preferred.
+ */
+ public boolean getPreferPublic () {
+ if (preferPublic == null) {
+ preferPublic = queryPreferPublic() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ return preferPublic.booleanValue();
+ }
+
+ /**
+ * Set the prefer public setting.
+ */
+ public void setPreferPublic (boolean preferPublic) {
+ this.preferPublic = preferPublic ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Return the current prefer public setting.
+ *
+ * @return True if public identifiers are preferred.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public boolean preferPublic () {
+ return getPreferPublic();
+ }
+
+ /**
+ * Obtain the static-catalog setting from the properties.
+ *
+ * <p>In the properties, a value of 'yes', 'true', or '1' is considered
+ * true, anything else is false.</p>
+ *
+ * @return The static-catalog setting from the propertyFile or the
+ * defaultUseStaticCatalog.
+ */
+ private boolean queryUseStaticCatalog () {
+ String staticCatalog = SecuritySupport.getSystemProperty(pStatic);
+
+ if (staticCatalog == null) {
+ if (resources==null) readProperties();
+ if (resources==null) return defaultUseStaticCatalog;
+ try {
+ staticCatalog = resources.getString("static-catalog");
+ } catch (MissingResourceException e) {
+ return defaultUseStaticCatalog;
+ }
+ }
+
+ if (staticCatalog == null) {
+ return defaultUseStaticCatalog;
+ }
+
+ return (staticCatalog.equalsIgnoreCase("true")
+ || staticCatalog.equalsIgnoreCase("yes")
+ || staticCatalog.equalsIgnoreCase("1"));
+ }
+
+ /**
+ * Get the current use static catalog setting.
+ */
+ public boolean getUseStaticCatalog() {
+ if (useStaticCatalog == null) {
+ useStaticCatalog = queryUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ return useStaticCatalog.booleanValue();
+ }
+
+ /**
+ * Set the use static catalog setting.
+ */
+ public void setUseStaticCatalog(boolean useStatic) {
+ useStaticCatalog = useStatic ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Get the current use static catalog setting.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public boolean staticCatalog() {
+ return getUseStaticCatalog();
+ }
+
+ /**
+ * Get a new catalog instance.
+ *
+ * This method always returns a new instance of the underlying catalog class.
+ */
+ public Catalog getPrivateCatalog() {
+ Catalog catalog = staticCatalog;
+
+ if (useStaticCatalog == null) {
+ useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ if (catalog == null || !useStaticCatalog.booleanValue()) {
+
+ try {
+ String catalogClassName = getCatalogClassName();
+
+ 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.setCatalogManager(this);
+ catalog.setupReaders();
+ catalog.loadSystemCatalogs();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ if (useStaticCatalog.booleanValue()) {
+ staticCatalog = catalog;
+ }
+ }
+
+ return catalog;
+ }
+
+ /**
+ * Get a catalog instance.
+ *
+ * If this manager uses static catalogs, the same static catalog will
+ * always be returned. Otherwise a new catalog will be returned.
+ */
+ public Catalog getCatalog() {
+ Catalog catalog = staticCatalog;
+
+ if (useStaticCatalog == null) {
+ useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ if (catalog == null || !useStaticCatalog.booleanValue()) {
+ catalog = getPrivateCatalog();
+ if (useStaticCatalog.booleanValue()) {
+ staticCatalog = catalog;
+ }
+ }
+
+ return catalog;
+ }
+
+ /**
+ * <p>Obtain the oasisXMLCatalogPI setting from the properties.</p>
+ *
+ * <p>In the properties, a value of 'yes', 'true', or '1' is considered
+ * true, anything else is false.</p>
+ *
+ * @return The oasisXMLCatalogPI setting from the propertyFile or the
+ * defaultOasisXMLCatalogPI.
+ */
+ public boolean queryAllowOasisXMLCatalogPI () {
+ String allow = SecuritySupport.getSystemProperty(pAllowPI);
+
+ if (allow == null) {
+ if (resources==null) readProperties();
+ if (resources==null) return defaultOasisXMLCatalogPI;
+ try {
+ allow = resources.getString("allow-oasis-xml-catalog-pi");
+ } catch (MissingResourceException e) {
+ return defaultOasisXMLCatalogPI;
+ }
+ }
+
+ if (allow == null) {
+ return defaultOasisXMLCatalogPI;
+ }
+
+ return (allow.equalsIgnoreCase("true")
+ || allow.equalsIgnoreCase("yes")
+ || allow.equalsIgnoreCase("1"));
+ }
+
+ /**
+ * Get the current XML Catalog PI setting.
+ */
+ public boolean getAllowOasisXMLCatalogPI () {
+ if (oasisXMLCatalogPI == null) {
+ oasisXMLCatalogPI = queryAllowOasisXMLCatalogPI() ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ return oasisXMLCatalogPI.booleanValue();
+ }
+
+ /**
+ * Set the XML Catalog PI setting
+ */
+ public void setAllowOasisXMLCatalogPI(boolean allowPI) {
+ oasisXMLCatalogPI = allowPI ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Get the current XML Catalog PI setting.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public boolean allowOasisXMLCatalogPI() {
+ return getAllowOasisXMLCatalogPI();
+ }
+
+ /**
+ * Obtain the Catalog class name setting from the properties.
+ *
+ */
+ public String queryCatalogClassName () {
+ String className = SecuritySupport.getSystemProperty(pClassname);
+
+ if (className == null) {
+ if (resources==null) readProperties();
+ if (resources==null) return null;
+ try {
+ return resources.getString("catalog-class-name");
+ } catch (MissingResourceException e) {
+ return null;
+ }
+ }
+
+ return className;
+ }
+
+ /**
+ * Get the current Catalog class name.
+ */
+ public String getCatalogClassName() {
+ if (catalogClassName == null) {
+ catalogClassName = queryCatalogClassName();
+ }
+
+ return catalogClassName;
+ }
+
+ /**
+ * Set the Catalog class name.
+ */
+ public void setCatalogClassName(String className) {
+ catalogClassName = className;
+ }
+
+ /**
+ * Get the current Catalog class name.
+ *
+ * @deprecated No longer static; use get/set methods.
+ */
+ public String catalogClassName() {
+ return getCatalogClassName();
+ }
}
Modified: xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/DOMCatalogReader.java
URL: http://svn.apache.org/viewvc/xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/DOMCatalogReader.java?rev=1544642&r1=1544641&r2=1544642&view=diff
==============================================================================
--- xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/DOMCatalogReader.java (original)
+++ xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/DOMCatalogReader.java Fri Nov 22 19:06:55 2013
@@ -70,174 +70,174 @@ import org.xml.sax.SAXException;
* @version 1.0
*/
public class DOMCatalogReader implements CatalogReader {
- /**
- * Mapping table from QNames to CatalogParser classes.
- *
- * <p>Each key in this hash table has the form "elementname"
- * or "{namespaceuri}elementname". The former is used if the
- * namespace URI is null.</p>
- */
- protected Hashtable namespaceMap = new Hashtable();
-
- /**
- * Add a new parser to the reader.
- *
- * <p>This method associates the specified parserClass with the
- * namespaceURI/rootElement names specified.</p>
- *
- * @param namespaceURI The namespace URI. <em>Not</em> the prefix.
- * @param rootElement The name of the root element.
- * @param parserClass The name of the parserClass to instantiate
- * for this kind of catalog.
- */
- public void setCatalogParser(String namespaceURI,
- String rootElement,
- String parserClass) {
- if (namespaceURI == null) {
- namespaceMap.put(rootElement, parserClass);
- } else {
- namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
+ /**
+ * Mapping table from QNames to CatalogParser classes.
+ *
+ * <p>Each key in this hash table has the form "elementname"
+ * or "{namespaceuri}elementname". The former is used if the
+ * namespace URI is null.</p>
+ */
+ protected Hashtable namespaceMap = new Hashtable();
+
+ /**
+ * Add a new parser to the reader.
+ *
+ * <p>This method associates the specified parserClass with the
+ * namespaceURI/rootElement names specified.</p>
+ *
+ * @param namespaceURI The namespace URI. <em>Not</em> the prefix.
+ * @param rootElement The name of the root element.
+ * @param parserClass The name of the parserClass to instantiate
+ * for this kind of catalog.
+ */
+ public void setCatalogParser(String namespaceURI,
+ String rootElement,
+ String parserClass) {
+ if (namespaceURI == null) {
+ namespaceMap.put(rootElement, parserClass);
+ } else {
+ namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
+ }
+ }
+
+ /**
+ * Get the name of the parser class for a given catalog type.
+ *
+ * <p>This method returns the parserClass associated with the
+ * namespaceURI/rootElement names specified.</p>
+ *
+ * @param namespaceURI The namespace URI. <em>Not</em> the prefix.
+ * @param rootElement The name of the root element.
+ * @return The parser class.
+ */
+ public String getCatalogParser(String namespaceURI,
+ String rootElement) {
+ if (namespaceURI == null) {
+ return (String) namespaceMap.get(rootElement);
+ } else {
+ return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
+ }
+ }
+
+ /**
+ * Null constructor; something for subclasses to call.
+ */
+ public DOMCatalogReader() { }
+
+ /**
+ * Read a catalog from an input stream.
+ *
+ * <p>This class reads a catalog from an input stream:</p>
+ *
+ * <ul>
+ * <li>Based on the QName of the root element, it determines which
+ * parser to instantiate for this catalog.</li>
+ * <li>It constructs a DOM Document from the catalog and</li>
+ * <li>For each child of the root node, it calls the parser's
+ * parseCatalogEntry method. This method is expected to make
+ * appropriate calls back into the catalog to add entries for the
+ * entries in the catalog. It is free to do this in whatever manner
+ * is appropriate (perhaps using just the node passed in, perhaps
+ * wandering arbitrarily throughout the tree).</li>
+ * </ul>
+ *
+ * @param catalog The catalog for which this reader is called.
+ * @param is The input stream that is to be read.
+ * @throws IOException if the URL cannot be read.
+ * @throws UnknownCatalogFormatException if the catalog format is
+ * not recognized.
+ * @throws UnparseableCatalogException if the catalog cannot be parsed.
+ * (For example, if it is supposed to be XML and isn't well-formed or
+ * if the parser class cannot be instantiated.)
+ */
+ public void readCatalog(Catalog catalog, InputStream is)
+ throws IOException, CatalogException {
+
+ DocumentBuilderFactory factory = null;
+ DocumentBuilder builder = null;
+
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(false);
+ factory.setValidating(false);
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException pce) {
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ }
+
+ Document doc = null;
+
+ try {
+ doc = builder.parse(is);
+ } catch (SAXException se) {
+ throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
+ }
+
+ Element root = doc.getDocumentElement();
+
+ String namespaceURI = Namespaces.getNamespaceURI(root);
+ String localName = Namespaces.getLocalName(root);
+
+ String domParserClass = getCatalogParser(namespaceURI,
+ localName);
+
+ if (domParserClass == null) {
+ if (namespaceURI == null) {
+ catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
+ + localName);
+ } else {
+ catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
+ + "{" + namespaceURI + "}"
+ + localName);
+ }
+ return;
+ }
+
+ DOMCatalogParser domParser = null;
+
+ try {
+ domParser = (DOMCatalogParser) Class.forName(domParserClass).newInstance();
+ } catch (ClassNotFoundException cnfe) {
+ catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (InstantiationException ie) {
+ catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (IllegalAccessException iae) {
+ catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (ClassCastException cce ) {
+ catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ }
+
+ Node node = root.getFirstChild();
+ while (node != null) {
+ domParser.parseCatalogEntry(catalog, node);
+ node = node.getNextSibling();
+ }
+ }
+
+ /**
+ * Read the catalog behind the specified URL.
+ *
+ * @see #readCatalog(Catalog, InputStream)
+ *
+ * @param catalog The catalog for which we are reading.
+ * @param fileUrl The URL of the document that should be read.
+ *
+ * @throws MalformedURLException if the specified URL cannot be
+ * turned into a URL object.
+ * @throws IOException if the URL cannot be read.
+ * @throws UnknownCatalogFormatException if the catalog format is
+ * not recognized.
+ * @throws UnparseableCatalogException if the catalog cannot be parsed.
+ * (For example, if it is supposed to be XML and isn't well-formed.)
+ */
+ public void readCatalog(Catalog catalog, String fileUrl)
+ throws MalformedURLException, IOException, CatalogException {
+ URL url = new URL(fileUrl);
+ URLConnection urlCon = url.openConnection();
+ readCatalog(catalog, urlCon.getInputStream());
}
- }
-
- /**
- * Get the name of the parser class for a given catalog type.
- *
- * <p>This method returns the parserClass associated with the
- * namespaceURI/rootElement names specified.</p>
- *
- * @param namespaceURI The namespace URI. <em>Not</em> the prefix.
- * @param rootElement The name of the root element.
- * @return The parser class.
- */
- public String getCatalogParser(String namespaceURI,
- String rootElement) {
- if (namespaceURI == null) {
- return (String) namespaceMap.get(rootElement);
- } else {
- return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
- }
- }
-
- /**
- * Null constructor; something for subclasses to call.
- */
- public DOMCatalogReader() { }
-
- /**
- * Read a catalog from an input stream.
- *
- * <p>This class reads a catalog from an input stream:</p>
- *
- * <ul>
- * <li>Based on the QName of the root element, it determines which
- * parser to instantiate for this catalog.</li>
- * <li>It constructs a DOM Document from the catalog and</li>
- * <li>For each child of the root node, it calls the parser's
- * parseCatalogEntry method. This method is expected to make
- * appropriate calls back into the catalog to add entries for the
- * entries in the catalog. It is free to do this in whatever manner
- * is appropriate (perhaps using just the node passed in, perhaps
- * wandering arbitrarily throughout the tree).</li>
- * </ul>
- *
- * @param catalog The catalog for which this reader is called.
- * @param is The input stream that is to be read.
- * @throws IOException if the URL cannot be read.
- * @throws UnknownCatalogFormatException if the catalog format is
- * not recognized.
- * @throws UnparseableCatalogException if the catalog cannot be parsed.
- * (For example, if it is supposed to be XML and isn't well-formed or
- * if the parser class cannot be instantiated.)
- */
- public void readCatalog(Catalog catalog, InputStream is)
- throws IOException, CatalogException {
-
- DocumentBuilderFactory factory = null;
- DocumentBuilder builder = null;
-
- factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(false);
- factory.setValidating(false);
- try {
- builder = factory.newDocumentBuilder();
- } catch (ParserConfigurationException pce) {
- throw new CatalogException(CatalogException.UNPARSEABLE);
- }
-
- Document doc = null;
-
- try {
- doc = builder.parse(is);
- } catch (SAXException se) {
- throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
- }
-
- Element root = doc.getDocumentElement();
-
- String namespaceURI = Namespaces.getNamespaceURI(root);
- String localName = Namespaces.getLocalName(root);
-
- String domParserClass = getCatalogParser(namespaceURI,
- localName);
-
- if (domParserClass == null) {
- if (namespaceURI == null) {
- catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
- + localName);
- } else {
- catalog.getCatalogManager().debug.message(1, "No Catalog parser for "
- + "{" + namespaceURI + "}"
- + localName);
- }
- return;
- }
-
- DOMCatalogParser domParser = null;
-
- try {
- domParser = (DOMCatalogParser) Class.forName(domParserClass).newInstance();
- } catch (ClassNotFoundException cnfe) {
- catalog.getCatalogManager().debug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (InstantiationException ie) {
- catalog.getCatalogManager().debug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (IllegalAccessException iae) {
- catalog.getCatalogManager().debug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (ClassCastException cce ) {
- catalog.getCatalogManager().debug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
- throw new CatalogException(CatalogException.UNPARSEABLE);
- }
-
- Node node = root.getFirstChild();
- while (node != null) {
- domParser.parseCatalogEntry(catalog, node);
- node = node.getNextSibling();
- }
- }
-
- /**
- * Read the catalog behind the specified URL.
- *
- * @see #readCatalog(Catalog, InputStream)
- *
- * @param catalog The catalog for which we are reading.
- * @param fileUrl The URL of the document that should be read.
- *
- * @throws MalformedURLException if the specified URL cannot be
- * turned into a URL object.
- * @throws IOException if the URL cannot be read.
- * @throws UnknownCatalogFormatException if the catalog format is
- * not recognized.
- * @throws UnparseableCatalogException if the catalog cannot be parsed.
- * (For example, if it is supposed to be XML and isn't well-formed.)
- */
- public void readCatalog(Catalog catalog, String fileUrl)
- throws MalformedURLException, IOException, CatalogException {
- URL url = new URL(fileUrl);
- URLConnection urlCon = url.openConnection();
- readCatalog(catalog, urlCon.getInputStream());
- }
}
Modified: xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java
URL: http://svn.apache.org/viewvc/xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java?rev=1544642&r1=1544641&r2=1544642&view=diff
==============================================================================
--- xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java (original)
+++ xerces/xml-commons/trunk/java/src/org/apache/xml/resolver/readers/SAXCatalogReader.java Fri Nov 22 19:06:55 2013
@@ -75,434 +75,434 @@ import org.xml.sax.SAXException;
* @version 1.0
*/
public class SAXCatalogReader implements CatalogReader, ContentHandler, DocumentHandler {
- /** The SAX Parser Factory */
- protected SAXParserFactory parserFactory = null;
+ /** The SAX Parser Factory */
+ protected SAXParserFactory parserFactory = null;
- /** The SAX Parser Class */
- protected String parserClass = null;
+ /** The SAX Parser Class */
+ protected String parserClass = null;
- /**
+ /**
* Mapping table from QNames to CatalogParser classes.
*
* <p>Each key in this hash table has the form "elementname"
* or "{namespaceuri}elementname". The former is used if the
* namespace URI is null.</p>
*/
- protected Hashtable namespaceMap = new Hashtable();
+ protected Hashtable namespaceMap = new Hashtable();
- /** The parser in use for the current catalog. */
- private SAXCatalogParser saxParser = null;
+ /** The parser in use for the current catalog. */
+ private SAXCatalogParser saxParser = null;
- /** Set if something goes horribly wrong. It allows the class to
+ /** Set if something goes horribly wrong. It allows the class to
* ignore the rest of the events that are received.
*/
- private boolean abandonHope = false;
+ private boolean abandonHope = false;
- /** If set, used for loading classes by reflection */
- private ClassLoader loader = null;
+ /** If set, used for loading classes by reflection */
+ private ClassLoader loader = null;
- /** The Catalog that we're working for. */
- private Catalog catalog;
+ /** The Catalog that we're working for. */
+ private Catalog catalog;
- /** Set the XML SAX Parser Factory.
- */
- public void setParserFactory(SAXParserFactory parserFactory) {
- this.parserFactory = parserFactory;
- }
-
- /** Set the XML SAX Parser Class
- */
- public void setParserClass(String parserClass) {
- this.parserClass = parserClass;
- }
-
- /** Get the parser factory currently in use. */
- public SAXParserFactory getParserFactory() {
- return parserFactory;
- }
-
- /** Get the parser class currently in use. */
- public String getParserClass() {
- return parserClass;
- }
-
- /**
- * Set the class loader to use when loading class by reflection. If not set,
- * the the class loader used to load this class is used.
- */
- public void setClassLoader(ClassLoader loader) {
- this.loader = loader;
- }
-
- /** The debug class to use for this reader.
- *
- * This is a bit of a hack. Anyway, whenever we read for a catalog,
- * we extract the debug object
- * from the catalog's manager so that we can use it to print messages.
- *
- * In production, we don't really expect any messages so it doesn't
- * really matter. But it's still a bit of a hack.
- */
- protected Debug debug = CatalogManager.getStaticManager().debug;
-
- /** The constructor */
- public SAXCatalogReader() {
- parserFactory = null;
- parserClass = null;
- }
-
- /** The constructor */
- public SAXCatalogReader(SAXParserFactory parserFactory) {
- this.parserFactory = parserFactory;
- }
-
- /** The constructor */
- public SAXCatalogReader(String parserClass) {
- this.parserClass = parserClass;
- }
-
- /**
- * Set the SAXCatalogParser class for the given namespace/root
- * element type.
- */
- public void setCatalogParser(String namespaceURI,
- String rootElement,
- String parserClass) {
- namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
- namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
- }
-
- /**
- * Get the SAXCatalogParser class for the given namespace/root
- * element type.
- */
- public String getCatalogParser(String namespaceURI,
- String rootElement) {
- namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
- return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
- }
-
- /**
- * Parse an XML Catalog file.
- *
- * @param catalog The catalog to which this catalog file belongs
- * @param fileUrl The URL or filename of the catalog file to process
- *
- * @throws MalformedURLException Improper fileUrl
- * @throws IOException Error reading catalog file
- */
- public void readCatalog(Catalog catalog, String fileUrl)
- throws MalformedURLException, IOException,
- CatalogException {
-
- URL url = null;
-
- try {
- url = new URL(fileUrl);
- } catch (MalformedURLException e) {
- url = new URL("file:///" + fileUrl);
- }
-
- debug = catalog.getCatalogManager().debug;
-
- try {
- URLConnection urlCon = url.openConnection();
- readCatalog(catalog, urlCon.getInputStream());
- } catch (FileNotFoundException e) {
- catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found",
- url.toString());
- }
- }
-
- /**
- * Parse an XML Catalog stream.
- *
- * @param catalog The catalog to which this catalog file belongs
- * @param is The input stream from which the catalog will be read
- *
- * @throws MalformedURLException Improper fileUrl
- * @throws IOException Error reading catalog file
- * @throws CatalogException A Catalog exception
- */
- public void readCatalog(Catalog catalog, InputStream is)
- throws IOException, CatalogException {
-
- // Create an instance of the parser
- if (parserFactory == null && parserClass == null) {
- debug.message(1, "Cannot read SAX catalog without a parser");
- throw new CatalogException(CatalogException.UNPARSEABLE);
- }
-
- debug = catalog.getCatalogManager().debug;
- EntityResolver bResolver = catalog.getCatalogManager().getBootstrapResolver();
-
- this.catalog = catalog;
-
- try {
- if (parserFactory != null) {
- SAXParser parser = parserFactory.newSAXParser();
- SAXParserHandler spHandler = new SAXParserHandler();
- spHandler.setContentHandler(this);
- if (bResolver != null) {
- spHandler.setEntityResolver(bResolver);
- }
- parser.parse(new InputSource(is), spHandler);
- } else {
- Parser parser = (Parser) Class.forName(parserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
- parser.setDocumentHandler(this);
- if (bResolver != null) {
- parser.setEntityResolver(bResolver);
- }
- parser.parse(new InputSource(is));
- }
- } catch (ClassNotFoundException cnfe) {
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (IllegalAccessException iae) {
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (InstantiationException ie) {
- throw new CatalogException(CatalogException.UNPARSEABLE);
- } catch (ParserConfigurationException pce) {
- throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
- } catch (SAXException se) {
- Exception e = se.getException();
- // FIXME: there must be a better way
- UnknownHostException uhe = new UnknownHostException();
- FileNotFoundException fnfe = new FileNotFoundException();
- if (e != null) {
- if (e.getClass() == uhe.getClass()) {
- throw new CatalogException(CatalogException.PARSE_FAILED,
- e.toString());
- } else if (e.getClass() == fnfe.getClass()) {
- throw new CatalogException(CatalogException.PARSE_FAILED,
- e.toString());
- }
- }
- throw new CatalogException(se);
- }
- }
-
- // ----------------------------------------------------------------------
- // Implement the SAX ContentHandler interface
-
- /** The SAX <code>setDocumentLocator</code> method. Does nothing. */
- public void setDocumentLocator (Locator locator) {
- if (saxParser != null) {
- saxParser.setDocumentLocator(locator);
- }
- }
-
- /** The SAX <code>startDocument</code> method. Does nothing. */
- public void startDocument () throws SAXException {
- saxParser = null;
- abandonHope = false;
- return;
- }
-
- /** The SAX <code>endDocument</code> method. Does nothing. */
- public void endDocument ()throws SAXException {
- if (saxParser != null) {
- saxParser.endDocument();
- }
- }
-
- /**
- * The SAX <code>startElement</code> method.
- *
- * <p>The catalog parser is selected based on the namespace of the
- * first element encountered in the catalog.</p>
- */
- public void startElement (String name,
- AttributeList atts)
- throws SAXException {
-
- if (abandonHope) {
- return;
- }
-
- if (saxParser == null) {
- String prefix = "";
- if (name.indexOf(':') > 0) {
- prefix = name.substring(0, name.indexOf(':'));
- }
-
- String localName = name;
- if (localName.indexOf(':') > 0) {
- localName = localName.substring(localName.indexOf(':')+1);
- }
-
- String namespaceURI = null;
- if (prefix.length() == 0) {
- namespaceURI = atts.getValue("xmlns");
- } else {
- namespaceURI = atts.getValue("xmlns:" + prefix);
- }
-
- String saxParserClass = getCatalogParser(namespaceURI,
- localName);
-
- if (saxParserClass == null) {
- abandonHope = true;
- if (namespaceURI == null) {
- debug.message(2, "No Catalog parser for " + name);
- } else {
- debug.message(2, "No Catalog parser for "
- + "{" + namespaceURI + "}"
- + name);
- }
- return;
- }
-
- try {
- saxParser = (SAXCatalogParser)
- Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
-
- saxParser.setCatalog(catalog);
- saxParser.startDocument();
- saxParser.startElement(name, atts);
- } catch (ClassNotFoundException cnfe) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, cnfe.toString());
- } catch (InstantiationException ie) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, ie.toString());
- } catch (IllegalAccessException iae) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, iae.toString());
- } catch (ClassCastException cce ) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, cce.toString());
- }
- } else {
- saxParser.startElement(name, atts);
- }
- }
-
- /**
- * The SAX2 <code>startElement</code> method.
- *
- * <p>The catalog parser is selected based on the namespace of the
- * first element encountered in the catalog.</p>
- */
- public void startElement (String namespaceURI,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
-
- if (abandonHope) {
- return;
- }
-
- if (saxParser == null) {
- String saxParserClass = getCatalogParser(namespaceURI,
- localName);
-
- if (saxParserClass == null) {
- abandonHope = true;
- if (namespaceURI == null) {
- debug.message(2, "No Catalog parser for " + localName);
- } else {
- debug.message(2, "No Catalog parser for "
- + "{" + namespaceURI + "}"
- + localName);
- }
- return;
- }
-
- try {
- saxParser = (SAXCatalogParser)
- Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
-
- saxParser.setCatalog(catalog);
- saxParser.startDocument();
- saxParser.startElement(namespaceURI, localName, qName, atts);
- } catch (ClassNotFoundException cnfe) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, cnfe.toString());
- } catch (InstantiationException ie) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, ie.toString());
- } catch (IllegalAccessException iae) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, iae.toString());
- } catch (ClassCastException cce ) {
- saxParser = null;
- abandonHope = true;
- debug.message(2, cce.toString());
- }
- } else {
- saxParser.startElement(namespaceURI, localName, qName, atts);
- }
- }
-
- /** The SAX <code>endElement</code> method. Does nothing. */
- public void endElement (String name) throws SAXException {
- if (saxParser != null) {
- saxParser.endElement(name);
- }
- }
-
- /** The SAX2 <code>endElement</code> method. Does nothing. */
- public void endElement (String namespaceURI,
- String localName,
- String qName) throws SAXException {
- if (saxParser != null) {
- saxParser.endElement(namespaceURI, localName, qName);
- }
- }
-
- /** The SAX <code>characters</code> method. Does nothing. */
- public void characters (char ch[], int start, int length)
- throws SAXException {
- if (saxParser != null) {
- saxParser.characters(ch, start, length);
- }
- }
-
- /** The SAX <code>ignorableWhitespace</code> method. Does nothing. */
- public void ignorableWhitespace (char ch[], int start, int length)
- throws SAXException {
- if (saxParser != null) {
- saxParser.ignorableWhitespace(ch, start, length);
- }
- }
-
- /** The SAX <code>processingInstruction</code> method. Does nothing. */
- public void processingInstruction (String target, String data)
- throws SAXException {
- if (saxParser != null) {
- saxParser.processingInstruction(target, data);
- }
- }
-
- /** The SAX <code>startPrefixMapping</code> method. Does nothing. */
- public void startPrefixMapping (String prefix, String uri)
- throws SAXException {
- if (saxParser != null) {
- saxParser.startPrefixMapping (prefix, uri);
- }
- }
-
- /** The SAX <code>endPrefixMapping</code> method. Does nothing. */
- public void endPrefixMapping (String prefix)
- throws SAXException {
- if (saxParser != null) {
- saxParser.endPrefixMapping (prefix);
- }
- }
-
- /** The SAX <code>skippedentity</code> method. Does nothing. */
- public void skippedEntity (String name)
- throws SAXException {
- if (saxParser != null) {
- saxParser.skippedEntity(name);
+ /** Set the XML SAX Parser Factory.
+ */
+ public void setParserFactory(SAXParserFactory parserFactory) {
+ this.parserFactory = parserFactory;
+ }
+
+ /** Set the XML SAX Parser Class
+ */
+ public void setParserClass(String parserClass) {
+ this.parserClass = parserClass;
+ }
+
+ /** Get the parser factory currently in use. */
+ public SAXParserFactory getParserFactory() {
+ return parserFactory;
+ }
+
+ /** Get the parser class currently in use. */
+ public String getParserClass() {
+ return parserClass;
+ }
+
+ /**
+ * Set the class loader to use when loading class by reflection. If not set,
+ * the the class loader used to load this class is used.
+ */
+ public void setClassLoader(ClassLoader loader) {
+ this.loader = loader;
+ }
+
+ /** The debug class to use for this reader.
+ *
+ * This is a bit of a hack. Anyway, whenever we read for a catalog,
+ * we extract the debug object
+ * from the catalog's manager so that we can use it to print messages.
+ *
+ * In production, we don't really expect any messages so it doesn't
+ * really matter. But it's still a bit of a hack.
+ */
+ protected Debug debug = CatalogManager.getStaticManager().debug;
+
+ /** The constructor */
+ public SAXCatalogReader() {
+ parserFactory = null;
+ parserClass = null;
+ }
+
+ /** The constructor */
+ public SAXCatalogReader(SAXParserFactory parserFactory) {
+ this.parserFactory = parserFactory;
+ }
+
+ /** The constructor */
+ public SAXCatalogReader(String parserClass) {
+ this.parserClass = parserClass;
+ }
+
+ /**
+ * Set the SAXCatalogParser class for the given namespace/root
+ * element type.
+ */
+ public void setCatalogParser(String namespaceURI,
+ String rootElement,
+ String parserClass) {
+ namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
+ namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
+ }
+
+ /**
+ * Get the SAXCatalogParser class for the given namespace/root
+ * element type.
+ */
+ public String getCatalogParser(String namespaceURI,
+ String rootElement) {
+ namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
+ return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
+ }
+
+ /**
+ * Parse an XML Catalog file.
+ *
+ * @param catalog The catalog to which this catalog file belongs
+ * @param fileUrl The URL or filename of the catalog file to process
+ *
+ * @throws MalformedURLException Improper fileUrl
+ * @throws IOException Error reading catalog file
+ */
+ public void readCatalog(Catalog catalog, String fileUrl)
+ throws MalformedURLException, IOException,
+ CatalogException {
+
+ URL url = null;
+
+ try {
+ url = new URL(fileUrl);
+ } catch (MalformedURLException e) {
+ url = new URL("file:///" + fileUrl);
+ }
+
+ debug = catalog.getCatalogManager().debug;
+
+ try {
+ URLConnection urlCon = url.openConnection();
+ readCatalog(catalog, urlCon.getInputStream());
+ } catch (FileNotFoundException e) {
+ catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found",
+ url.toString());
+ }
+ }
+
+ /**
+ * Parse an XML Catalog stream.
+ *
+ * @param catalog The catalog to which this catalog file belongs
+ * @param is The input stream from which the catalog will be read
+ *
+ * @throws MalformedURLException Improper fileUrl
+ * @throws IOException Error reading catalog file
+ * @throws CatalogException A Catalog exception
+ */
+ public void readCatalog(Catalog catalog, InputStream is)
+ throws IOException, CatalogException {
+
+ // Create an instance of the parser
+ if (parserFactory == null && parserClass == null) {
+ debug.message(1, "Cannot read SAX catalog without a parser");
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ }
+
+ debug = catalog.getCatalogManager().debug;
+ EntityResolver bResolver = catalog.getCatalogManager().getBootstrapResolver();
+
+ this.catalog = catalog;
+
+ try {
+ if (parserFactory != null) {
+ SAXParser parser = parserFactory.newSAXParser();
+ SAXParserHandler spHandler = new SAXParserHandler();
+ spHandler.setContentHandler(this);
+ if (bResolver != null) {
+ spHandler.setEntityResolver(bResolver);
+ }
+ parser.parse(new InputSource(is), spHandler);
+ } else {
+ Parser parser = (Parser) Class.forName(parserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
+ parser.setDocumentHandler(this);
+ if (bResolver != null) {
+ parser.setEntityResolver(bResolver);
+ }
+ parser.parse(new InputSource(is));
+ }
+ } catch (ClassNotFoundException cnfe) {
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (IllegalAccessException iae) {
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (InstantiationException ie) {
+ throw new CatalogException(CatalogException.UNPARSEABLE);
+ } catch (ParserConfigurationException pce) {
+ throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
+ } catch (SAXException se) {
+ Exception e = se.getException();
+ // FIXME: there must be a better way
+ UnknownHostException uhe = new UnknownHostException();
+ FileNotFoundException fnfe = new FileNotFoundException();
+ if (e != null) {
+ if (e.getClass() == uhe.getClass()) {
+ throw new CatalogException(CatalogException.PARSE_FAILED,
+ e.toString());
+ } else if (e.getClass() == fnfe.getClass()) {
+ throw new CatalogException(CatalogException.PARSE_FAILED,
+ e.toString());
+ }
+ }
+ throw new CatalogException(se);
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Implement the SAX ContentHandler interface
+
+ /** The SAX <code>setDocumentLocator</code> method. Does nothing. */
+ public void setDocumentLocator (Locator locator) {
+ if (saxParser != null) {
+ saxParser.setDocumentLocator(locator);
+ }
+ }
+
+ /** The SAX <code>startDocument</code> method. Does nothing. */
+ public void startDocument () throws SAXException {
+ saxParser = null;
+ abandonHope = false;
+ return;
+ }
+
+ /** The SAX <code>endDocument</code> method. Does nothing. */
+ public void endDocument ()throws SAXException {
+ if (saxParser != null) {
+ saxParser.endDocument();
+ }
+ }
+
+ /**
+ * The SAX <code>startElement</code> method.
+ *
+ * <p>The catalog parser is selected based on the namespace of the
+ * first element encountered in the catalog.</p>
+ */
+ public void startElement (String name,
+ AttributeList atts)
+ throws SAXException {
+
+ if (abandonHope) {
+ return;
+ }
+
+ if (saxParser == null) {
+ String prefix = "";
+ if (name.indexOf(':') > 0) {
+ prefix = name.substring(0, name.indexOf(':'));
+ }
+
+ String localName = name;
+ if (localName.indexOf(':') > 0) {
+ localName = localName.substring(localName.indexOf(':')+1);
+ }
+
+ String namespaceURI = null;
+ if (prefix.length() == 0) {
+ namespaceURI = atts.getValue("xmlns");
+ } else {
+ namespaceURI = atts.getValue("xmlns:" + prefix);
+ }
+
+ String saxParserClass = getCatalogParser(namespaceURI,
+ localName);
+
+ if (saxParserClass == null) {
+ abandonHope = true;
+ if (namespaceURI == null) {
+ debug.message(2, "No Catalog parser for " + name);
+ } else {
+ debug.message(2, "No Catalog parser for "
+ + "{" + namespaceURI + "}"
+ + name);
+ }
+ return;
+ }
+
+ try {
+ saxParser = (SAXCatalogParser)
+ Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
+
+ saxParser.setCatalog(catalog);
+ saxParser.startDocument();
+ saxParser.startElement(name, atts);
+ } catch (ClassNotFoundException cnfe) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, cnfe.toString());
+ } catch (InstantiationException ie) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, ie.toString());
+ } catch (IllegalAccessException iae) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, iae.toString());
+ } catch (ClassCastException cce ) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, cce.toString());
+ }
+ } else {
+ saxParser.startElement(name, atts);
+ }
+ }
+
+ /**
+ * The SAX2 <code>startElement</code> method.
+ *
+ * <p>The catalog parser is selected based on the namespace of the
+ * first element encountered in the catalog.</p>
+ */
+ public void startElement (String namespaceURI,
+ String localName,
+ String qName,
+ Attributes atts)
+ throws SAXException {
+
+ if (abandonHope) {
+ return;
+ }
+
+ if (saxParser == null) {
+ String saxParserClass = getCatalogParser(namespaceURI,
+ localName);
+
+ if (saxParserClass == null) {
+ abandonHope = true;
+ if (namespaceURI == null) {
+ debug.message(2, "No Catalog parser for " + localName);
+ } else {
+ debug.message(2, "No Catalog parser for "
+ + "{" + namespaceURI + "}"
+ + localName);
+ }
+ return;
+ }
+
+ try {
+ saxParser = (SAXCatalogParser)
+ Class.forName(saxParserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
+
+ saxParser.setCatalog(catalog);
+ saxParser.startDocument();
+ saxParser.startElement(namespaceURI, localName, qName, atts);
+ } catch (ClassNotFoundException cnfe) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, cnfe.toString());
+ } catch (InstantiationException ie) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, ie.toString());
+ } catch (IllegalAccessException iae) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, iae.toString());
+ } catch (ClassCastException cce ) {
+ saxParser = null;
+ abandonHope = true;
+ debug.message(2, cce.toString());
+ }
+ } else {
+ saxParser.startElement(namespaceURI, localName, qName, atts);
+ }
+ }
+
+ /** The SAX <code>endElement</code> method. Does nothing. */
+ public void endElement (String name) throws SAXException {
+ if (saxParser != null) {
+ saxParser.endElement(name);
+ }
+ }
+
+ /** The SAX2 <code>endElement</code> method. Does nothing. */
+ public void endElement (String namespaceURI,
+ String localName,
+ String qName) throws SAXException {
+ if (saxParser != null) {
+ saxParser.endElement(namespaceURI, localName, qName);
+ }
+ }
+
+ /** The SAX <code>characters</code> method. Does nothing. */
+ public void characters (char ch[], int start, int length)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.characters(ch, start, length);
+ }
+ }
+
+ /** The SAX <code>ignorableWhitespace</code> method. Does nothing. */
+ public void ignorableWhitespace (char ch[], int start, int length)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.ignorableWhitespace(ch, start, length);
+ }
+ }
+
+ /** The SAX <code>processingInstruction</code> method. Does nothing. */
+ public void processingInstruction (String target, String data)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.processingInstruction(target, data);
+ }
+ }
+
+ /** The SAX <code>startPrefixMapping</code> method. Does nothing. */
+ public void startPrefixMapping (String prefix, String uri)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.startPrefixMapping (prefix, uri);
+ }
+ }
+
+ /** The SAX <code>endPrefixMapping</code> method. Does nothing. */
+ public void endPrefixMapping (String prefix)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.endPrefixMapping (prefix);
+ }
+ }
+
+ /** The SAX <code>skippedentity</code> method. Does nothing. */
+ public void skippedEntity (String name)
+ throws SAXException {
+ if (saxParser != null) {
+ saxParser.skippedEntity(name);
+ }
}
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org