aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java')
-rw-r--r--src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java71
1 files changed, 39 insertions, 32 deletions
diff --git a/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java b/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
index d0f036f..bf3adc2 100644
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
@@ -1,15 +1,15 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
*/
-
/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * 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
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ * 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,
@@ -20,12 +20,10 @@
package com.sun.org.apache.xerces.internal.impl ;
-import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;
import com.sun.org.apache.xerces.internal.impl.io.UCSReader;
import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
-import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
import com.sun.org.apache.xerces.internal.util.*;
import com.sun.org.apache.xerces.internal.util.URI;
@@ -47,12 +45,11 @@ import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Stack;
-import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
@@ -368,7 +365,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
// entities
/** Entities. */
- protected Hashtable fEntities = new Hashtable();
+ protected Map<String, Entity> fEntities = new HashMap<>();
/** Entity stack. */
protected Stack fEntityStack = new Stack();
@@ -405,6 +402,8 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* If this constructor is used to create the object, reset() should be invoked on this object
*/
public XMLEntityManager() {
+ //for entity managers not created by parsers
+ fSecurityManager = new XMLSecurityManager(true);
fEntityStorage = new XMLEntityStorage(this) ;
setScannerVersion(Constants.XML_VERSION_1_0);
} // <init>()
@@ -582,6 +581,8 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/**
* This method uses the passed-in XMLInputSource to make
* fCurrentEntity usable for reading.
+ *
+ * @param reference flag to indicate whether the entity is an Entity Reference.
* @param name name of the entity (XML is it's the document entity)
* @param xmlInputSource the input source, with sufficient information
* to begin scanning characters.
@@ -592,7 +593,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* XNIException If any parser-specific goes wrong.
* @return the encoding of the new entity or null if a character stream was employed
*/
- public String setupCurrentEntity(String name, XMLInputSource xmlInputSource,
+ public String setupCurrentEntity(boolean reference, String name, XMLInputSource xmlInputSource,
boolean literal, boolean isExternal)
throws IOException, XNIException {
// get information
@@ -835,7 +836,9 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* in the prolog of the XML document is not considered. Hence, prolog can
* be read in Chunks of data instead of byte by byte.
*/
- fCurrentEntity = new com.sun.xml.internal.stream.Entity.ScannedEntity(name,new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandedSystemId),stream, reader, encoding, literal, encodingExternallySpecified, isExternal);
+ fCurrentEntity = new Entity.ScannedEntity(reference, name,
+ new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandedSystemId),
+ stream, reader, encoding, literal, encodingExternallySpecified, isExternal);
fCurrentEntity.setEncodingExternallySpecified(encodingExternallySpecified);
fEntityScanner.setCurrentEntity(fCurrentEntity);
fResourceIdentifier.setValues(publicId, literalSystemId, baseSystemId, expandedSystemId);
@@ -855,7 +858,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
*/
public boolean isExternalEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -872,7 +875,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
*/
public boolean isEntityDeclInExternalSubset(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -902,13 +905,13 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
public boolean isDeclaredEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
return entity != null;
}
public boolean isUnparsedEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -1103,6 +1106,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/**
* Starts a named entity.
*
+ * @param isGE flag to indicate whether the entity is a General Entity
* @param entityName The name of the entity to start.
* @param literal True if this entity is started within a literal
* value.
@@ -1110,11 +1114,11 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* @throws IOException Thrown on i/o error.
* @throws XNIException Thrown by entity handler to signal an error.
*/
- public void startEntity(String entityName, boolean literal)
+ public void startEntity(boolean isGE, String entityName, boolean literal)
throws IOException, XNIException {
// was entity declared?
- Entity entity = (Entity)fEntityStorage.getEntity(entityName);
+ Entity entity = fEntityStorage.getEntity(entityName);
if (entity == null) {
if (fEntityHandler != null) {
String encoding = null;
@@ -1234,7 +1238,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
}
// start the entity
- startEntity(entityName, xmlInputSource, literal, external);
+ startEntity(isGE, entityName, xmlInputSource, literal, external);
} // startEntity(String,boolean)
@@ -1249,7 +1253,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
*/
public void startDocumentEntity(XMLInputSource xmlInputSource)
throws IOException, XNIException {
- startEntity(XMLEntity, xmlInputSource, false, true);
+ startEntity(false, XMLEntity, xmlInputSource, false, true);
} // startDocumentEntity(XMLInputSource)
//xxx these methods are not required.
@@ -1264,7 +1268,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
*/
public void startDTDEntity(XMLInputSource xmlInputSource)
throws IOException, XNIException {
- startEntity(DTDEntity, xmlInputSource, false, true);
+ startEntity(false, DTDEntity, xmlInputSource, false, true);
} // startDTDEntity(XMLInputSource)
// indicate start of external subset so that
@@ -1283,6 +1287,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* This method can be used to insert an application defined XML
* entity stream into the parsing stream.
*
+ * @param isGE flag to indicate whether the entity is a General Entity
* @param name The name of the entity.
* @param xmlInputSource The input source of the entity.
* @param literal True if this entity is started within a
@@ -1292,12 +1297,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* @throws IOException Thrown on i/o error.
* @throws XNIException Thrown by entity handler to signal an error.
*/
- public void startEntity(String name,
+ public void startEntity(boolean isGE, String name,
XMLInputSource xmlInputSource,
boolean literal, boolean isExternal)
throws IOException, XNIException {
- String encoding = setupCurrentEntity(name, xmlInputSource, literal, isExternal);
+ String encoding = setupCurrentEntity(isGE, name, xmlInputSource, literal, isExternal);
//when entity expansion limit is set by the Application, we need to
//check for the entity expansion limit set by the parser, if number of entity
@@ -1309,7 +1314,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
}
if( fSecurityManager != null && fSecurityManager.isOverLimit(entityExpansionIndex, fLimitAnalyzer)){
fSecurityManager.debugPrint(fLimitAnalyzer);
- fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,"EntityExpansionLimitExceeded",
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,"EntityExpansionLimit",
new Object[]{fSecurityManager.getLimitValueByIndex(entityExpansionIndex)},
XMLErrorReporter.SEVERITY_FATAL_ERROR );
// is there anything better to do than reset the counter?
@@ -1425,10 +1430,6 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
// XMLComponent methods
//
public void reset(PropertyManager propertyManager){
- //reset fEntityStorage
- fEntityStorage.reset(propertyManager);
- //reset XMLEntityReaderImpl
- fEntityScanner.reset(propertyManager);
// xerces properties
fSymbolTable = (SymbolTable)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY);
fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY);
@@ -1451,6 +1452,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
fSecurityManager = (XMLSecurityManager)propertyManager.getProperty(SECURITY_MANAGER);
+ fLimitAnalyzer = new XMLLimitAnalyzer();
+ //reset fEntityStorage
+ fEntityStorage.reset(propertyManager);
+ //reset XMLEntityReaderImpl
+ fEntityScanner.reset(propertyManager);
+
// initialize state
//fStandalone = false;
fEntities.clear();
@@ -1537,7 +1544,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
// a class acting as a component manager but not
// implementing that interface for whatever reason.
public void reset() {
-
+ fLimitAnalyzer = new XMLLimitAnalyzer();
// initialize state
fStandalone = false;
fEntities.clear();