KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Resolver.java - Represents an extension of OASIS Open Catalog files.
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.IOException JavaDoc;
60 import java.io.InputStream JavaDoc;
61 import java.io.FileNotFoundException JavaDoc;
62 import java.util.Enumeration JavaDoc;
63 import java.util.Vector JavaDoc;
64 import java.net.URL JavaDoc;
65 import java.net.URLConnection JavaDoc;
66 import java.net.MalformedURLException JavaDoc;
67
68 import org.jboss.util.xml.catalog.readers.ExtendedXMLCatalogReader;
69 import org.jboss.util.xml.catalog.readers.OASISXMLCatalogReader;
70 import org.jboss.util.xml.catalog.readers.SAXCatalogReader;
71 import org.jboss.util.xml.catalog.readers.TR9401CatalogReader;
72 import org.jboss.util.xml.catalog.readers.XCatalogReader;
73
74 import javax.xml.parsers.SAXParserFactory JavaDoc;
75
76 /**
77  * An extension to OASIS Open Catalog files, this class supports
78  * suffix-based matching and an external RFC2483 resolver.
79  *
80  * @see Catalog
81  *
82  * @author Norman Walsh
83  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
84  *
85  * @version 1.0
86  */

87 public class Resolver extends Catalog {
88   /**
89    * The URISUFFIX Catalog Entry type.
90    *
91    * <p>URI suffix entries match URIs that end in a specified suffix.</p>
92    */

93   public static final int URISUFFIX = CatalogEntry.addEntryType("URISUFFIX", 2);
94
95   /**
96    * The SYSTEMSUFFIX Catalog Entry type.
97    *
98    * <p>System suffix entries match system identifiers that end in a
99    * specified suffix.</p>
100    */

101   public static final int SYSTEMSUFFIX = CatalogEntry.addEntryType("SYSTEMSUFFIX", 2);
102
103   /**
104    * The RESOLVER Catalog Entry type.
105    *
106    * <p>A hook for providing support for web-based backup resolvers.</p>
107    */

108   public static final int RESOLVER = CatalogEntry.addEntryType("RESOLVER", 1);
109
110   /**
111    * The SYSTEMREVERSE Catalog Entry type.
112    *
113    * <p>This is a bit of a hack. There's no actual SYSTEMREVERSE entry,
114    * but this entry type is used to indicate that a reverse lookup is
115    * being performed. (This allows the Resolver to implement
116    * RFC2483 I2N and I2NS.)
117    */

118   public static final int SYSTEMREVERSE
119     = CatalogEntry.addEntryType("SYSTEMREVERSE", 1);
120
121   /**
122    * Setup readers.
123    */

124   public void setupReaders() {
125     SAXParserFactory JavaDoc spf = SAXParserFactory.newInstance();
126     spf.setNamespaceAware(true);
127     spf.setValidating(false);
128
129     SAXCatalogReader saxReader = new SAXCatalogReader(spf);
130
131     saxReader.setCatalogParser(null, "XMLCatalog",
132                    XCatalogReader.class.getName());
133
134     saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,
135                    "catalog",
136                    ExtendedXMLCatalogReader.class.getName());
137
138     addReader("application/xml", saxReader);
139
140     TR9401CatalogReader textReader = new TR9401CatalogReader();
141     addReader("text/plain", textReader);
142   }
143
144   /**
145    * Cleanup and process a Catalog entry.
146    *
147    * <p>This method processes each Catalog entry, changing mapped
148    * relative system identifiers into absolute ones (based on the current
149    * base URI), and maintaining other information about the current
150    * catalog.</p>
151    *
152    * @param entry The CatalogEntry to process.
153    */

