KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > resolver > readers > TR9401CatalogReader


1 // TR9401CatalogReader.java - Read OASIS Catalog files
2

3 /*
4  * Copyright 2001-2004 The Apache Software Foundation or its licensors,
5  * as applicable.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.sun.org.apache.xml.internal.resolver.readers;
21
22 import java.io.InputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.util.Vector JavaDoc;
26 import com.sun.org.apache.xml.internal.resolver.Catalog;
27 import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
28 import com.sun.org.apache.xml.internal.resolver.CatalogException;
29
30 /**
31  * Parses OASIS Open Catalog files.
32  *
33  * <p>This class reads OASIS Open Catalog files, returning a stream
34  * of tokens.</p>
35  *
36  * <p>This code interrogates the following non-standard system properties:</p>
37  *
38  * <dl>
39  * <dt><b>xml.catalog.debug</b></dt>
40  * <dd><p>Sets the debug level. A value of 0 is assumed if the
41  * property is not set or is not a number.</p></dd>
42  * </dl>
43  *
44  * @see Catalog
45  *
46  * @author Norman Walsh
47  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
48  *
49  * @version 1.0
50  */

51 public class TR9401CatalogReader extends TextCatalogReader {
52
53   /**
54    * Start parsing an OASIS TR9401 Open Catalog file. The file is
55    * actually read and parsed
56    * as needed by <code>nextEntry</code>.
57    *
58    * <p>In a TR9401 Catalog the 'DELEGATE' entry delegates public
59    * identifiers. There is no delegate entry for system identifiers
60    * or URIs.</p>
61    *
62    * @param catalog The Catalog to populate
63    * @param is The input stream from which to read the TR9401 Catalog
64    *
65    * @throws MalformedURLException Improper fileUrl
66    * @throws IOException Error reading catalog file
67    */

68   public void readCatalog(Catalog catalog, InputStream JavaDoc is)
69     throws MalformedURLException JavaDoc, IOException JavaDoc {
70
71     catfile = is;
72
73     if (catfile == null) {
74       return;
75     }
76
77     Vector JavaDoc unknownEntry = null;
78
79     try {
80       while (true) {
81     String JavaDoc token = nextToken();
82
83     if (token == null) {
84       if (unknownEntry != null) {
85         catalog.unknownEntry(unknownEntry);
86         unknownEntry = null;
87       }
88       catfile.close();
89       catfile = null;
90       return;
91     }
92
93     String JavaDoc entryToken = null;
94     if (caseSensitive) {
95       entryToken = token;
96     } else {
97       entryToken = token.toUpperCase();
98     }
99
100     if (entryToken.equals("DELEGATE")) {
101       entryToken = "DELEGATE_PUBLIC";
102     }
103
104     try {
105       int type = CatalogEntry.getEntryType(entryToken);
106       int numArgs = CatalogEntry.getEntryArgCount(type);
107       Vector JavaDoc args = new Vector JavaDoc();
108
109       if (unknownEntry != null) {
110         catalog.unknownEntry(unknownEntry);
111         unknownEntry = null;
112       }
113
114       for (int count = 0; count < numArgs; count++) {
115         args.addElement(nextToken());
116       }
117
118       catalog.addEntry(new CatalogEntry(entryToken, args));
119     } catch (CatalogException cex) {
120       if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
121         if (unknownEntry == null) {
122           unknownEntry = new Vector JavaDoc();
123         }
124         unknownEntry.addElement(token);
125       } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
126         catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token);
127         unknownEntry = null;
128       } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) {
129         catalog.getCatalogManager().debug.message(1, cex.getMessage());
130       }
131     }
132       }
133     } catch (CatalogException cex2) {
134       if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) {
135     catalog.getCatalogManager().debug.message(1, cex2.getMessage());
136       }
137     }
138
139   }
140 }
141
Popular Tags