FileDocCategorySizeDatePackage
CatalogManager.javaAPI DocJava SE 6 API23186Tue Jun 10 00:22:58 BST 2008com.sun.org.apache.xml.internal.resolver

CatalogManager

public class CatalogManager extends Object
CatalogManager provides an interface to the catalog properties.

Properties can come from two places: from system properties or from a CatalogManager.properties file. This class provides a transparent interface to both, with system properties preferred over property file values.

The following table summarizes the properties:

System Property CatalogManager.properties
Property
Description
xml.catalog.ignoreMissing   If true, a missing CatalogManager.properties file or missing properties within that file will not generate warning messages. See also the ignoreMissingProperties method.
xml.catalog.files catalogs The semicolon-delimited list of catalog files.
  relative-catalogs If false, relative catalog URIs are made absolute with respect to the base URI of the CatalogManager.properties file. This setting only applies to catalog URIs obtained from the catalogs property in the CatalogManager.properties file
xml.catalog.verbosity verbosity If non-zero, the Catalog classes will print informative and debugging messages. The higher the number, the more messages.
xml.catalog.prefer prefer Which identifier is preferred, "public" or "system"?
xml.catalog.staticCatalog static-catalog Should a single catalog be constructed for all parsing, or should a different catalog be created for each parser?
xml.catalog.allowPI allow-oasis-xml-catalog-pi If the source document contains "oasis-xml-catalog" processing instructions, should they be used?
xml.catalog.className catalog-class-name If you're using the convenience classes com.sun.org.apache.xml.internal.resolver.tools.*), this setting allows you to specify an alternate class name to use for the underlying catalog.
see
Catalog
author
Norman Walsh Norman.Walsh@Sun.COM
version
1.0

Fields Summary
private static String
pFiles
private static String
pVerbosity
private static String
pPrefer
private static String
pStatic
private static String
pAllowPI
private static String
pClassname
private static String
pIgnoreMissing
private static CatalogManager
staticManager
A static CatalogManager instance for sharing
private com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolver
bResolver
The bootstrap resolver to use when loading XML Catalogs.
private boolean
ignoreMissingProperties
Flag to ignore missing property files and/or properties
private ResourceBundle
resources
Holds the resources after they are loaded from the file.
private String
propertyFile
The name of the CatalogManager properties file.
private URL
propertyFileURI
The location of the propertyFile
private String
defaultCatalogFiles
Default catalog files list.
private String
catalogFiles
Current catalog files list.
private boolean
fromPropertiesFile
Did the catalogFiles come from the properties file?
private int
defaultVerbosity
Default verbosity level if there is no property setting for it.
private Integer
verbosity
Current verbosity level.
private boolean
defaultPreferPublic
Default preference setting.
private Boolean
preferPublic
Current preference setting.
private boolean
defaultUseStaticCatalog
Default setting of the static catalog flag.
private Boolean
useStaticCatalog
Current setting of the static catalog flag.
private static com.sun.org.apache.xml.internal.resolver.Catalog
staticCatalog
The static catalog used by this manager.
private boolean
defaultOasisXMLCatalogPI
Default setting of the oasisXMLCatalogPI flag.
private Boolean
oasisXMLCatalogPI
Current setting of the oasisXMLCatalogPI flag.
private boolean
defaultRelativeCatalogs
Default setting of the relativeCatalogs flag.
private Boolean
relativeCatalogs
Current setting of the relativeCatalogs flag.
private String
catalogClassName
Current catalog class name.
public com.sun.org.apache.xml.internal.resolver.helpers.Debug
debug
The manager's debug object. Used for printing debugging messages.

This field is public so that objects that have access to this CatalogManager can use this debug object.

Constructors Summary
public CatalogManager()
Constructor.


    
    
    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.
  
public CatalogManager(String propertyFile)
Constructor that specifies an explicit property file.

    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.
  
Methods Summary
public booleanallowOasisXMLCatalogPI()
Get the current XML Catalog PI setting.

deprecated
No longer static; use get/set methods.

    return getAllowOasisXMLCatalogPI();
  
public java.lang.StringcatalogClassName()
Get the current Catalog class name.

deprecated
No longer static; use get/set methods.

    return getCatalogClassName();
  
public java.util.VectorcatalogFiles()
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.

    return getCatalogFiles();
  
public booleangetAllowOasisXMLCatalogPI()
Get the current XML Catalog PI setting.

    if (oasisXMLCatalogPI == null) {
      oasisXMLCatalogPI = new Boolean(queryAllowOasisXMLCatalogPI());
    }

    return oasisXMLCatalogPI.booleanValue();
  
public com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolvergetBootstrapResolver()
Get the bootstrap resolver.

    return bResolver;
  
public com.sun.org.apache.xml.internal.resolver.CataloggetCatalog()
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.

    Catalog catalog = staticCatalog;

    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(getUseStaticCatalog());
    }

    if (catalog == null || !useStaticCatalog.booleanValue()) {
      catalog = getPrivateCatalog();
      if (useStaticCatalog.booleanValue()) {
	staticCatalog = catalog;
      }
    }

    return catalog;
  
public java.lang.StringgetCatalogClassName()
Get the current Catalog class name.

    if (catalogClassName == null) {
      catalogClassName = queryCatalogClassName();
    }

    return catalogClassName;
  
public java.util.VectorgetCatalogFiles()
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.

    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;
  
public booleangetIgnoreMissingProperties()
How are missing properties handled?

If true, missing or unreadable property files will not be reported. Otherwise, a message will be sent to System.err.

    return ignoreMissingProperties;
  