154   public void addEntry(CatalogEntry entry) {
155     int type = entry.getEntryType();
156
157     if (type == URISUFFIX) {
158       String JavaDoc suffix = normalizeURI(entry.getEntryArg(0));
159       String JavaDoc fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
160
161       entry.setEntryArg(1, fsi);
162
163       catalogManager.debug.message(4, "URISUFFIX", suffix, fsi);
164     } else if (type == SYSTEMSUFFIX) {
165       String JavaDoc suffix = normalizeURI(entry.getEntryArg(0));
166       String JavaDoc fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
167
168       entry.setEntryArg(1, fsi);
169
170       catalogManager.debug.message(4, "SYSTEMSUFFIX", suffix, fsi);
171     }
172
173     super.addEntry(entry);
174   }
175
176   /**
177    * Return the applicable URI.
178    *
179    * <p>If a URI entry exists in the Catalog
180    * for the URI specified, return the mapped value.</p>
181    *
182    * <p>In the Resolver (as opposed to the Catalog) class, if the
183    * URI isn't found by the usual algorithm, URISUFFIX entries are
184    * considered.</p>
185    *
186    * <p>URI comparison is case sensitive.</p>
187    *
188    * @param uri The URI to locate in the catalog.
189    *
190    * @return The resolved URI.
191    *
192    * @throws MalformedURLException The system identifier of a
193    * subordinate catalog cannot be turned into a valid URL.
194    * @throws IOException Error reading subordinate catalog file.
195    */

196   public String JavaDoc resolveURI(String JavaDoc uri)
197     throws MalformedURLException JavaDoc, IOException JavaDoc {
198
199     String JavaDoc resolved = super.resolveURI(uri);
200     if (resolved != null) {
201       return resolved;
202     }
203
204     Enumeration JavaDoc enumt = catalogEntries.elements();
205     while (enumt.hasMoreElements()) {
206       CatalogEntry e = (CatalogEntry) enumt.nextElement();
207       if (e.getEntryType() == RESOLVER) {
208     resolved = resolveExternalSystem(uri, e.getEntryArg(0));
209     if (resolved != null) {
210       return resolved;
211     }
212       } else if (e.getEntryType() == URISUFFIX) {
213     String JavaDoc suffix = e.getEntryArg(0);
214     String JavaDoc result = e.getEntryArg(1);
215
216     if (suffix.length() <= uri.length()
217         && uri.substring(uri.length()-suffix.length()).equals(suffix)) {
218       return result;
219     }
220       }
221     }
222
223     // Otherwise, look in the subordinate catalogs
224
return resolveSubordinateCatalogs(Catalog.URI,
225                       null,
226                       null,
227                       uri);
228   }
229
230   /**
231    * Return the applicable SYSTEM system identifier, resorting
232    * to external RESOLVERs if necessary.
233    *
234    * <p>If a SYSTEM entry exists in the Catalog
235    * for the system ID specified, return the mapped value.</p>
236    *
237    * <p>In the Resolver (as opposed to the Catalog) class, if the
238    * URI isn't found by the usual algorithm, SYSTEMSUFFIX entries are
239    * considered.</p>
240    *
241    * <p>On Windows-based operating systems, the comparison between
242    * the system identifier provided and the SYSTEM entries in the
243    * Catalog is case-insensitive.</p>
244    *
245    * @param systemId The system ID to locate in the catalog.
246    *
247    * @return The system identifier to use for systemId.
248    *
249    * @throws MalformedURLException The formal system identifier of a
250    * subordinate catalog cannot be turned into a valid URL.
251    * @throws IOException Error reading subordinate catalog file.
252    */

