Source Code Cross Referenced for CatalogManager.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » org » apache » xml » internal » resolver » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb xjc » com.sun.org.apache.xml.internal.resolver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // CatalogManager.java - Access CatalogManager.properties
002:
003:        /*
004:         * Copyright 2001-2004 The Apache Software Foundation or its licensors,
005:         * as applicable.
006:         * 
007:         * Licensed under the Apache License, Version 2.0 (the "License");
008:         * you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at
010:         * 
011:         *      http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        package com.sun.org.apache.xml.internal.resolver;
021:
022:        import java.io.InputStream;
023:
024:        import java.net.URL;
025:        import java.net.MalformedURLException;
026:
027:        import java.util.MissingResourceException;
028:        import java.util.PropertyResourceBundle;
029:        import java.util.ResourceBundle;
030:        import java.util.StringTokenizer;
031:        import java.util.Vector;
032:
033:        import com.sun.org.apache.xml.internal.resolver.helpers.Debug;
034:        import com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolver;
035:        import com.sun.org.apache.xml.internal.resolver.Catalog;
036:
037:        /**
038:         * CatalogManager provides an interface to the catalog properties.
039:         *
040:         * <p>Properties can come from two places: from system properties or
041:         * from a <i>CatalogManager.properties</i> file. This class provides a transparent
042:         * interface to both, with system properties preferred over property file values.</p>
043:         *
044:         * <p>The following table summarizes the properties:</p>
045:         *
046:         * <table border="1">
047:         * <thead>
048:         * <tr>
049:         * <td>System Property</td>
050:         * <td>CatalogManager.properties<br/>Property</td>
051:         * <td>Description</td>
052:         * </tr>
053:         * </thead>
054:         * <tbody>
055:         * <tr>
056:         * <td>xml.catalog.ignoreMissing</td>
057:         * <td>&#160;</td>
058:         * <td>If true, a missing <i>CatalogManager.properties</i> file or missing properties
059:         * within that file will not generate warning messages. See also the
060:         * <i>ignoreMissingProperties</i> method.</td>
061:         * </tr>
062:         *
063:         * <tr>
064:         * <td>xml.catalog.files</td>
065:         * <td>catalogs</td>
066:         * <td>The <emph>semicolon-delimited</emph> list of catalog files.</td>
067:         * </tr>
068:         *
069:         * <tr>
070:         * <td>&#160;</td>
071:         * <td>relative-catalogs</td>
072:         * <td>If false, relative catalog URIs are made absolute with respect to the base URI of
073:         * the <i>CatalogManager.properties</i> file. This setting only applies to catalog
074:         * URIs obtained from the <i>catalogs</i> property <emph>in the</emph>
075:         * <i>CatalogManager.properties</i> file</td>
076:         * </tr>
077:         *
078:         * <tr>
079:         * <td>xml.catalog.verbosity</td>
080:         * <td>verbosity</td>
081:         * <td>If non-zero, the Catalog classes will print informative and debugging messages.
082:         * The higher the number, the more messages.</td>
083:         * </tr>
084:         *
085:         * <tr>
086:         * <td>xml.catalog.prefer</td>
087:         * <td>prefer</td>
088:         * <td>Which identifier is preferred, "public" or "system"?</td>
089:         * </tr>
090:         *
091:         * <tr>
092:         * <td>xml.catalog.staticCatalog</td>
093:         * <td>static-catalog</td>
094:         * <td>Should a single catalog be constructed for all parsing, or should a different
095:         * catalog be created for each parser?</td>
096:         * </tr>
097:         *
098:         * <tr>
099:         * <td>xml.catalog.allowPI</td>
100:         * <td>allow-oasis-xml-catalog-pi</td>
101:         * <td>If the source document contains "oasis-xml-catalog" processing instructions,
102:         * should they be used?</td>
103:         * </tr>
104:         *
105:         * <tr>
106:         * <td>xml.catalog.className</td>
107:         * <td>catalog-class-name</td>
108:         * <td>If you're using the convenience classes
109:         * <tt>com.sun.org.apache.xml.internal.resolver.tools.*</tt>), this setting
110:         * allows you to specify an alternate class name to use for the underlying
111:         * catalog.</td>
112:         * </tr>
113:         * </tbody>
114:         * </table>
115:         *
116:         * @see Catalog
117:         *
118:         * @author Norman Walsh
119:         * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
120:         *
121:         * @version 1.0
122:         */
123:
124:        public class CatalogManager {
125:            private static String pFiles = "xml.catalog.files";
126:            private static String pVerbosity = "xml.catalog.verbosity";
127:            private static String pPrefer = "xml.catalog.prefer";
128:            private static String pStatic = "xml.catalog.staticCatalog";
129:            private static String pAllowPI = "xml.catalog.allowPI";
130:            private static String pClassname = "xml.catalog.className";
131:            private static String pIgnoreMissing = "xml.catalog.ignoreMissing";
132:
133:            /** A static CatalogManager instance for sharing */
134:            private static CatalogManager staticManager = new CatalogManager();
135:
136:            /** The bootstrap resolver to use when loading XML Catalogs. */
137:            private BootstrapResolver bResolver = new BootstrapResolver();
138:
139:            /** Flag to ignore missing property files and/or properties */
140:            private boolean ignoreMissingProperties = (System
141:                    .getProperty(pIgnoreMissing) != null || System
142:                    .getProperty(pFiles) != null);
143:
144:            /** Holds the resources after they are loaded from the file. */
145:            private ResourceBundle resources;
146:
147:            /** The name of the CatalogManager properties file. */
148:            private String propertyFile = "CatalogManager.properties";
149:
150:            /** The location of the propertyFile */
151:            private URL propertyFileURI = null;
152:
153:            /** Default catalog files list. */
154:            private String defaultCatalogFiles = "./xcatalog";
155:
156:            /** Current catalog files list. */
157:            private String catalogFiles = null;
158:
159:            /** Did the catalogFiles come from the properties file? */
160:            private boolean fromPropertiesFile = false;
161:
162:            /** Default verbosity level if there is no property setting for it. */
163:            private int defaultVerbosity = 1;
164:
165:            /** Current verbosity level. */
166:            private Integer verbosity = null;
167:
168:            /** Default preference setting. */
169:            private boolean defaultPreferPublic = true;
170:
171:            /** Current preference setting. */
172:            private Boolean preferPublic = null;
173:
174:            /** Default setting of the static catalog flag. */
175:            private boolean defaultUseStaticCatalog = true;
176:
177:            /** Current setting of the static catalog flag. */
178:            private Boolean useStaticCatalog = null;
179:
180:            /** The static catalog used by this manager. */
181:            private static Catalog staticCatalog = null;
182:
183:            /** Default setting of the oasisXMLCatalogPI flag. */
184:            private boolean defaultOasisXMLCatalogPI = true;
185:
186:            /** Current setting of the oasisXMLCatalogPI flag. */
187:            private Boolean oasisXMLCatalogPI = null;
188:
189:            /** Default setting of the relativeCatalogs flag. */
190:            private boolean defaultRelativeCatalogs = true;
191:
192:            /** Current setting of the relativeCatalogs flag. */
193:            private Boolean relativeCatalogs = null;
194:
195:            /** Current catalog class name. */
196:            private String catalogClassName = null;
197:
198:            /** The manager's debug object. Used for printing debugging messages.
199:             *
200:             * <p>This field is public so that objects that have access to this
201:             * CatalogManager can use this debug object.</p>
202:             */
203:            public Debug debug = null;
204:
205:            /** Constructor. */
206:            public CatalogManager() {
207:                debug = new Debug();
208:                // Note that we don't setDebug() here; we do that lazily. Either the
209:                // user will set it explicitly, or we'll do it automagically if they
210:                // read from the propertyFile for some other reason. That way, there's
211:                // no attempt to read from the file before the caller has had a chance
212:                // to avoid it.
213:            }
214:
215:            /** Constructor that specifies an explicit property file. */
216:            public CatalogManager(String propertyFile) {
217:                this .propertyFile = propertyFile;
218:
219:                debug = new Debug();
220:                // Note that we don't setDebug() here; we do that lazily. Either the
221:                // user will set it explicitly, or we'll do it automagically if they
222:                // read from the propertyFile for some other reason. That way, there's
223:                // no attempt to read from the file before the caller has had a chance
224:                // to avoid it.
225:            }
226:
227:            /** Set the bootstrap resolver.*/
228:            public void setBootstrapResolver(BootstrapResolver resolver) {
229:                bResolver = resolver;
230:            }
231:
232:            /** Get the bootstrap resolver.*/
233:            public BootstrapResolver getBootstrapResolver() {
234:                return bResolver;
235:            }
236:
237:            /**
238:             * Load the properties from the propertyFile and build the
239:             * resources from it.
240:             */
241:            private synchronized void readProperties() {
242:                try {
243:                    propertyFileURI = CatalogManager.class.getResource("/"
244:                            + propertyFile);
245:                    InputStream in = CatalogManager.class
246:                            .getResourceAsStream("/" + propertyFile);
247:                    if (in == null) {
248:                        if (!ignoreMissingProperties) {
249:                            System.err.println("Cannot find " + propertyFile);
250:                            // there's no reason to give this warning more than once
251:                            ignoreMissingProperties = true;
252:                        }
253:                        return;
254:                    }
255:                    resources = new PropertyResourceBundle(in);
256:                } catch (MissingResourceException mre) {
257:                    if (!ignoreMissingProperties) {
258:                        System.err.println("Cannot read " + propertyFile);
259:                    }
260:                } catch (java.io.IOException e) {
261:                    if (!ignoreMissingProperties) {
262:                        System.err.println("Failure trying to read "
263:                                + propertyFile);
264:                    }
265:                }
266:
267:                // This is a bit of a hack. After we've successfully read the properties,
268:                // use them to set the default debug level, if the user hasn't already set
269:                // the default debug level.
270:                if (verbosity == null) {
271:                    try {
272:                        String verbStr = resources.getString("verbosity");
273:                        int verb = Integer.parseInt(verbStr.trim());
274:                        debug.setDebug(verb);
275:                        verbosity = new Integer(verb);
276:                    } catch (Exception e) {
277:                        // nop
278:                    }
279:                }
280:            }
281:
282:            /**
283:             * Allow access to the static CatalogManager
284:             */
285:            public static CatalogManager getStaticManager() {
286:                return staticManager;
287:            }
288:
289:            /**
290:             * How are missing properties handled?
291:             *
292:             * <p>If true, missing or unreadable property files will
293:             * not be reported. Otherwise, a message will be sent to System.err.
294:             * </p>
295:             */
296:            public boolean getIgnoreMissingProperties() {
297:                return ignoreMissingProperties;
298:            }
299:
300:            /**
301:             * How should missing properties be handled?
302:             *
303:             * <p>If ignore is true, missing or unreadable property files will
304:             * not be reported. Otherwise, a message will be sent to System.err.
305:             * </p>
306:             */
307:            public void setIgnoreMissingProperties(boolean ignore) {
308:                ignoreMissingProperties = ignore;
309:            }
310:
311:            /**
312:             * How are missing properties handled?
313:             *
314:             * <p>If ignore is true, missing or unreadable property files will
315:             * not be reported. Otherwise, a message will be sent to System.err.
316:             * </p>
317:             *
318:             * @deprecated No longer static; use get/set methods.
319:             */
320:            public void ignoreMissingProperties(boolean ignore) {
321:                setIgnoreMissingProperties(ignore);
322:            }
323:
324:            /**
325:             * Obtain the verbosity setting from the properties.
326:             *
327:             * @return The verbosity level from the propertyFile or the
328:             * defaultVerbosity.
329:             */
330:            private int queryVerbosity() {
331:                String defaultVerbStr = Integer.toString(defaultVerbosity);
332:
333:                String verbStr = System.getProperty(pVerbosity);
334:
335:                if (verbStr == null) {
336:                    if (resources == null)
337:                        readProperties();
338:                    if (resources != null) {
339:                        try {
340:                            verbStr = resources.getString("verbosity");
341:                        } catch (MissingResourceException e) {
342:                            verbStr = defaultVerbStr;
343:                        }
344:                    } else {
345:                        verbStr = defaultVerbStr;
346:                    }
347:                }
348:
349:                int verb = defaultVerbosity;
350:
351:                try {
352:                    verb = Integer.parseInt(verbStr.trim());
353:                } catch (Exception e) {
354:                    System.err.println("Cannot parse verbosity: \"" + verbStr
355:                            + "\"");
356:                }
357:
358:                // This is a bit of a hack. After we've successfully got the verbosity,
359:                // we have to use it to set the default debug level,
360:                // if the user hasn't already set the default debug level.
361:                if (verbosity == null) {
362:                    debug.setDebug(verb);
363:                    verbosity = new Integer(verb);
364:                }
365:
366:                return verb;
367:            }
368:
369:            /**
370:             * What is the current verbosity?
371:             */
372:            public int getVerbosity() {
373:                if (verbosity == null) {
374:                    verbosity = new Integer(queryVerbosity());
375:                }
376:
377:                return verbosity.intValue();
378:            }
379:
380:            /**
381:             * Set the current verbosity.
382:             */
383:            public void setVerbosity(int verbosity) {
384:                this .verbosity = new Integer(verbosity);
385:                debug.setDebug(verbosity);
386:            }
387:
388:            /**
389:             * What is the current verbosity?
390:             *
391:             * @deprecated No longer static; use get/set methods.
392:             */
393:            public int verbosity() {
394:                return getVerbosity();
395:            }
396:
397:            /**
398:             * Obtain the relativeCatalogs setting from the properties.
399:             *
400:             * @return The relativeCatalogs setting from the propertyFile or the
401:             * defaultRelativeCatalogs.
402:             */
403:            private boolean queryRelativeCatalogs() {
404:                if (resources == null)
405:                    readProperties();
406:
407:                if (resources == null)
408:                    return defaultRelativeCatalogs;
409:
410:                try {
411:                    String allow = resources.getString("relative-catalogs");
412:                    return (allow.equalsIgnoreCase("true")
413:                            || allow.equalsIgnoreCase("yes") || allow
414:                            .equalsIgnoreCase("1"));
415:                } catch (MissingResourceException e) {
416:                    return defaultRelativeCatalogs;
417:                }
418:            }
419:
420:            /**
421:             * Get the relativeCatalogs setting.
422:             *
423:             * <p>This property is used when the catalogFiles property is
424:             * interrogated. If true, then relative catalog entry file names
425:             * are returned. If false, relative catalog entry file names are
426:             * made absolute with respect to the properties file before returning
427:             * them.</p>
428:             *
429:             * <p>This property <emph>only applies</emph> when the catalog files
430:             * come from a properties file. If they come from a system property or
431:             * the default list, they are never considered relative. (What would
432:             * they be relative to?)</p>
433:             *
434:             * <p>In the properties, a value of 'yes', 'true', or '1' is considered
435:             * true, anything else is false.</p>
436:             *
437:             * @return The relativeCatalogs setting from the propertyFile or the
438:             * defaultRelativeCatalogs.
439:             */
440:            public boolean getRelativeCatalogs() {
441:                if (relativeCatalogs == null) {
442:                    relativeCatalogs = new Boolean(queryRelativeCatalogs());
443:                }
444:
445:                return relativeCatalogs.booleanValue();
446:            }
447:
448:            /**
449:             * Set the relativeCatalogs setting.
450:             *
451:             * @see #getRelativeCatalogs()
452:             */
453:            public void setRelativeCatalogs(boolean relative) {
454:                relativeCatalogs = new Boolean(relative);
455:            }
456:
457:            /**
458:             * Get the relativeCatalogs setting.
459:             *
460:             * @deprecated No longer static; use get/set methods.
461:             */
462:            public boolean relativeCatalogs() {
463:                return getRelativeCatalogs();
464:            }
465:
466:            /**
467:             * Obtain the list of catalog files from the properties.
468:             *
469:             * @return A semicolon delimited list of catlog file URIs
470:             */
471:            private String queryCatalogFiles() {
472:                String catalogList = System.getProperty(pFiles);
473:                fromPropertiesFile = false;
474:
475:                if (catalogList == null) {
476:                    if (resources == null)
477:                        readProperties();
478:                    if (resources != null) {
479:                        try {
480:                            catalogList = resources.getString("catalogs");
481:                            fromPropertiesFile = true;
482:                        } catch (MissingResourceException e) {
483:                            System.err.println(propertyFile
484:                                    + ": catalogs not found.");
485:                            catalogList = null;
486:                        }
487:                    }
488:                }
489:
490:                if (catalogList == null) {
491:                    catalogList = defaultCatalogFiles;
492:                }
493:
494:                return catalogList;
495:            }
496:
497:            /**
498:             * Return the current list of catalog files.
499:             *
500:             * @return A vector of the catalog file names or null if no catalogs
501:             * are available in the properties.
502:             */
503:            public Vector getCatalogFiles() {
504:                if (catalogFiles == null) {
505:                    catalogFiles = queryCatalogFiles();
506:                }
507:
508:                StringTokenizer files = new StringTokenizer(catalogFiles, ";");
509:                Vector catalogs = new Vector();
510:                while (files.hasMoreTokens()) {
511:                    String catalogFile = files.nextToken();
512:                    URL absURI = null;
513:
514:                    if (fromPropertiesFile && !relativeCatalogs()) {
515:                        try {
516:                            absURI = new URL(propertyFileURI, catalogFile);
517:                            catalogFile = absURI.toString();
518:                        } catch (MalformedURLException mue) {
519:                            absURI = null;
520:                        }
521:                    }
522:
523:                    catalogs.add(catalogFile);
524:                }
525:
526:                return catalogs;
527:            }
528:
529:            /**
530:             * Set the list of catalog files.
531:             */
532:            public void setCatalogFiles(String fileList) {
533:                catalogFiles = fileList;
534:                fromPropertiesFile = false;
535:            }
536:
537:            /**
538:             * Return the current list of catalog files.
539:             *
540:             * @return A vector of the catalog file names or null if no catalogs
541:             * are available in the properties.
542:             *
543:             * @deprecated No longer static; use get/set methods.
544:             */
545:            public Vector catalogFiles() {
546:                return getCatalogFiles();
547:            }
548:
549:            /**
550:             * Obtain the preferPublic setting from the properties.
551:             *
552:             * <p>In the properties, a value of 'public' is true,
553:             * anything else is false.</p>
554:             *
555:             * @return True if prefer is public or the
556:             * defaultPreferSetting.
557:             */
558:            private boolean queryPreferPublic() {
559:                String prefer = System.getProperty(pPrefer);
560:
561:                if (prefer == null) {
562:                    if (resources == null)
563:                        readProperties();
564:                    if (resources == null)
565:                        return defaultPreferPublic;
566:                    try {
567:                        prefer = resources.getString("prefer");
568:                    } catch (MissingResourceException e) {
569:                        return defaultPreferPublic;
570:                    }
571:                }
572:
573:                if (prefer == null) {
574:                    return defaultPreferPublic;
575:                }
576:
577:                return (prefer.equalsIgnoreCase("public"));
578:            }
579:
580:            /**
581:             * Return the current prefer public setting.
582:             *
583:             * @return True if public identifiers are preferred.
584:             */
585:            public boolean getPreferPublic() {
586:                if (preferPublic == null) {
587:                    preferPublic = new Boolean(queryPreferPublic());
588:                }
589:                return preferPublic.booleanValue();
590:            }
591:
592:            /**
593:             * Set the prefer public setting.
594:             */
595:            public void setPreferPublic(boolean preferPublic) {
596:                this .preferPublic = new Boolean(preferPublic);
597:            }
598:
599:            /**
600:             * Return the current prefer public setting.
601:             *
602:             * @return True if public identifiers are preferred.
603:             *
604:             * @deprecated No longer static; use get/set methods.
605:             */
606:            public boolean preferPublic() {
607:                return getPreferPublic();
608:            }
609:
610:            /**
611:             * Obtain the static-catalog setting from the properties.
612:             *
613:             * <p>In the properties, a value of 'yes', 'true', or '1' is considered
614:             * true, anything else is false.</p>
615:             *
616:             * @return The static-catalog setting from the propertyFile or the
617:             * defaultUseStaticCatalog.
618:             */
619:            private boolean queryUseStaticCatalog() {
620:                String staticCatalog = System.getProperty(pStatic);
621:
622:                if (staticCatalog == null) {
623:                    if (resources == null)
624:                        readProperties();
625:                    if (resources == null)
626:                        return defaultUseStaticCatalog;
627:                    try {
628:                        staticCatalog = resources.getString("static-catalog");
629:                    } catch (MissingResourceException e) {
630:                        return defaultUseStaticCatalog;
631:                    }
632:                }
633:
634:                if (staticCatalog == null) {
635:                    return defaultUseStaticCatalog;
636:                }
637:
638:                return (staticCatalog.equalsIgnoreCase("true")
639:                        || staticCatalog.equalsIgnoreCase("yes") || staticCatalog
640:                        .equalsIgnoreCase("1"));
641:            }
642:
643:            /**
644:             * Get the current use static catalog setting.
645:             */
646:            public boolean getUseStaticCatalog() {
647:                if (useStaticCatalog == null) {
648:                    useStaticCatalog = new Boolean(queryUseStaticCatalog());
649:                }
650:
651:                return useStaticCatalog.booleanValue();
652:            }
653:
654:            /**
655:             * Set the use static catalog setting.
656:             */
657:            public void setUseStaticCatalog(boolean useStatic) {
658:                useStaticCatalog = new Boolean(useStatic);
659:            }
660:
661:            /**
662:             * Get the current use static catalog setting.
663:             *
664:             * @deprecated No longer static; use get/set methods.
665:             */
666:            public boolean staticCatalog() {
667:                return getUseStaticCatalog();
668:            }
669:
670:            /**
671:             * Get a new catalog instance.
672:             *
673:             * This method always returns a new instance of the underlying catalog class.
674:             */
675:            public Catalog getPrivateCatalog() {
676:                Catalog catalog = staticCatalog;
677:
678:                if (useStaticCatalog == null) {
679:                    useStaticCatalog = new Boolean(getUseStaticCatalog());
680:                }
681:
682:                if (catalog == null || !useStaticCatalog.booleanValue()) {
683:
684:                    try {
685:                        String catalogClassName = getCatalogClassName();
686:
687:                        if (catalogClassName == null) {
688:                            catalog = new Catalog();
689:                        } else {
690:                            try {
691:                                catalog = (Catalog) Class.forName(
692:                                        catalogClassName).newInstance();
693:                            } catch (ClassNotFoundException cnfe) {
694:                                debug
695:                                        .message(
696:                                                1,
697:                                                "Catalog class named '"
698:                                                        + catalogClassName
699:                                                        + "' could not be found. Using default.");
700:                                catalog = new Catalog();
701:                            } catch (ClassCastException cnfe) {
702:                                debug.message(1, "Class named '"
703:                                        + catalogClassName
704:                                        + "' is not a Catalog. Using default.");
705:                                catalog = new Catalog();
706:                            }
707:                        }
708:
709:                        catalog.setCatalogManager(this );
710:                        catalog.setupReaders();
711:                        catalog.loadSystemCatalogs();
712:                    } catch (Exception ex) {
713:                        ex.printStackTrace();
714:                    }
715:
716:                    if (useStaticCatalog.booleanValue()) {
717:                        staticCatalog = catalog;
718:                    }
719:                }
720:
721:                return catalog;
722:            }
723:
724:            /**
725:             * Get a catalog instance.
726:             *
727:             * If this manager uses static catalogs, the same static catalog will
728:             * always be returned. Otherwise a new catalog will be returned.
729:             */
730:            public Catalog getCatalog() {
731:                Catalog catalog = staticCatalog;
732:
733:                if (useStaticCatalog == null) {
734:                    useStaticCatalog = new Boolean(getUseStaticCatalog());
735:                }
736:
737:                if (catalog == null || !useStaticCatalog.booleanValue()) {
738:                    catalog = getPrivateCatalog();
739:                    if (useStaticCatalog.booleanValue()) {
740:                        staticCatalog = catalog;
741:                    }
742:                }
743:
744:                return catalog;
745:            }
746:
747:            /**
748:             * <p>Obtain the oasisXMLCatalogPI setting from the properties.</p>
749:             *
750:             * <p>In the properties, a value of 'yes', 'true', or '1' is considered
751:             * true, anything else is false.</p>
752:             *
753:             * @return The oasisXMLCatalogPI setting from the propertyFile or the
754:             * defaultOasisXMLCatalogPI.
755:             */
756:            public boolean queryAllowOasisXMLCatalogPI() {
757:                String allow = System.getProperty(pAllowPI);
758:
759:                if (allow == null) {
760:                    if (resources == null)
761:                        readProperties();
762:                    if (resources == null)
763:                        return defaultOasisXMLCatalogPI;
764:                    try {
765:                        allow = resources
766:                                .getString("allow-oasis-xml-catalog-pi");
767:                    } catch (MissingResourceException e) {
768:                        return defaultOasisXMLCatalogPI;
769:                    }
770:                }
771:
772:                if (allow == null) {
773:                    return defaultOasisXMLCatalogPI;
774:                }
775:
776:                return (allow.equalsIgnoreCase("true")
777:                        || allow.equalsIgnoreCase("yes") || allow
778:                        .equalsIgnoreCase("1"));
779:            }
780:
781:            /**
782:             * Get the current XML Catalog PI setting.
783:             */
784:            public boolean getAllowOasisXMLCatalogPI() {
785:                if (oasisXMLCatalogPI == null) {
786:                    oasisXMLCatalogPI = new Boolean(
787:                            queryAllowOasisXMLCatalogPI());
788:                }
789:
790:                return oasisXMLCatalogPI.booleanValue();
791:            }
792:
793:            /**
794:             * Set the XML Catalog PI setting
795:             */
796:            public void setAllowOasisXMLCatalogPI(boolean allowPI) {
797:                oasisXMLCatalogPI = new Boolean(allowPI);
798:            }
799:
800:            /**
801:             * Get the current XML Catalog PI setting.
802:             *
803:             * @deprecated No longer static; use get/set methods.
804:             */
805:            public boolean allowOasisXMLCatalogPI() {
806:                return getAllowOasisXMLCatalogPI();
807:            }
808:
809:            /**
810:             * Obtain the Catalog class name setting from the properties.
811:             *
812:             */
813:            public String queryCatalogClassName() {
814:                String className = System.getProperty(pClassname);
815:
816:                if (className == null) {
817:                    if (resources == null)
818:                        readProperties();
819:                    if (resources == null)
820:                        return null;
821:                    try {
822:                        return resources.getString("catalog-class-name");
823:                    } catch (MissingResourceException e) {
824:                        return null;
825:                    }
826:                }
827:
828:                return className;
829:            }
830:
831:            /**
832:             * Get the current Catalog class name.
833:             */
834:            public String getCatalogClassName() {
835:                if (catalogClassName == null) {
836:                    catalogClassName = queryCatalogClassName();
837:                }
838:
839:                return catalogClassName;
840:            }
841:
842:            /**
843:             * Set the Catalog class name.
844:             */
845:            public void setCatalogClassName(String className) {
846:                catalogClassName = className;
847:            }
848:
849:            /**
850:             * Get the current Catalog class name.
851:             *
852:             * @deprecated No longer static; use get/set methods.
853:             */
854:            public String catalogClassName() {
855:                return getCatalogClassName();
856:            }
857:        }
w__w__w__.j__a__v__a2s___.c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.