1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.parsers; 23 24 import java.io.IOException; 25 26 import com.sun.org.apache.xerces.internal.impl.Constants; 27 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; 28 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; 29 import com.sun.org.apache.xerces.internal.xni.XNIException; 30 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 31 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; 32 33 import org.xml.sax.SAXNotSupportedException; 34 import org.xml.sax.SAXNotRecognizedException; 35 36 /** 37 * Base class of all XML-related parsers. 38 * <p> 39 * In addition to the features and properties recognized by the parser 40 * configuration, this parser recognizes these additional features and 41 * properties: 42 * <ul> 43 * <li>Properties 44 * <ul> 45 * <li>http://apache.org/xml/properties/internal/error-handler</li> 46 * <li>http://apache.org/xml/properties/internal/entity-resolver</li> 47 * </ul> 48 * </ul> 49 * 50 * @author Arnaud Le Hors, IBM 51 * @author Andy Clark, IBM 52 * 53 * @version $Id: XMLParser.java,v 1.5 2007/07/20 14:11:21 spericas Exp $ 54 */ 55 public abstract class XMLParser { 56 57 // 58 // Constants 59 // 60 61 // properties 62 63 /** Property identifier: entity resolver. */ 64 protected static final String ENTITY_RESOLVER = 65 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 66 67 /** Property identifier: error handler. */ 68 protected static final String ERROR_HANDLER = 69 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 70 71 /** Recognized properties. */ 72 private static final String[] RECOGNIZED_PROPERTIES = { 73 ENTITY_RESOLVER, 74 ERROR_HANDLER, 75 }; 76 77 // 78 // Data 79 // 80 81 /** The parser configuration. */ 82 protected XMLParserConfiguration fConfiguration; 83 84 /** The XML Security Manager. */ 85 XMLSecurityManager securityManager; 86 87 /** The XML Security Property Manager. */ 88 XMLSecurityPropertyManager securityPropertyManager; 89 90 91 // 92 // Constructors 93 // 94 95 /** 96 * Query the state of a feature. 97 */ 98 public boolean getFeature(String featureId) 99 throws SAXNotSupportedException, SAXNotRecognizedException { 100 return fConfiguration.getFeature(featureId); 101 102 } 103 104 /** 105 * Default Constructor. 106 */ 107 protected XMLParser(XMLParserConfiguration config) { 108 109 // save configuration 110 fConfiguration = config; 111 112 // add default recognized properties 113 fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES); 114 115 } // <init>(XMLParserConfiguration) 116 117 // 118 // Public methods 119 // 120 121 /** 122 * parse 123 * 124 * @param inputSource 125 * 126 * @exception XNIException 127 * @exception java.io.IOException 128 */ 129 public void parse(XMLInputSource inputSource) 130 throws XNIException, IOException { 131 // null indicates that the parser is called directly, initialize them 132 if (securityManager == null) { 133 securityManager = new XMLSecurityManager(true); 134 fConfiguration.setProperty(Constants.SECURITY_MANAGER, securityManager); 135 } 136 if (securityPropertyManager == null) { 137 securityPropertyManager = new XMLSecurityPropertyManager(); 138 fConfiguration.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager); 139 } 140 141 reset(); 142 fConfiguration.parse(inputSource); 143 144 } // parse(XMLInputSource) 145 146 // 147 // Protected methods 148 // 149 150 /** 151 * reset all components before parsing 152 */ 153 protected void reset() throws XNIException { 154 } // reset() 155 156 } // class XMLParser