253   public String JavaDoc resolveSystem(String JavaDoc systemId)
254     throws MalformedURLException JavaDoc, IOException JavaDoc {
255
256     String JavaDoc resolved = super.resolveSystem(systemId);
257     if (resolved != null) {
258       return resolved;
259     }
260
261     Enumeration JavaDoc enumt = catalogEntries.elements();
262     while (enumt.hasMoreElements()) {
263       CatalogEntry e = (CatalogEntry) enumt.nextElement();
264       if (e.getEntryType() == RESOLVER) {
265     resolved = resolveExternalSystem(systemId, e.getEntryArg(0));
266     if (resolved != null) {
267       return resolved;
268     }
269       } else if (e.getEntryType() == SYSTEMSUFFIX) {
270     String JavaDoc suffix = e.getEntryArg(0);
271     String JavaDoc result = e.getEntryArg(1);
272
273     if (suffix.length() <= systemId.length()
274         && systemId.substring(systemId.length()-suffix.length()).equals(suffix)) {
275       return result;
276     }
277       }
278     }
279
280     return resolveSubordinateCatalogs(Catalog.SYSTEM,
281                       null,
282                       null,
283                       systemId);
284   }
285
286   /**
287    * Return the applicable PUBLIC or SYSTEM identifier, resorting
288    * to external resolvers if necessary.
289    *
290    * <p>This method searches the Catalog and returns the system
291    * identifier specified for the given system or
292    * public identifiers. If
293    * no appropriate PUBLIC or SYSTEM entry is found in the Catalog,
294    * null is returned.</p>
295    *
296    * <p>Note that a system or public identifier in the current catalog
297    * (or subordinate catalogs) will be used in preference to an
298    * external resolver. Further, if a systemId is present, the external
299    * resolver(s) will be queried for that before the publicId.</p>
300    *
301    * @param publicId The public identifier to locate in the catalog.
302    * Public identifiers are normalized before comparison.
303    * @param systemId The nominal system identifier for the entity
304    * in question (as provided in the source document).
305    *
306    * @throws MalformedURLException The formal system identifier of a
307    * subordinate catalog cannot be turned into a valid URL.
308    * @throws IOException Error reading subordinate catalog file.
309    *
310    * @return The system identifier to use.
311    * Note that the nominal system identifier is not returned if a
312    * match is not found in the catalog, instead null is returned
313    * to indicate that no match was found.
314    */

315   public String JavaDoc resolvePublic(String JavaDoc publicId, String JavaDoc systemId)
316     throws MalformedURLException JavaDoc, IOException JavaDoc {
317
318     String JavaDoc resolved = super.resolvePublic(publicId, systemId);
319     if (resolved != null) {
320       return resolved;
321     }
322
323     Enumeration JavaDoc enumt = catalogEntries.elements();
324     while (enumt.hasMoreElements()) {
325       CatalogEntry e = (CatalogEntry) enumt.nextElement();
326       if (e.getEntryType() == RESOLVER) {
327     if (systemId != null) {
328       resolved = resolveExternalSystem(systemId,
329                        e.getEntryArg(0));
330       if (resolved != null) {
331         return resolved;
332       }
333     }
334     resolved = resolveExternalPublic(publicId, e.getEntryArg(0));
335     if (resolved != null) {
336       return resolved;
337     }
338       }
339     }
340
341     return resolveSubordinateCatalogs(Catalog.PUBLIC,
342                       null,
343                       publicId,
344                       systemId);
345   }
346
347     /**
348      * Query an external RFC2483 resolver for a system identifier.
349      *
350      * @param systemId The system ID to locate.
351      * @param resolver The name of the resolver to use.
352      *
353      * @return The system identifier to use for the systemId.
354      */

355     protected String JavaDoc resolveExternalSystem(String JavaDoc systemId, String JavaDoc resolver)
356     throws MalformedURLException JavaDoc, IOException JavaDoc {
357     Resolver r = queryResolver(resolver, "i2l", systemId, null);
358     if (r != null) {
359         return r.resolveSystem(systemId);
360     } else {
361         return null;
362     }
363     }
364
365     /**
366      * Query an external RFC2483 resolver for a public identifier.
367      *
368      * @param publicId The system ID to locate.
369      * @param resolver The name of the resolver to use.
370      *
371      * @return The system identifier to use for the systemId.
372      */

373     protected String JavaDoc resolveExternalPublic(String JavaDoc publicId, String JavaDoc resolver)
374     throws MalformedURLException JavaDoc, IOException JavaDoc {
375     Resolver r = queryResolver(resolver, "fpi2l", publicId, null);
376     if (r != null) {
377         return r.resolvePublic(publicId, null);
378     } else {
379         return null;
380     }
381     }
382
383     /**
384      * Query an external RFC2483 resolver.
385      *
386      * @param resolver The URL of the RFC2483 resolver.
387      * @param command The command to send the resolver.
388      * @param arg1 The first argument to the resolver.
389      * @param arg2 The second argument to the resolver, usually null.
390      *
391      * @return The Resolver constructed.
392      */

