xmlgrammarpreparser.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 379 行 · 第 1/2 页
JAVA
379 行
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001, 2002 The Apache Software Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.parsers;import java.io.IOException;import java.util.Enumeration;import java.util.Hashtable;import java.util.Locale;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.grammars.Grammar;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarLoader;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;/** * <p> This class provides an easy way for a user to preparse grammars * of various types. By default, it knows how to preparse external * DTD's and schemas; it provides an easy way for user applications to * register classes that know how to parse additional grammar types. * By default, it does no grammar caching; but it provides ways for * user applications to do so. * * @author Neil Graham, IBM * * @version $Id: XMLGrammarPreparser.java,v 1.8 2004/02/17 07:14:49 neeraj Exp $ */public class XMLGrammarPreparser { // // Constants // // feature: continue-after-fatal-error private final static String CONTINUE_AFTER_FATAL_ERROR = Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; /** Property identifier: symbol table. */ protected static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; /** Property identifier: error reporter. */ protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; /** Property identifier: error handler. */ protected static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; /** Property identifier: entity resolver. */ protected static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; /** Property identifier: grammar pool . */ protected static final String GRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; // the "built-in" grammar loaders private static final Hashtable KNOWN_LOADERS = new Hashtable(); static { KNOWN_LOADERS.put(XMLGrammarDescription.XML_SCHEMA, "com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader"); KNOWN_LOADERS.put(XMLGrammarDescription.XML_DTD, "com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDLoader"); } /** Recognized properties. */ private static final String[] RECOGNIZED_PROPERTIES = { SYMBOL_TABLE, ERROR_REPORTER, ERROR_HANDLER, ENTITY_RESOLVER, GRAMMAR_POOL, }; // Data protected SymbolTable fSymbolTable; protected XMLErrorReporter fErrorReporter; protected XMLEntityResolver fEntityResolver; protected XMLGrammarPool fGrammarPool; protected Locale fLocale; // Hashtable holding our loaders private Hashtable fLoaders; // // Constructors // /** Default constructor. */ public XMLGrammarPreparser() { this(new SymbolTable()); } // <init>() /** * Constructs a preparser using the specified symbol table. * * @param symbolTable The symbol table to use. */ public XMLGrammarPreparser (SymbolTable symbolTable) { fSymbolTable = symbolTable; fLoaders = new Hashtable(); setLocale(Locale.getDefault()); fErrorReporter = new XMLErrorReporter(); fErrorReporter.setLocale(fLocale); fEntityResolver = new XMLEntityManager(); // those are all the basic properties... } // <init>(SymbolTable) // // Public methods // /* * Register a type of grammar to make it preparsable. If * the second parameter is null, the parser will use its built-in * facilities for that grammar type. * This should be called by the application immediately * after creating this object and before initializing any properties/features. * @param type URI identifying the type of the grammar * @param loader an object capable of preparsing that type; null if the ppreparser should use built-in knowledge. * @return true if successful; false if no built-in knowledge of * the type or if unable to instantiate the string we know about */ public boolean registerPreparser(String grammarType, XMLGrammarLoader loader) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?