aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/xml/internal/stream
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/xml/internal/stream')
-rw-r--r--src/com/sun/xml/internal/stream/Entity.java6
-rw-r--r--src/com/sun/xml/internal/stream/XMLEntityStorage.java31
-rw-r--r--src/com/sun/xml/internal/stream/dtd/nonvalidating/DTDGrammar.java162
3 files changed, 43 insertions, 156 deletions
diff --git a/src/com/sun/xml/internal/stream/Entity.java b/src/com/sun/xml/internal/stream/Entity.java
index 9806cf7..9c2a8ad 100644
--- a/src/com/sun/xml/internal/stream/Entity.java
+++ b/src/com/sun/xml/internal/stream/Entity.java
@@ -344,6 +344,9 @@ public abstract class Entity {
// to know that prolog is read
public boolean xmlDeclChunkRead = false;
+ // flag to indicate whether the Entity is a General Entity
+ public boolean isGE = false;
+
/** returns the name of the current encoding
* @return current encoding name
*/
@@ -388,10 +391,11 @@ public abstract class Entity {
//
/** Constructs a scanned entity. */
- public ScannedEntity(String name,
+ public ScannedEntity(boolean isGE, String name,
XMLResourceIdentifier entityLocation,
InputStream stream, Reader reader,
String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) {
+ this.isGE = isGE;
this.name = name ;
this.entityLocation = entityLocation;
this.stream = stream;
diff --git a/src/com/sun/xml/internal/stream/XMLEntityStorage.java b/src/com/sun/xml/internal/stream/XMLEntityStorage.java
index 56735e5..6252f22 100644
--- a/src/com/sun/xml/internal/stream/XMLEntityStorage.java
+++ b/src/com/sun/xml/internal/stream/XMLEntityStorage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,20 @@
package com.sun.xml.internal.stream;
-import java.util.Hashtable;
-
+import com.sun.org.apache.xerces.internal.impl.Constants;
+import com.sun.org.apache.xerces.internal.impl.PropertyManager;
+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.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.URI;
import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
+import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
-import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
-import com.sun.org.apache.xerces.internal.impl.PropertyManager;
-import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
-import com.sun.org.apache.xerces.internal.impl.Constants;
-import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
/**
*
@@ -62,7 +63,7 @@ public class XMLEntityStorage {
protected boolean fWarnDuplicateEntityDef;
/** Entities. */
- protected Hashtable fEntities = new Hashtable();
+ protected Map<String, Entity> fEntities = new HashMap<>();
protected Entity.ScannedEntity fCurrentEntity ;
@@ -138,7 +139,7 @@ public class XMLEntityStorage {
* @see SymbolTable
*/
public Entity getEntity(String name) {
- return (Entity)fEntities.get(name);
+ return fEntities.get(name);
} // getEntity(String)
public boolean hasEntities() {
@@ -150,7 +151,7 @@ public class XMLEntityStorage {
} // getEntity(String)
public Enumeration getEntityKeys() {
- return fEntities.keys();
+ return Collections.enumeration(fEntities.keySet());
}
/**
* Adds an internal entity declaration.
@@ -263,7 +264,7 @@ public class XMLEntityStorage {
*/
public boolean isExternalEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -280,7 +281,7 @@ public class XMLEntityStorage {
*/
public boolean isEntityDeclInExternalSubset(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -333,7 +334,7 @@ public class XMLEntityStorage {
*/
public boolean isUnparsedEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -348,7 +349,7 @@ public class XMLEntityStorage {
*/
public boolean isDeclaredEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
return entity != null;
}
/**
diff --git a/src/com/sun/xml/internal/stream/dtd/nonvalidating/DTDGrammar.java b/src/com/sun/xml/internal/stream/dtd/nonvalidating/DTDGrammar.java
index 08cc010..a389735 100644
--- a/src/com/sun/xml/internal/stream/dtd/nonvalidating/DTDGrammar.java
+++ b/src/com/sun/xml/internal/stream/dtd/nonvalidating/DTDGrammar.java
@@ -1,15 +1,15 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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,20 +20,20 @@
package com.sun.xml.internal.stream.dtd.nonvalidating;
-import java.util.Hashtable;
-import java.util.ArrayList;
-import java.util.List;
-
import com.sun.org.apache.xerces.internal.util.SymbolTable;
+import com.sun.org.apache.xerces.internal.util.XMLSymbols;
import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.xni.QName;
-import com.sun.org.apache.xerces.internal.util.XMLSymbols;
import com.sun.org.apache.xerces.internal.xni.XMLLocator;
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSource;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* A DTD grammar. This class implements the XNI handler interfaces
@@ -140,10 +140,10 @@ public class DTDGrammar {
private int fAttributeDeclNextAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][];
/** Element index mapping table. */
- private QNameHashtable fElementIndexMap = new QNameHashtable();
+ private final Map<String, Integer> fElementIndexMap = new HashMap<>();
/** Temporary qualified name. */
- private QName fQName = new QName();
+ private final QName fQName = new QName();
/** Temporary Attribute decl. */
protected XMLAttributeDecl fAttributeDecl = new XMLAttributeDecl();
@@ -156,7 +156,7 @@ public class DTDGrammar {
/** table of XMLElementDecl */
- Hashtable fElementDeclTab = new Hashtable();
+ Map<String, XMLElementDecl> fElementDeclTab = new HashMap<>();
/** Default constructor. */
public DTDGrammar(SymbolTable symbolTable) {
@@ -213,7 +213,7 @@ public class DTDGrammar {
public void elementDecl(String name, String contentModel, Augmentations augs)
throws XNIException {
- XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ;
+ XMLElementDecl tmpElementDecl = fElementDeclTab.get(name) ;
if ( tmpElementDecl != null ) {
if (tmpElementDecl.type == -1) {
fCurrentElementIndex = getElementDeclIndex(name);
@@ -299,7 +299,7 @@ public class DTDGrammar {
normalizeDefaultAttrValue(defaultValue);
}
- if ( this.fElementDeclTab.containsKey( (String) elementName) ) {
+ if ( this.fElementDeclTab.containsKey(elementName)) {
//if ElementDecl has already being created in the Grammar then remove from table,
//this.fElementDeclTab.remove( (String) elementName );
}
@@ -431,7 +431,10 @@ public class DTDGrammar {
* @return index of the elementDeclName in scope
*/
public int getElementDeclIndex(String elementDeclName) {
- int mapping = fElementIndexMap.get(elementDeclName);
+ Integer mapping = fElementIndexMap.get(elementDeclName);
+ if (mapping == null) {
+ mapping = -1;
+ }
//System.out.println("getElementDeclIndex("+elementDeclName+") -> "+mapping);
return mapping;
} // getElementDeclIndex(String):int
@@ -824,127 +827,6 @@ public class DTDGrammar {
return newarray;
}
- //
- // Classes
- //
-
-
- /**
- * A simple Hashtable implementation that takes a tuple (String, String)
- * as the key and a int as value.
- *
- * @author Eric Ye, IBM
- * @author Andy Clark, IBM
- */
- protected static final class QNameHashtable {
-
- //
- // Constants
- //
- public static final boolean UNIQUE_STRINGS = true;
-
- /** Initial bucket size (4). */
- private static final int INITIAL_BUCKET_SIZE = 4;
-
- // NOTE: Changed previous hashtable size from 512 to 101 so
- // that we get a better distribution for hashing. -Ac
- /** Hashtable size (101). */
- private static final int HASHTABLE_SIZE = 101;
-
- //
- // Data
- //
- private Object[][] fHashTable = new Object[HASHTABLE_SIZE][];
-
- //
- // Public methods
- //
- /** Associates the given value with the specified key tuple. */
- public void put(String key, int value) {
-
- // REVISIT: Why +2? -Ac
- int hash = (hash(key)+2) % HASHTABLE_SIZE;
- Object[] bucket = fHashTable[hash];
-
- if (bucket == null) {
- bucket = new Object[1 + 2*INITIAL_BUCKET_SIZE];
- bucket[0] = new int[]{1};
- bucket[1] = key;
- bucket[2] = new int[]{value};
- fHashTable[hash] = bucket;
- } else {
- int count = ((int[])bucket[0])[0];
- int offset = 1 + 2*count;
- if (offset == bucket.length) {
- int newSize = count + INITIAL_BUCKET_SIZE;
- Object[] newBucket = new Object[1 + 2*newSize];
- System.arraycopy(bucket, 0, newBucket, 0, offset);
- bucket = newBucket;
- fHashTable[hash] = bucket;
- }
- boolean found = false;
- int j=1;
- for (int i=0; i<count; i++){
- if ((String)bucket[j] == key) {
- ((int[])bucket[j+1])[0] = value;
- found = true;
- break;
- }
- j += 2;
- }
- if (! found) {
- bucket[offset++] = key;
- bucket[offset]= new int[]{value};
- ((int[])bucket[0])[0] = ++count;
- }
-
- }
- //System.out.println("put("+key+" -> "+value+')');
- //System.out.println("get("+key+") -> "+get(key));
-
- } // put(int,String,String,int)
-
- /** Returns the value associated with the specified key tuple. */
- public int get(String key) {
- int hash = (hash(key)+2) % HASHTABLE_SIZE;
- Object[] bucket = fHashTable[hash];
-
- if (bucket == null) {
- return -1;
- }
- int count = ((int[])bucket[0])[0];
-
- int j=1;
- for (int i=0; i<count; i++){
- if ((String)bucket[j] == key) {
- return ((int[])bucket[j+1])[0];
- }
- j += 2;
- }
- return -1;
-
- } // get(int,String,String)
-
- //
- // Protected methods
- //
-
- /** Returns a hash value for the specified symbol. */
- protected int hash(String symbol) {
-
- if (symbol == null) {
- return 0;
- }
- int code = 0;
- int length = symbol.length();
- for (int i = 0; i < length; i++) {
- code = code * 37 + symbol.charAt(i);
- }
- return code & 0x7FFFFFF;
-
- } // hash(String):int
-
- } // class QNameHashtable
/**
* Normalize the attribute value of a non CDATA default attribute
* collapsing sequences of space characters (x20)