393     protected Resolver queryResolver(String JavaDoc resolver,
394                      String JavaDoc command,
395                      String JavaDoc arg1,
396                      String JavaDoc arg2) {
397     InputStream JavaDoc iStream = null;
398     String JavaDoc RFC2483 = resolver + "?command=" + command
399         + "&format=tr9401&uri=" + arg1
400         + "&uri2=" + arg2;
401     String JavaDoc line = null;
402
403     try {
404         URL JavaDoc url = new URL JavaDoc(RFC2483);
405
406         URLConnection JavaDoc urlCon = url.openConnection();
407
408         urlCon.setUseCaches(false);
409
410         Resolver r = (Resolver) newCatalog();
411
412         String JavaDoc cType = urlCon.getContentType();
413
414         // I don't care about the character set or subtype
415
if (cType.indexOf(";") > 0) {
416         cType = cType.substring(0, cType.indexOf(";"));
417         }
418
419         r.parseCatalog(cType, urlCon.getInputStream());
420
421         return r;
422     } catch (CatalogException cex) {
423       if (cex.getExceptionType() == CatalogException.UNPARSEABLE) {
424         catalogManager.debug.message(1, "Unparseable catalog: " + RFC2483);
425       } else if (cex.getExceptionType()
426              == CatalogException.UNKNOWN_FORMAT) {
427         catalogManager.debug.message(1, "Unknown catalog format: " + RFC2483);
428       }
429       return null;
430     } catch (MalformedURLException JavaDoc mue) {
431         catalogManager.debug.message(1, "Malformed resolver URL: " + RFC2483);
432         return null;
433     } catch (IOException JavaDoc ie) {
434         catalogManager.debug.message(1, "I/O Exception opening resolver: " + RFC2483);
435         return null;
436     }
437     }
438
439     /**
440      * Append two vectors, returning the result.
441      *
442      * @param vec The first vector
443      * @param appvec The vector to be appended
444      * @return The vector vec, with appvec's elements appended to it
445      */

446     private Vector JavaDoc appendVector(Vector JavaDoc vec, Vector JavaDoc appvec) {
447     if (appvec != null) {
448         for (int count = 0; count < appvec.size(); count++) {
449         vec.addElement(appvec.elementAt(count));
450         }
451     }
452     return vec;
453     }
454
455     /**
456      * Find the URNs for a given system identifier in all catalogs.
457      *
458      * @param systemId The system ID to locate.
459      *
460      * @return A vector of URNs that map to the systemId.
461      */

462     public Vector JavaDoc resolveAllSystemReverse(String JavaDoc systemId)
463     throws MalformedURLException JavaDoc, IOException JavaDoc {
464     Vector JavaDoc resolved = new Vector JavaDoc();
465
466     // If there's a SYSTEM entry in this catalog, use it
467
if (systemId != null) {
468         Vector JavaDoc localResolved = resolveLocalSystemReverse(systemId);
469         resolved = appendVector(resolved, localResolved);
470     }
471
472     // Otherwise, look in the subordinate catalogs
473
Vector JavaDoc subResolved = resolveAllSubordinateCatalogs(SYSTEMREVERSE,
474                                null,
475                                null,
476                                systemId);
477
478     return appendVector(resolved, subResolved);
479     }
480
481     /**
482      * Find the URN for a given system identifier.
483      *
484      * @param systemId The system ID to locate.
485      *
486      * @return A (single) URN that maps to the systemId.
487      */

