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.impl ;
22
23 import com.sun.org.apache.xerces.internal.impl.Constants;
24 import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;
25 import com.sun.org.apache.xerces.internal.impl.io.UCSReader;
26 import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;
27 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
28 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
29 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
30 import com.sun.org.apache.xerces.internal.util.*;
31 import com.sun.org.apache.xerces.internal.util.SecurityManager;
32 import com.sun.org.apache.xerces.internal.util.URI;
33 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
34 import com.sun.org.apache.xerces.internal.xni.Augmentations;
35 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
36 import com.sun.org.apache.xerces.internal.xni.XNIException;
37 import com.sun.org.apache.xerces.internal.xni.parser.*;
38 import com.sun.xml.internal.stream.Entity;
39 import com.sun.xml.internal.stream.StaxEntityResolverWrapper;
40 import com.sun.xml.internal.stream.StaxXMLInputSource;
41 import com.sun.xml.internal.stream.XMLEntityStorage;
42 import java.io.*;
43 import java.lang.reflect.Method;
44 import java.net.HttpURLConnection;
45 import java.net.URISyntaxException;
46 import java.net.URL;
47 import java.net.URLConnection;
48 import java.util.Hashtable;
49 import java.util.Iterator;
50 import java.util.Locale;
51 import java.util.Map;
52 import java.util.Stack;
53 import javax.xml.XMLConstants;
149 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
150
151 protected static final String STAX_ENTITY_RESOLVER =
152 Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY;
153
154 // property identifier: ValidationManager
155 protected static final String VALIDATION_MANAGER =
156 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
157
158 /** property identifier: buffer size. */
159 protected static final String BUFFER_SIZE =
160 Constants.XERCES_PROPERTY_PREFIX + Constants.BUFFER_SIZE_PROPERTY;
161
162 /** property identifier: security manager. */
163 protected static final String SECURITY_MANAGER =
164 Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
165
166 protected static final String PARSER_SETTINGS =
167 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
168
169 /** property identifier: access external dtd. */
170 protected static final String ACCESS_EXTERNAL_DTD = XMLConstants.ACCESS_EXTERNAL_DTD;
171
172 /** access external dtd: file protocol */
173 static final String EXTERNAL_ACCESS_DEFAULT = Constants.EXTERNAL_ACCESS_DEFAULT;
174
175
176 // recognized features and properties
177
178 /** Recognized features. */
179 private static final String[] RECOGNIZED_FEATURES = {
180 VALIDATION,
181 EXTERNAL_GENERAL_ENTITIES,
182 EXTERNAL_PARAMETER_ENTITIES,
183 ALLOW_JAVA_ENCODINGS,
184 WARN_ON_DUPLICATE_ENTITYDEF,
185 STANDARD_URI_CONFORMANT
186 };
187
188 /** Feature defaults. */
189 private static final Boolean[] FEATURE_DEFAULTS = {
190 null,
191 Boolean.TRUE,
192 Boolean.TRUE,
193 Boolean.TRUE,
194 Boolean.FALSE,
195 Boolean.FALSE
196 };
197
198 /** Recognized properties. */
199 private static final String[] RECOGNIZED_PROPERTIES = {
200 SYMBOL_TABLE,
201 ERROR_REPORTER,
202 ENTITY_RESOLVER,
203 VALIDATION_MANAGER,
204 BUFFER_SIZE,
205 SECURITY_MANAGER,
206 ACCESS_EXTERNAL_DTD
207 };
208
209 /** Property defaults. */
210 private static final Object[] PROPERTY_DEFAULTS = {
211 null,
212 null,
213 null,
214 null,
215 new Integer(DEFAULT_BUFFER_SIZE),
216 null,
217 EXTERNAL_ACCESS_DEFAULT
218 };
219
220 private static final String XMLEntity = "[xml]".intern();
221 private static final String DTDEntity = "[dtd]".intern();
222
223 // debugging
224
225 /**
226 * Debug printing of buffer. This debugging flag works best when you
227 * resize the DEFAULT_BUFFER_SIZE down to something reasonable like
228 * 64 characters.
229 */
230 private static final boolean DEBUG_BUFFER = false;
231
232 /** warn on duplicate Entity declaration.
233 * http://apache.org/xml/features/warn-on-duplicate-entitydef
234 */
235 protected boolean fWarnDuplicateEntityDef;
236
237 /** Debug some basic entities. */
1404 // XMLComponent methods
1405 //
1406 public void reset(PropertyManager propertyManager){
1407 //reset fEntityStorage
1408 fEntityStorage.reset(propertyManager);
1409 //reset XMLEntityReaderImpl
1410 fEntityScanner.reset(propertyManager);
1411 // xerces properties
1412 fSymbolTable = (SymbolTable)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY);
1413 fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY);
1414 try {
1415 fStaxEntityResolver = (StaxEntityResolverWrapper)propertyManager.getProperty(STAX_ENTITY_RESOLVER);
1416 } catch (XMLConfigurationException e) {
1417 fStaxEntityResolver = null;
1418 }
1419
1420 // Zephyr feature ignore-external-dtd is the opposite of Xerces' load-external-dtd
1421 fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
1422
1423 // JAXP 1.5 feature
1424 fAccessExternalDTD = (String) propertyManager.getProperty(ACCESS_EXTERNAL_DTD);
1425
1426 // initialize state
1427 //fStandalone = false;
1428 fEntities.clear();
1429 fEntityStack.removeAllElements();
1430 fCurrentEntity = null;
1431 fValidation = false;
1432 fExternalGeneralEntities = true;
1433 fExternalParameterEntities = true;
1434 fAllowJavaEncodings = true ;
1435 }
1436
1437 /**
1438 * Resets the component. The component can query the component manager
1439 * about any features and properties that affect the operation of the
1440 * component.
1441 *
1442 * @param componentManager The component manager.
1443 *
1444 * @throws SAXException Thrown by component on initialization error.
1468 // sax features
1469 fValidation = componentManager.getFeature(VALIDATION, false);
1470 fExternalGeneralEntities = componentManager.getFeature(EXTERNAL_GENERAL_ENTITIES, true);
1471 fExternalParameterEntities = componentManager.getFeature(EXTERNAL_PARAMETER_ENTITIES, true);
1472
1473 // xerces features
1474 fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false);
1475 fWarnDuplicateEntityDef = componentManager.getFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
1476 fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT, false);
1477 fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD, true);
1478
1479 // xerces properties
1480 fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
1481 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
1482 fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER, null);
1483 fStaxEntityResolver = (StaxEntityResolverWrapper)componentManager.getProperty(STAX_ENTITY_RESOLVER, null);
1484 fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER, null);
1485 fSecurityManager = (SecurityManager)componentManager.getProperty(SECURITY_MANAGER, null);
1486
1487 // JAXP 1.5 feature
1488 fAccessExternalDTD = (String) componentManager.getProperty(ACCESS_EXTERNAL_DTD, EXTERNAL_ACCESS_DEFAULT);
1489
1490 //reset general state
1491 reset();
1492
1493 fEntityScanner.reset(componentManager);
1494 fEntityStorage.reset(componentManager);
1495
1496 } // reset(XMLComponentManager)
1497
1498 // reset general state. Should not be called other than by
1499 // a class acting as a component manager but not
1500 // implementing that interface for whatever reason.
1501 public void reset() {
1502 fEntityExpansionLimit = (fSecurityManager != null)?fSecurityManager.getEntityExpansionLimit():0;
1503
1504 // initialize state
1505 fStandalone = false;
1506 fEntities.clear();
1507 fEntityStack.removeAllElements();
1508 fEntityExpansionCount = 0;
1624 return;
1625 }
1626 if (suffixLength == Constants.BUFFER_SIZE_PROPERTY.length() &&
1627 propertyId.endsWith(Constants.BUFFER_SIZE_PROPERTY)) {
1628 Integer bufferSize = (Integer)value;
1629 if (bufferSize != null &&
1630 bufferSize.intValue() > DEFAULT_XMLDECL_BUFFER_SIZE) {
1631 fBufferSize = bufferSize.intValue();
1632 fEntityScanner.setBufferSize(fBufferSize);
1633 fBufferPool.setExternalBufferSize(fBufferSize);
1634 }
1635 }
1636 if (suffixLength == Constants.SECURITY_MANAGER_PROPERTY.length() &&
1637 propertyId.endsWith(Constants.SECURITY_MANAGER_PROPERTY)) {
1638 fSecurityManager = (SecurityManager)value;
1639 fEntityExpansionLimit = (fSecurityManager != null)?fSecurityManager.getEntityExpansionLimit():0;
1640 }
1641 }
1642
1643 //JAXP 1.5 properties
1644 if (propertyId.startsWith(Constants.JAXPAPI_PROPERTY_PREFIX)) {
1645 if (propertyId.equals(ACCESS_EXTERNAL_DTD))
1646 {
1647 fAccessExternalDTD = (String)value;
1648 }
1649 }
1650 }
1651
1652 /**
1653 * Returns a list of property identifiers that are recognized by
1654 * this component. This method may return null if no properties
1655 * are recognized by this component.
1656 */
1657 public String[] getRecognizedProperties() {
1658 return (String[])(RECOGNIZED_PROPERTIES.clone());
1659 } // getRecognizedProperties():String[]
1660 /**
1661 * Returns the default state for a feature, or null if this
1662 * component does not want to report a default value for this
1663 * feature.
1664 *
1665 * @param featureId The feature identifier.
1666 *
1667 * @since Xerces 2.2.0
1668 */
1669 public Boolean getFeatureDefault(String featureId) {
1670 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
|
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.impl ;
22
23 import com.sun.org.apache.xerces.internal.impl.Constants;
24 import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;
25 import com.sun.org.apache.xerces.internal.impl.io.UCSReader;
26 import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;
27 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
28 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
29 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
30 import com.sun.org.apache.xerces.internal.util.*;
31 import com.sun.org.apache.xerces.internal.util.SecurityManager;
32 import com.sun.org.apache.xerces.internal.util.URI;
33 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
34 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
35 import com.sun.org.apache.xerces.internal.xni.Augmentations;
36 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
37 import com.sun.org.apache.xerces.internal.xni.XNIException;
38 import com.sun.org.apache.xerces.internal.xni.parser.*;
39 import com.sun.xml.internal.stream.Entity;
40 import com.sun.xml.internal.stream.StaxEntityResolverWrapper;
41 import com.sun.xml.internal.stream.StaxXMLInputSource;
42 import com.sun.xml.internal.stream.XMLEntityStorage;
43 import java.io.*;
44 import java.lang.reflect.Method;
45 import java.net.HttpURLConnection;
46 import java.net.URISyntaxException;
47 import java.net.URL;
48 import java.net.URLConnection;
49 import java.util.Hashtable;
50 import java.util.Iterator;
51 import java.util.Locale;
52 import java.util.Map;
53 import java.util.Stack;
54 import javax.xml.XMLConstants;
150 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
151
152 protected static final String STAX_ENTITY_RESOLVER =
153 Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY;
154
155 // property identifier: ValidationManager
156 protected static final String VALIDATION_MANAGER =
157 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
158
159 /** property identifier: buffer size. */
160 protected static final String BUFFER_SIZE =
161 Constants.XERCES_PROPERTY_PREFIX + Constants.BUFFER_SIZE_PROPERTY;
162
163 /** property identifier: security manager. */
164 protected static final String SECURITY_MANAGER =
165 Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
166
167 protected static final String PARSER_SETTINGS =
168 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
169
170 /** Property identifier: Security property manager. */
171 private static final String XML_SECURITY_PROPERTY_MANAGER =
172 Constants.XML_SECURITY_PROPERTY_MANAGER;
173
174 /** access external dtd: file protocol */
175 static final String EXTERNAL_ACCESS_DEFAULT = Constants.EXTERNAL_ACCESS_DEFAULT;
176
177
178 // recognized features and properties
179
180 /** Recognized features. */
181 private static final String[] RECOGNIZED_FEATURES = {
182 VALIDATION,
183 EXTERNAL_GENERAL_ENTITIES,
184 EXTERNAL_PARAMETER_ENTITIES,
185 ALLOW_JAVA_ENCODINGS,
186 WARN_ON_DUPLICATE_ENTITYDEF,
187 STANDARD_URI_CONFORMANT
188 };
189
190 /** Feature defaults. */
191 private static final Boolean[] FEATURE_DEFAULTS = {
192 null,
193 Boolean.TRUE,
194 Boolean.TRUE,
195 Boolean.TRUE,
196 Boolean.FALSE,
197 Boolean.FALSE
198 };
199
200 /** Recognized properties. */
201 private static final String[] RECOGNIZED_PROPERTIES = {
202 SYMBOL_TABLE,
203 ERROR_REPORTER,
204 ENTITY_RESOLVER,
205 VALIDATION_MANAGER,
206 BUFFER_SIZE,
207 SECURITY_MANAGER,
208 XML_SECURITY_PROPERTY_MANAGER
209 };
210
211 /** Property defaults. */
212 private static final Object[] PROPERTY_DEFAULTS = {
213 null,
214 null,
215 null,
216 null,
217 new Integer(DEFAULT_BUFFER_SIZE),
218 null,
219 null
220 };
221
222 private static final String XMLEntity = "[xml]".intern();
223 private static final String DTDEntity = "[dtd]".intern();
224
225 // debugging
226
227 /**
228 * Debug printing of buffer. This debugging flag works best when you
229 * resize the DEFAULT_BUFFER_SIZE down to something reasonable like
230 * 64 characters.
231 */
232 private static final boolean DEBUG_BUFFER = false;
233
234 /** warn on duplicate Entity declaration.
235 * http://apache.org/xml/features/warn-on-duplicate-entitydef
236 */
237 protected boolean fWarnDuplicateEntityDef;
238
239 /** Debug some basic entities. */
1406 // XMLComponent methods
1407 //
1408 public void reset(PropertyManager propertyManager){
1409 //reset fEntityStorage
1410 fEntityStorage.reset(propertyManager);
1411 //reset XMLEntityReaderImpl
1412 fEntityScanner.reset(propertyManager);
1413 // xerces properties
1414 fSymbolTable = (SymbolTable)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY);
1415 fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY);
1416 try {
1417 fStaxEntityResolver = (StaxEntityResolverWrapper)propertyManager.getProperty(STAX_ENTITY_RESOLVER);
1418 } catch (XMLConfigurationException e) {
1419 fStaxEntityResolver = null;
1420 }
1421
1422 // Zephyr feature ignore-external-dtd is the opposite of Xerces' load-external-dtd
1423 fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
1424
1425 // JAXP 1.5 feature
1426 XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager) propertyManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
1427 fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
1428
1429 // initialize state
1430 //fStandalone = false;
1431 fEntities.clear();
1432 fEntityStack.removeAllElements();
1433 fCurrentEntity = null;
1434 fValidation = false;
1435 fExternalGeneralEntities = true;
1436 fExternalParameterEntities = true;
1437 fAllowJavaEncodings = true ;
1438 }
1439
1440 /**
1441 * Resets the component. The component can query the component manager
1442 * about any features and properties that affect the operation of the
1443 * component.
1444 *
1445 * @param componentManager The component manager.
1446 *
1447 * @throws SAXException Thrown by component on initialization error.
1471 // sax features
1472 fValidation = componentManager.getFeature(VALIDATION, false);
1473 fExternalGeneralEntities = componentManager.getFeature(EXTERNAL_GENERAL_ENTITIES, true);
1474 fExternalParameterEntities = componentManager.getFeature(EXTERNAL_PARAMETER_ENTITIES, true);
1475
1476 // xerces features
1477 fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false);
1478 fWarnDuplicateEntityDef = componentManager.getFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
1479 fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT, false);
1480 fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD, true);
1481
1482 // xerces properties
1483 fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
1484 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
1485 fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER, null);
1486 fStaxEntityResolver = (StaxEntityResolverWrapper)componentManager.getProperty(STAX_ENTITY_RESOLVER, null);
1487 fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER, null);
1488 fSecurityManager = (SecurityManager)componentManager.getProperty(SECURITY_MANAGER, null);
1489
1490 // JAXP 1.5 feature
1491 XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER, null);
1492 if (spm == null) {
1493 spm = new XMLSecurityPropertyManager();
1494 }
1495 fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
1496
1497 //reset general state
1498 reset();
1499
1500 fEntityScanner.reset(componentManager);
1501 fEntityStorage.reset(componentManager);
1502
1503 } // reset(XMLComponentManager)
1504
1505 // reset general state. Should not be called other than by
1506 // a class acting as a component manager but not
1507 // implementing that interface for whatever reason.
1508 public void reset() {
1509 fEntityExpansionLimit = (fSecurityManager != null)?fSecurityManager.getEntityExpansionLimit():0;
1510
1511 // initialize state
1512 fStandalone = false;
1513 fEntities.clear();
1514 fEntityStack.removeAllElements();
1515 fEntityExpansionCount = 0;
1631 return;
1632 }
1633 if (suffixLength == Constants.BUFFER_SIZE_PROPERTY.length() &&
1634 propertyId.endsWith(Constants.BUFFER_SIZE_PROPERTY)) {
1635 Integer bufferSize = (Integer)value;
1636 if (bufferSize != null &&
1637 bufferSize.intValue() > DEFAULT_XMLDECL_BUFFER_SIZE) {
1638 fBufferSize = bufferSize.intValue();
1639 fEntityScanner.setBufferSize(fBufferSize);
1640 fBufferPool.setExternalBufferSize(fBufferSize);
1641 }
1642 }
1643 if (suffixLength == Constants.SECURITY_MANAGER_PROPERTY.length() &&
1644 propertyId.endsWith(Constants.SECURITY_MANAGER_PROPERTY)) {
1645 fSecurityManager = (SecurityManager)value;
1646 fEntityExpansionLimit = (fSecurityManager != null)?fSecurityManager.getEntityExpansionLimit():0;
1647 }
1648 }
1649
1650 //JAXP 1.5 properties
1651 if (propertyId.equals(XML_SECURITY_PROPERTY_MANAGER))
1652 {
1653 XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager)value;
1654 fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
1655 }
1656 }
1657
1658 /**
1659 * Returns a list of property identifiers that are recognized by
1660 * this component. This method may return null if no properties
1661 * are recognized by this component.
1662 */
1663 public String[] getRecognizedProperties() {
1664 return (String[])(RECOGNIZED_PROPERTIES.clone());
1665 } // getRecognizedProperties():String[]
1666 /**
1667 * Returns the default state for a feature, or null if this
1668 * component does not want to report a default value for this
1669 * feature.
1670 *
1671 * @param featureId The feature identifier.
1672 *
1673 * @since Xerces 2.2.0
1674 */
1675 public Boolean getFeatureDefault(String featureId) {
1676 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
|