KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > xml > catalog > CatalogManager


1 // CatalogManager.java - Access CatalogManager.properties
2

3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" must
29  * not be used to endorse or promote products derived from this
30  * software without prior written permission. For written
31  * permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * nor may "Apache" appear in their name, without prior written
35  * permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 package org.jboss.util.xml.catalog;
58
59 import java.io.InputStream JavaDoc;
60
61 import java.net.URL JavaDoc;
62 import java.net.MalformedURLException JavaDoc;
63
64 import java.util.MissingResourceException JavaDoc;
65 import java.util.PropertyResourceBundle JavaDoc;
66 import java.util.ResourceBundle JavaDoc;
67 import java.util.StringTokenizer JavaDoc;
68 import java.util.Vector JavaDoc;
69
70 import org.jboss.util.xml.catalog.Catalog;
71 import org.jboss.util.xml.catalog.helpers.BootstrapResolver;
72 import org.jboss.util.xml.catalog.helpers.Debug;
73
74 /**
75  * CatalogManager provides an interface to the catalog properties.
76  *
77  * <p>Properties can come from two places: from system properties or
78  * from a <i>CatalogManager.properties</i> file. This class provides a transparent
79  * interface to both, with system properties preferred over property file values.</p>
80  *
81  * <p>The following table summarizes the properties:</p>
82  *
83  * <table border="1">
84  * <thead>
85  * <tr>
86  * <td>System Property</td>
87  * <td>CatalogManager.properties<br/>Property</td>
88  * <td>Description</td>
89  * </tr>
90  * </thead>
91  * <tbody>
92  * <tr>
93  * <td>xml.catalog.ignoreMissing</td>
94  * <td>&#160;</td>
95  * <td>If true, a missing <i>CatalogManager.properties</i> file or missing properties
96  * within that file will not generate warning messages. See also the
97  * <i>ignoreMissingProperties</i> method.</td>
98  * </tr>
99  *
100  * <tr>
101  * <td>xml.catalog.files</td>
102  * <td>catalogs</td>
103  * <td>The <emph>semicolon-delimited</emph> list of catalog files.</td>
104  * </tr>
105  *
106  * <tr>
107  * <td>&#160;</td>
108  * <td>relative-catalogs</td>
109  * <td>If false, relative catalog URIs are made absolute with respect to the base URI of
110  * the <i>CatalogManager.properties</i> file. This setting only applies to catalog
111  * URIs obtained from the <i>catalogs</i> property <emph>in the</emph>
112  * <i>CatalogManager.properties</i> file</td>
113  * </tr>
114  *
115  * <tr>
116  * <td>xml.catalog.verbosity</td>
117  * <td>verbosity</td>
118  * <td>If non-zero, the Catalog classes will print informative and debugging messages.
119  * The higher the number, the more messages.</td>
120  * </tr>
121  *
122  * <tr>
123  * <td>xml.catalog.prefer</td>
124  * <td>prefer</td>
125  * <td>Which identifier is preferred, "public" or "system"?</td>
126  * </tr>
127  *
128  * <tr>
129  * <td>xml.catalog.staticCatalog</td>
130  * <td>static-catalog</td>
131  * <td>Should a single catalog be constructed for all parsing, or should a different
132  * catalog be created for each parser?</td>
133  * </tr>
134  *
135  * <tr>
136  * <td>xml.catalog.allowPI</td>
137  * <td>allow-oasis-xml-catalog-pi</td>
138  * <td>If the source document contains "oasis-xml-catalog" processing instructions,
139  * should they be used?</td>
140  * </tr>
141  *
142  * <tr>
143  * <td>xml.catalog.className</td>
144  * <td>catalog-class-name</td>
145  * <td>If you're using the convenience classes
146  * <tt>org.apache.xml.resolver.tools.*</tt>), this setting
147  * allows you to specify an alternate class name to use for the underlying
148  * catalog.</td>
149  * </tr>
150  * </tbody>
151  * </table>
152  *
153  * @see Catalog
154  *
155  * @author Norman Walsh
156  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
157  *
158  * @version 1.0
159  */