488     public String JavaDoc resolveSystemReverse(String JavaDoc systemId)
489     throws MalformedURLException JavaDoc, IOException JavaDoc {
490     Vector JavaDoc resolved = resolveAllSystemReverse(systemId);
491     if (resolved != null && resolved.size() > 0) {
492         return (String JavaDoc) resolved.elementAt(0);
493     } else {
494         return null;
495     }
496     }
497
498     /**
499      * Return the applicable SYSTEM system identifiers.
500      *
501      * <p>If one or more SYSTEM entries exists in the Catalog
502      * for the system ID specified, return the mapped values.</p>
503      *
504      * <p>The caller is responsible for doing any necessary
505      * normalization of the system identifier before calling
506      * this method. For example, a relative system identifier in
507      * a document might be converted to an absolute system identifier
508      * before attempting to resolve it.</p>
509      *
510      * <p>Note that this function will force all subordinate catalogs
511      * to be loaded.</p>
512      *
513      * <p>On Windows-based operating systems, the comparison between
514      * the system identifier provided and the SYSTEM entries in the
515      * Catalog is case-insensitive.</p>
516      *
517      * @param systemId The system ID to locate in the catalog.
518      *
519      * @return The system identifier to use for the notation.
520      *
521      * @throws MalformedURLException The formal system identifier of a
522      * subordinate catalog cannot be turned into a valid URL.
523      * @throws IOException Error reading subordinate catalog file.
524      */

525     public Vector JavaDoc resolveAllSystem(String JavaDoc systemId)
526     throws MalformedURLException JavaDoc, IOException JavaDoc {
527     Vector JavaDoc resolutions = new Vector JavaDoc();
528
529     // If there are SYSTEM entries in this catalog, start with them
530
if (systemId != null) {
531         Vector JavaDoc localResolutions = resolveAllLocalSystem(systemId);
532         resolutions = appendVector(resolutions, localResolutions);
533     }
534
535     // Then look in the subordinate catalogs
536
Vector JavaDoc subResolutions = resolveAllSubordinateCatalogs(SYSTEM,
537                                   null,
538                                   null,
539                                   systemId);
540     resolutions = appendVector(resolutions, subResolutions);
541
542     if (resolutions.size() > 0) {
543         return resolutions;
544     } else {
545         return null;
546     }
547     }
548
549     /**
550      * Return all applicable SYSTEM system identifiers in this
551      * catalog.
552      *
553      * <p>If one or more SYSTEM entries exists in the catalog file
554      * for the system ID specified, return the mapped values.</p>
555      *
556      * @param systemId The system ID to locate in the catalog
557      *
558      * @return A vector of the mapped system identifiers or null
559      */

560     private Vector JavaDoc resolveAllLocalSystem(String JavaDoc systemId) {
561     Vector JavaDoc map = new Vector JavaDoc();
562     String JavaDoc osname = System.getProperty("os.name");
563     boolean windows = (osname.indexOf("Windows") >= 0);
564     Enumeration JavaDoc enumt = catalogEntries.elements();
565     while (enumt.hasMoreElements()) {
566         CatalogEntry e = (CatalogEntry) enumt.nextElement();
567         if (e.getEntryType() == SYSTEM
568         && (e.getEntryArg(0).equals(systemId)
569             || (windows
570             && e.getEntryArg(0).equalsIgnoreCase(systemId)))) {
571         map.addElement(e.getEntryArg(1));
572         }
573     }
574     if (map.size() == 0) {
575         return null;
576     } else {
577         return map;
578     }
579     }
580
581     /**
582      * Find the URNs for a given system identifier in the current catalog.
583      *
584      * @param systemId The system ID to locate.
585      *
586      * @return A vector of URNs that map to the systemId.
587      */

588     private Vector JavaDoc resolveLocalSystemReverse(String JavaDoc systemId) {
589     Vector JavaDoc map = new Vector JavaDoc();
590     String JavaDoc osname = System.getProperty("os.name");
591     boolean windows = (osname.indexOf("Windows") >= 0);
592     Enumeration JavaDoc enumt = catalogEntries.elements();
593     while (enumt.hasMoreElements()) {
594         CatalogEntry e = (CatalogEntry) enumt.nextElement();
595         if (e.getEntryType() == SYSTEM
596         && (e.getEntryArg(1).equals(systemId)
597             || (windows
598             && e.getEntryArg(1).equalsIgnoreCase(systemId)))) {
599         map.addElement(e.getEntryArg(0));
600         }
601     }
602     if (map.size() == 0) {
603         return null;
604     } else {
605         return map;
606     }
607     }
608
609     /**
610      * Search the subordinate catalogs, in order, looking for all
611      * match.
612      *
613      * <p>This method searches the Catalog and returns all of the system
614      * identifiers specified for the given entity type with the given
615      * name, public, and system identifiers. In some contexts, these
616      * may be null.</p>
617      *
618      * @param entityType The CatalogEntry type for which this query is
619      * being conducted. This is necessary in order to do the approprate
620      * query on a subordinate catalog.
621      * @param entityName The name of the entity being searched for, if
622      * appropriate.
623      * @param publicId The public identifier of the entity in question
624      * (as provided in the source document).
625      * @param systemId The nominal system identifier for the entity
626      * in question (as provided in the source document).
627      *
628      * @throws MalformedURLException The formal system identifier of a
629      * delegated catalog cannot be turned into a valid URL.
630      * @throws IOException Error reading delegated catalog file.
631      *
632      * @return The system identifier to use.
633      * Note that the nominal system identifier is not returned if a
634      * match is not found in the catalog, instead null is returned
635      * to indicate that no match was found.
636      */