public booleangetPreferPublic()
Return the current prefer public setting.

return
True if public identifiers are preferred.

    if (preferPublic == null) {
      preferPublic = new Boolean(queryPreferPublic());
    }
    return preferPublic.booleanValue();
  
public com.sun.org.apache.xml.internal.resolver.CataloggetPrivateCatalog()
Get a new catalog instance. This method always returns a new instance of the underlying catalog class.

    Catalog catalog = staticCatalog;

    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(getUseStaticCatalog());
    }

    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;
  
public booleangetRelativeCatalogs()
Get the relativeCatalogs setting.

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.

This property only applies 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?)

In the properties, a value of 'yes', 'true', or '1' is considered true, anything else is false.

return
The relativeCatalogs setting from the propertyFile or the defaultRelativeCatalogs.

    if (relativeCatalogs == null) {
      relativeCatalogs = new Boolean(queryRelativeCatalogs());
    }

    return relativeCatalogs.booleanValue();
  
public static com.sun.org.apache.xml.internal.resolver.CatalogManagergetStaticManager()
Allow access to the static CatalogManager

    return staticManager;
  
public booleangetUseStaticCatalog()
Get the current use static catalog setting.

    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(queryUseStaticCatalog());
    }

    return useStaticCatalog.booleanValue();
  
public intgetVerbosity()
What is the current verbosity?

    if (verbosity == null) {
      verbosity = new Integer(queryVerbosity());
    }

    return verbosity.intValue();
  
public voidignoreMissingProperties(boolean ignore)
How are missing properties handled?

If ignore is true, missing or unreadable property files will not be reported. Otherwise, a message will be sent to System.err.

deprecated
No longer static; use get/set methods.

    setIgnoreMissingProperties(ignore);
  
public booleanpreferPublic()
Return the current prefer public setting.

return
True if public identifiers are preferred.
deprecated
No longer static; use get/set methods.

    return getPreferPublic();
  
public booleanqueryAllowOasisXMLCatalogPI()

Obtain the oasisXMLCatalogPI setting from the properties.

In the properties, a value of 'yes', 'true', or '1' is considered true, anything else is false.

return
The oasisXMLCatalogPI setting from the propertyFile or the defaultOasisXMLCatalogPI.

    String allow = System.getProperty(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"));
  
public java.lang.StringqueryCatalogClassName()
Obtain the Catalog class name setting from the properties.

    String className = System.getProperty(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;
  
private java.lang.StringqueryCatalogFiles()
Obtain the list of catalog files from the properties.

return
A semicolon delimited list of catlog file URIs

    String catalogList = System.getProperty(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;
  
private booleanqueryPreferPublic()
Obtain the preferPublic setting from the properties.

In the properties, a value of 'public' is true, anything else is false.

return
True if prefer is public or the defaultPreferSetting.

    String prefer = System.getProperty(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"));
  
private booleanqueryRelativeCatalogs()
Obtain the relativeCatalogs setting from the properties.

return
The relativeCatalogs setting from the propertyFile or the defaultRelativeCatalogs.

    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;
    }
  
private booleanqueryUseStaticCatalog()
Obtain the static-catalog setting from the properties.

In the properties, a value of 'yes', 'true', or '1' is considered true, anything else is false.

return
The static-catalog setting from the propertyFile or the defaultUseStaticCatalog.

    String staticCatalog = System.getProperty(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"));
  
private intqueryVerbosity()
Obtain the verbosity setting from the properties.

return
The verbosity level from the propertyFile or the defaultVerbosity.

    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;
  
private synchronized voidreadProperties()
Load the properties from the propertyFile and build the resources from it.

    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
      }
    }
  
public booleanrelativeCatalogs()
Get the relativeCatalogs setting.

deprecated
No longer static; use get/set methods.

    return getRelativeCatalogs();
  
public voidsetAllowOasisXMLCatalogPI(boolean allowPI)
Set the XML Catalog PI setting

    oasisXMLCatalogPI = new Boolean(allowPI);
  
public voidsetBootstrapResolver(com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolver resolver)
Set the bootstrap resolver.

    bResolver = resolver;
  
public voidsetCatalogClassName(java.lang.String className)
Set the Catalog class name.

    catalogClassName = className;
  
public voidsetCatalogFiles(java.lang.String fileList)
Set the list of catalog files.

    catalogFiles = fileList;
    fromPropertiesFile = false;
  
public voidsetIgnoreMissingProperties(boolean ignore)
How should missing properties be handled?

If ignore is true, missing or unreadable property files will not be reported. Otherwise, a message will be sent to System.err.

    ignoreMissingProperties = ignore;
  
public voidsetPreferPublic(boolean preferPublic)
Set the prefer public setting.

    this.preferPublic = new Boolean(preferPublic);
  
public voidsetRelativeCatalogs(boolean relative)
Set the relativeCatalogs setting.

see
#getRelativeCatalogs()

    relativeCatalogs = new Boolean(relative);
  
public voidsetUseStaticCatalog(boolean useStatic)
Set the use static catalog setting.

    useStaticCatalog = new Boolean(useStatic);
  
public voidsetVerbosity(int verbosity)
Set the current verbosity.

    this.verbosity = new Integer(verbosity);
    debug.setDebug(verbosity);
  
public booleanstaticCatalog()
Get the current use static catalog setting.

deprecated
No longer static; use get/set methods.

    return getUseStaticCatalog();
  
public intverbosity()
What is the current verbosity?

deprecated
No longer static; use get/set methods.

    return getVerbosity();