160
161 public class CatalogManager {
162   private static String JavaDoc pFiles = "xml.catalog.files";
163   private static String JavaDoc pVerbosity = "xml.catalog.verbosity";
164   private static String JavaDoc pPrefer = "xml.catalog.prefer";
165   private static String JavaDoc pStatic = "xml.catalog.staticCatalog";
166   private static String JavaDoc pAllowPI = "xml.catalog.allowPI";
167   private static String JavaDoc pClassname = "xml.catalog.className";
168   private static String JavaDoc pIgnoreMissing = "xml.catalog.ignoreMissing";
169
170   /** A static CatalogManager instance for sharing */
171   private static CatalogManager staticManager = new CatalogManager();
172
173   /** The bootstrap resolver to use when loading XML Catalogs. */
174   private BootstrapResolver bResolver = new BootstrapResolver();
175
176   /** Flag to ignore missing property files and/or properties */
177   private boolean ignoreMissingProperties
178     = (System.getProperty(pIgnoreMissing) != null
179        || System.getProperty(pFiles) != null);
180
181   /** Holds the resources after they are loaded from the file. */
182   private ResourceBundle JavaDoc resources;
183
184   /** The name of the CatalogManager properties file. */
185   private String JavaDoc propertyFile = "CatalogManager.properties";
186
187   /** The location of the propertyFile */
188   private URL JavaDoc propertyFileURI = null;
189
190   /** Default catalog files list. */
191   private String JavaDoc defaultCatalogFiles = "./xcatalog";
192
193   /** Current catalog files list. */
194   private String JavaDoc catalogFiles = null;
195
196   /** Did the catalgoFiles come from the properties file? */
197   private boolean fromPropertiesFile = false;
198
199   /** Default verbosity level if there is no property setting for it. */
200   private int defaultVerbosity = 1;
201
202   /** Current verbosity level. */
203   private Integer JavaDoc verbosity = null;
204
205   /** Default preference setting. */
206   private boolean defaultPreferPublic = true;
207
208   /** Current preference setting. */
209   private Boolean JavaDoc preferPublic = null;
210
211   /** Default setting of the static catalog flag. */
212   private boolean defaultUseStaticCatalog = true;
213
214   /** Current setting of the static catalog flag. */
215   private Boolean JavaDoc useStaticCatalog = null;
216
217   /** The static catalog used by this manager. */
218   private static Catalog staticCatalog = null;
219
220   /** Default setting of the oasisXMLCatalogPI flag. */
221   private boolean defaultOasisXMLCatalogPI = true;
222
223   /** Current setting of the oasisXMLCatalogPI flag. */
224   private Boolean JavaDoc oasisXMLCatalogPI = null;
225
226   /** Default setting of the relativeCatalogs flag. */
227   private boolean defaultRelativeCatalogs = true;
228
229   /** Current setting of the relativeCatalogs flag. */
230   private Boolean JavaDoc relativeCatalogs = null;
231
232   /** Current catalog class name. */
233   private String JavaDoc catalogClassName = null;
234
235   /** The manager's debug object. Used for printing debugging messages.
236    *
237    * <p>This field is public so that objects that have access to this
238    * CatalogManager can use this debug object.</p>
239    */

240   public Debug debug = null;
241
242   /** Constructor. */
243   public CatalogManager() {
244     debug = new Debug();
245     // Note that we don't setDebug() here; we do that lazily. Either the
246
// user will set it explicitly, or we'll do it automagically if they
247
// read from the propertyFile for some other reason. That way, there's
248
// no attempt to read from the file before the caller has had a chance
249
// to avoid it.
250
}
251
252   /** Constructor that specifies an explicit property file. */
253   public CatalogManager(String JavaDoc propertyFile) {
254     this.propertyFile = propertyFile;
255
256     debug = new Debug();
257     // Note that we don't setDebug() here; we do that lazily. Either the
258
// user will set it explicitly, or we'll do it automagically if they
259
// read from the propertyFile for some other reason. That way, there's
260
// no attempt to read from the file before the caller has had a chance
261
// to avoid it.
262
}
263
264   /** Set the bootstrap resolver.*/
265   public void setBootstrapResolver(BootstrapResolver resolver) {
266     bResolver = resolver;
267   }
268
269   /** Get the bootstrap resolver.*/
270   public BootstrapResolver getBootstrapResolver() {
271     return bResolver;
272   }
273
274   /**
275    * Load the properties from the propertyFile and build the
276    * resources from it.
277    */

278   private synchronized void readProperties() {
279     try {
280       propertyFileURI = CatalogManager.class.getResource("/"+propertyFile);
281       InputStream JavaDoc in =
282     CatalogManager.class.getResourceAsStream("/"+propertyFile);
283       if (in==null) {
284     if (!ignoreMissingProperties) {
285       System.err.println("Cannot find "+propertyFile);
286       // there's no reason to give this warning more than once
287
ignoreMissingProperties = true;
288     }
289     return;
290       }
291       resources = new PropertyResourceBundle JavaDoc(in);
292     } catch (MissingResourceException JavaDoc mre) {
293       if (!ignoreMissingProperties) {
294     System.err.println("Cannot read "+propertyFile);
295       }
296     } catch (java.io.IOException JavaDoc e) {
297       if (!ignoreMissingProperties) {
298     System.err.println("Failure trying to read "+propertyFile);
299       }
300     }
301
302     // This is a bit of a hack. After we've successfully read the properties,
303
// use them to set the default debug level, if the user hasn't already set
304
// the default debug level.
305
if (verbosity == null) {
306       try {
307     String JavaDoc verbStr = resources.getString("verbosity");
308     int verb = Integer.parseInt(verbStr.trim());
309     debug.setDebug(verb);
310     verbosity = new Integer JavaDoc(verb);
311       } catch (Exception JavaDoc e) {
312     // nop
313
}
314     }
315   }
316
317   /**
318    * Allow access to the static CatalogManager
319    */

320   public static CatalogManager getStaticManager() {
321     return staticManager;
322   }
323
324   /**
325    * How are missing properties handled?
326    *
327    * <p>If true, missing or unreadable property files will
328    * not be reported. Otherwise, a message will be sent to System.err.
329    * </p>
330    */

331   public boolean getIgnoreMissingProperties() {
332     return ignoreMissingProperties;
333   }
334
335   /**
336    * How should missing properties be handled?
337    *
338    * <p>If ignore is true, missing or unreadable property files will
339    * not be reported. Otherwise, a message will be sent to System.err.
340    * </p>
341    */

342   public void setIgnoreMissingProperties(boolean ignore) {
343     ignoreMissingProperties = ignore;
344   }
345
346   /**
347    * How are missing properties handled?
348    *
349    * <p>If ignore is true, missing or unreadable property files will
350    * not be reported. Otherwise, a message will be sent to System.err.
351    * </p>
352    *
353    * @deprecated No longer static; use get/set methods.
354    */

355   public void ignoreMissingProperties(boolean ignore) {
356     setIgnoreMissingProperties(ignore);
357   }
358
359   /**
360    * Obtain the verbosity setting from the properties.
361    *
362    * @return The verbosity level from the propertyFile or the
363    * defaultVerbosity.
364    */

365   private int queryVerbosity () {
366     String JavaDoc verbStr = System.getProperty(pVerbosity);
367
368     if (verbStr == null) {
369       if (resources==null) readProperties();
370       if (resources==null) return defaultVerbosity;
371       try {
372     verbStr = resources.getString("verbosity");
373       } catch (MissingResourceException JavaDoc e) {
374     return defaultVerbosity;
375       }
376     }
377
378     try {
379       int verb = Integer.parseInt(verbStr.trim());
380       return verb;
381     } catch (Exception JavaDoc e) {
382       System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
383       return defaultVerbosity;
384     }
385   }
386
387   /**
388    * What is the current verbosity?
389    */

390   public int getVerbosity() {
391     if (verbosity == null) {
392       verbosity = new Integer JavaDoc(queryVerbosity());
393     }
394
395     return verbosity.intValue();
396   }
397
398   /**
399    * Set the current verbosity.
400    */

401   public void setVerbosity (int verbosity) {
402     this.verbosity = new Integer JavaDoc(verbosity);
403     debug.setDebug(verbosity);
404   }
405
406   /**
407    * What is the current verbosity?
408    *
409    * @deprecated No longer static; use get/set methods.
410    */

411   public int verbosity () {
412     return getVerbosity();
413   }
414
415   /**
416    * Obtain the relativeCatalogs setting from the properties.
417    *
418    * @return The relativeCatalogs setting from the propertyFile or the
419    * defaultRelativeCatalogs.
420    */

421   private boolean queryRelativeCatalogs () {
422     if (resources==null) readProperties();
423
424     if (resources==null) return defaultRelativeCatalogs;
425
426     try {
427       String JavaDoc allow = resources.getString("relative-catalogs");
428       return (allow.equalsIgnoreCase("true")
429           || allow.equalsIgnoreCase("yes")
430           || allow.equalsIgnoreCase("1"));
431     } catch (MissingResourceException JavaDoc e) {
432       return defaultRelativeCatalogs;
433     }
434   }
435
436   /**
437    * Get the relativeCatalogs setting.
438    *
439    * <p>This property is used when the catalogFiles property is
440    * interrogated. If true, then relative catalog entry file names
441    * are returned. If false, relative catalog entry file names are
442    * made absolute with respect to the properties file before returning
443    * them.</p>
444    *
445    * <p>This property <emph>only applies</emph> when the catalog files
446    * come from a properties file. If they come from a system property or
447    * the default list, they are never considered relative. (What would
448    * they be relative to?)</p>
449    *
450    * <p>In the properties, a value of 'yes', 'true', or '1' is considered
451    * true, anything else is false.</p>
452    *
453    * @return The relativeCatalogs setting from the propertyFile or the
454    * defaultRelativeCatalogs.
455    */

456   public boolean getRelativeCatalogs () {
457     if (relativeCatalogs == null) {
458       relativeCatalogs = new Boolean JavaDoc(queryRelativeCatalogs());
459     }
460
461     return relativeCatalogs.booleanValue();
462   }
463
464   /**
465    * Set the relativeCatalogs setting.
466    *
467    * @return The relativeCatalogs setting from the propertyFile or the
468    * defaultRelativeCatalogs.
469    *
470    * @see #getRelativeCatalogs()
471    */

472   public void setRelativeCatalogs (boolean relative) {
473     relativeCatalogs = new Boolean JavaDoc(relative);
474   }
475
476   /**
477    * Get the relativeCatalogs setting.
478    *
479    * @deprecated No longer static; use get/set methods.
480    */

481   public boolean relativeCatalogs () {
482     return getRelativeCatalogs();
483   }
484
485   /**
486    * Obtain the list of catalog files from the properties.
487    *
488    * @return A semicolon delimited list of catlog file URIs
489    */

490   private String JavaDoc queryCatalogFiles () {
491     String JavaDoc catalogList = System.getProperty(pFiles);
492     fromPropertiesFile = false;
493
494     if (catalogList == null) {
495       if (resources == null) readProperties();
496       if (resources != null) {
497     try {
498       catalogList = resources.getString("catalogs");
499       fromPropertiesFile = true;
500     } catch (MissingResourceException JavaDoc e) {
501       System.err.println(propertyFile + ": catalogs not found.");
502       catalogList = null;
503     }
504       }
505     }
506
507     if (catalogList == null) {
508       catalogList = defaultCatalogFiles;
509     }
510
511     return catalogList;
512   }
513
514   /**
515    * Return the current list of catalog files.
516    *
517    * @return A vector of the catalog file names or null if no catalogs
518    * are available in the properties.
519    */

520   public Vector JavaDoc getCatalogFiles() {
521     if (catalogFiles == null) {
522       catalogFiles = queryCatalogFiles();
523     }
524
525     StringTokenizer JavaDoc files = new StringTokenizer JavaDoc(catalogFiles, ";");
526     Vector JavaDoc catalogs = new Vector JavaDoc();
527     while (files.hasMoreTokens()) {
528       String JavaDoc catalogFile = files.nextToken();
529       URL JavaDoc absURI = null;
530
531       if (fromPropertiesFile && !relativeCatalogs()) {
532     try {
533       absURI = new URL JavaDoc(propertyFileURI, catalogFile);
534       catalogFile = absURI.toString();
535     } catch (MalformedURLException JavaDoc mue) {
536       absURI = null;
537     }
538       }
539
540       catalogs.add(catalogFile);
541     }
542
543     return catalogs;
544   }
545
546   /**
547    * Set the list of catalog files.
548    */

549   public void setCatalogFiles(String JavaDoc fileList) {
550     catalogFiles = fileList;
551     fromPropertiesFile = false;
552   }
553
554   /**
555    * Return the current list of catalog files.
556    *
557    * @return A vector of the catalog file names or null if no catalogs
558    * are available in the properties.
559    *
560    * @deprecated No longer static; use get/set methods.
561    */

562   public Vector JavaDoc catalogFiles() {
563     return getCatalogFiles();
564   }
565
566   /**
567    * Obtain the preferPublic setting from the properties.
568    *
569    * <p>In the properties, a value of 'public' is true,
570    * anything else is false.</p>
571    *
572    * @return True if prefer is public or the
573    * defaultPreferSetting.
574    */

575   private boolean queryPreferPublic () {
576     String JavaDoc prefer = System.getProperty(pPrefer);
577
578     if (prefer == null) {
579       if (resources==null) readProperties();
580       if (resources==null) return defaultPreferPublic;
581       try {
582     prefer = resources.getString("prefer");
583       } catch (MissingResourceException JavaDoc e) {
584     return defaultPreferPublic;
585       }
586     }
587
588     if (prefer == null) {
589       return defaultPreferPublic;
590     }
591
592     return (prefer.equalsIgnoreCase("public"));
593   }
594
595   /**
596    * Return the current prefer public setting.
597    *
598    * @return True if public identifiers are preferred.
599    */

600   public boolean getPreferPublic () {
601     if (preferPublic == null) {
602       preferPublic = new Boolean JavaDoc(queryPreferPublic());
603     }
604     return preferPublic.booleanValue();
605   }
606
607   /**
608    * Set the prefer public setting.
609    *
610    * @return True if public identifiers are preferred.
611    */

612   public void setPreferPublic (boolean preferPublic) {
613     this.preferPublic = new Boolean JavaDoc(preferPublic);
614   }
615
616   /**
617    * Return the current prefer public setting.
618    *
619    * @return True if public identifiers are preferred.
620    *
621    * @deprecated No longer static; use get/set methods.
622    */

623   public boolean preferPublic () {
624     return getPreferPublic();
625   }
626
627   /**
628    * Obtain the static-catalog setting from the properties.
629    *
630    * <p>In the properties, a value of 'yes', 'true', or '1' is considered
631    * true, anything else is false.</p>
632    *
633    * @return The static-catalog setting from the propertyFile or the
634    * defaultUseStaticCatalog.
635    */

636   private boolean queryUseStaticCatalog () {
637     String JavaDoc staticCatalog = System.getProperty(pStatic);
638
639     if (useStaticCatalog == null) {
640       if (resources==null) readProperties();
641       if (resources==null) return defaultUseStaticCatalog;
642       try {
643     staticCatalog = resources.getString("static-catalog");
644       } catch (MissingResourceException JavaDoc e) {
645     return defaultUseStaticCatalog;
646       }
647     }
648
649     if (staticCatalog == null) {
650       return defaultUseStaticCatalog;
651     }
652
653     return (staticCatalog.equalsIgnoreCase("true")
654         || staticCatalog.equalsIgnoreCase("yes")
655         || staticCatalog.equalsIgnoreCase("1"));
656   }
657
658   /**
659    * Get the current use static catalog setting.
660    */

661   public boolean getUseStaticCatalog() {
662     if (useStaticCatalog == null) {
663       useStaticCatalog = new Boolean JavaDoc(queryUseStaticCatalog());
664     }
665
666     return useStaticCatalog.booleanValue();
667   }
668
669   /**
670    * Set the use static catalog setting.
671    */

672   public void setUseStaticCatalog(boolean useStatic) {
673     useStaticCatalog = new Boolean JavaDoc(useStatic);
674   }
675
676   /**
677    * Get the current use static catalog setting.
678    *
679    * @deprecated No longer static; use get/set methods.
680    */

681   public boolean staticCatalog() {
682     return getUseStaticCatalog();
683   }
684
685   /**
686    * Get a new catalog instance.
687    *
688    * This method always returns a new instance of the underlying catalog class.
689    */

690   public Catalog getPrivateCatalog() {
691     Catalog catalog = staticCatalog;
692
693     if (useStaticCatalog == null) {
694       useStaticCatalog = new Boolean JavaDoc(getUseStaticCatalog());
695     }
696
697     if (catalog == null || !useStaticCatalog.booleanValue()) {
698
699       try {
700     String JavaDoc catalogClassName = getCatalogClassName();
701
702     if (catalogClassName == null) {
703       catalog = new Catalog();
704     } else {
705       try {
706         catalog = (Catalog) Class.forName(catalogClassName).newInstance();
707       } catch (ClassNotFoundException JavaDoc cnfe) {
708         debug.message(1,"Catalog class named '"
709               + catalogClassName
710               + "' could not be found. Using default.");
711         catalog = new Catalog();
712       } catch (ClassCastException JavaDoc cnfe) {
713         debug.message(1,"Class named '"
714               + catalogClassName
715               + "' is not a Catalog. Using default.");
716         catalog = new Catalog();
717       }
718     }
719
720     catalog.setCatalogManager(this);
721     catalog.setupReaders();
722     catalog.loadSystemCatalogs();
723       } catch (Exception JavaDoc ex) {
724     ex.printStackTrace();
725       }
726
727       if (useStaticCatalog.booleanValue()) {
728     staticCatalog = catalog;
729       }
730     }
731
732     return catalog;
733   }
734
735   /**
736    * Get a catalog instance.
737    *
738    * If this manager uses static catalogs, the same static catalog will
739    * always be returned. Otherwise a new catalog will be returned.
740    */

741   public Catalog getCatalog() {
742     Catalog catalog = staticCatalog;
743
744     if (useStaticCatalog == null) {
745       useStaticCatalog = new Boolean JavaDoc(getUseStaticCatalog());
746     }
747
748     if (catalog == null || !useStaticCatalog.booleanValue()) {
749       catalog = getPrivateCatalog();
750       if (useStaticCatalog.booleanValue()) {
751     staticCatalog = catalog;
752       }
753     }
754
755     return catalog;
756   }
757
758   /**
759    * <p>Obtain the oasisXMLCatalogPI setting from the properties.</p>
760    *
761    * <p>In the properties, a value of 'yes', 'true', or '1' is considered
762    * true, anything else is false.</p>
763    *
764    * @return The oasisXMLCatalogPI setting from the propertyFile or the
765    * defaultOasisXMLCatalogPI.
766    */

767   public boolean queryAllowOasisXMLCatalogPI () {
768     String JavaDoc allow = System.getProperty(pAllowPI);
769
770     if (allow == null) {
771       if (resources==null) readProperties();
772       if (resources==null) return defaultOasisXMLCatalogPI;
773       try {
774     allow = resources.getString("allow-oasis-xml-catalog-pi");
775       } catch (MissingResourceException JavaDoc e) {
776     return defaultOasisXMLCatalogPI;
777       }
778     }
779
780     if (allow == null) {
781       return defaultOasisXMLCatalogPI;
782     }
783
784     return (allow.equalsIgnoreCase("true")
785         || allow.equalsIgnoreCase("yes")
786         || allow.equalsIgnoreCase("1"));
787   }
788
789   /**
790    * Get the current XML Catalog PI setting.
791    */

792   public boolean getAllowOasisXMLCatalogPI () {
793     if (oasisXMLCatalogPI == null) {
794       oasisXMLCatalogPI = new Boolean JavaDoc(queryAllowOasisXMLCatalogPI());
795     }
796
797     return oasisXMLCatalogPI.booleanValue();
798   }
799
800   /**
801    * Set the XML Catalog PI setting
802    */

803   public void setAllowOasisXMLCatalogPI(boolean allowPI) {
804     oasisXMLCatalogPI = new Boolean JavaDoc(allowPI);
805   }
806
807   /**
808    * Get the current XML Catalog PI setting.
809    *
810    * @deprecated No longer static; use get/set methods.
811    */

812   public boolean allowOasisXMLCatalogPI() {
813     return getAllowOasisXMLCatalogPI();
814   }
815
816   /**
817    * Obtain the Catalog class name setting from the properties.
818    *
819    */

820   public String JavaDoc queryCatalogClassName () {
821     String JavaDoc className = System.getProperty(pClassname);
822
823     if (className == null) {
824       if (resources==null) readProperties();
825       if (resources==null) return null;
826       try {
827     return resources.getString("catalog-class-name");
828       } catch (MissingResourceException JavaDoc e) {
829     return null;
830       }
831     }
832
833     return className;
834   }
835
836   /**
837    * Get the current Catalog class name.
838    */

839   public String JavaDoc getCatalogClassName() {
840     if (catalogClassName == null) {
841       catalogClassName = queryCatalogClassName();
842     }
843
844     return catalogClassName;
845   }
846
847   /**
848    * Set the Catalog class name.
849    */

850   public void setCatalogClassName(String JavaDoc className) {
851     catalogClassName = className;
852   }
853
854   /**
855    * Get the current Catalog class name.
856    *
857    * @deprecated No longer static; use get/set methods.
858    */

859   public String JavaDoc catalogClassName() {
860     return getCatalogClassName();
861   }
862 }
863
Popular Tags