1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 // TextCatalogReader.java - Read text/plain Catalog files
6
7 /*
8 * Copyright 2001-2004 The Apache Software Foundation or its licensors,
9 * as applicable.
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24 package com.sun.org.apache.xml.internal.resolver.readers;
25
26 import java.io.InputStream;
27 import java.io.IOException;
28 import java.io.FileNotFoundException;
29 import java.net.URL;
30 import java.net.URLConnection;
31 import java.net.MalformedURLException;
32 import java.util.Vector;
33 import java.util.Stack;
34 import com.sun.org.apache.xml.internal.resolver.Catalog;
35 import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
36 import com.sun.org.apache.xml.internal.resolver.CatalogException;
37 import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
38
39 /**
40 * Parses plain text Catalog files.
41 *
42 * <p>This class reads plain text Open Catalog files.</p>
43 *
44 * @see Catalog
45 *
46 * @author Norman Walsh
47 * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
48 *
49 */
50 public class TextCatalogReader implements CatalogReader {
51 /** The input stream used to read the catalog */
52 protected InputStream catfile = null;
53
54 /**
55 * Character lookahead stack. Reading a catalog sometimes requires
56 * up to two characters of lookahead.
57 */
123 Vector unknownEntry = null;
124
125 try {
126 while (true) {
127 String token = nextToken();
128
129 if (token == null) {
130 if (unknownEntry != null) {
131 catalog.unknownEntry(unknownEntry);
132 unknownEntry = null;
133 }
134 catfile.close();
135 catfile = null;
136 return;
137 }
138
139 String entryToken = null;
140 if (caseSensitive) {
141 entryToken = token;
142 } else {
143 entryToken = token.toUpperCase();
144 }
145
146 try {
147 int type = CatalogEntry.getEntryType(entryToken);
148 int numArgs = CatalogEntry.getEntryArgCount(type);
149 Vector args = new Vector();
150
151 if (unknownEntry != null) {
152 catalog.unknownEntry(unknownEntry);
153 unknownEntry = null;
154 }
155
156 for (int count = 0; count < numArgs; count++) {
157 args.addElement(nextToken());
158 }
159
160 catalog.addEntry(new CatalogEntry(entryToken, args));
161 } catch (CatalogException cex) {
162 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
163 if (unknownEntry == null) {
|
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.sun.org.apache.xml.internal.resolver.readers;
19
20 import com.sun.org.apache.xml.internal.resolver.Catalog;
21 import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
22 import com.sun.org.apache.xml.internal.resolver.CatalogException;
23 import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
24 import java.io.FileNotFoundException;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 import java.net.URLConnection;
30 import java.util.Locale;
31 import java.util.Stack;
32 import java.util.Vector;
33
34 /**
35 * Parses plain text Catalog files.
36 *
37 * <p>This class reads plain text Open Catalog files.</p>
38 *
39 * @see Catalog
40 *
41 * @author Norman Walsh
42 * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
43 *
44 */
45 public class TextCatalogReader implements CatalogReader {
46 /** The input stream used to read the catalog */
47 protected InputStream catfile = null;
48
49 /**
50 * Character lookahead stack. Reading a catalog sometimes requires
51 * up to two characters of lookahead.
52 */
118 Vector unknownEntry = null;
119
120 try {
121 while (true) {
122 String token = nextToken();
123
124 if (token == null) {
125 if (unknownEntry != null) {
126 catalog.unknownEntry(unknownEntry);
127 unknownEntry = null;
128 }
129 catfile.close();
130 catfile = null;
131 return;
132 }
133
134 String entryToken = null;
135 if (caseSensitive) {
136 entryToken = token;
137 } else {
138 entryToken = token.toUpperCase(Locale.ENGLISH);
139 }
140
141 try {
142 int type = CatalogEntry.getEntryType(entryToken);
143 int numArgs = CatalogEntry.getEntryArgCount(type);
144 Vector args = new Vector();
145
146 if (unknownEntry != null) {
147 catalog.unknownEntry(unknownEntry);
148 unknownEntry = null;
149 }
150
151 for (int count = 0; count < numArgs; count++) {
152 args.addElement(nextToken());
153 }
154
155 catalog.addEntry(new CatalogEntry(entryToken, args));
156 } catch (CatalogException cex) {
157 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
158 if (unknownEntry == null) {
|