1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2000-2005 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.parsers;
  22 
  23 import com.sun.org.apache.xerces.internal.impl.Constants;
  24 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  25 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
  26 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  27 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
  28 import org.xml.sax.SAXNotRecognizedException;
  29 import org.xml.sax.SAXNotSupportedException;
  30 
  31 /**
  32  * This is the main Xerces SAX parser class. It uses the abstract SAX
  33  * parser with a document scanner, a dtd scanner, and a validator, as
  34  * well as a grammar pool.
  35  *
  36  * @author Arnaud  Le Hors, IBM
  37  * @author Andy Clark, IBM
  38  *
  39  * @version $Id: SAXParser.java,v 1.7 2010-11-01 04:40:09 joehw Exp $
  40  */
  41 public class SAXParser
  42     extends AbstractSAXParser {
  43 
  44     //
  45     // Constants
  46     //
  47 
  48     // features
  49 
  50     /** Feature identifier: notify built-in refereces. */
  51     protected static final String NOTIFY_BUILTIN_REFS =
  52         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
  53 
  54     protected static final String REPORT_WHITESPACE =
  55             Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE;
  56 
  57     /** Recognized features. */
  58     private static final String[] RECOGNIZED_FEATURES = {
  59         NOTIFY_BUILTIN_REFS,
  60         REPORT_WHITESPACE
  61     };
  62 
  63     // properties
  64 
  65     /** Property identifier: symbol table. */
  66     protected static final String SYMBOL_TABLE =
  67         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
  68 
  69     /** Property identifier: XML grammar pool. */
  70     protected static final String XMLGRAMMAR_POOL =
  71         Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY;
  72 
  73     /** Recognized properties. */
  74     private static final String[] RECOGNIZED_PROPERTIES = {
  75         SYMBOL_TABLE,
  76         XMLGRAMMAR_POOL,
  77     };
  78 
  79     //
  80     // Constructors
  81     //
  82 
  83     /**
  84      * Constructs a SAX parser using the specified parser configuration.
  85      */
  86     public SAXParser(XMLParserConfiguration config) {
  87         super(config);
  88     } // <init>(XMLParserConfiguration)
  89 
  90     /**
  91      * Constructs a SAX parser using the dtd/xml schema parser configuration.
  92      */
  93     public SAXParser() {
  94         this(null, null);
  95     } // <init>()
  96 
  97     /**
  98      * Constructs a SAX parser using the specified symbol table.
  99      */
 100     public SAXParser(SymbolTable symbolTable) {
 101         this(symbolTable, null);
 102     } // <init>(SymbolTable)
 103 
 104     /**
 105      * Constructs a SAX parser using the specified symbol table and
 106      * grammar pool.
 107      */
 108     public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
 109         super(new XIncludeAwareParserConfiguration());
 110 
 111         // set features
 112         fConfiguration.addRecognizedFeatures(RECOGNIZED_FEATURES);
 113         fConfiguration.setFeature(NOTIFY_BUILTIN_REFS, true);
 114 
 115         // set properties
 116         fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
 117         if (symbolTable != null) {
 118             fConfiguration.setProperty(SYMBOL_TABLE, symbolTable);
 119         }
 120         if (grammarPool != null) {
 121             fConfiguration.setProperty(XMLGRAMMAR_POOL, grammarPool);
 122         }
 123 
 124     } // <init>(SymbolTable,XMLGrammarPool)
 125 
 126     /**
 127      * Sets the particular property in the underlying implementation of
 128      * org.xml.sax.XMLReader.
 129      */
 130     public void setProperty(String name, Object value)
 131         throws SAXNotRecognizedException, SAXNotSupportedException {
 132         XMLSecurityPropertyManager spm = new XMLSecurityPropertyManager();
 133         int index = spm.getIndex(name);
 134         if (index > -1) {
 135             /**
 136              * this is a direct call to this parser, not a subclass since
 137              * internally the support of this property is done through
 138              * XMLSecurityPropertyManager
 139              */
 140             spm.setValue(index, XMLSecurityPropertyManager.State.APIPROPERTY, (String)value);
 141             super.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, spm);
 142         } else {
 143             super.setProperty(name, value);
 144         }
 145     }
 146 } // class SAXParser