catalogmanager.java
来自「JAVA 所有包」· Java 代码 · 共 836 行 · 第 1/2 页
JAVA
836 行
// CatalogManager.java - Access CatalogManager.properties/* * Copyright 2001-2004 The Apache Software Foundation or its licensors, * as applicable. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xml.internal.resolver;import java.io.InputStream;import java.net.URL;import java.net.MalformedURLException;import java.util.MissingResourceException;import java.util.PropertyResourceBundle;import java.util.ResourceBundle;import java.util.StringTokenizer;import java.util.Vector;import com.sun.org.apache.xml.internal.resolver.helpers.Debug;import com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolver;import com.sun.org.apache.xml.internal.resolver.Catalog;/** * CatalogManager provides an interface to the catalog properties. * * <p>Properties can come from two places: from system properties or * from a <i>CatalogManager.properties</i> file. This class provides a transparent * interface to both, with system properties preferred over property file values.</p> * * <p>The following table summarizes the properties:</p> * * <table border="1"> * <thead> * <tr> * <td>System Property</td> * <td>CatalogManager.properties<br/>Property</td> * <td>Description</td> * </tr> * </thead> * <tbody> * <tr> * <td>xml.catalog.ignoreMissing</td> * <td> </td> * <td>If true, a missing <i>CatalogManager.properties</i> file or missing properties * within that file will not generate warning messages. See also the * <i>ignoreMissingProperties</i> method.</td> * </tr> * * <tr> * <td>xml.catalog.files</td> * <td>catalogs</td> * <td>The <emph>semicolon-delimited</emph> list of catalog files.</td> * </tr> * * <tr> * <td> </td> * <td>relative-catalogs</td> * <td>If false, relative catalog URIs are made absolute with respect to the base URI of * the <i>CatalogManager.properties</i> file. This setting only applies to catalog * URIs obtained from the <i>catalogs</i> property <emph>in the</emph> * <i>CatalogManager.properties</i> file</td> * </tr> * * <tr> * <td>xml.catalog.verbosity</td> * <td>verbosity</td> * <td>If non-zero, the Catalog classes will print informative and debugging messages. * The higher the number, the more messages.</td> * </tr> * * <tr> * <td>xml.catalog.prefer</td> * <td>prefer</td> * <td>Which identifier is preferred, "public" or "system"?</td> * </tr> * * <tr> * <td>xml.catalog.staticCatalog</td> * <td>static-catalog</td> * <td>Should a single catalog be constructed for all parsing, or should a different * catalog be created for each parser?</td> * </tr> * * <tr> * <td>xml.catalog.allowPI</td> * <td>allow-oasis-xml-catalog-pi</td> * <td>If the source document contains "oasis-xml-catalog" processing instructions, * should they be used?</td> * </tr> * * <tr> * <td>xml.catalog.className</td> * <td>catalog-class-name</td> * <td>If you're using the convenience classes * <tt>com.sun.org.apache.xml.internal.resolver.tools.*</tt>), this setting * allows you to specify an alternate class name to use for the underlying * catalog.</td> * </tr> * </tbody> * </table> * * @see Catalog * * @author Norman Walsh * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a> * * @version 1.0 */public class CatalogManager { private static String pFiles = "xml.catalog.files"; private static String pVerbosity = "xml.catalog.verbosity"; private static String pPrefer = "xml.catalog.prefer"; private static String pStatic = "xml.catalog.staticCatalog"; private static String pAllowPI = "xml.catalog.allowPI"; private static String pClassname = "xml.catalog.className"; private static String pIgnoreMissing = "xml.catalog.ignoreMissing"; /** A static CatalogManager instance for sharing */ private static CatalogManager staticManager = new CatalogManager(); /** 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 = (System.getProperty(pIgnoreMissing) != null || System.getProperty(pFiles) != null); /** 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 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 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(); // Note that we don't setDebug() here; we do that lazily. Either the // user will set it explicitly, or we'll do it automagically if they // read from the propertyFile for some other reason. That way, there's // no attempt to read from the file before the caller has had a chance // to avoid it. } /** Constructor that specifies an explicit property file. */ public CatalogManager(String propertyFile) { this.propertyFile = propertyFile; debug = new Debug(); // Note that we don't setDebug() here; we do that lazily. Either the // user will set it explicitly, or we'll do it automagically if they // read from the propertyFile for some other reason. That way, there's // no attempt to read from the file before the caller has had a chance // to avoid it. } /** Set the bootstrap resolver.*/ public void setBootstrapResolver(BootstrapResolver resolver) { bResolver = resolver; } /** Get the bootstrap resolver.*/ public BootstrapResolver getBootstrapResolver() { return bResolver; } /** * 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 = System.getProperty(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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?