286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A// TR9401CatalogReader.java - Read OASIS Catalog files
286N/A
286N/A/*
286N/A * Copyright 2001-2004 The Apache Software Foundation or its licensors,
286N/A * as applicable.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xml.internal.resolver.readers;
286N/A
286N/Aimport java.io.InputStream;
286N/Aimport java.io.IOException;
286N/Aimport java.net.MalformedURLException;
286N/Aimport java.util.Vector;
286N/Aimport com.sun.org.apache.xml.internal.resolver.Catalog;
286N/Aimport com.sun.org.apache.xml.internal.resolver.CatalogEntry;
286N/Aimport com.sun.org.apache.xml.internal.resolver.CatalogException;
286N/A
286N/A/**
286N/A * Parses OASIS Open Catalog files.
286N/A *
286N/A * <p>This class reads OASIS Open Catalog files, returning a stream
286N/A * of tokens.</p>
286N/A *
286N/A * <p>This code interrogates the following non-standard system properties:</p>
286N/A *
286N/A * <dl>
286N/A * <dt><b>xml.catalog.debug</b></dt>
286N/A * <dd><p>Sets the debug level. A value of 0 is assumed if the
286N/A * property is not set or is not a number.</p></dd>
286N/A * </dl>
286N/A *
286N/A * @see Catalog
286N/A *
286N/A * @author Norman Walsh
286N/A * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
286N/A *
286N/A */
286N/Apublic class TR9401CatalogReader extends TextCatalogReader {
286N/A
286N/A /**
286N/A * Start parsing an OASIS TR9401 Open Catalog file. The file is
286N/A * actually read and parsed
286N/A * as needed by <code>nextEntry</code>.
286N/A *
286N/A * <p>In a TR9401 Catalog the 'DELEGATE' entry delegates public
286N/A * identifiers. There is no delegate entry for system identifiers
286N/A * or URIs.</p>
286N/A *
286N/A * @param catalog The Catalog to populate
286N/A * @param is The input stream from which to read the TR9401 Catalog
286N/A *
286N/A * @throws MalformedURLException Improper fileUrl
286N/A * @throws IOException Error reading catalog file
286N/A */
286N/A public void readCatalog(Catalog catalog, InputStream is)
286N/A throws MalformedURLException, IOException {
286N/A
286N/A catfile = is;
286N/A
286N/A if (catfile == null) {
286N/A return;
286N/A }
286N/A
286N/A Vector unknownEntry = null;
286N/A
286N/A try {
286N/A while (true) {
286N/A String token = nextToken();
286N/A
286N/A if (token == null) {
286N/A if (unknownEntry != null) {
286N/A catalog.unknownEntry(unknownEntry);
286N/A unknownEntry = null;
286N/A }
286N/A catfile.close();
286N/A catfile = null;
286N/A return;
286N/A }
286N/A
286N/A String entryToken = null;
286N/A if (caseSensitive) {
286N/A entryToken = token;
286N/A } else {
286N/A entryToken = token.toUpperCase();
286N/A }
286N/A
286N/A if (entryToken.equals("DELEGATE")) {
286N/A entryToken = "DELEGATE_PUBLIC";
286N/A }
286N/A
286N/A try {
286N/A int type = CatalogEntry.getEntryType(entryToken);
286N/A int numArgs = CatalogEntry.getEntryArgCount(type);
286N/A Vector args = new Vector();
286N/A
286N/A if (unknownEntry != null) {
286N/A catalog.unknownEntry(unknownEntry);
286N/A unknownEntry = null;
286N/A }
286N/A
286N/A for (int count = 0; count < numArgs; count++) {
286N/A args.addElement(nextToken());
286N/A }
286N/A
286N/A catalog.addEntry(new CatalogEntry(entryToken, args));
286N/A } catch (CatalogException cex) {
286N/A if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
286N/A if (unknownEntry == null) {
286N/A unknownEntry = new Vector();
286N/A }
286N/A unknownEntry.addElement(token);
286N/A } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
286N/A catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token);
286N/A unknownEntry = null;
286N/A } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) {
286N/A catalog.getCatalogManager().debug.message(1, cex.getMessage());
286N/A }
286N/A }
286N/A }
286N/A } catch (CatalogException cex2) {
286N/A if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) {
286N/A catalog.getCatalogManager().debug.message(1, cex2.getMessage());
286N/A }
286N/A }
286N/A
286N/A }
286N/A}