oasisxmlcatalogreader.java
来自「JAVA 所有包」· Java 代码 · 共 539 行 · 第 1/2 页
JAVA
539 行
// OASISXMLCatalogReader.java - Read XML Catalog files/* * Copyright 2001-2004 The Apache Software Foundation or its licensors, * as applicable. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xml.internal.resolver.readers;import java.util.Stack;import java.util.Vector;import java.util.Enumeration;import com.sun.org.apache.xml.internal.resolver.Catalog;import com.sun.org.apache.xml.internal.resolver.CatalogEntry;import com.sun.org.apache.xml.internal.resolver.CatalogException;import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;import org.xml.sax.*;import org.w3c.dom.*;/** * Parse OASIS Entity Resolution Technical Committee * XML Catalog files. * * @see Catalog * * @author Norman Walsh * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a> * * @version 1.0 */public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalogParser { /** The catalog object needs to be stored by the object so that * SAX callbacks can use it. */ protected Catalog catalog = null; /** The namespace name of OASIS ERTC catalogs */ public static final String namespaceName = "urn:oasis:names:tc:entity:xmlns:xml:catalog"; /** The namespace name of OASIS ERTC TR9401 catalog extension */ public static final String tr9401NamespaceName = "urn:oasis:names:tc:entity:xmlns:tr9401:catalog"; protected Stack baseURIStack = new Stack(); protected Stack overrideStack = new Stack(); protected Stack namespaceStack = new Stack(); /** Set the current catalog. */ public void setCatalog (Catalog catalog) { this.catalog = catalog; debug = catalog.getCatalogManager().debug; } /** Get the current catalog. */ public Catalog getCatalog () { return catalog; } /** * Are we in an extension namespace? * * @return true if the current stack of open namespaces includes * an extension namespace. */ protected boolean inExtensionNamespace() { boolean inExtension = false; Enumeration elements = namespaceStack.elements(); while (!inExtension && elements.hasMoreElements()) { String ns = (String) elements.nextElement(); if (ns == null) { inExtension = true; } else { inExtension = (!ns.equals(tr9401NamespaceName) && !ns.equals(namespaceName)); } } return inExtension; } // ---------------------------------------------------------------------- // Implement the SAX ContentHandler interface /** The SAX <code>setDocumentLocator</code> method does nothing. */ public void setDocumentLocator (Locator locator) { return; } /** The SAX <code>startDocument</code> method does nothing. */ public void startDocument () throws SAXException { baseURIStack.push(catalog.getCurrentBase()); overrideStack.push(catalog.getDefaultOverride()); return; } /** The SAX <code>endDocument</code> method does nothing. */ public void endDocument () throws SAXException { return; } /** * The SAX <code>startElement</code> method recognizes elements * from the plain catalog format and instantiates CatalogEntry * objects for them. * * @param namespaceURI The namespace name of the element. * @param localName The local name of the element. * @param qName The QName of the element. * @param atts The list of attributes on the element. * * @see CatalogEntry */ public void startElement (String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { int entryType = -1; Vector entryArgs = new Vector(); namespaceStack.push(namespaceURI); boolean inExtension = inExtensionNamespace(); if (namespaceURI != null && namespaceName.equals(namespaceURI) && !inExtension) { // This is an XML Catalog entry if (atts.getValue("xml:base") != null) { String baseURI = atts.getValue("xml:base"); entryType = Catalog.BASE; entryArgs.add(baseURI); baseURIStack.push(baseURI); debug.message(4, "xml:base", baseURI); try { CatalogEntry ce = new CatalogEntry(entryType, entryArgs); catalog.addEntry(ce); } catch (CatalogException cex) { if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { debug.message(1, "Invalid catalog entry type", localName); } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { debug.message(1, "Invalid catalog entry (base)", localName); } } entryType = -1; entryArgs = new Vector(); } else { baseURIStack.push(baseURIStack.peek()); } if ((localName.equals("catalog") || localName.equals("group")) && atts.getValue("prefer") != null) { String override = atts.getValue("prefer"); if (override.equals("public")) { override = "yes"; } else if (override.equals("system")) { override = "no"; } else { debug.message(1, "Invalid prefer: must be 'system' or 'public'", localName); override = catalog.getDefaultOverride(); } entryType = Catalog.OVERRIDE; entryArgs.add(override); overrideStack.push(override); debug.message(4, "override", override); try { CatalogEntry ce = new CatalogEntry(entryType, entryArgs); catalog.addEntry(ce); } catch (CatalogException cex) { if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { debug.message(1, "Invalid catalog entry type", localName); } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { debug.message(1, "Invalid catalog entry (override)", localName); } } entryType = -1; entryArgs = new Vector(); } else { overrideStack.push(overrideStack.peek()); } if (localName.equals("delegatePublic")) { if (checkAttributes(atts, "publicIdStartString", "catalog")) { entryType = Catalog.DELEGATE_PUBLIC; entryArgs.add(atts.getValue("publicIdStartString")); entryArgs.add(atts.getValue("catalog")); debug.message(4, "delegatePublic", PublicId.normalize(atts.getValue("publicIdStartString")), atts.getValue("catalog")); } } else if (localName.equals("delegateSystem")) { if (checkAttributes(atts, "systemIdStartString", "catalog")) { entryType = Catalog.DELEGATE_SYSTEM; entryArgs.add(atts.getValue("systemIdStartString")); entryArgs.add(atts.getValue("catalog")); debug.message(4, "delegateSystem", atts.getValue("systemIdStartString"), atts.getValue("catalog")); } } else if (localName.equals("delegateURI")) { if (checkAttributes(atts, "uriStartString", "catalog")) { entryType = Catalog.DELEGATE_URI; entryArgs.add(atts.getValue("uriStartString")); entryArgs.add(atts.getValue("catalog")); debug.message(4, "delegateURI", atts.getValue("uriStartString"), atts.getValue("catalog")); } } else if (localName.equals("rewriteSystem")) { if (checkAttributes(atts, "systemIdStartString", "rewritePrefix")) { entryType = Catalog.REWRITE_SYSTEM; entryArgs.add(atts.getValue("systemIdStartString")); entryArgs.add(atts.getValue("rewritePrefix")); debug.message(4, "rewriteSystem", atts.getValue("systemIdStartString"), atts.getValue("rewritePrefix")); } } else if (localName.equals("systemSuffix")) { if (checkAttributes(atts, "systemIdSuffix", "uri")) { entryType = Catalog.SYSTEM_SUFFIX; entryArgs.add(atts.getValue("systemIdSuffix")); entryArgs.add(atts.getValue("uri")); debug.message(4, "systemSuffix", atts.getValue("systemIdSuffix"), atts.getValue("uri")); } } else if (localName.equals("rewriteURI")) { if (checkAttributes(atts, "uriStartString", "rewritePrefix")) { entryType = Catalog.REWRITE_URI; entryArgs.add(atts.getValue("uriStartString")); entryArgs.add(atts.getValue("rewritePrefix")); debug.message(4, "rewriteURI", atts.getValue("uriStartString"), atts.getValue("rewritePrefix")); } } else if (localName.equals("uriSuffix")) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?