637     private synchronized Vector JavaDoc resolveAllSubordinateCatalogs(int entityType,
638                           String JavaDoc entityName,
639                           String JavaDoc publicId,
640                           String JavaDoc systemId)
641     throws MalformedURLException JavaDoc, IOException JavaDoc {
642
643     Vector JavaDoc resolutions = new Vector JavaDoc();
644
645     for (int catPos = 0; catPos < catalogs.size(); catPos++) {
646         Resolver c = null;
647
648         try {
649         c = (Resolver) catalogs.elementAt(catPos);
650         } catch (ClassCastException JavaDoc e) {
651         String JavaDoc catfile = (String JavaDoc) catalogs.elementAt(catPos);
652         c = (Resolver) newCatalog();
653
654         try {
655             c.parseCatalog(catfile);
656         } catch (MalformedURLException JavaDoc mue) {
657             catalogManager.debug.message(1, "Malformed Catalog URL", catfile);
658         } catch (FileNotFoundException JavaDoc fnfe) {
659             catalogManager.debug.message(1, "Failed to load catalog, file not found",
660               catfile);
661         } catch (IOException JavaDoc ioe) {
662             catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile);
663         }
664
665         catalogs.setElementAt(c, catPos);
666         }
667
668         String JavaDoc resolved = null;
669
670         // Ok, now what are we supposed to call here?
671
if (entityType == DOCTYPE) {
672         resolved = c.resolveDoctype(entityName,
673                         publicId,
674                         systemId);
675         if (resolved != null) {
676             // Only find one DOCTYPE resolution
677
resolutions.addElement(resolved);
678             return resolutions;
679         }
680         } else if (entityType == DOCUMENT) {
681         resolved = c.resolveDocument();
682         if (resolved != null) {
683             // Only find one DOCUMENT resolution
684
resolutions.addElement(resolved);
685             return resolutions;
686         }
687         } else if (entityType == ENTITY) {
688         resolved = c.resolveEntity(entityName,
689                        publicId,
690                        systemId);
691         if (resolved != null) {
692             // Only find one ENTITY resolution
693
resolutions.addElement(resolved);
694             return resolutions;
695         }
696         } else if (entityType == NOTATION) {
697         resolved = c.resolveNotation(entityName,
698                          publicId,
699                          systemId);
700         if (resolved != null) {
701             // Only find one NOTATION resolution
702
resolutions.addElement(resolved);
703             return resolutions;
704         }
705         } else if (entityType == PUBLIC) {
706         resolved = c.resolvePublic(publicId, systemId);
707         if (resolved != null) {
708             // Only find one PUBLIC resolution
709
resolutions.addElement(resolved);
710             return resolutions;
711         }
712         } else if (entityType == SYSTEM) {
713         Vector JavaDoc localResolutions = c.resolveAllSystem(systemId);
714         resolutions = appendVector(resolutions, localResolutions);
715         break;
716         } else if (entityType == SYSTEMREVERSE) {
717         Vector JavaDoc localResolutions = c.resolveAllSystemReverse(systemId);
718         resolutions = appendVector(resolutions, localResolutions);
719         }
720     }
721
722     if (resolutions != null) {
723         return resolutions;
724     } else {
725         return null;
726     }
727     }
728 }
729
730
731
732
733
Popular Tags