> auxClasses) {
_auxClasses = auxClasses;
}
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 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
*
@@ -24,6 +24,23 @@
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+import com.sun.org.apache.xalan.internal.xsltc.DOM;
+import com.sun.org.apache.xalan.internal.xsltc.Translet;
+import com.sun.org.apache.xalan.internal.xsltc.dom.AbsoluteIterator;
+import com.sun.org.apache.xalan.internal.xsltc.dom.ArrayNodeListIterator;
+import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
+import com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM;
+import com.sun.org.apache.xalan.internal.xsltc.dom.SingletonIterator;
+import com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator;
+import com.sun.org.apache.xml.internal.dtm.Axis;
+import com.sun.org.apache.xml.internal.dtm.DTM;
+import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
+import com.sun.org.apache.xml.internal.dtm.DTMManager;
+import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
+import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
+import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
+import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
+import com.sun.org.apache.xml.internal.utils.XML11Char;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.FieldPosition;
@@ -32,31 +49,11 @@
import java.util.Locale;
import java.util.ResourceBundle;
import javax.xml.transform.dom.DOMSource;
-
-import com.sun.org.apache.xalan.internal.xsltc.DOM;
-import com.sun.org.apache.xalan.internal.xsltc.Translet;
-import com.sun.org.apache.xalan.internal.xsltc.dom.AbsoluteIterator;
-import com.sun.org.apache.xml.internal.dtm.Axis;
-import com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter;
-import com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM;
-import com.sun.org.apache.xalan.internal.xsltc.dom.SingletonIterator;
-import com.sun.org.apache.xalan.internal.xsltc.dom.StepIterator;
-import com.sun.org.apache.xalan.internal.xsltc.dom.ArrayNodeListIterator;
-import com.sun.org.apache.xml.internal.dtm.DTM;
-import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
-import com.sun.org.apache.xml.internal.dtm.DTMManager;
-import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
-import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
-
-import org.w3c.dom.DOMException;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
-import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
-import com.sun.org.apache.xml.internal.utils.XML11Char;
/**
* Standard XSLT functions. All standard functions expect the current node
@@ -983,7 +980,7 @@
/**
* Utility function: used to format/adjust a double to a string. The
- * DecimalFormat object comes from the 'formatSymbols' hashtable in
+ * DecimalFormat object comes from the 'formatSymbols' map in
* AbstractTranslet.
*/
private static FieldPosition _fieldPosition = new FieldPosition(0);
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java Fri Jul 29 04:24:19 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,345 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2001-2004 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
- *
- * 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * $Id: Hashtable.java,v 1.2.4.1 2005/09/06 11:05:18 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.runtime;
-
-import java.util.Enumeration;
-
-/**
- * IMPORTANT NOTE:
- * This code was taken from Sun's Java1.1 JDK java.util.HashTable.java
- * All "synchronized" keywords and some methods we do not need have been
- * all been removed.
- */
-
-/**
- * Object that wraps entries in the hash-table
- * @author Morten Jorgensen
- */
-class HashtableEntry {
- int hash;
- Object key;
- Object value;
- HashtableEntry next;
-
- protected Object clone() {
- HashtableEntry entry = new HashtableEntry();
- entry.hash = hash;
- entry.key = key;
- entry.value = value;
- entry.next = (next != null) ? (HashtableEntry)next.clone() : null;
- return entry;
- }
-}
-
-/**
- * The main hash-table implementation
- */
-public class Hashtable {
-
- private transient HashtableEntry table[]; // hash-table entries
- private transient int count; // number of entries
- private int threshold; // current size of hash-tabke
- private float loadFactor; // load factor
-
- /**
- * Constructs a new, empty hashtable with the specified initial
- * capacity and the specified load factor.
- */
- public Hashtable(int initialCapacity, float loadFactor) {
- if (initialCapacity <= 0) initialCapacity = 11;
- if (loadFactor <= 0.0) loadFactor = 0.75f;
- this.loadFactor = loadFactor;
- table = new HashtableEntry[initialCapacity];
- threshold = (int)(initialCapacity * loadFactor);
- }
-
- /**
- * Constructs a new, empty hashtable with the specified initial capacity
- * and default load factor.
- */
- public Hashtable(int initialCapacity) {
- this(initialCapacity, 0.75f);
- }
-
- /**
- * Constructs a new, empty hashtable with a default capacity and load
- * factor.
- */
- public Hashtable() {
- this(101, 0.75f);
- }
-
- /**
- * Returns the number of keys in this hashtable.
- */
- public int size() {
- return count;
- }
-
- /**
- * Tests if this hashtable maps no keys to values.
- */
- public boolean isEmpty() {
- return count == 0;
- }
-
- /**
- * Returns an enumeration of the keys in this hashtable.
- */
- public Enumeration keys() {
- return new HashtableEnumerator(table, true);
- }
-
- /**
- * Returns an enumeration of the values in this hashtable.
- * Use the Enumeration methods on the returned object to fetch the elements
- * sequentially.
- */
- public Enumeration elements() {
- return new HashtableEnumerator(table, false);
- }
-
- /**
- * Tests if some key maps into the specified value in this hashtable.
- * This operation is more expensive than the containsKey
- * method.
- */
- public boolean contains(Object value) {
-
- if (value == null) throw new NullPointerException();
-
- int i;
- HashtableEntry e;
- HashtableEntry tab[] = table;
-
- for (i = tab.length ; i-- > 0 ;) {
- for (e = tab[i] ; e != null ; e = e.next) {
- if (e.value.equals(value)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Tests if the specified object is a key in this hashtable.
- */
- public boolean containsKey(Object key) {
- HashtableEntry e;
- HashtableEntry tab[] = table;
- int hash = key.hashCode();
- int index = (hash & 0x7FFFFFFF) % tab.length;
-
- for (e = tab[index] ; e != null ; e = e.next)
- if ((e.hash == hash) && e.key.equals(key))
- return true;
-
- return false;
- }
-
- /**
- * Returns the value to which the specified key is mapped in this hashtable.
- */
- public Object get(Object key) {
- HashtableEntry e;
- HashtableEntry tab[] = table;
- int hash = key.hashCode();
- int index = (hash & 0x7FFFFFFF) % tab.length;
-
- for (e = tab[index] ; e != null ; e = e.next)
- if ((e.hash == hash) && e.key.equals(key))
- return e.value;
-
- return null;
- }
-
- /**
- * Rehashes the contents of the hashtable into a hashtable with a
- * larger capacity. This method is called automatically when the
- * number of keys in the hashtable exceeds this hashtable's capacity
- * and load factor.
- */
- protected void rehash() {
- HashtableEntry e, old;
- int i, index;
- int oldCapacity = table.length;
- HashtableEntry oldTable[] = table;
-
- int newCapacity = oldCapacity * 2 + 1;
- HashtableEntry newTable[] = new HashtableEntry[newCapacity];
-
- threshold = (int)(newCapacity * loadFactor);
- table = newTable;
-
- for (i = oldCapacity ; i-- > 0 ;) {
- for (old = oldTable[i] ; old != null ; ) {
- e = old;
- old = old.next;
- index = (e.hash & 0x7FFFFFFF) % newCapacity;
- e.next = newTable[index];
- newTable[index] = e;
- }
- }
- }
-
- /**
- * Maps the specified key
to the specified
- * value
in this hashtable. Neither the key nor the
- * value can be null
.
- *
- * The value can be retrieved by calling the get
method
- * with a key that is equal to the original key.
- */
- public Object put(Object key, Object value) {
- // Make sure the value is not null
- if (value == null) throw new NullPointerException();
-
- // Makes sure the key is not already in the hashtable.
- HashtableEntry e;
- HashtableEntry tab[] = table;
- int hash = key.hashCode();
- int index = (hash & 0x7FFFFFFF) % tab.length;
-
- for (e = tab[index] ; e != null ; e = e.next) {
- if ((e.hash == hash) && e.key.equals(key)) {
- Object old = e.value;
- e.value = value;
- return old;
- }
- }
-
- // Rehash the table if the threshold is exceeded
- if (count >= threshold) {
- rehash();
- return put(key, value);
- }
-
- // Creates the new entry.
- e = new HashtableEntry();
- e.hash = hash;
- e.key = key;
- e.value = value;
- e.next = tab[index];
- tab[index] = e;
- count++;
- return null;
- }
-
- /**
- * Removes the key (and its corresponding value) from this
- * hashtable. This method does nothing if the key is not in the hashtable.
- */
- public Object remove(Object key) {
- HashtableEntry e, prev;
- HashtableEntry tab[] = table;
- int hash = key.hashCode();
- int index = (hash & 0x7FFFFFFF) % tab.length;
- for (e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
- if ((e.hash == hash) && e.key.equals(key)) {
- if (prev != null)
- prev.next = e.next;
- else
- tab[index] = e.next;
- count--;
- return e.value;
- }
- }
- return null;
- }
-
- /**
- * Clears this hashtable so that it contains no keys.
- */
- public void clear() {
- HashtableEntry tab[] = table;
- for (int index = tab.length; --index >= 0; )
- tab[index] = null;
- count = 0;
- }
-
- /**
- * Returns a rather long string representation of this hashtable.
- * Handy for debugging - leave it here!!!
- */
- public String toString() {
- int i;
- int max = size() - 1;
- StringBuffer buf = new StringBuffer();
- Enumeration k = keys();
- Enumeration e = elements();
- buf.append("{");
-
- for (i = 0; i <= max; i++) {
- String s1 = k.nextElement().toString();
- String s2 = e.nextElement().toString();
- buf.append(s1).append('=').append(s2);
- if (i < max) buf.append(", ");
- }
- buf.append("}");
- return buf.toString();
- }
-
- /**
- * A hashtable enumerator class. This class should remain opaque
- * to the client. It will use the Enumeration interface.
- */
- class HashtableEnumerator implements Enumeration {
- boolean keys;
- int index;
- HashtableEntry table[];
- HashtableEntry entry;
-
- HashtableEnumerator(HashtableEntry table[], boolean keys) {
- this.table = table;
- this.keys = keys;
- this.index = table.length;
- }
-
- public boolean hasMoreElements() {
- if (entry != null) {
- return true;
- }
- while (index-- > 0) {
- if ((entry = table[index]) != null) {
- return true;
- }
- }
- return false;
- }
-
- public Object nextElement() {
- if (entry == null) {
- while ((index-- > 0) && ((entry = table[index]) == null));
- }
- if (entry != null) {
- HashtableEntry e = entry;
- entry = e.next;
- return keys ? e.key : e.value;
- }
- return null;
- }
- }
-
-}
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/DOM2SAX.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/DOM2SAX.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/DOM2SAX.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 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
*
@@ -24,14 +24,15 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
+import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
+import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
import java.io.IOException;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Stack;
import java.util.Vector;
-
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
@@ -44,8 +45,6 @@
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
-import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
/**
* @author G. Todd Miller
@@ -59,7 +58,7 @@
private ContentHandler _sax = null;
private LexicalHandler _lex = null;
private SAXImpl _saxImpl = null;
- private Hashtable _nsPrefixes = new Hashtable();
+ private Map _nsPrefixes = new HashMap<>();
public DOM2SAX(Node root) {
_dom = root;
@@ -91,7 +90,7 @@
throws SAXException
{
boolean pushed = true;
- Stack uriStack = (Stack) _nsPrefixes.get(prefix);
+ Stack uriStack = _nsPrefixes.get(prefix);
if (uriStack != null) {
if (uriStack.isEmpty()) {
@@ -124,7 +123,7 @@
private void endPrefixMapping(String prefix)
throws SAXException
{
- final Stack uriStack = (Stack) _nsPrefixes.get(prefix);
+ final Stack uriStack = _nsPrefixes.get(prefix);
if (uriStack != null) {
_sax.endPrefixMapping(prefix);
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXEvent2SAX.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXEvent2SAX.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXEvent2SAX.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, 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
@@ -75,7 +75,6 @@
private ContentHandler _sax = null;
private LexicalHandler _lex = null;
private SAXImpl _saxImpl = null;
- //private Hashtable _nsPrefixes = new Hashtable();
private String version = null;
private String encoding = null;
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXStream2SAX.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXStream2SAX.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/StAXStream2SAX.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, 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,12 +25,12 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
+import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
import java.io.IOException;
-import java.util.Hashtable;
-import java.util.Stack;
-import java.util.Vector;
-import java.util.Iterator;
-
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
@@ -45,22 +45,6 @@
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ext.Locator2;
import org.xml.sax.helpers.AttributesImpl;
-import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
-
-
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.Characters;
-import javax.xml.stream.events.EndElement;
-import javax.xml.stream.events.Namespace;
-import javax.xml.stream.events.ProcessingInstruction;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.StartDocument;
-import javax.xml.stream.events.XMLEvent;
@@ -80,7 +64,6 @@
private ContentHandler _sax = null;
private LexicalHandler _lex = null;
private SAXImpl _saxImpl = null;
- //private Hashtable _nsPrefixes = new Hashtable();
public StAXStream2SAX(XMLStreamReader staxSrc) {
staxStreamReader = staxSrc;
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,15 +1,15 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
- *
- * 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,
@@ -30,13 +30,15 @@
import com.sun.org.apache.xalan.internal.xsltc.Translet;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
import java.io.IOException;
+import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.xml.XMLConstants;
@@ -89,7 +91,7 @@
/**
* Contains the list of auxiliary class definitions.
*/
- private Hashtable _auxClasses = null;
+ private transient Map> _auxClasses = null;
/**
* Output properties of this translet.
@@ -122,19 +124,39 @@
*/
private transient TransformerFactoryImpl _tfactory = null;
- private boolean _useServicesMechanism;
+ /**
+ * A flag to determine whether the Service Mechanism is used
+ */
+ private transient boolean _useServicesMechanism;
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
*/
- private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
+ private transient String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
+
+ /**
+ * @serialField _name String The Name of the main class
+ * @serialField _bytecodes byte[][] Class definition
+ * @serialField _class Class[] The translet class definition(s).
+ * @serialField _transletIndex int The index of the main translet class
+ * @serialField _outputProperties Properties Output properties of this translet.
+ * @serialField _indentNumber int Number of spaces to add for output indentation.
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("_name", String.class),
+ new ObjectStreamField("_bytecodes", byte[][].class),
+ new ObjectStreamField("_class", Class[].class),
+ new ObjectStreamField("_transletIndex", int.class),
+ new ObjectStreamField("_outputProperties", Properties.class),
+ new ObjectStreamField("_indentNumber", int.class),
+ };
static final class TransletClassLoader extends ClassLoader {
-
private final Map _loadedExternalExtensionFunctions;
- TransletClassLoader(ClassLoader parent) {
- super(parent);
+ TransletClassLoader(ClassLoader parent) {
+ super(parent);
_loadedExternalExtensionFunctions = null;
}
@@ -154,7 +176,7 @@
ret = super.loadClass(name);
}
return ret;
- }
+ }
/**
* Access to final protected superclass member from outer class.
@@ -214,6 +236,7 @@
* if yes then we need to deserialize the URIResolver
* Fix for bugzilla bug 22438
*/
+ @SuppressWarnings("unchecked")
private void readObject(ObjectInputStream is)
throws IOException, ClassNotFoundException
{
@@ -226,7 +249,16 @@
}
}
- is.defaultReadObject();
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = is.readFields();
+ _name = (String)gf.get("_name", null);
+ _bytecodes = (byte[][])gf.get("_bytecodes", null);
+ _class = (Class[])gf.get("_class", null);
+ _transletIndex = gf.get("_transletIndex", -1);
+
+ _outputProperties = (Properties)gf.get("_outputProperties", null);
+ _indentNumber = gf.get("_indentNumber", 0);
+
if (is.readBoolean()) {
_uriResolver = (URIResolver) is.readObject();
}
@@ -242,7 +274,22 @@
*/
private void writeObject(ObjectOutputStream os)
throws IOException, ClassNotFoundException {
- os.defaultWriteObject();
+ if (_auxClasses != null) {
+ //throw with the same message as when Hashtable was used for compatibility.
+ throw new NotSerializableException(
+ "com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable");
+ }
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = os.putFields();
+ pf.put("_name", _name);
+ pf.put("_bytecodes", _bytecodes);
+ pf.put("_class", _class);
+ pf.put("_transletIndex", _transletIndex);
+ pf.put("_outputProperties", _outputProperties);
+ pf.put("_indentNumber", _indentNumber);
+ os.writeFields();
+
if (_uriResolver instanceof Serializable) {
os.writeBoolean(true);
os.writeObject((Serializable) _uriResolver);
@@ -360,7 +407,7 @@
_class = new Class[classCount];
if (classCount > 1) {
- _auxClasses = new Hashtable();
+ _auxClasses = new HashMap<>();
}
for (int i = 0; i < classCount; i++) {
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 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
*
@@ -49,7 +49,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
-import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
@@ -73,7 +72,8 @@
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stax.*;
+import javax.xml.transform.stax.StAXResult;
+import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
@@ -146,13 +146,13 @@
private String _jarFileName = null;
/**
- * This Hashtable is used to store parameters for locating
+ * This Map is used to store parameters for locating
* processing instructions in XML docs.
*/
- private Hashtable _piParams = null;
+ private Map _piParams = null;
/**
- * The above hashtable stores objects of this class.
+ * The above Map stores objects of this class.
*/
private static class PIParamWrapper {
public String _media = null;
@@ -932,7 +932,7 @@
// PI in an XML input document
if ((_piParams != null) && (_piParams.get(source) != null)) {
// Get the parameters for this Source object
- PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
+ PIParamWrapper p = _piParams.get(source);
// Pass them on to the compiler (which will pass then to the parser)
if (p != null) {
xsltc.setPIParameters(p._media, p._title, p._charset);
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java
--- a/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 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
*
@@ -26,6 +26,22 @@
import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
+import com.sun.org.apache.xalan.internal.xsltc.DOM;
+import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
+import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
+import com.sun.org.apache.xalan.internal.xsltc.Translet;
+import com.sun.org.apache.xalan.internal.xsltc.TransletException;
+import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
+import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
+import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
+import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
+import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
+import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
+import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
+import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory;
+import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
+import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
+import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -38,11 +54,12 @@
import java.net.URLConnection;
import java.net.UnknownServiceException;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
-import java.lang.reflect.Constructor;
-
+import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -63,29 +80,6 @@
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.XMLConstants;
-
-import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
-
-import com.sun.org.apache.xalan.internal.xsltc.DOM;
-import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
-import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
-import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
-import com.sun.org.apache.xalan.internal.xsltc.Translet;
-import com.sun.org.apache.xalan.internal.xsltc.TransletException;
-import com.sun.org.apache.xml.internal.serializer.OutputPropertiesFactory;
-import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
-import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
-import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
-import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
-import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
-import com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory;
-
-import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
-import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
-
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -221,11 +215,11 @@
private XMLSecurityManager _securityManager;
/**
- * A hashtable to store parameters for the identity transform. These
+ * A map to store parameters for the identity transform. These
* are not needed during the transformation, but we must keep track of
* them to be fully complaint with the JAXP API.
*/
- private Hashtable _parameters = null;
+ private Map _parameters = null;
/**
* This class wraps an ErrorListener into a MessageHandler in order to
@@ -828,31 +822,6 @@
}
/**
- * The translet stores all CDATA sections set in the element
- * in a Hashtable. This method will re-construct the whitespace separated
- * list of elements given in the element.
- */
- private String makeCDATAString(Hashtable cdata) {
- // Return a 'null' string if no CDATA section elements were specified
- if (cdata == null) return null;
-
- StringBuffer result = new StringBuffer();
-
- // Get an enumeration of all the elements in the hashtable
- Enumeration elements = cdata.keys();
- if (elements.hasMoreElements()) {
- result.append((String)elements.nextElement());
- while (elements.hasMoreElements()) {
- String element = (String)elements.nextElement();
- result.append(' ');
- result.append(element);
- }
- }
-
- return(result.toString());
- }
-
- /**
* Implements JAXP's Transformer.getOutputProperties().
* Returns a copy of the output properties for the transformation. This is
* a set of layered properties. The first layer contains properties set by
@@ -1220,7 +1189,7 @@
if (_isIdentity) {
if (_parameters == null) {
- _parameters = new Hashtable();
+ _parameters = new HashMap<>();
}
_parameters.put(name, value);
}
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java
--- a/src/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004,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
*
@@ -17,25 +17,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.sun.org.apache.xerces.internal.dom;
-import java.lang.reflect.Constructor;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.util.URI;
-import com.sun.org.apache.xerces.internal.impl.Constants;
-
-import org.w3c.dom.DOMConfiguration;
-import org.w3c.dom.UserDataHandler;
+import com.sun.org.apache.xerces.internal.util.XML11Char;
import com.sun.org.apache.xerces.internal.util.XMLChar;
-import com.sun.org.apache.xerces.internal.util.XML11Char;
-import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
+import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
+import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
@@ -50,6 +52,7 @@
import org.w3c.dom.Notation;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
+import org.w3c.dom.UserDataHandler;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.ls.DOMImplementationLS;
@@ -82,17 +85,15 @@
* @version $Id: CoreDocumentImpl.java,v 1.9 2010-11-01 04:39:37 joehw Exp $
* @since PR-DOM-Level-1-19980818.
*/
-
-
public class CoreDocumentImpl
-extends ParentNode implements Document {
+ extends ParentNode implements Document {
- /**TODO::
- * 1. Change XML11Char method names similar to XMLChar. That will prevent lot
- * of dirty version checking code.
- *
- * 2. IMO during cloneNode qname/isXMLName check should not be made.
- */
+ /**
+ * TODO:: 1. Change XML11Char method names similar to XMLChar. That will
+ * prevent lot of dirty version checking code.
+ *
+ * 2. IMO during cloneNode qname/isXMLName check should not be made.
+ */
//
// Constants
//
@@ -130,13 +131,12 @@
/**Experimental DOM Level 3 feature: documentURI */
protected String fDocumentURI;
- //Revisit :: change to a better data structure.
+ //Revisit :: change to a better data structure.
/** Table for user data attached to this document nodes. */
- protected Hashtable userData;
-
+ private Map> nodeUserData;
/** Identifiers. */
- protected Hashtable identifiers;
+ protected Map identifiers;
// DOM Level 3: normalizeDocument
transient DOMNormalizer domNormalizer = null;
@@ -207,7 +207,7 @@
// document. Node number values are negative integers. Nodes are
// assigned numbers on demand.
private int nodeCounter = 0;
- private Hashtable nodeTable;
+ private Map nodeTable;
private boolean xml11Version = false; //by default 1.0
//
// Static initialization
@@ -243,6 +243,52 @@
} // static
+ /**
+ * @serialField docType DocumentTypeImpl document type
+ * @serialField docElement ElementImpl document element
+ * @serialField fFreeNLCache NodeListCache NodeListCache free list
+ * @serialField encoding String Document encoding
+ * @serialField actualEncoding String Document actualEncoding
+ * @serialField version String Document version
+ * @serialField standalone boolean Document standalone
+ * @serialField fDocumentURI String Document URI
+ * @serialField userData Hashtable user data attached to the nodes. Note that
+ * it was original called "userData". It has been changed to nodeUserData to
+ * avoid confusion with those that are actually values of the map.
+ * @serialField identifiers Hashtable identifiers
+ * @serialField changes int flag indicates whether the node has changed
+ * @serialField allowGrammarAccess boolean Allow grammar access
+ * @serialField errorChecking boolean Bypass error checking
+ * @serialField ancestorChecking boolean Ancestor checking
+ * @serialField xmlVersionChanged boolean Indicate whether the version has changed
+ * @serialField documentNumber int Document number
+ * @serialField nodeCounter int Node counter
+ * @serialField nodeTable Hashtable Node table
+ * @serialField xml11Version boolean XML version
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("docType", DocumentTypeImpl.class),
+ new ObjectStreamField("docElement", ElementImpl.class),
+ new ObjectStreamField("fFreeNLCache", NodeListCache.class),
+ new ObjectStreamField("encoding", String.class),
+ new ObjectStreamField("actualEncoding", String.class),
+ new ObjectStreamField("version", String.class),
+ new ObjectStreamField("standalone", boolean.class),
+ new ObjectStreamField("fDocumentURI", String.class),
+ new ObjectStreamField("userData", Hashtable.class),
+ new ObjectStreamField("identifiers", Hashtable.class),
+ new ObjectStreamField("changes", int.class),
+ new ObjectStreamField("allowGrammarAccess", boolean.class),
+ new ObjectStreamField("errorChecking", boolean.class),
+ new ObjectStreamField("ancestorChecking", boolean.class),
+ new ObjectStreamField("xmlVersionChanged", boolean.class),
+ new ObjectStreamField("documentNumber", int.class),
+ new ObjectStreamField("nodeCounter", int.class),
+ new ObjectStreamField("nodeTable", Hashtable.class),
+ new ObjectStreamField("xml11Version", boolean.class),
+ };
+
//
// Constructors
//
@@ -343,24 +389,21 @@
}
if (deep) {
- Hashtable reversedIdentifiers = null;
+ Map reversedIdentifiers = null;
if (identifiers != null) {
// Build a reverse mapping from element to identifier.
- reversedIdentifiers = new Hashtable();
- Enumeration elementIds = identifiers.keys();
- while (elementIds.hasMoreElements()) {
- Object elementId = elementIds.nextElement();
- reversedIdentifiers.put(identifiers.get(elementId),
- elementId);
+ reversedIdentifiers = new HashMap<>(identifiers.size());
+ for (String elementId : identifiers.keySet()) {
+ reversedIdentifiers.put(identifiers.get(elementId), elementId);
}
}
// Copy children into new document.
for (ChildNode kid = firstChild; kid != null;
- kid = kid.nextSibling) {
+ kid = kid.nextSibling) {
newdoc.appendChild(newdoc.importNode(kid, true, true,
- reversedIdentifiers));
+ reversedIdentifiers));
}
}
@@ -385,7 +428,7 @@
* document element nor the document type in any way
*/
public Node insertBefore(Node newChild, Node refChild)
- throws DOMException {
+ throws DOMException {
// Only one such child permitted
int type = newChild.getNodeType();
@@ -447,7 +490,7 @@
* document element nor the document type in any way
*/
public Node replaceChild(Node newChild, Node oldChild)
- throws DOMException {
+ throws DOMException {
// Adopt orphan doctypes
if (newChild.getOwnerDocument() == null &&
@@ -463,8 +506,8 @@
newChild.getNodeType() == Node.ELEMENT_NODE))) {
throw new DOMException(
- DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
+ DOMException.HIERARCHY_REQUEST_ERR,
+ DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
}
super.replaceChild(newChild, oldChild);
@@ -491,7 +534,7 @@
* @since DOM Level 3
*/
public void setTextContent(String textContent)
- throws DOMException {
+ throws DOMException {
// no-op
}
@@ -508,7 +551,7 @@
// plus, only features whose interfaces are directly castable are
// considered.
if ((feature.equalsIgnoreCase("+XPath"))
- && (anyVersion || version.equals("3.0"))) {
+ && (anyVersion || version.equals("3.0"))) {
// If an XPathEvaluator was created previously
// return it otherwise create a new one.
@@ -527,7 +570,7 @@
Class interfaces[] = xpathClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (interfaces[i].getName().equals(
- "org.w3c.dom.xpath.XPathEvaluator")) {
+ "org.w3c.dom.xpath.XPathEvaluator")) {
fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
return fXPathEvaluator;
}
@@ -557,14 +600,14 @@
* if the attribute name is not acceptable.
*/
public Attr createAttribute(String name)
- throws DOMException {
+ throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "INVALID_CHARACTER_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "INVALID_CHARACTER_ERR",
+ null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new AttrImpl(this, name);
@@ -581,7 +624,7 @@
* not yet implemented.)
*/
public CDATASection createCDATASection(String data)
- throws DOMException {
+ throws DOMException {
return new CDATASectionImpl(this, data);
}
@@ -615,7 +658,7 @@
* acceptable.
*/
public Element createElement(String tagName)
- throws DOMException {
+ throws DOMException {
if (errorChecking && !isXMLName(tagName,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
@@ -636,7 +679,7 @@
* implemented.)
*/
public EntityReference createEntityReference(String name)
- throws DOMException {
+ throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
@@ -660,8 +703,8 @@
* not yet implemented.)
*/
public ProcessingInstruction createProcessingInstruction(String target,
- String data)
- throws DOMException {
+ String data)
+ throws DOMException {
if (errorChecking && !isXMLName(target,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
@@ -695,7 +738,6 @@
return docType;
}
-
/**
* Convenience method, allowing direct access to the child node
* which is considered the root of the actual document content. For
@@ -787,7 +829,6 @@
return errorChecking;
}
-
/**
* DOM Level 3 CR - Experimental. (Was getActualEncoding)
*
@@ -921,8 +962,8 @@
* @since DOM Level 3
*/
public void setXmlStandalone(boolean value)
- throws DOMException {
- standalone = value;
+ throws DOMException {
+ standalone = value;
}
/**
@@ -993,9 +1034,9 @@
if(colon1 != -1){
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "NAMESPACE_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "NAMESPACE_ERR",
+ null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
if (!isXMLName(name,xml11Version)) {
@@ -1021,7 +1062,7 @@
copyEventListeners(el, nel);
// remove user data from old node
- Hashtable data = removeUserDataTable(el);
+ Map data = removeUserDataTable(el);
// remove old node from parent if any
Node parent = el.getParentNode();
@@ -1094,7 +1135,7 @@
copyEventListeners(at, nat);
// remove user data from old node
- Hashtable data = removeUserDataTable(at);
+ Map data = removeUserDataTable(at);
// move children to new node
Node child = at.getFirstChild();
@@ -1329,13 +1370,13 @@
* parameter is from an other document.
*/
public String saveXML(Node node)
- throws DOMException {
- if ( errorChecking && node != null &&
- this != node.getOwnerDocument() ) {
+ throws DOMException {
+ if (errorChecking && node != null
+ && this != node.getOwnerDocument()) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
- DOMImplementationLS domImplLS = (DOMImplementationLS)DOMImplementationImpl.getDOMImplementation();
+ DOMImplementationLS domImplLS = (DOMImplementationLS) DOMImplementationImpl.getDOMImplementation();
LSSerializer xmlWriter = domImplLS.createLSSerializer();
if (node == null) {
node = this;
@@ -1344,8 +1385,8 @@
}
/**
- * Sets whether the DOM implementation generates mutation events
- * upon operations.
+ * Sets whether the DOM implementation generates mutation events upon
+ * operations.
*/
void setMutationEvents(boolean set) {
// does nothing by default - overidden in subclass
@@ -1359,47 +1400,40 @@
return false;
}
-
-
// non-DOM factory methods
-
/**
- * NON-DOM
- * Factory method; creates a DocumentType having this Document
- * as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
- * DTD information unspecified.)
+ * NON-DOM Factory method; creates a DocumentType having this Document as
+ * its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
+ * information unspecified.)
*
* @param name The name of the Entity we wish to provide a value for.
*
- * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
- * DTDs are not permitted. (HTML not yet implemented.)
+ * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where DTDs
+ * are not permitted. (HTML not yet implemented.)
*/
public DocumentType createDocumentType(String qualifiedName,
- String publicID,
- String systemID)
- throws DOMException {
+ String publicID,
+ String systemID)
+ throws DOMException {
return new DocumentTypeImpl(this, qualifiedName, publicID, systemID);
} // createDocumentType(String):DocumentType
/**
- * NON-DOM
- * Factory method; creates an Entity having this Document
- * as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
- * DTD information unspecified.)
+ * NON-DOM Factory method; creates an Entity having this Document as its
+ * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
+ * information unspecified.)
*
* @param name The name of the Entity we wish to provide a value for.
*
* @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
- * nonstandard entities are not permitted. (HTML not yet
- * implemented.)
+ * nonstandard entities are not permitted. (HTML not yet implemented.)
*/
public Entity createEntity(String name)
- throws DOMException {
+ throws DOMException {
-
- if (errorChecking && !isXMLName(name,xml11Version)) {
+ if (errorChecking && !isXMLName(name, xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
@@ -1408,21 +1442,19 @@
} // createEntity(String):Entity
/**
- * NON-DOM
- * Factory method; creates a Notation having this Document
- * as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
- * DTD information unspecified.)
+ * NON-DOM Factory method; creates a Notation having this Document as its
+ * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
+ * information unspecified.)
*
* @param name The name of the Notation we wish to describe
*
* @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
- * notations are not permitted. (HTML not yet
- * implemented.)
+ * notations are not permitted. (HTML not yet implemented.)
*/
public Notation createNotation(String name)
- throws DOMException {
+ throws DOMException {
- if (errorChecking && !isXMLName(name,xml11Version)) {
+ if (errorChecking && !isXMLName(name, xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
@@ -1435,9 +1467,9 @@
* definitions hold default attribute values.
*/
public ElementDefinitionImpl createElementDefinition(String name)
- throws DOMException {
+ throws DOMException {
- if (errorChecking && !isXMLName(name,xml11Version)) {
+ if (errorChecking && !isXMLName(name, xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
@@ -1446,23 +1478,23 @@
} // createElementDefinition(String):ElementDefinitionImpl
// other non-DOM methods
-
- /** NON-DOM: Get the number associated with this document. Used to
- * order documents in the implementation.
+ /**
+ * NON-DOM: Get the number associated with this document. Used to order
+ * documents in the implementation.
*/
protected int getNodeNumber() {
- if (documentNumber==0) {
+ if (documentNumber == 0) {
- CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation();
+ CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl) CoreDOMImplementationImpl.getDOMImplementation();
documentNumber = cd.assignDocumentNumber();
}
return documentNumber;
}
-
- /** NON-DOM: Get a number associated with a node created with respect
- * to this document. Needed for compareDocumentPosition when nodes
- * are disconnected. This is only used on demand.
+ /**
+ * NON-DOM: Get a number associated with a node created with respect to this
+ * document. Needed for compareDocumentPosition when nodes are disconnected.
+ * This is only used on demand.
*/
protected int getNodeNumber(Node node) {
@@ -1472,18 +1504,17 @@
// Node numbers are negative, from -1 to -n
int num;
if (nodeTable == null) {
- nodeTable = new Hashtable();
+ nodeTable = new HashMap<>();
num = --nodeCounter;
nodeTable.put(node, new Integer(num));
- }
- else {
- Integer n = (Integer)nodeTable.get(node);
- if (n== null) {
+ } else {
+ Integer n = nodeTable.get(node);
+ if (n == null) {
num = --nodeCounter;
- nodeTable.put(node, new Integer(num));
+ nodeTable.put(node, num);
+ } else {
+ num = n.intValue();
}
- else
- num = n.intValue();
}
return num;
}
@@ -1498,7 +1529,7 @@
* and a NOT_SUPPORTED_ERR exception is thrown if attempted.
*/
public Node importNode(Node source, boolean deep)
- throws DOMException {
+ throws DOMException {
return importNode(source, deep, false, null);
} // importNode(Node,boolean):Node
@@ -1507,18 +1538,18 @@
* provides the core functionality for the public importNode and cloneNode
* methods.
*
- * The reversedIdentifiers parameter is provided for cloneNode to
- * preserve the document's identifiers. The Hashtable has Elements as the
- * keys and their identifiers as the values. When an element is being
- * imported, a check is done for an associated identifier. If one exists,
- * the identifier is registered with the new, imported element. If
- * reversedIdentifiers is null, the parameter is not applied.
+ * The reversedIdentifiers parameter is provided for cloneNode to preserve
+ * the document's identifiers. The Map has Elements as the keys and
+ * their identifiers as the values. When an element is being imported, a
+ * check is done for an associated identifier. If one exists, the identifier
+ * is registered with the new, imported element. If reversedIdentifiers is
+ * null, the parameter is not applied.
*/
private Node importNode(Node source, boolean deep, boolean cloningDoc,
- Hashtable reversedIdentifiers)
- throws DOMException {
- Node newnode=null;
- Hashtable userData = null;
+ Map reversedIdentifiers)
+ throws DOMException {
+ Node newnode = null;
+ Map userData = null;
// Sigh. This doesn't work; too many nodes have private data that
// would have to be manually tweaked. May be able to add local
@@ -1531,8 +1562,9 @@
// newnode.ownerDocument=this;
// }
// else
- if(source instanceof NodeImpl)
- userData = ((NodeImpl)source).getUserDataRecord();
+ if (source instanceof NodeImpl) {
+ userData = ((NodeImpl) source).getUserDataRecord();
+ }
int type = source.getNodeType();
switch (type) {
case ELEMENT_NODE: {
@@ -1543,7 +1575,7 @@
newElement = createElement(source.getNodeName());
else
newElement = createElementNS(source.getNamespaceURI(),
- source.getNodeName());
+ source.getNodeName());
// Copy element's attributes, if any.
NamedNodeMap sourceAttrs = source.getAttributes();
@@ -1558,7 +1590,7 @@
// But for importNode defaults should be ignored.
if (attr.getSpecified() || cloningDoc) {
Attr newAttr = (Attr)importNode(attr, true, cloningDoc,
- reversedIdentifiers);
+ reversedIdentifiers);
// Attach attribute according to namespace
// support/qualification.
@@ -1567,17 +1599,18 @@
newElement.setAttributeNode(newAttr);
else
newElement.setAttributeNodeNS(newAttr);
+ }
}
}
- }
// Register element identifier.
if (reversedIdentifiers != null) {
// Does element have an associated identifier?
- Object elementId = reversedIdentifiers.get(source);
+ String elementId = reversedIdentifiers.get(source);
if (elementId != null) {
- if (identifiers == null)
- identifiers = new Hashtable();
+ if (identifiers == null) {
+ identifiers = new HashMap<>();
+ }
identifiers.put(elementId, newElement);
}
@@ -1594,7 +1627,7 @@
newnode = createAttribute(source.getNodeName());
} else {
newnode = createAttributeNS(source.getNamespaceURI(),
- source.getNodeName());
+ source.getNodeName());
}
}
else {
@@ -1663,7 +1696,7 @@
case PROCESSING_INSTRUCTION_NODE: {
newnode = createProcessingInstruction(source.getNodeName(),
- source.getNodeValue());
+ source.getNodeValue());
break;
}
@@ -1682,15 +1715,15 @@
DocumentType srcdoctype = (DocumentType)source;
DocumentTypeImpl newdoctype = (DocumentTypeImpl)
createDocumentType(srcdoctype.getNodeName(),
- srcdoctype.getPublicId(),
- srcdoctype.getSystemId());
+ srcdoctype.getPublicId(),
+ srcdoctype.getSystemId());
// Values are on NamedNodeMaps
NamedNodeMap smap = srcdoctype.getEntities();
NamedNodeMap tmap = newdoctype.getEntities();
if(smap != null) {
for(int i = 0; i < smap.getLength(); i++) {
tmap.setNamedItem(importNode(smap.item(i), true, true,
- reversedIdentifiers));
+ reversedIdentifiers));
}
}
smap = srcdoctype.getNotations();
@@ -1698,7 +1731,7 @@
if (smap != null) {
for(int i = 0; i < smap.getLength(); i++) {
tmap.setNamedItem(importNode(smap.item(i), true, true,
- reversedIdentifiers));
+ reversedIdentifiers));
}
}
@@ -1741,10 +1774,10 @@
// If deep, replicate and attach the kids.
if (deep) {
for (Node srckid = source.getFirstChild();
- srckid != null;
- srckid = srckid.getNextSibling()) {
+ srckid != null;
+ srckid = srckid.getNextSibling()) {
newnode.appendChild(importNode(srckid, true, cloningDoc,
- reversedIdentifiers));
+ reversedIdentifiers));
}
}
if (newnode.getNodeType() == Node.ENTITY_NODE) {
@@ -1752,7 +1785,7 @@
}
return newnode;
- } // importNode(Node,boolean,boolean,Hashtable):Node
+ } // importNode(Node,boolean,boolean,Map):Node
/**
* DOM Level 3 WD - Experimental
@@ -1763,7 +1796,7 @@
**/
public Node adoptNode(Node source) {
NodeImpl node;
- Hashtable userData = null;
+ Map userData;
try {
node = (NodeImpl) source;
} catch (ClassCastException e) {
@@ -1774,8 +1807,8 @@
// Return null if the source is null
if (source == null ) {
- return null;
- } else if (source != null && source.getOwnerDocument() != null) {
+ return null;
+ } else if (source.getOwnerDocument() != null) {
DOMImplementation thisImpl = this.getImplementation();
DOMImplementation otherImpl = source.getOwnerDocument().getImplementation();
@@ -1795,7 +1828,7 @@
// Adopting between two dissimilar DOM's is not allowed
return null;
}
- }
+ }
}
switch (node.getNodeType()) {
@@ -1808,12 +1841,13 @@
}
//2. specified flag is set to true
attr.isSpecified(true);
- userData = node.getUserDataRecord();
+ userData = node.getUserDataRecord();
//3. change ownership
attr.setOwnerDocument(this);
- if(userData != null )
- setUserDataTable(node,userData);
+ if (userData != null) {
+ setUserDataTable(node, userData);
+ }
break;
}
//entity, notation nodes are read only nodes.. so they can't be adopted.
@@ -1832,7 +1866,7 @@
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
case ENTITY_REFERENCE_NODE: {
- userData = node.getUserDataRecord();
+ userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
@@ -1845,8 +1879,9 @@
}
// change ownership
node.setOwnerDocument(this);
- if(userData != null)
- setUserDataTable(node,userData);
+ if (userData != null) {
+ setUserDataTable(node, userData);
+ }
// set its new replacement value if any
if (docType == null) {
break;
@@ -1857,14 +1892,14 @@
break;
}
for (child = entityNode.getFirstChild();
- child != null; child = child.getNextSibling()) {
+ child != null; child = child.getNextSibling()) {
Node childClone = child.cloneNode(true);
node.appendChild(childClone);
}
break;
}
case ELEMENT_NODE: {
- userData = node.getUserDataRecord();
+ userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
@@ -1872,14 +1907,15 @@
}
// change ownership
node.setOwnerDocument(this);
- if(userData != null)
- setUserDataTable(node,userData);
+ if (userData != null) {
+ setUserDataTable(node, userData);
+ }
// reconcile default attributes
((ElementImpl)node).reconcileDefaultAttributes();
break;
}
default: {
- userData = node.getUserDataRecord();
+ userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
@@ -1887,15 +1923,17 @@
}
// change ownership
node.setOwnerDocument(this);
- if(userData != null)
- setUserDataTable(node,userData);
+ if (userData != null) {
+ setUserDataTable(node, userData);
+ }
}
}
//DOM L3 Core CR
- //http://www.w3.org/TR/2003/CR-DOM-Level-3-Core-20031107/core.html#UserDataHandler-ADOPTED
- if(userData != null)
- callUserDataHandlers(source, null, UserDataHandler.NODE_ADOPTED,userData);
+ //http://www.w3.org/TR/2003/CR-DOM-Level-3-Core-20031107/core.html#UserDataHandler-ADOPTED
+ if (userData != null) {
+ callUserDataHandlers(source, null, UserDataHandler.NODE_ADOPTED, userData);
+ }
return node;
}
@@ -1994,7 +2032,7 @@
}
if (identifiers == null) {
- identifiers = new Hashtable();
+ identifiers = new HashMap<>();
}
identifiers.put(idName, element);
@@ -2052,25 +2090,9 @@
} // removeIdentifier(String)
- /** Returns an enumeration registered of identifier names. */
- public Enumeration getIdentifiers() {
-
- if (needsSyncData()) {
- synchronizeData();
- }
-
- if (identifiers == null) {
- identifiers = new Hashtable();
- }
-
- return identifiers.keys();
-
- } // getIdentifiers():Enumeration
-
//
// DOM2: Namespace methods
//
-
/**
* Introduced in DOM Level 2.
* Creates an element of the given qualified name and namespace URI.
@@ -2095,7 +2117,7 @@
* @since WD-DOM-Level-2-19990923
*/
public Element createElementNS(String namespaceURI, String qualifiedName)
- throws DOMException {
+ throws DOMException {
return new ElementNSImpl(this, namespaceURI, qualifiedName);
}
@@ -2114,8 +2136,8 @@
* name contains an invalid character.
*/
public Element createElementNS(String namespaceURI, String qualifiedName,
- String localpart)
- throws DOMException {
+ String localpart)
+ throws DOMException {
return new ElementNSImpl(this, namespaceURI, qualifiedName, localpart);
}
@@ -2138,7 +2160,7 @@
* @since WD-DOM-Level-2-19990923
*/
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
- throws DOMException {
+ throws DOMException {
return new AttrNSImpl(this, namespaceURI, qualifiedName);
}
@@ -2158,8 +2180,8 @@
* name contains an invalid character.
*/
public Attr createAttributeNS(String namespaceURI, String qualifiedName,
- String localpart)
- throws DOMException {
+ String localpart)
+ throws DOMException {
return new AttrNSImpl(this, namespaceURI, qualifiedName, localpart);
}
@@ -2180,7 +2202,7 @@
* @since WD-DOM-Level-2-19990923
*/
public NodeList getElementsByTagNameNS(String namespaceURI,
- String localName) {
+ String localName) {
return new DeepNodeListImpl(this, namespaceURI, localName);
}
@@ -2233,11 +2255,11 @@
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
- && XMLChar.isValidNCName(local);
+ && XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
- && XML11Char.isXML11ValidNCName(local);
+ && XML11Char.isXML11ValidNCName(local);
}
return validNCName;
@@ -2323,37 +2345,33 @@
* REVISIT: we could use a free list of UserDataRecord here
*/
public Object setUserData(Node n, String key,
- Object data, UserDataHandler handler) {
+ Object data, UserDataHandler handler) {
if (data == null) {
- if (userData != null) {
- Hashtable t = (Hashtable) userData.get(n);
+ if (nodeUserData != null) {
+ Map t = nodeUserData.get(n);
if (t != null) {
- Object o = t.remove(key);
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
+ UserDataRecord r = t.remove(key);
+ if (r != null) {
return r.fData;
}
}
}
return null;
- }
- else {
- Hashtable t;
- if (userData == null) {
- userData = new Hashtable();
- t = new Hashtable();
- userData.put(n, t);
- }
- else {
- t = (Hashtable) userData.get(n);
+ } else {
+ Map t;
+ if (nodeUserData == null) {
+ nodeUserData = new HashMap<>();
+ t = new HashMap<>();
+ nodeUserData.put(n, t);
+ } else {
+ t = nodeUserData.get(n);
if (t == null) {
- t = new Hashtable();
- userData.put(n, t);
+ t = new HashMap<>();
+ nodeUserData.put(n, t);
}
}
- Object o = t.put(key, new UserDataRecord(data, handler));
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
+ UserDataRecord r = t.put(key, new UserDataRecord(data, handler));
+ if (r != null) {
return r.fData;
}
return null;
@@ -2372,42 +2390,41 @@
* @since DOM Level 3
*/
public Object getUserData(Node n, String key) {
- if (userData == null) {
+ if (nodeUserData == null) {
return null;
}
- Hashtable t = (Hashtable) userData.get(n);
+ Map t = nodeUserData.get(n);
if (t == null) {
return null;
}
- Object o = t.get(key);
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
+ UserDataRecord r = t.get(key);
+ if (r != null) {
return r.fData;
}
return null;
}
- protected Hashtable getUserDataRecord(Node n){
- if (userData == null) {
+ protected Map getUserDataRecord(Node n) {
+ if (nodeUserData == null) {
return null;
}
- Hashtable t = (Hashtable) userData.get(n);
+ Map t = nodeUserData.get(n);
if (t == null) {
return null;
}
- return t;
- }
+ return t;
+ }
- /**
+ /**
* Remove user data table for the given node.
* @param n The node this operation applies to.
* @return The removed table.
*/
- Hashtable removeUserDataTable(Node n) {
- if (userData == null) {
+ Map removeUserDataTable(Node n) {
+ if (nodeUserData == null) {
return null;
}
- return (Hashtable) userData.get(n);
+ return nodeUserData.get(n);
}
/**
@@ -2415,11 +2432,13 @@
* @param n The node this operation applies to.
* @param data The user data table.
*/
- void setUserDataTable(Node n, Hashtable data) {
- if (userData == null)
- userData = new Hashtable();
+ void setUserDataTable(Node n, Map data) {
+ if (nodeUserData == null) {
+ nodeUserData = new HashMap<>();
+ }
+
if (data != null) {
- userData.put(n, data);
+ nodeUserData.put(n, data);
}
}
@@ -2430,41 +2449,39 @@
* @param operation The operation - import, clone, or delete.
*/
void callUserDataHandlers(Node n, Node c, short operation) {
- if (userData == null) {
+ if (nodeUserData == null) {
return;
}
- //Hashtable t = (Hashtable) userData.get(n);
- if(n instanceof NodeImpl){
- Hashtable t = ((NodeImpl)n).getUserDataRecord();
- if (t == null || t.isEmpty()) {
- return;
- }
- callUserDataHandlers(n, c, operation,t);
- }
+
+ if (n instanceof NodeImpl) {
+ Map t = ((NodeImpl) n).getUserDataRecord();
+ if (t == null || t.isEmpty()) {
+ return;
+ }
+ callUserDataHandlers(n, c, operation, t);
+ }
}
- /**
+ /**
* Call user data handlers when a node is deleted (finalized)
* @param n The node this operation applies to.
* @param c The copy node or null.
* @param operation The operation - import, clone, or delete.
- * @param handlers Data associated with n.
- */
- void callUserDataHandlers(Node n, Node c, short operation,Hashtable userData) {
+ * @param handlers Data associated with n.
+ */
+ void callUserDataHandlers(Node n, Node c, short operation, Map userData) {
if (userData == null || userData.isEmpty()) {
return;
}
- Enumeration keys = userData.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- UserDataRecord r = (UserDataRecord) userData.get(key);
+ for (String key : userData.keySet()) {
+ UserDataRecord r = userData.get(key);
if (r.fHandler != null) {
r.fHandler.handle(operation, key, r.fData, n, c);
}
}
}
- /**
+ /**
* Call user data handlers to let them know the nodes they are related to
* are being deleted. The alternative would be to do that on Node but
* because the nodes are used as the keys we have a reference to them that
@@ -2479,29 +2496,29 @@
// 2. It affects the performance greatly in multi-thread environment.
// -SG
/*public void finalize() {
- if (userData == null) {
- return;
- }
- Enumeration nodes = userData.keys();
- while (nodes.hasMoreElements()) {
- Object node = nodes.nextElement();
- Hashtable t = (Hashtable) userData.get(node);
- if (t != null && !t.isEmpty()) {
- Enumeration keys = t.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- UserDataRecord r = (UserDataRecord) t.get(key);
- if (r.fHandler != null) {
- r.fHandler.handle(UserDataHandler.NODE_DELETED,
- key, r.fData, null, null);
- }
- }
- }
- }
- }*/
+ if (userData == null) {
+ return;
+ }
+ Enumeration nodes = userData.keys();
+ while (nodes.hasMoreElements()) {
+ Object node = nodes.nextElement();
+ Hashtable t = (Hashtable) userData.get(node);
+ if (t != null && !t.isEmpty()) {
+ Enumeration keys = t.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ UserDataRecord r = (UserDataRecord) t.get(key);
+ if (r.fHandler != null) {
+ r.fHandler.handle(UserDataHandler.NODE_DELETED,
+ key, r.fData, null, null);
+ }
+ }
+ }
+ }
+ }*/
protected final void checkNamespaceWF( String qname, int colon1,
- int colon2) {
+ int colon2) {
if (!errorChecking) {
return;
@@ -2512,42 +2529,42 @@
if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "NAMESPACE_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "NAMESPACE_ERR",
+ null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
protected final void checkDOMNSErr(String prefix,
- String namespace) {
+ String namespace) {
if (errorChecking) {
if (namespace == null) {
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "NAMESPACE_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "NAMESPACE_ERR",
+ null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
else if (prefix.equals("xml")
- && !namespace.equals(NamespaceContext.XML_URI)) {
+ && !namespace.equals(NamespaceContext.XML_URI)) {
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "NAMESPACE_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "NAMESPACE_ERR",
+ null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
else if (
prefix.equals("xmlns")
- && !namespace.equals(NamespaceContext.XMLNS_URI)
- || (!prefix.equals("xmlns")
- && namespace.equals(NamespaceContext.XMLNS_URI))) {
+ && !namespace.equals(NamespaceContext.XMLNS_URI)
+ || (!prefix.equals("xmlns")
+ && namespace.equals(NamespaceContext.XMLNS_URI))) {
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "NAMESPACE_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "NAMESPACE_ERR",
+ null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
@@ -2565,24 +2582,24 @@
return;
}
- // check that both prefix and local part match NCName
+ // check that both prefix and local part match NCName
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
- && XMLChar.isValidNCName(local);
+ && XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
- && XML11Char.isXML11ValidNCName(local);
+ && XML11Char.isXML11ValidNCName(local);
}
if (!validNCName) {
// REVISIT: add qname parameter to the message
String msg =
DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- "INVALID_CHARACTER_ERR",
- null);
+ DOMMessageFormatter.DOM_DOMAIN,
+ "INVALID_CHARACTER_ERR",
+ null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
@@ -2629,14 +2646,14 @@
// Event related methods overidden in subclass
protected void addEventListener(NodeImpl node, String type,
- EventListener listener,
- boolean useCapture) {
+ EventListener listener,
+ boolean useCapture) {
// does nothing by default - overidden in subclass
}
protected void removeEventListener(NodeImpl node, String type,
- EventListener listener,
- boolean useCapture) {
+ EventListener listener,
+ boolean useCapture) {
// does nothing by default - overidden in subclass
}
@@ -2763,4 +2780,91 @@
void renamedElement(Element oldEl, Element newEl) {
}
+ /**
+ * @serialData Serialized fields. Convert Maps to Hashtables for backward
+ * compatibility.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // Convert Maps to Hashtables
+ Hashtable> nud = null;
+ if (nodeUserData != null) {
+ nud = new Hashtable<>();
+ for (Map.Entry> e : nodeUserData.entrySet()) {
+ //e.getValue() will not be null since an entry is always put with a non-null value
+ nud.put(e.getKey(), new Hashtable<>(e.getValue()));
+ }
+ }
+
+ Hashtable ids = (identifiers == null)? null : new Hashtable<>(identifiers);
+ Hashtable nt = (nodeTable == null)? null : new Hashtable<>(nodeTable);
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = out.putFields();
+ pf.put("docType", docType);
+ pf.put("docElement", docElement);
+ pf.put("fFreeNLCache", fFreeNLCache);
+ pf.put("encoding", encoding);
+ pf.put("actualEncoding", actualEncoding);
+ pf.put("version", version);
+ pf.put("standalone", standalone);
+ pf.put("fDocumentURI", fDocumentURI);
+
+ //userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
+ pf.put("userData", nud);
+ pf.put("identifiers", ids);
+ pf.put("changes", changes);
+ pf.put("allowGrammarAccess", allowGrammarAccess);
+ pf.put("errorChecking", errorChecking);
+ pf.put("ancestorChecking", ancestorChecking);
+ pf.put("xmlVersionChanged", xmlVersionChanged);
+ pf.put("documentNumber", documentNumber);
+ pf.put("nodeCounter", nodeCounter);
+ pf.put("nodeTable", nt);
+ pf.put("xml11Version", xml11Version);
+ out.writeFields();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = in.readFields();
+ docType = (DocumentTypeImpl)gf.get("docType", null);
+ docElement = (ElementImpl)gf.get("docElement", null);
+ fFreeNLCache = (NodeListCache)gf.get("fFreeNLCache", null);
+ encoding = (String)gf.get("encoding", null);
+ actualEncoding = (String)gf.get("actualEncoding", null);
+ version = (String)gf.get("version", null);
+ standalone = gf.get("standalone", false);
+ fDocumentURI = (String)gf.get("fDocumentURI", null);
+
+ //userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
+ Hashtable> nud =
+ (Hashtable>)gf.get("userData", null);
+
+ Hashtable ids = (Hashtable)gf.get("identifiers", null);
+
+ changes = gf.get("changes", 0);
+ allowGrammarAccess = gf.get("allowGrammarAccess", false);
+ errorChecking = gf.get("errorChecking", true);
+ ancestorChecking = gf.get("ancestorChecking", true);
+ xmlVersionChanged = gf.get("xmlVersionChanged", false);
+ documentNumber = gf.get("documentNumber", 0);
+ nodeCounter = gf.get("nodeCounter", 0);
+
+ Hashtable nt = (Hashtable)gf.get("nodeTable", null);
+
+ xml11Version = gf.get("xml11Version", false);
+
+ //convert Hashtables back to HashMaps
+ if (nud != null) {
+ nodeUserData = new HashMap<>();
+ for (Map.Entry> e : nud.entrySet()) {
+ nodeUserData.put(e.getKey(), new HashMap<>(e.getValue()));
+ }
+ }
+
+ if (ids != null) identifiers = new HashMap<>(ids);
+ if (nt != null) nodeTable = new HashMap<>(nt);
+ }
} // class CoreDocumentImpl
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java
--- a/src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/DeferredDocumentImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004,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
*
@@ -21,7 +21,7 @@
package com.sun.org.apache.xerces.internal.dom;
import java.util.ArrayList;
-
+import java.util.HashMap;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -2057,9 +2057,9 @@
element+')');
}
- // create hashtable
+ // create Map
if (identifiers == null) {
- identifiers = new java.util.Hashtable();
+ identifiers = new HashMap<>();
}
// save ID and its associated element
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java
--- a/src/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001,2002,2004,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
*
@@ -20,13 +20,19 @@
package com.sun.org.apache.xerces.internal.dom;
-import java.io.Serializable;
-import java.util.Hashtable;
-import java.util.Vector;
-
import com.sun.org.apache.xerces.internal.dom.events.EventImpl;
import com.sun.org.apache.xerces.internal.dom.events.MutationEventImpl;
-import org.w3c.dom.UserDataHandler;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
@@ -34,6 +40,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.UserDataHandler;
import org.w3c.dom.events.DocumentEvent;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventException;
@@ -96,18 +103,33 @@
/** Iterators */
// REVISIT: Should this be transient? -Ac
- protected Vector iterators;
+ protected List iterators;
/** Ranges */
// REVISIT: Should this be transient? -Ac
- protected Vector ranges;
+ protected List ranges;
/** Table for event listeners registered to this document nodes. */
- protected Hashtable eventListeners;
+ protected Map> eventListeners;
/** Bypass mutation events firing. */
protected boolean mutationEvents = false;
+
+ /**
+ * @serialField iterators Vector Node iterators
+ * @serialField ranges Vector ranges
+ * @serialField eventListeners Hashtable Event listeners
+ * @serialField mutationEvents boolean Bypass mutation events firing
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("iterators", Vector.class),
+ new ObjectStreamField("ranges", Vector.class),
+ new ObjectStreamField("eventListeners", Hashtable.class),
+ new ObjectStreamField("mutationEvents", boolean.class),
+ };
+
//
// Constructors
//
@@ -227,10 +249,10 @@
filter,
entityReferenceExpansion);
if (iterators == null) {
- iterators = new Vector();
+ iterators = new ArrayList<>();
}
- iterators.addElement(iterator);
+ iterators.add(iterator);
return iterator;
}
@@ -287,7 +309,7 @@
if (nodeIterator == null) return;
if (iterators == null) return;
- iterators.removeElement(nodeIterator);
+ iterators.remove(nodeIterator);
}
//
@@ -298,12 +320,11 @@
public Range createRange() {
if (ranges == null) {
- ranges = new Vector();
+ ranges = new ArrayList<>();
}
Range range = new RangeImpl(this);
-
- ranges.addElement(range);
+ ranges.add(range);
return range;
@@ -318,7 +339,7 @@
if (range == null) return;
if (ranges == null) return;
- ranges.removeElement(range);
+ ranges.remove(range);
}
/**
@@ -330,7 +351,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).receiveReplacedText(node);
+ ((RangeImpl)ranges.get(i)).receiveReplacedText(node);
}
}
}
@@ -344,7 +365,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).receiveDeletedText(node,
+ ((RangeImpl)ranges.get(i)).receiveDeletedText(node,
offset, count);
}
}
@@ -359,7 +380,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).receiveInsertedText(node,
+ ((RangeImpl)ranges.get(i)).receiveInsertedText(node,
offset, count);
}
}
@@ -374,7 +395,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).receiveSplitData(node,
+ ((RangeImpl)ranges.get(i)).receiveSplitData(node,
newNode, offset);
}
}
@@ -437,9 +458,9 @@
* node here won't be GC'ed as long as some listener is registered on it,
* since the eventsListeners table will have a reference to the node.
*/
- protected void setEventListeners(NodeImpl n, Vector listeners) {
+ private void setEventListeners(NodeImpl n, List listeners) {
if (eventListeners == null) {
- eventListeners = new Hashtable();
+ eventListeners = new HashMap<>();
}
if (listeners == null) {
eventListeners.remove(n);
@@ -457,11 +478,11 @@
/**
* Retreive event listener registered on a given node
*/
- protected Vector getEventListeners(NodeImpl n) {
+ private List getEventListeners(NodeImpl n) {
if (eventListeners == null) {
return null;
}
- return (Vector) eventListeners.get(n);
+ return eventListeners.get(n);
}
//
@@ -515,6 +536,7 @@
* @param useCapture True iff listener is registered on
* capturing phase rather than at-target or bubbling
*/
+ @Override
protected void addEventListener(NodeImpl node, String type,
EventListener listener, boolean useCapture)
{
@@ -527,12 +549,12 @@
// Simplest way to code that is to zap the previous entry, if any.
removeEventListener(node, type, listener, useCapture);
- Vector nodeListeners = getEventListeners(node);
+ List nodeListeners = getEventListeners(node);
if(nodeListeners == null) {
- nodeListeners = new Vector();
+ nodeListeners = new ArrayList<>();
setEventListeners(node, nodeListeners);
}
- nodeListeners.addElement(new LEntry(type, listener, useCapture));
+ nodeListeners.add(new LEntry(type, listener, useCapture));
// Record active listener
LCount lc = LCount.lookup(type);
@@ -558,6 +580,7 @@
* @param useCapture True iff listener is registered on
* capturing phase rather than at-target or bubbling
*/
+ @Override
protected void removeEventListener(NodeImpl node, String type,
EventListener listener,
boolean useCapture)
@@ -565,7 +588,7 @@
// If this couldn't be a valid listener registration, ignore request
if (type == null || type.equals("") || listener == null)
return;
- Vector nodeListeners = getEventListeners(node);
+ List nodeListeners = getEventListeners(node);
if (nodeListeners == null)
return;
@@ -573,12 +596,12 @@
// each listener may be registered only once per type per phase.
// count-down is OK for deletions!
for (int i = nodeListeners.size() - 1; i >= 0; --i) {
- LEntry le = (LEntry) nodeListeners.elementAt(i);
+ LEntry le = nodeListeners.get(i);
if (le.useCapture == useCapture && le.listener == listener &&
le.type.equals(type)) {
- nodeListeners.removeElementAt(i);
+ nodeListeners.remove(i);
// Storage management: Discard empty listener lists
- if (nodeListeners.size() == 0)
+ if (nodeListeners.isEmpty())
setEventListeners(node, null);
// Remove active listener
@@ -597,12 +620,13 @@
}
} // removeEventListener(NodeImpl,String,EventListener,boolean) :void
+ @Override
protected void copyEventListeners(NodeImpl src, NodeImpl tgt) {
- Vector nodeListeners = getEventListeners(src);
+ List nodeListeners = getEventListeners(src);
if (nodeListeners == null) {
return;
}
- setEventListeners(tgt, (Vector) nodeListeners.clone());
+ setEventListeners(tgt, new ArrayList<>(nodeListeners));
}
/**
@@ -655,6 +679,7 @@
* @return true if the event's preventDefault()
* method was invoked by an EventListener; otherwise false.
*/
+ @Override
protected boolean dispatchEvent(NodeImpl node, Event event) {
if (event == null) return false;
@@ -691,11 +716,11 @@
// is issued to the Element rather than the Attr
// and causes a _second_ DOMSubtreeModified in the Element's
// tree.
- Vector pv = new Vector(10,10);
+ List pv = new ArrayList<>(10);
Node p = node;
Node n = p.getParentNode();
while (n != null) {
- pv.addElement(n);
+ pv.add(n);
p = n;
n = n.getParentNode();
}
@@ -710,15 +735,15 @@
break; // Someone set the flag. Phase ends.
// Handle all capturing listeners on this node
- NodeImpl nn = (NodeImpl) pv.elementAt(j);
+ NodeImpl nn = (NodeImpl) pv.get(j);
evt.currentTarget = nn;
- Vector nodeListeners = getEventListeners(nn);
+ List nodeListeners = getEventListeners(nn);
if (nodeListeners != null) {
- Vector nl = (Vector) nodeListeners.clone();
+ List nl = (List)((ArrayList)nodeListeners).clone();
// call listeners in the order in which they got registered
int nlsize = nl.size();
for (int i = 0; i < nlsize; i++) {
- LEntry le = (LEntry) nl.elementAt(i);
+ LEntry le = nl.get(i);
if (le.useCapture && le.type.equals(evt.type) &&
nodeListeners.contains(le)) {
try {
@@ -741,13 +766,13 @@
// node are _not_ invoked, even during the capture phase.
evt.eventPhase = Event.AT_TARGET;
evt.currentTarget = node;
- Vector nodeListeners = getEventListeners(node);
+ List nodeListeners = getEventListeners(node);
if (!evt.stopPropagation && nodeListeners != null) {
- Vector nl = (Vector) nodeListeners.clone();
+ List nl = (List)((ArrayList)nodeListeners).clone();
// call listeners in the order in which they got registered
int nlsize = nl.size();
for (int i = 0; i < nlsize; i++) {
- LEntry le = (LEntry) nl.elementAt(i);
+ LEntry le = (LEntry) nl.get(i);
if (!le.useCapture && le.type.equals(evt.type) &&
nodeListeners.contains(le)) {
try {
@@ -772,16 +797,16 @@
break; // Someone set the flag. Phase ends.
// Handle all bubbling listeners on this node
- NodeImpl nn = (NodeImpl) pv.elementAt(j);
+ NodeImpl nn = (NodeImpl) pv.get(j);
evt.currentTarget = nn;
nodeListeners = getEventListeners(nn);
if (nodeListeners != null) {
- Vector nl = (Vector) nodeListeners.clone();
+ List nl = (List)((ArrayList)nodeListeners).clone();
// call listeners in the order in which they got
// registered
int nlsize = nl.size();
for (int i = 0; i < nlsize; i++) {
- LEntry le = (LEntry) nl.elementAt(i);
+ LEntry le = nl.get(i);
if (!le.useCapture && le.type.equals(evt.type) &&
nodeListeners.contains(le)) {
try {
@@ -1118,7 +1143,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).insertedNodeFromDOM(newInternal);
+ ((RangeImpl)ranges.get(i)).insertedNodeFromDOM(newInternal);
}
}
}
@@ -1132,7 +1157,7 @@
if (iterators != null) {
int size = iterators.size();
for (int i = 0; i != size; i++) {
- ((NodeIteratorImpl)iterators.elementAt(i)).removeNode(oldChild);
+ ((NodeIteratorImpl)iterators.get(i)).removeNode(oldChild);
}
}
@@ -1140,7 +1165,7 @@
if (ranges != null) {
int size = ranges.size();
for (int i = 0; i != size; i++) {
- ((RangeImpl)ranges.elementAt(i)).removeNode(oldChild);
+ ((RangeImpl)ranges.get(i)).removeNode(oldChild);
}
}
@@ -1302,4 +1327,53 @@
// REVISIT: To be implemented!!!
}
+
+ /**
+ * @serialData Serialized fields. Convert Maps to Hashtables and Lists
+ * to Vectors for backward compatibility.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // Convert Maps to Hashtables, Lists to Vectors
+ Vector it = (iterators == null)? null : new Vector<>(iterators);
+ Vector r = (ranges == null)? null : new Vector<>(ranges);
+
+ Hashtable> el = null;
+ if (eventListeners != null) {
+ el = new Hashtable<>();
+ for (Map.Entry> e : eventListeners.entrySet()) {
+ el.put(e.getKey(), new Vector<>(e.getValue()));
+ }
+ }
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = out.putFields();
+ pf.put("iterators", it);
+ pf.put("ranges", r);
+ pf.put("eventListeners", el);
+ pf.put("mutationEvents", mutationEvents);
+ out.writeFields();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = in.readFields();
+ Vector it = (Vector)gf.get("iterators", null);
+ Vector r = (Vector)gf.get("ranges", null);
+ Hashtable> el =
+ (Hashtable>)gf.get("eventListeners", null);
+
+ mutationEvents = gf.get("mutationEvents", false);
+
+ //convert Hashtables back to HashMaps and Vectors to Lists
+ if (it != null) iterators = new ArrayList<>(it);
+ if (r != null) ranges = new ArrayList<>(r);
+ if (el != null) {
+ eventListeners = new HashMap<>();
+ for (Map.Entry> e : el.entrySet()) {
+ eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
+ }
+ }
+ }
} // class DocumentImpl
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/DocumentTypeImpl.java
--- a/src/com/sun/org/apache/xerces/internal/dom/DocumentTypeImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/DocumentTypeImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004 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
*
@@ -20,11 +20,17 @@
package com.sun.org.apache.xerces.internal.dom;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NamedNodeMap;
-import java.util.Hashtable;
import org.w3c.dom.UserDataHandler;
/**
@@ -95,10 +101,37 @@
// a number, on demand, for ordering purposes for compareDocumentPosition
private int doctypeNumber=0;
+ private Map userData = null;
+
+
+ /**
+ * @serialField name String document type name
+ * @serialField entities NamedNodeMapImpl entities
+ * @serialField notations NamedNodeMapImpl notations
+ * @serialField elements NamedNodeMapImpl elements
+ * @serialField publicID String support public ID
+ * @serialField systemID String support system ID
+ * @serialField internalSubset String support internal subset
+ * @serialField doctypeNumber int Doctype number
+ * @serialField userData Hashtable user data
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("name", String.class),
+ new ObjectStreamField("entities", NamedNodeMapImpl.class),
+ new ObjectStreamField("notations", NamedNodeMapImpl.class),
+ new ObjectStreamField("elements", NamedNodeMapImpl.class),
+ new ObjectStreamField("publicID", String.class),
+ new ObjectStreamField("systemID", String.class),
+ new ObjectStreamField("internalSubset", String.class),
+ new ObjectStreamField("doctypeNumber", int.class),
+ new ObjectStreamField("userData", Hashtable.class),
+ };
+
//
// Constructors
//
- private Hashtable userData = null;
+
/** Factory method for creating a document type node. */
public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String name) {
super(ownerDocument);
@@ -445,22 +478,20 @@
public Object setUserData(String key,
Object data, UserDataHandler handler) {
if(userData == null)
- userData = new Hashtable();
+ userData = new HashMap<>();
if (data == null) {
if (userData != null) {
- Object o = userData.remove(key);
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
- return r.fData;
+ UserDataRecord udr = userData.remove(key);
+ if (udr != null) {
+ return udr.fData;
}
}
return null;
}
else {
- Object o = userData.put(key, new UserDataRecord(data, handler));
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
- return r.fData;
+ UserDataRecord udr = userData.put(key, new UserDataRecord(data, handler));
+ if (udr != null) {
+ return udr.fData;
}
}
return null;
@@ -470,16 +501,58 @@
if (userData == null) {
return null;
}
- Object o = userData.get(key);
- if (o != null) {
- UserDataRecord r = (UserDataRecord) o;
- return r.fData;
+ UserDataRecord udr = userData.get(key);
+ if (udr != null) {
+ return udr.fData;
}
return null;
}
- protected Hashtable getUserDataRecord(){
+ @Override
+ protected Map getUserDataRecord(){
return userData;
}
+ /**
+ * @serialData Serialized fields. Convert Map to Hashtable for backward
+ * compatibility.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // Convert the HashMap to Hashtable
+ Hashtable ud = (userData == null)? null : new Hashtable<>(userData);
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = out.putFields();
+ pf.put("name", name);
+ pf.put("entities", entities);
+ pf.put("notations", notations);
+ pf.put("elements", elements);
+ pf.put("publicID", publicID);
+ pf.put("systemID", systemID);
+ pf.put("internalSubset", internalSubset);
+ pf.put("doctypeNumber", doctypeNumber);
+ pf.put("userData", ud);
+ out.writeFields();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = in.readFields();
+ name = (String)gf.get("name", null);
+ entities = (NamedNodeMapImpl)gf.get("entities", null);
+ notations = (NamedNodeMapImpl)gf.get("notations", null);
+ elements = (NamedNodeMapImpl)gf.get("elements", null);
+ publicID = (String)gf.get("publicID", null);
+ systemID = (String)gf.get("systemID", null);
+ internalSubset = (String)gf.get("internalSubset", null);
+ doctypeNumber = gf.get("doctypeNumber", 0);
+
+ Hashtable ud =
+ (Hashtable)gf.get("userData", null);
+
+ //convert the Hashtable back to HashMap
+ if (ud != null) userData = new HashMap<>(ud);
+ }
} // class DocumentTypeImpl
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/LCount.java
--- a/src/com/sun/org/apache/xerces/internal/dom/LCount.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/LCount.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004 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
*
@@ -22,20 +22,13 @@
/** Internal class LCount is used to track the number of
listeners registered for a given event name, as an entry
- in a global hashtable. This should allow us to avoid generating,
- or discard, events for which no listeners are registered.
+ in a global Map. This should allow us to avoid generating,
+ or discarding, events for which no listeners are registered.
***** There should undoubtedly be methods here to manipulate
this table. At the moment that code's residing in NodeImpl.
Move it when we have a chance to do so. Sorry; we were
rushed.
-
- ???? CONCERN: Hashtables are known to be "overserialized" in
- current versions of Java. That may impact performance.
-
- ???? CONCERN: The hashtable should probably be a per-document object.
- Finer granularity would be even better, but would cost more cycles to
- resolve and might not save enough event traffic to be worth the investment.
*/
/**
* @xerces.internal
@@ -44,7 +37,7 @@
class LCount
{
- static java.util.Hashtable lCounts=new java.util.Hashtable();
+ static final java.util.Map lCounts=new java.util.concurrent.ConcurrentHashMap<>();
public int captures=0,bubbles=0,defaults, total=0;
static LCount lookup(String evtName)
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/NodeImpl.java
--- a/src/com/sun/org/apache/xerces/internal/dom/NodeImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/NodeImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004 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
*
@@ -23,15 +23,14 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.util.Hashtable;
-
-import org.w3c.dom.UserDataHandler;
+import java.util.Map;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.UserDataHandler;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
@@ -1793,7 +1792,7 @@
return ownerDocument().getUserData(this, key);
}
- protected Hashtable getUserDataRecord(){
+ protected Map getUserDataRecord(){
return ownerDocument().getUserDataRecord(this);
}
@@ -1845,7 +1844,7 @@
* NON-DOM: As an alternative to subclassing the DOM, this implementation
* has been extended with the ability to attach an object to each node.
* (If you need multiple objects, you can attach a collection such as a
- * vector or hashtable, then attach your application information to that.)
+ * List or Map, then attach your application information to that.)
* Important Note: You are responsible for removing references
* to your data on nodes that are no longer used. Failure to do so will
* prevent the nodes, your data is attached to, to be garbage collected
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/dom/ParentNode.java
--- a/src/com/sun/org/apache/xerces/internal/dom/ParentNode.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/dom/ParentNode.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004,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
*
@@ -20,10 +20,10 @@
package com.sun.org.apache.xerces.internal.dom;
-import java.io.Serializable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -1023,7 +1023,7 @@
/*
* a class to store some user data along with its handler
*/
- class UserDataRecord implements Serializable {
+ protected class UserDataRecord implements Serializable {
/** Serialization version. */
private static final long serialVersionUID = 3258126977134310455L;
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/Constants.java
--- a/src/com/sun/org/apache/xerces/internal/impl/Constants.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/Constants.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -242,6 +242,14 @@
*/
public static final String JDK_GENEAL_ENTITY_SIZE_LIMIT =
ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
+
+ /**
+ * JDK node count limit in entities that limits the total number of nodes
+ * in all of entity references.
+ */
+ public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
+ ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
+
/**
* JDK maximum parameter entity size limit
*/
@@ -295,6 +303,13 @@
* JDK maximum general entity size limit
*/
public static final String SP_GENEAL_ENTITY_SIZE_LIMIT = "jdk.xml.maxGeneralEntitySizeLimit";
+
+ /**
+ * JDK node count limit in entities that limits the total number of nodes
+ * in all of entity references.
+ */
+ public static final String SP_ENTITY_REPLACEMENT_LIMIT = "jdk.xml.entityReplacementLimit";
+
/**
* JDK maximum parameter entity size limit
*/
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,62 +1,21 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 1999-2004 The Apache Software Foundation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * 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
*
- * 4. The names "Xerces" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 1999, International
- * Business Machines, Inc., http://www.apache.org. For more
- * information on the Apache Software Foundation, please see
- * .
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.sun.org.apache.xerces.internal.impl;
@@ -156,7 +115,7 @@
protected boolean scanPubidLiteral(XMLString literal)
throws IOException, XNIException
{
- int quote = fEntityScanner.scanChar();
+ int quote = fEntityScanner.scanChar(null);
if (quote != '\'' && quote != '"') {
reportFatalError("QuoteRequiredInPublicID", null);
return false;
@@ -167,7 +126,7 @@
boolean skipSpace = true;
boolean dataok = true;
while (true) {
- int c = fEntityScanner.scanChar();
+ int c = fEntityScanner.scanChar(null);
// REVISIT: it could really only be \n or 0x20; all else is normalized, no? - neilg
if (c == ' ' || c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
if (!skipSpace) {
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XML11DocumentScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,74 +1,32 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 1999-2004 The Apache Software Foundation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * 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
*
- * 4. The names "Xerces" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 1999, International
- * Business Machines, Inc., http://www.apache.org. For more
- * information on the Apache Software Foundation, please see
- * .
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.sun.org.apache.xerces.internal.impl;
-import java.io.IOException;
-
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.XML11Char;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.xni.XNIException;
+import java.io.IOException;
/**
* This class is responsible for scanning XML document structure
@@ -135,7 +93,7 @@
// happens when there is the character reference
// but scanContent doesn't do entity expansions...
// is this *really* necessary??? - NG
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
content.append((char)c);
c = -1;
}
@@ -144,7 +102,7 @@
} */
if (c == ']') {
- content.append((char)fEntityScanner.scanChar());
+ content.append((char)fEntityScanner.scanChar(null));
// remember where we are in case we get an endEntity before we
// could flush the buffer out - this happens when we're parsing an
// entity which ends with a ]
@@ -153,12 +111,12 @@
// We work on a single character basis to handle cases such as:
// ']]]>' which we might otherwise miss.
//
- if (fEntityScanner.skipChar(']')) {
+ if (fEntityScanner.skipChar(']', null)) {
content.append(']');
- while (fEntityScanner.skipChar(']')) {
+ while (fEntityScanner.skipChar(']', null)) {
content.append(']');
}
- if (fEntityScanner.skipChar('>')) {
+ if (fEntityScanner.skipChar('>', null)) {
reportFatalError("CDEndInContent", null);
}
}
@@ -185,6 +143,7 @@
* @param checkEntities true if undeclared entities should be reported as VC violation,
* false if undeclared entities should be reported as WFC violation.
* @param eleName The name of element to which this attribute belongs.
+ * @param isNSURI The flag indicating whether the content is a namespace URI
*
* @return true if the non-normalized and normalized value are the same
*
@@ -194,7 +153,7 @@
protected boolean scanAttributeValue(XMLString value,
XMLString nonNormalizedValue,
String atName,
- boolean checkEntities,String eleName)
+ boolean checkEntities,String eleName, boolean isNSURI)
throws IOException, XNIException
{
// quote
@@ -203,10 +162,10 @@
reportFatalError("OpenQuoteExpected", new Object[]{eleName,atName});
}
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(NameType.ATTRIBUTE);
int entityDepth = fEntityDepth;
- int c = fEntityScanner.scanLiteral(quote, value);
+ int c = fEntityScanner.scanLiteral(quote, value, isNSURI);
if (DEBUG_ATTR_NORMALIZATION) {
System.out.println("** scanLiteral -> \""
+ value.toString() + "\"");
@@ -216,7 +175,7 @@
if (c == quote && (fromIndex = isUnchangedByNormalization(value)) == -1) {
/** Both the non-normalized and normalized attribute values are equal. **/
nonNormalizedValue.setValues(value);
- int cquote = fEntityScanner.scanChar();
+ int cquote = fEntityScanner.scanChar(NameType.ATTRIBUTE);
if (cquote != quote) {
reportFatalError("CloseQuoteExpected", new Object[]{eleName,atName});
}
@@ -239,11 +198,11 @@
+ fStringBuffer.toString() + "\"");
}
if (c == '&') {
- fEntityScanner.skipChar('&');
+ fEntityScanner.skipChar('&', NameType.REFERENCE);
if (entityDepth == fEntityDepth) {
fStringBuffer2.append('&');
}
- if (fEntityScanner.skipChar('#')) {
+ if (fEntityScanner.skipChar('#', NameType.REFERENCE)) {
if (entityDepth == fEntityDepth) {
fStringBuffer2.append('#');
}
@@ -257,59 +216,22 @@
}
}
else {
- String entityName = fEntityScanner.scanName();
+ String entityName = fEntityScanner.scanName(NameType.REFERENCE);
if (entityName == null) {
reportFatalError("NameRequiredInReference", null);
}
else if (entityDepth == fEntityDepth) {
fStringBuffer2.append(entityName);
}
- if (!fEntityScanner.skipChar(';')) {
+ if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInReference",
new Object []{entityName});
}
else if (entityDepth == fEntityDepth) {
fStringBuffer2.append(';');
}
- if (entityName == fAmpSymbol) {
- fStringBuffer.append('&');
- if (DEBUG_ATTR_NORMALIZATION) {
- System.out.println("** value5: \""
- + fStringBuffer.toString()
- + "\"");
- }
- }
- else if (entityName == fAposSymbol) {
- fStringBuffer.append('\'');
- if (DEBUG_ATTR_NORMALIZATION) {
- System.out.println("** value7: \""
- + fStringBuffer.toString()
- + "\"");
- }
- }
- else if (entityName == fLtSymbol) {
- fStringBuffer.append('<');
- if (DEBUG_ATTR_NORMALIZATION) {
- System.out.println("** value9: \""
- + fStringBuffer.toString()
- + "\"");
- }
- }
- else if (entityName == fGtSymbol) {
- fStringBuffer.append('>');
- if (DEBUG_ATTR_NORMALIZATION) {
- System.out.println("** valueB: \""
- + fStringBuffer.toString()
- + "\"");
- }
- }
- else if (entityName == fQuotSymbol) {
- fStringBuffer.append('"');
- if (DEBUG_ATTR_NORMALIZATION) {
- System.out.println("** valueD: \""
- + fStringBuffer.toString()
- + "\"");
- }
+ if (resolveCharacter(entityName, fStringBuffer)) {
+ checkEntityLimit(false, fEntityScanner.fCurrentEntity.name, 1);
}
else {
if (fEntityManager.isExternalEntity(entityName)) {
@@ -332,7 +254,7 @@
new Object[]{entityName});
}
}
- fEntityManager.startEntity(entityName, true);
+ fEntityManager.startEntity(true, entityName, true);
}
}
}
@@ -340,13 +262,13 @@
else if (c == '<') {
reportFatalError("LessthanInAttValue",
new Object[] { eleName, atName });
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
if (entityDepth == fEntityDepth) {
fStringBuffer2.append((char)c);
}
}
else if (c == '%' || c == ']') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append((char)c);
if (entityDepth == fEntityDepth) {
fStringBuffer2.append((char)c);
@@ -360,7 +282,7 @@
// XML11EntityScanner. Not sure why
// this check was originally necessary. - NG
else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append(' ');
if (entityDepth == fEntityDepth) {
fStringBuffer2.append('\n');
@@ -383,12 +305,12 @@
else if (c != -1 && isInvalidLiteral(c)) {
reportFatalError("InvalidCharInAttValue",
new Object[] {eleName, atName, Integer.toString(c, 16)});
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
if (entityDepth == fEntityDepth) {
fStringBuffer2.append((char)c);
}
}
- c = fEntityScanner.scanLiteral(quote, value);
+ c = fEntityScanner.scanLiteral(quote, value, isNSURI);
if (entityDepth == fEntityDepth) {
fStringBuffer2.append(value);
}
@@ -405,7 +327,7 @@
nonNormalizedValue.setValues(fStringBuffer2);
// quote
- int cquote = fEntityScanner.scanChar();
+ int cquote = fEntityScanner.scanChar(null);
if (cquote != quote) {
reportFatalError("CloseQuoteExpected", new Object[]{eleName,atName});
}
@@ -440,7 +362,7 @@
protected boolean scanPubidLiteral(XMLString literal)
throws IOException, XNIException
{
- int quote = fEntityScanner.scanChar();
+ int quote = fEntityScanner.scanChar(null);
if (quote != '\'' && quote != '"') {
reportFatalError("QuoteRequiredInPublicID", null);
return false;
@@ -451,7 +373,7 @@
boolean skipSpace = true;
boolean dataok = true;
while (true) {
- int c = fEntityScanner.scanChar();
+ int c = fEntityScanner.scanChar(null);
// REVISIT: none of these except \n and 0x20 should make it past the entity scanner
if (c == ' ' || c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
if (!skipSpace) {
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,72 +1,34 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 1999-2002 The Apache Software Foundation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * 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
*
- * 4. The names "Xerces" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 1999, International
- * Business Machines, Inc., http://www.apache.org. For more
- * information on the Apache Software Foundation, please see
- * .
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.sun.org.apache.xerces.internal.impl;
+import com.sun.org.apache.xerces.internal.impl.XMLScanner.NameType;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.XML11Char;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
import com.sun.org.apache.xerces.internal.xni.QName;
import com.sun.org.apache.xerces.internal.xni.XMLString;
+import com.sun.xml.internal.stream.Entity;
import java.io.IOException;
/**
@@ -132,7 +94,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanChar() throws IOException {
+ protected int scanChar(NameType nt) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -140,6 +102,7 @@
}
// scan character
+ int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[fCurrentEntity.position++];
boolean external = false;
if (c == '\n' ||
@@ -150,6 +113,7 @@
invokeListeners(1);
fCurrentEntity.ch[0] = (char)c;
load(1, false, false);
+ offset = 0;
}
if (c == '\r' && external) {
int cc = fCurrentEntity.ch[fCurrentEntity.position++];
@@ -162,6 +126,9 @@
// return character that was scanned
fCurrentEntity.columnNumber++;
+ if (!detectingVersion) {
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
+ }
return c;
} // scanChar():int
@@ -181,7 +148,7 @@
* @see com.sun.org.apache.xerces.internal.util.SymbolTable
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
*/
- public String scanNmtoken() throws IOException {
+ protected String scanNmtoken() throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true, true);
@@ -288,6 +255,8 @@
* Note: The string returned must be a symbol. The
* SymbolTable can be used for this purpose.
*
+ * @param nt The type of the name (element or attribute)
+ *
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*
@@ -295,7 +264,7 @@
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
*/
- public String scanName() throws IOException {
+ protected String scanName(NameType nt) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
load(0, true, true);
@@ -350,23 +319,11 @@
return null;
}
+ int length = 0;
do {
ch = fCurrentEntity.ch[fCurrentEntity.position];
if (XML11Char.isXML11Name(ch)) {
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, offset)) > 0) {
offset = 0;
if (load(length, false, false)) {
break;
@@ -374,20 +331,7 @@
}
}
else if (XML11Char.isXML11NameHighSurrogate(ch)) {
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, offset)) > 0) {
offset = 0;
if (load(length, false, false)) {
--fCurrentEntity.position;
@@ -401,20 +345,7 @@
--fCurrentEntity.position;
break;
}
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, offset)) > 0) {
offset = 0;
if (load(length, false, false)) {
break;
@@ -427,12 +358,14 @@
}
while (true);
- int length = fCurrentEntity.position - offset;
+ length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
// return name
String symbol = null;
if (length > 0) {
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
+ checkEntityLimit(nt, fCurrentEntity, offset, length);
symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
}
return symbol;
@@ -455,7 +388,7 @@
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCName
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCNameStart
*/
- public String scanNCName() throws IOException {
+ protected String scanNCName() throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -611,6 +544,7 @@
* this purpose.
*
* @param qname The qualified name structure to fill.
+ * @param nt The type of the name (element or attribute)
*
* @return Returns true if a qualified name appeared immediately on
* the input and was scanned, false otherwise.
@@ -622,7 +556,7 @@
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
*/
- public boolean scanQName(QName qname) throws IOException {
+ protected boolean scanQName(QName qname, XMLScanner.NameType nt) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -642,6 +576,7 @@
fCurrentEntity.columnNumber++;
String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
qname.setValues(null, name, name, null);
+ checkEntityLimit(nt, fCurrentEntity, 0, 1);
return true;
}
}
@@ -672,6 +607,7 @@
fCurrentEntity.columnNumber += 2;
String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
qname.setValues(null, name, name, null);
+ checkEntityLimit(nt, fCurrentEntity, 0, 2);
return true;
}
}
@@ -681,6 +617,7 @@
}
int index = -1;
+ int length = 0;
boolean sawIncompleteSurrogatePair = false;
do {
ch = fCurrentEntity.ch[fCurrentEntity.position];
@@ -690,21 +627,10 @@
break;
}
index = fCurrentEntity.position;
+ //check prefix before further read
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, index - offset);
}
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, index)) > 0) {
if (index != -1) {
index = index - offset;
}
@@ -715,20 +641,7 @@
}
}
else if (XML11Char.isXML11NameHighSurrogate(ch)) {
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, index)) > 0) {
if (index != -1) {
index = index - offset;
}
@@ -747,20 +660,7 @@
--fCurrentEntity.position;
break;
}
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.ch.length) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.ch.length << 1];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- }
- else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, index)) > 0) {
if (index != -1) {
index = index - offset;
}
@@ -776,7 +676,7 @@
}
while (true);
- int length = fCurrentEntity.position - offset;
+ length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
if (length > 0) {
@@ -786,6 +686,8 @@
offset, length);
if (index != -1) {
int prefixLength = index - offset;
+ //check the result: prefix
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, prefixLength);
prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
offset, prefixLength);
int len = length - prefixLength - 1;
@@ -798,14 +700,19 @@
null,
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
+ //check the result: localpart
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, index + 1, len);
localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
index + 1, len);
}
else {
localpart = rawname;
+ //check the result: localpart
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
}
qname.setValues(prefix, localpart, rawname, null);
+ checkEntityLimit(nt, fCurrentEntity, offset, length);
return true;
}
return false;
@@ -838,7 +745,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanContent(XMLString content) throws IOException {
+ protected int scanContent(XMLString content) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -856,6 +763,7 @@
int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[offset];
int newlines = 0;
+ boolean counted = false;
boolean external = fCurrentEntity.isExternal();
if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
do {
@@ -865,11 +773,13 @@
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
+ checkEntityLimit(null, fCurrentEntity, offset, newlines);
offset = 0;
fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
fCurrentEntity.position = newlines;
fCurrentEntity.startPosition = newlines;
if (load(newlines, false, true)) {
+ counted = true;
break;
}
}
@@ -888,11 +798,13 @@
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
+ checkEntityLimit(null, fCurrentEntity, offset, newlines);
offset = 0;
fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
fCurrentEntity.position = newlines;
fCurrentEntity.startPosition = newlines;
if (load(newlines, false, true)) {
+ counted = true;
break;
}
}
@@ -907,6 +819,7 @@
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
+ checkEntityLimit(null, fCurrentEntity, offset, length);
content.setValues(fCurrentEntity.ch, offset, length);
return -1;
}
@@ -934,6 +847,9 @@
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ if (!counted) {
+ checkEntityLimit(null, fCurrentEntity, offset, length);
+ }
content.setValues(fCurrentEntity.ch, offset, length);
// return next character
@@ -972,6 +888,7 @@
* @param quote The quote character that signifies the end of the
* attribute value data.
* @param content The content structure to fill.
+ * @param isNSURI a flag indicating whether the content is a Namespace URI
*
* @return Returns the next character on the input, if known. This
* value may be -1 but this does note designate
@@ -980,7 +897,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanLiteral(int quote, XMLString content)
+ protected int scanLiteral(int quote, XMLString content, boolean isNSURI)
throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -1078,6 +995,11 @@
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+
+ checkEntityLimit(null, fCurrentEntity, offset, length);
+ if (isNSURI) {
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
+ }
content.setValues(fCurrentEntity.ch, offset, length);
// return next character
@@ -1127,7 +1049,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean scanData(String delimiter, XMLStringBuffer buffer)
+ protected boolean scanData(String delimiter, XMLStringBuffer buffer)
throws IOException {
boolean done = false;
@@ -1159,6 +1081,7 @@
if (fCurrentEntity.position >= fCurrentEntity.count - delimLen) {
// something must be wrong with the input: e.g., file ends an unterminated comment
int length = fCurrentEntity.count - fCurrentEntity.position;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, fCurrentEntity.position, length);
buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
fCurrentEntity.columnNumber += fCurrentEntity.count;
fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
@@ -1223,6 +1146,7 @@
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
buffer.append(fCurrentEntity.ch, offset, length);
return true;
}
@@ -1261,6 +1185,7 @@
fCurrentEntity.position--;
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
buffer.append(fCurrentEntity.ch, offset, length);
return true;
}
@@ -1298,6 +1223,7 @@
fCurrentEntity.position--;
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
buffer.append(fCurrentEntity.ch, offset, length);
return true;
}
@@ -1305,6 +1231,7 @@
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
if (done) {
length -= delimLen;
}
@@ -1329,7 +1256,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean skipChar(int c) throws IOException {
+ protected boolean skipChar(int c, NameType nt) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -1337,6 +1264,7 @@
}
// skip character
+ int offset = fCurrentEntity.position;
int cc = fCurrentEntity.ch[fCurrentEntity.position];
if (cc == c) {
fCurrentEntity.position++;
@@ -1347,12 +1275,14 @@
else {
fCurrentEntity.columnNumber++;
}
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
return true;
}
else if (c == '\n' && ((cc == 0x2028 || cc == 0x85) && fCurrentEntity.isExternal())) {
fCurrentEntity.position++;
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
return true;
}
else if (c == '\n' && (cc == '\r' ) && fCurrentEntity.isExternal()) {
@@ -1368,6 +1298,7 @@
}
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
return true;
}
@@ -1390,7 +1321,7 @@
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace
* @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Space
*/
- public boolean skipSpaces() throws IOException {
+ protected boolean skipSpaces() throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -1410,7 +1341,7 @@
// skip spaces
int c = fCurrentEntity.ch[fCurrentEntity.position];
-
+ int offset = fCurrentEntity.position - 1;
// External -- Match: S + 0x85 + 0x2028, and perform end of line normalization
if (fCurrentEntity.isExternal()) {
if (XML11Char.isXML11Space(c)) {
@@ -1446,6 +1377,11 @@
else {
fCurrentEntity.columnNumber++;
}
+
+ //If this is a general entity, spaces within a start element should be counted
+ checkEntityLimit(null, fCurrentEntity, offset, fCurrentEntity.position - offset);
+ offset = fCurrentEntity.position;
+
// load more characters, if needed
if (!entityChanged)
fCurrentEntity.position++;
@@ -1485,6 +1421,11 @@
else {
fCurrentEntity.columnNumber++;
}
+
+ //If this is a general entity, spaces within a start element should be counted
+ checkEntityLimit(null, fCurrentEntity, offset, fCurrentEntity.position - offset);
+ offset = fCurrentEntity.position;
+
// load more characters, if needed
if (!entityChanged)
fCurrentEntity.position++;
@@ -1518,7 +1459,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean skipString(String s) throws IOException {
+ protected boolean skipString(String s) throws IOException {
// load more characters, if needed
if (fCurrentEntity.position == fCurrentEntity.count) {
@@ -1527,6 +1468,7 @@
// skip string
final int length = s.length();
+ final int beforeSkip = fCurrentEntity.position ;
for (int i = 0; i < length; i++) {
char c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c != s.charAt(i)) {
@@ -1546,6 +1488,9 @@
}
}
fCurrentEntity.columnNumber += length;
+ if (!detectingVersion) {
+ checkEntityLimit(null, fCurrentEntity, beforeSkip, length);
+ }
return true;
} // skipString(String):boolean
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XML11NSDocumentScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XML11NSDocumentScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XML11NSDocumentScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,62 +1,21 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 1999-2003 The Apache Software Foundation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 The Apache Software Foundation.
*
- * 4. The names "Xerces" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
+ * 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
*
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 2002, International
- * Business Machines, Inc., http://www.apache.org. For more
- * information on the Apache Software Foundation, please see
- * .
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.sun.org.apache.xerces.internal.impl;
@@ -67,6 +26,7 @@
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
import com.sun.org.apache.xerces.internal.util.XMLSymbols;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.xni.QName;
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
@@ -176,7 +136,7 @@
if (DEBUG_START_END_ELEMENT)
System.out.println(">>> scanStartElementNS()");
// Note: namespace processing is on by default
- fEntityScanner.scanQName(fElementQName);
+ fEntityScanner.scanQName(fElementQName, NameType.ATTRIBUTE);
// REVISIT - [Q] Why do we need this local variable? -- mrglavas
String rawname = fElementQName.rawname;
if (fBindNamespaces) {
@@ -214,11 +174,11 @@
// end tag?
int c = fEntityScanner.peekChar();
if (c == '>') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
break;
} else if (c == '/') {
- fEntityScanner.scanChar();
- if (!fEntityScanner.skipChar('>')) {
+ fEntityScanner.scanChar(null);
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError(
"ElementUnterminated",
new Object[] { rawname });
@@ -340,36 +300,37 @@
}
// call handler
-
- if (empty) {
-
- //decrease the markup depth..
- fMarkupDepth--;
+ if (empty) {
+ //decrease the markup depth..
+ fMarkupDepth--;
- // check that this element was opened in the same entity
- if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
- reportFatalError(
- "ElementEntityMismatch",
- new Object[] { fCurrentElement.rawname });
- }
+ // check that this element was opened in the same entity
+ if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
+ reportFatalError(
+ "ElementEntityMismatch",
+ new Object[] { fCurrentElement.rawname });
+ }
+ if (fDocumentHandler != null) {
fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
+ }
- /*if (fBindNamespaces) {
- fNamespaceContext.popContext();
- }*/
- fScanEndElement = true;
+ /*if (fBindNamespaces) {
+ fNamespaceContext.popContext();
+ }*/
+ fScanEndElement = true;
- //pop the element off the stack..
- fElementStack.popElement();
- } else {
+ //pop the element off the stack..
+ fElementStack.popElement();
+ } else {
+ if(dtdGrammarUtil != null) {
+ dtdGrammarUtil.startElement(fElementQName, fAttributes);
+ }
- if(dtdGrammarUtil != null)
- dtdGrammarUtil.startElement(fElementQName, fAttributes);
-
- if (fDocumentHandler != null)
+ if (fDocumentHandler != null) {
fDocumentHandler.startElement(fElementQName, fAttributes, null);
}
+ }
if (DEBUG_START_END_ELEMENT)
System.out.println("<<< scanStartElement(): " + empty);
@@ -385,7 +346,7 @@
protected void scanStartElementName ()
throws IOException, XNIException {
// Note: namespace processing is on by default
- fEntityScanner.scanQName(fElementQName);
+ fEntityScanner.scanQName(fElementQName, NameType.ATTRIBUTE);
// Must skip spaces here because the DTD scanner
// would consume them at the end of the external subset.
fSawSpace = fEntityScanner.skipSpaces();
@@ -435,11 +396,11 @@
// end tag?
int c = fEntityScanner.peekChar();
if (c == '>') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
break;
} else if (c == '/') {
- fEntityScanner.scanChar();
- if (!fEntityScanner.skipChar('>')) {
+ fEntityScanner.scanChar(null);
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError(
"ElementUnterminated",
new Object[] { rawname });
@@ -611,11 +572,11 @@
System.out.println(">>> scanAttribute()");
// name
- fEntityScanner.scanQName(fAttributeQName);
+ fEntityScanner.scanQName(fAttributeQName, NameType.ATTRIBUTE);
// equals
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('=')) {
+ if (!fEntityScanner.skipChar('=', NameType.ATTRIBUTE)) {
reportFatalError(
"EqRequiredInAttribute",
new Object[] {
@@ -654,13 +615,20 @@
//REVISIT: one more case needs to be included: external PE and standalone is no
boolean isVC = fHasExternalDTD && !fStandalone;
- // REVISIT: it seems that this function should not take attributes, and length
- scanAttributeValue(
- this.fTempString,
- fTempString2,
- fAttributeQName.rawname,
- isVC,
- fCurrentElement.rawname);
+ /**
+ * Determine whether this is a namespace declaration that will be subject
+ * to the name limit check in the scanAttributeValue operation.
+ * Namespace declaration format: xmlns="..." or xmlns:prefix="..."
+ * Note that prefix:xmlns="..." isn't a namespace.
+ */
+ String localpart = fAttributeQName.localpart;
+ String prefix = fAttributeQName.prefix != null
+ ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;
+ boolean isNSDecl = fBindNamespaces & (prefix == XMLSymbols.PREFIX_XMLNS ||
+ prefix == XMLSymbols.EMPTY_STRING && localpart == XMLSymbols.PREFIX_XMLNS);
+
+ scanAttributeValue(this.fTempString, fTempString2, fAttributeQName.rawname,
+ isVC, fCurrentElement.rawname, isNSDecl);
String value = fTempString.toString();
attributes.setValue(attrIndex, value);
attributes.setNonNormalizedValue(attrIndex, fTempString2.toString());
@@ -668,18 +636,14 @@
// record namespace declarations if any.
if (fBindNamespaces) {
-
- String localpart = fAttributeQName.localpart;
- String prefix =
- fAttributeQName.prefix != null
- ? fAttributeQName.prefix
- : XMLSymbols.EMPTY_STRING;
- // when it's of form xmlns="..." or xmlns:prefix="...",
- // it's a namespace declaration. but prefix:xmlns="..." isn't.
- if (prefix == XMLSymbols.PREFIX_XMLNS
- || prefix == XMLSymbols.EMPTY_STRING
- && localpart == XMLSymbols.PREFIX_XMLNS) {
-
+ if (isNSDecl) {
+ if (value.length() > fXMLNameLimit) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MaxXMLNameLimit",
+ new Object[]{value, value.length(), fXMLNameLimit,
+ fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.MAX_NAME_LIMIT)},
+ XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ }
// get the internalized value of this attribute
String uri = fSymbolTable.addSymbol(value);
@@ -792,7 +756,7 @@
// end
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', NameType.ELEMENTEND)) {
reportFatalError(
"ETagUnterminated",
new Object[] { endElementName.rawname });
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -41,9 +41,6 @@
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.Augmentations;
-import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
-import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
-import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.xml.internal.stream.Entity;
@@ -369,6 +366,9 @@
}
// we're done, set starting state for external subset
setScannerState(SCANNER_STATE_TEXT_DECL);
+ // we're done scanning DTD.
+ fLimitAnalyzer.reset(XMLSecurityManager.Limit.GENEAL_ENTITY_SIZE_LIMIT);
+ fLimitAnalyzer.reset(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT);
return false;
}
} while (complete);
@@ -378,6 +378,26 @@
} // scanDTDInternalSubset(boolean,boolean,boolean):boolean
+ /**
+ * Skip the DTD if javax.xml.stream.supportDTD is false.
+ *
+ * @param supportDTD The value of the property javax.xml.stream.supportDTD.
+ * @return true if DTD is skipped, false otherwise.
+ * @throws java.io.IOException if i/o error occurs
+ */
+ @Override
+ public boolean skipDTD(boolean supportDTD) throws IOException {
+ if (!supportDTD) {
+ fStringBuffer.clear();
+ if (!fEntityScanner.scanData("]", fStringBuffer)) {
+ fEntityScanner.fCurrentEntity.position--;
+ }
+
+ return true;
+ }
+ return false;
+ }
+
//
// XMLComponent methods
//
@@ -704,7 +724,7 @@
fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",
new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);
}
- fEntityManager.startEntity(fSymbolTable.addSymbol(pName),
+ fEntityManager.startEntity(false, fSymbolTable.addSymbol(pName),
literal);
// if we actually got a new entity and it's external
// parse text decl if there is any
@@ -738,7 +758,7 @@
fStringBuffer.clear();
fStringBuffer.append("xml");
while (isValidNameChar(fEntityScanner.peekChar())) {
- fStringBuffer.append((char)fEntityScanner.scanChar());
+ fStringBuffer.append((char)fEntityScanner.scanChar(null));
}
String target =
fSymbolTable.addSymbol(fStringBuffer.ch,
@@ -838,7 +858,7 @@
}
// element name
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ELEMENTSTART);
if (name == null) {
reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_ELEMENTDECL",
null);
@@ -871,7 +891,7 @@
}
}
else {
- if (!fEntityScanner.skipChar('(')) {
+ if (!fEntityScanner.skipChar('(', null)) {
reportFatalError("MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN",
new Object[]{name});
}
@@ -901,7 +921,7 @@
fReportEntity = false;
skipSeparator(false, !scanningInternalSubset());
// end
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("ElementDeclUnterminated", new Object[]{name});
}
fReportEntity = true;
@@ -938,7 +958,7 @@
fDTDContentModelHandler.pcdata(null);
}
skipSeparator(false, !scanningInternalSubset());
- while (fEntityScanner.skipChar('|')) {
+ while (fEntityScanner.skipChar('|', null)) {
fStringBuffer.append('|');
// call handler
if (fDTDContentModelHandler != null) {
@@ -947,7 +967,7 @@
}
skipSeparator(false, !scanningInternalSubset());
- childName = fEntityScanner.scanName();
+ childName = fEntityScanner.scanName(NameType.ENTITY);
if (childName == null) {
reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_MIXED_CONTENT",
new Object[]{elName});
@@ -976,7 +996,7 @@
reportFatalError("MixedContentUnterminated",
new Object[]{elName});
}
- else if (fEntityScanner.skipChar(')')){
+ else if (fEntityScanner.skipChar(')', null)){
fStringBuffer.append(')');
// call handler
if (fDTDContentModelHandler != null) {
@@ -1014,7 +1034,7 @@
int currentOp = 0;
int c;
while (true) {
- if (fEntityScanner.skipChar('(')) {
+ if (fEntityScanner.skipChar('(', null)) {
fMarkUpDepth++;
fStringBuffer.append('(');
// call handler
@@ -1028,7 +1048,7 @@
continue;
}
skipSeparator(false, !scanningInternalSubset());
- String childName = fEntityScanner.scanName();
+ String childName = fEntityScanner.scanName(NameType.ELEMENTSTART);
if (childName == null) {
reportFatalError("MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN",
new Object[]{elName});
@@ -1055,7 +1075,7 @@
}
fDTDContentModelHandler.occurrence(oc, null);
}
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append((char)c);
}
while (true) {
@@ -1068,7 +1088,7 @@
fDTDContentModelHandler.separator(XMLDTDContentModelHandler.SEPARATOR_SEQUENCE,
null);
}
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append(',');
break;
}
@@ -1079,7 +1099,7 @@
fDTDContentModelHandler.separator(XMLDTDContentModelHandler.SEPARATOR_CHOICE,
null);
}
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append('|');
break;
}
@@ -1125,7 +1145,7 @@
}
else {
// no occurrence specified
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fStringBuffer.append(')');
}
fMarkUpDepth--;
@@ -1157,7 +1177,7 @@
}
// element name
- String elName = fEntityScanner.scanName();
+ String elName = fEntityScanner.scanName(NameType.ELEMENTSTART);
if (elName == null) {
reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_ATTLISTDECL",
null);
@@ -1171,7 +1191,7 @@
// spaces
if (!skipSeparator(true, !scanningInternalSubset())) {
// no space, is it the end yet?
- if (fEntityScanner.skipChar('>')) {
+ if (fEntityScanner.skipChar('>', null)) {
// yes, stop here
// call handler
if (fDTDHandler != null) {
@@ -1187,8 +1207,8 @@
}
// definitions
- while (!fEntityScanner.skipChar('>')) {
- String name = fEntityScanner.scanName();
+ while (!fEntityScanner.skipChar('>', null)) {
+ String name = fEntityScanner.scanName(NameType.ATTRIBUTE);
if (name == null) {
reportFatalError("AttNameRequiredInAttDef",
new Object[]{elName});
@@ -1324,7 +1344,7 @@
new Object[]{elName, atName});
}
// open paren
- int c = fEntityScanner.scanChar();
+ int c = fEntityScanner.scanChar(null);
if (c != '(') {
reportFatalError("MSG_OPEN_PAREN_REQUIRED_IN_NOTATIONTYPE",
new Object[]{elName, atName});
@@ -1332,7 +1352,7 @@
fMarkUpDepth++;
do {
skipSeparator(false, !scanningInternalSubset());
- String aName = fEntityScanner.scanName();
+ String aName = fEntityScanner.scanName(NameType.ATTRIBUTE);
if (aName == null) {
reportFatalError("MSG_NAME_REQUIRED_IN_NOTATIONTYPE",
new Object[]{elName, atName});
@@ -1340,7 +1360,7 @@
ensureEnumerationSize(fEnumerationCount + 1);
fEnumeration[fEnumerationCount++] = aName;
skipSeparator(false, !scanningInternalSubset());
- c = fEntityScanner.scanChar();
+ c = fEntityScanner.scanChar(null);
} while (c == '|');
if (c != ')') {
reportFatalError("NotationTypeUnterminated",
@@ -1351,7 +1371,7 @@
else { // Enumeration
type = "ENUMERATION";
// open paren
- int c = fEntityScanner.scanChar();
+ int c = fEntityScanner.scanChar(null);
if (c != '(') {
// "OPEN_PAREN_REQUIRED_BEFORE_ENUMERATION_IN_ATTRDECL",
reportFatalError("AttTypeRequiredInAttDef",
@@ -1368,7 +1388,7 @@
ensureEnumerationSize(fEnumerationCount + 1);
fEnumeration[fEnumerationCount++] = token;
skipSeparator(false, !scanningInternalSubset());
- c = fEntityScanner.scanChar();
+ c = fEntityScanner.scanChar(null);
} while (c == '|');
if (c != ')') {
reportFatalError("EnumerationUnterminated",
@@ -1418,7 +1438,7 @@
// AttValue
boolean isVC = !fStandalone && (fSeenExternalDTD || fSeenExternalPE) ;
scanAttributeValue(defaultVal, nonNormalizedDefaultVal, atName,
- fAttributes, 0, isVC, elName);
+ fAttributes, 0, isVC, elName, false);
}
return defaultType;
@@ -1446,7 +1466,7 @@
boolean sawPERef = false;
fReportEntity = false;
if (fEntityScanner.skipSpaces()) {
- if (!fEntityScanner.skipChar('%')) {
+ if (!fEntityScanner.skipChar('%', NameType.REFERENCE)) {
isPEDecl = false; //
}
else if (skipSeparator(true, !scanningInternalSubset())) {
@@ -1467,7 +1487,7 @@
sawPERef = true;
}
}
- else if (scanningInternalSubset() || !fEntityScanner.skipChar('%')) {
+ else if (scanningInternalSubset() || !fEntityScanner.skipChar('%', NameType.REFERENCE)) {
// or
reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ENTITY_NAME_IN_ENTITYDECL",
null);
@@ -1484,11 +1504,11 @@
}
if (sawPERef) {
while (true) {
- String peName = fEntityScanner.scanName();
+ String peName = fEntityScanner.scanName(NameType.REFERENCE);
if (peName == null) {
reportFatalError("NameRequiredInPEReference", null);
}
- else if (!fEntityScanner.skipChar(';')) {
+ else if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInPEReference",
new Object[]{peName});
}
@@ -1496,20 +1516,20 @@
startPE(peName, false);
}
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('%'))
+ if (!fEntityScanner.skipChar('%', NameType.REFERENCE))
break;
if (!isPEDecl) {
if (skipSeparator(true, !scanningInternalSubset())) {
isPEDecl = true;
break;
}
- isPEDecl = fEntityScanner.skipChar('%');
+ isPEDecl = fEntityScanner.skipChar('%', NameType.REFERENCE);
}
}
}
// name
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ENTITY);
if (name == null) {
reportFatalError("MSG_ENTITY_NAME_REQUIRED_IN_ENTITYDECL", null);
}
@@ -1544,7 +1564,7 @@
reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_UNPARSED_ENTITYDECL",
new Object[]{name});
}
- notation = fEntityScanner.scanName();
+ notation = fEntityScanner.scanName(NameType.NOTATION);
if (notation == null) {
reportFatalError("MSG_NOTATION_NAME_REQUIRED_FOR_UNPARSED_ENTITYDECL",
new Object[]{name});
@@ -1566,7 +1586,7 @@
skipSeparator(false, !scanningInternalSubset());
// end
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("EntityDeclUnterminated", new Object[]{name});
}
fMarkUpDepth--;
@@ -1621,7 +1641,7 @@
protected final void scanEntityValue(String entityName, boolean isPEDecl, XMLString value,
XMLString nonNormalizedValue)
throws IOException, XNIException {
- int quote = fEntityScanner.scanChar();
+ int quote = fEntityScanner.scanChar(null);
if (quote != '\'' && quote != '"') {
reportFatalError("OpenQuoteMissingInDecl", null);
}
@@ -1632,29 +1652,28 @@
XMLString literal2 = fString;
int countChar = 0;
if (fLimitAnalyzer == null ) {
- fLimitAnalyzer = new XMLLimitAnalyzer();
+ fLimitAnalyzer = fEntityManager.fLimitAnalyzer;
}
fLimitAnalyzer.startEntity(entityName);
- if (fEntityScanner.scanLiteral(quote, fString) != quote) {
+ if (fEntityScanner.scanLiteral(quote, fString, false) != quote) {
fStringBuffer.clear();
fStringBuffer2.clear();
+ int offset;
do {
- if (isPEDecl && fLimitAnalyzer != null) {
- checkLimit("%" + entityName, fString.length + countChar);
- }
countChar = 0;
+ offset = fStringBuffer.length;
fStringBuffer.append(fString);
fStringBuffer2.append(fString);
- if (fEntityScanner.skipChar('&')) {
- if (fEntityScanner.skipChar('#')) {
+ if (fEntityScanner.skipChar('&', NameType.REFERENCE)) {
+ if (fEntityScanner.skipChar('#', NameType.REFERENCE)) {
fStringBuffer2.append("");
scanCharReferenceValue(fStringBuffer, fStringBuffer2);
}
else {
fStringBuffer.append('&');
fStringBuffer2.append('&');
- String eName = fEntityScanner.scanName();
+ String eName = fEntityScanner.scanName(NameType.REFERENCE);
if (eName == null) {
reportFatalError("NameRequiredInReference",
null);
@@ -1663,7 +1682,7 @@
fStringBuffer.append(eName);
fStringBuffer2.append(eName);
}
- if (!fEntityScanner.skipChar(';')) {
+ if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInReference",
new Object[]{eName});
}
@@ -1673,15 +1692,15 @@
}
}
}
- else if (fEntityScanner.skipChar('%')) {
+ else if (fEntityScanner.skipChar('%', NameType.REFERENCE)) {
while (true) {
fStringBuffer2.append('%');
- String peName = fEntityScanner.scanName();
+ String peName = fEntityScanner.scanName(NameType.REFERENCE);
if (peName == null) {
reportFatalError("NameRequiredInPEReference",
null);
}
- else if (!fEntityScanner.skipChar(';')) {
+ else if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInPEReference",
new Object[]{peName});
}
@@ -1698,20 +1717,20 @@
// REVISIT: This will make returning the non-
// normalized value harder. -Ac
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('%'))
+ if (!fEntityScanner.skipChar('%', NameType.REFERENCE))
break;
}
}
else {
- countChar++;
int c = fEntityScanner.peekChar();
if (XMLChar.isHighSurrogate(c)) {
+ countChar++;
scanSurrogates(fStringBuffer2);
}
else if (isInvalidLiteral(c)) {
reportFatalError("InvalidCharInLiteral",
new Object[]{Integer.toHexString(c)});
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
}
// if it's not the delimiting quote or if it is but from a
// different entity than the one this literal started from,
@@ -1719,26 +1738,30 @@
else if (c != quote || entityDepth != fEntityDepth) {
fStringBuffer.append((char)c);
fStringBuffer2.append((char)c);
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
}
}
- } while (fEntityScanner.scanLiteral(quote, fString) != quote);
+ checkEntityLimit(isPEDecl, entityName, fStringBuffer.length - offset + countChar);
+ } while (fEntityScanner.scanLiteral(quote, fString, false) != quote);
+ checkEntityLimit(isPEDecl, entityName, fString.length);
fStringBuffer.append(fString);
fStringBuffer2.append(fString);
literal = fStringBuffer;
literal2 = fStringBuffer2;
} else {
- if (isPEDecl) {
- checkLimit("%" + entityName, literal);
- }
+ checkEntityLimit(isPEDecl, entityName, literal);
}
value.setValues(literal);
nonNormalizedValue.setValues(literal2);
if (fLimitAnalyzer != null) {
- fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT, entityName);
+ if (isPEDecl) {
+ fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT, entityName);
+ } else {
+ fLimitAnalyzer.endEntity(XMLSecurityManager.Limit.GENEAL_ENTITY_SIZE_LIMIT, entityName);
+ }
}
- if (!fEntityScanner.skipChar(quote)) {
+ if (!fEntityScanner.skipChar(quote, null)) {
reportFatalError("CloseQuoteMissingInDecl", null);
}
} // scanEntityValue(XMLString,XMLString):void
@@ -1763,7 +1786,7 @@
}
// notation name
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.NOTATION);
if (name == null) {
reportFatalError("MSG_NOTATION_NAME_REQUIRED_IN_NOTATIONDECL",
null);
@@ -1790,7 +1813,7 @@
skipSeparator(false, !scanningInternalSubset());
// end
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("NotationDeclUnterminated", new Object[]{name});
}
fMarkUpDepth--;
@@ -1838,7 +1861,7 @@
XMLErrorReporter.SEVERITY_ERROR);
}
// call handler
- if (!fEntityScanner.skipChar('[')) {
+ if (!fEntityScanner.skipChar('[', null)) {
reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null);
}
@@ -1863,7 +1886,7 @@
fDTDHandler.startConditional(XMLDTDHandler.CONDITIONAL_IGNORE,
null);
}
- if (!fEntityScanner.skipChar('[')) {
+ if (!fEntityScanner.skipChar('[', null)) {
reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null);
}
fReportEntity = true;
@@ -1872,7 +1895,7 @@
fIgnoreConditionalBuffer.clear();
}
while (true) {
- if (fEntityScanner.skipChar('<')) {
+ if (fEntityScanner.skipChar('<', null)) {
if (fDTDHandler != null) {
fIgnoreConditionalBuffer.append('<');
}
@@ -1880,8 +1903,8 @@
// These tests are split so that we handle cases like
// '<', etc.
//
- if (fEntityScanner.skipChar(']')) {
+ if (fEntityScanner.skipChar(']', null)) {
if (fDTDHandler != null) {
fIgnoreConditionalBuffer.append(']');
}
- while (fEntityScanner.skipChar(']')) {
+ while (fEntityScanner.skipChar(']', null)) {
/* empty loop body */
if (fDTDHandler != null) {
fIgnoreConditionalBuffer.append(']');
}
}
- if (fEntityScanner.skipChar('>')) {
+ if (fEntityScanner.skipChar('>', null)) {
if (fIncludeSectDepth-- == initialDepth) {
fMarkUpDepth--;
// call handler
@@ -1928,7 +1951,7 @@
}
}
else {
- int c = fEntityScanner.scanChar();
+ int c = fEntityScanner.scanChar(null);
if (fScannerState == SCANNER_STATE_END_OF_INPUT) {
reportFatalError("IgnoreSectUnterminated", null);
return;
@@ -1965,16 +1988,16 @@
//System.out.println("scanDecls"+fScannerState);
while (again && fScannerState == SCANNER_STATE_MARKUP_DECL) {
again = complete;
- if (fEntityScanner.skipChar('<')) {
+ if (fEntityScanner.skipChar('<', null)) {
fMarkUpDepth++;
- if (fEntityScanner.skipChar('?')) {
+ if (fEntityScanner.skipChar('?', null)) {
fStringBuffer.clear();
scanPI(fStringBuffer);
fMarkUpDepth--; // we're done with this decl
}
- else if (fEntityScanner.skipChar('!')) {
- if (fEntityScanner.skipChar('-')) {
- if (!fEntityScanner.skipChar('-')) {
+ else if (fEntityScanner.skipChar('!', null)) {
+ if (fEntityScanner.skipChar('-', null)) {
+ if (!fEntityScanner.skipChar('-', null)) {
reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD",
null);
} else {
@@ -1993,7 +2016,7 @@
else if (fEntityScanner.skipString("NOTATION")) {
scanNotationDecl();
}
- else if (fEntityScanner.skipChar('[') &&
+ else if (fEntityScanner.skipChar('[', null) &&
!scanningInternalSubset()) {
scanConditionalSect(fPEDepth);
}
@@ -2008,10 +2031,10 @@
reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null);
}
}
- else if (fIncludeSectDepth > 0 && fEntityScanner.skipChar(']')) {
+ else if (fIncludeSectDepth > 0 && fEntityScanner.skipChar(']', null)) {
// end of conditional section?
- if (!fEntityScanner.skipChar(']')
- || !fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar(']', null)
+ || !fEntityScanner.skipChar('>', null)) {
reportFatalError("IncludeSectUnterminated", null);
}
// call handler
@@ -2058,21 +2081,21 @@
throws IOException, XNIException {
int depth = fPEDepth;
boolean sawSpace = fEntityScanner.skipSpaces();
- if (!lookForPERefs || !fEntityScanner.skipChar('%')) {
+ if (!lookForPERefs || !fEntityScanner.skipChar('%', NameType.REFERENCE)) {
return !spaceRequired || sawSpace || (depth != fPEDepth);
}
while (true) {
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ENTITY);
if (name == null) {
reportFatalError("NameRequiredInPEReference", null);
}
- else if (!fEntityScanner.skipChar(';')) {
+ else if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInPEReference",
new Object[]{name});
}
startPE(name, false);
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('%'))
+ if (!fEntityScanner.skipChar('%', NameType.REFERENCE))
return true;
}
}
@@ -2152,44 +2175,8 @@
setScannerState(SCANNER_STATE_TEXT_DECL);
//new SymbolTable());
- fLimitAnalyzer = new XMLLimitAnalyzer();
- }
-
- /**
- * Add the count of the content buffer and check if the accumulated
- * value exceeds the limit
- * @param entityName entity name
- * @param buffer content buffer
- */
- private void checkLimit(String entityName, XMLString buffer) {
- checkLimit(entityName, buffer.length);
- }
-
- /**
- * Add the count and check limit
- * @param entityName entity name
- * @param len length of the buffer
- */
- private void checkLimit(String entityName, int len) {
- if (fLimitAnalyzer == null) {
- fLimitAnalyzer = new XMLLimitAnalyzer();
- }
- fLimitAnalyzer.addValue(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT, entityName, len);
- if (fSecurityManager.isOverLimit(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
- fSecurityManager.debugPrint(fLimitAnalyzer);
- reportFatalError("MaxEntitySizeLimit", new Object[]{entityName,
- fLimitAnalyzer.getValue(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT),
- fSecurityManager.getLimit(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT),
- fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT)});
- }
- if (fSecurityManager.isOverLimit(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
- fSecurityManager.debugPrint(fLimitAnalyzer);
- reportFatalError("TotalEntitySizeLimit",
- new Object[]{fLimitAnalyzer.getTotalValue(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getLimit(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT)});
- }
-
+ fLimitAnalyzer = fEntityManager.fLimitAnalyzer;
+ fSecurityManager = fEntityManager.fSecurityManager;
}
public DTDGrammar getGrammar(){
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -21,21 +21,17 @@
package com.sun.org.apache.xerces.internal.impl;
-import com.sun.xml.internal.stream.XMLBufferListener;
-import com.sun.xml.internal.stream.XMLEntityStorage;
-import com.sun.xml.internal.stream.XMLInputFactoryImpl;
-import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
-
-import java.io.EOFException;
-import java.io.IOException;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.events.XMLEvent;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
import com.sun.org.apache.xerces.internal.util.XMLAttributesIteratorImpl;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
import com.sun.org.apache.xerces.internal.util.XMLSymbols;
+import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
+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.xni.XMLAttributes;
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
@@ -47,18 +43,12 @@
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
-import com.sun.org.apache.xerces.internal.xni.Augmentations;
-import com.sun.org.apache.xerces.internal.impl.Constants;
-import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
-import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
-import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
-import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
-import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
-import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
-import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.State;
-import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
-import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
-import javax.xml.XMLConstants;
+import com.sun.xml.internal.stream.XMLBufferListener;
+import com.sun.xml.internal.stream.XMLEntityStorage;
+import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
+import java.io.EOFException;
+import java.io.IOException;
+import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.XMLEvent;
@@ -89,7 +79,7 @@
// Constants
//
- protected int fElementAttributeLimit;
+ protected int fElementAttributeLimit, fXMLNameLimit;
/** External subset resolver. **/
protected ExternalSubsetResolver fExternalSubsetResolver;
@@ -425,7 +415,7 @@
*/
public void setInputSource(XMLInputSource inputSource) throws IOException {
fEntityManager.setEntityHandler(this);
- fEntityManager.startEntity("$fragment$", inputSource, false, true);
+ fEntityManager.startEntity(false, "$fragment$", inputSource, false, true);
// fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
} // setInputSource(XMLInputSource)
@@ -460,6 +450,7 @@
//fDocumentHandler.startElement(getElementQName(),fAttributes,null);
break;
case XMLStreamConstants.CHARACTERS :
+ fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity);
fDocumentHandler.characters(getCharacterData(),null);
break;
case XMLStreamConstants.SPACE:
@@ -468,13 +459,15 @@
//fDocumentHandler.ignorableWhitespace(getCharacterData(), null);
break;
case XMLStreamConstants.ENTITY_REFERENCE :
+ fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity);
//entity reference callback are given in startEntity
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION :
+ fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity);
fDocumentHandler.processingInstruction(getPITarget(),getPIData(),null);
break;
case XMLStreamConstants.COMMENT :
- //System.out.println(" in COMMENT of the XMLNSDocumentScannerImpl");
+ fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity);
fDocumentHandler.comment(getCharacterData(),null);
break;
case XMLStreamConstants.DTD :
@@ -483,6 +476,7 @@
//therefore we don't need to take care of anything here. So Just break;
break;
case XMLStreamConstants.CDATA:
+ fEntityScanner.checkNodeCount(fEntityScanner.fCurrentEntity);
fDocumentHandler.startCDATA(null);
//xxx: check if CDATA values comes from getCharacterData() function
fDocumentHandler.characters(getCharacterData(),null);
@@ -660,11 +654,12 @@
if (fSecurityManager != null) {
fElementAttributeLimit = fSecurityManager.getLimit(XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT);
+ fXMLNameLimit = fSecurityManager.getLimit(XMLSecurityManager.Limit.MAX_NAME_LIMIT);
} else {
fElementAttributeLimit = 0;
+ fXMLNameLimit = XMLSecurityManager.Limit.MAX_NAME_LIMIT.defaultValue();
}
- fLimitAnalyzer = new XMLLimitAnalyzer();
- fEntityManager.setLimitAnalyzer(fLimitAnalyzer);
+ fLimitAnalyzer = fEntityManager.fLimitAnalyzer;
}
/**
@@ -1278,9 +1273,9 @@
fElementQName = fElementStack.nextElement();
// name
if (fNamespaces) {
- fEntityScanner.scanQName(fElementQName);
+ fEntityScanner.scanQName(fElementQName, NameType.ELEMENTSTART);
} else {
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ELEMENTSTART);
fElementQName.setValues(null, name, name, null);
}
@@ -1381,11 +1376,11 @@
// end tag?
final int c = fEntityScanner.peekChar();
if (c == '>') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
return true;
} else if (c == '/') {
- fEntityScanner.scanChar();
- if (!fEntityScanner.skipChar('>')) {
+ fEntityScanner.scanChar(null);
+ if (!fEntityScanner.skipChar('>', NameType.ELEMENTEND)) {
reportFatalError("ElementUnterminated",
new Object[]{fElementQName.rawname});
}
@@ -1518,15 +1513,15 @@
// name
if (fNamespaces) {
- fEntityScanner.scanQName(fAttributeQName);
+ fEntityScanner.scanQName(fAttributeQName, NameType.ATTRIBUTENAME);
} else {
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ATTRIBUTENAME);
fAttributeQName.setValues(null, name, name, null);
}
// equals
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('=')) {
+ if (!fEntityScanner.skipChar('=', NameType.ATTRIBUTE)) {
reportFatalError("EqRequiredInAttribute",
new Object[] {fCurrentElement.rawname, fAttributeQName.rawname});
}
@@ -1544,9 +1539,8 @@
//can safely add the attribute later..
XMLString tmpStr = getString();
- scanAttributeValue(tmpStr, fTempString2,
- fAttributeQName.rawname, attributes,
- attIndex, isVC, fCurrentElement.rawname);
+ scanAttributeValue(tmpStr, fTempString2, fAttributeQName.rawname, attributes,
+ attIndex, isVC, fCurrentElement.rawname, false);
// content
int oldLen = attributes.getLength();
@@ -1594,13 +1588,13 @@
if (c == '\r') {
// happens when there is the character reference
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
content.append((char)c);
c = -1;
} else if (c == ']') {
//fStringBuffer.clear();
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
- content.append((char)fEntityScanner.scanChar());
+ content.append((char)fEntityScanner.scanChar(null));
// remember where we are in case we get an endEntity before we
// could flush the buffer out - this happens when we're parsing an
// entity which ends with a ]
@@ -1609,12 +1603,12 @@
// We work on a single character basis to handle cases such as:
// ']]]>' which we might otherwise miss.
//
- if (fEntityScanner.skipChar(']')) {
+ if (fEntityScanner.skipChar(']', null)) {
content.append(']');
- while (fEntityScanner.skipChar(']')) {
+ while (fEntityScanner.skipChar(']', null)) {
content.append(']');
}
- if (fEntityScanner.skipChar('>')) {
+ if (fEntityScanner.skipChar('>', null)) {
reportFatalError("CDEndInContent", null);
}
}
@@ -1689,7 +1683,7 @@
} else {
reportFatalError("InvalidCharInCDSect",
new Object[]{Integer.toString(c,16)});
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
}
}
//by this time we have also read surrogate contents if any...
@@ -1751,7 +1745,7 @@
// end
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', NameType.ELEMENTEND)) {
reportFatalError("ETagUnterminated",
new Object[]{rawname});
}
@@ -1841,12 +1835,12 @@
* notification.
*/
protected void scanEntityReference(XMLStringBuffer content) throws IOException, XNIException {
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.REFERENCE);
if (name == null) {
reportFatalError("NameRequiredInReference", null);
return;
}
- if (!fEntityScanner.skipChar(';')) {
+ if (!fEntityScanner.skipChar(';', NameType.REFERENCE)) {
reportFatalError("SemicolonRequiredInReference", new Object []{name});
}
if (fEntityStore.isUnparsedEntity(name)) {
@@ -1905,7 +1899,7 @@
//if that was the case it its taken care in XMLEntityManager.startEntity()
//we immediately call the endEntity. Application gets to know if there was
//any entity that was not declared.
- fEntityManager.startEntity(name, false);
+ fEntityManager.startEntity(true, name, false);
//set the scaner state to content.. parser will automatically revive itself at any point of time.
//setScannerState(SCANNER_STATE_CONTENT);
//return true ;
@@ -1943,6 +1937,7 @@
*/
private void handleCharacter(char c, String entity, XMLStringBuffer content) throws XNIException {
foundBuiltInRefs = true;
+ checkEntityLimit(false, fEntityScanner.fCurrentEntity.name, 1);
content.append(c);
if (fDocumentHandler != null) {
fSingleChar[0] = c;
@@ -2605,13 +2600,13 @@
switch(ch){
case '?' :{
setScannerState(SCANNER_STATE_PI);
- fEntityScanner.skipChar(ch);
+ fEntityScanner.skipChar(ch, null);
break;
}
case '!' :{
- fEntityScanner.skipChar(ch);
- if (fEntityScanner.skipChar('-')) {
- if (!fEntityScanner.skipChar('-')) {
+ fEntityScanner.skipChar(ch, null);
+ if (fEntityScanner.skipChar('-', null)) {
+ if (!fEntityScanner.skipChar('-', NameType.COMMENT)) {
reportFatalError("InvalidCommentStart",
null);
}
@@ -2626,7 +2621,7 @@
}
case '/' :{
setScannerState(SCANNER_STATE_END_ELEMENT_TAG);
- fEntityScanner.skipChar(ch);
+ fEntityScanner.skipChar(ch, NameType.ELEMENTEND);
break;
}
default :{
@@ -2642,9 +2637,9 @@
}//startOfMarkup
private void startOfContent() throws IOException {
- if (fEntityScanner.skipChar('<')) {
+ if (fEntityScanner.skipChar('<', null)) {
setScannerState(SCANNER_STATE_START_OF_MARKUP);
- } else if (fEntityScanner.skipChar('&')) {
+ } else if (fEntityScanner.skipChar('&', NameType.REFERENCE)) {
setScannerState(SCANNER_STATE_REFERENCE) ; //XMLEvent.ENTITY_REFERENCE ); //SCANNER_STATE_REFERENCE
} else {
//element content is there..
@@ -2717,10 +2712,10 @@
case SCANNER_STATE_CONTENT: {
final int ch = fEntityScanner.peekChar();
if (ch == '<') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
setScannerState(SCANNER_STATE_START_OF_MARKUP);
} else if (ch == '&') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(NameType.REFERENCE);
setScannerState(SCANNER_STATE_REFERENCE) ; //XMLEvent.ENTITY_REFERENCE ); //SCANNER_STATE_REFERENCE
break;
} else {
@@ -2820,9 +2815,9 @@
if(DEBUG){
System.out.println("fTempString = " + fTempString);
}
- if(fEntityScanner.skipChar('<')){
+ if(fEntityScanner.skipChar('<', null)){
//check if we have reached end of element
- if(fEntityScanner.skipChar('/')){
+ if(fEntityScanner.skipChar('/', NameType.ELEMENTEND)){
//increase the mark up depth
fMarkupDepth++;
fLastSectionWasCharacterData = false;
@@ -2851,8 +2846,6 @@
if(DEBUG){
System.out.println("NOT USING THE BUFFER, STRING = " + fTempString.toString());
}
- //check limit before returning event
- checkLimit(fContentBuffer);
if(dtdGrammarUtil!= null && dtdGrammarUtil.isIgnorableWhiteSpace(fContentBuffer)){
if(DEBUG)System.out.println("Return SPACE EVENT");
return XMLEvent.SPACE;
@@ -2874,7 +2867,7 @@
}
// happens when there is the character reference
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
fUsebuffer = true;
fContentBuffer.append((char)c);
c = -1 ;
@@ -2882,7 +2875,7 @@
//fStringBuffer.clear();
//xxx: We know the next chracter.. we should just skip it and add ']' directlry
fUsebuffer = true;
- fContentBuffer.append((char)fEntityScanner.scanChar());
+ fContentBuffer.append((char)fEntityScanner.scanChar(null));
// remember where we are in case we get an endEntity before we
// could flush the buffer out - this happens when we're parsing an
// entity which ends with a ]
@@ -2891,12 +2884,12 @@
// We work on a single character basis to handle cases such as:
// ']]]>' which we might otherwise miss.
//
- if (fEntityScanner.skipChar(']')) {
+ if (fEntityScanner.skipChar(']', null)) {
fContentBuffer.append(']');
- while (fEntityScanner.skipChar(']')) {
+ while (fEntityScanner.skipChar(']', null)) {
fContentBuffer.append(']');
}
- if (fEntityScanner.skipChar('>')) {
+ if (fEntityScanner.skipChar('>', null)) {
reportFatalError("CDEndInContent", null);
}
}
@@ -2909,12 +2902,12 @@
// we need not to grow the buffer only when isCoalesce() is not true;
if (c == '<') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
setScannerState(SCANNER_STATE_START_OF_MARKUP);
break;
}//xxx what should be the behavior if entity reference is present in the content ?
else if (c == '&') {
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(NameType.REFERENCE);
setScannerState(SCANNER_STATE_REFERENCE);
break;
}///xxx since this part is also characters, it should be merged...
@@ -2927,7 +2920,7 @@
reportFatalError("InvalidCharInContent",
new Object[] {
Integer.toString(c, 16)});
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
}
break;
}
@@ -2951,8 +2944,6 @@
fLastSectionWasCharacterData = true ;
continue;
}else{
- //check limit before returning event
- checkLimit(fContentBuffer);
if(dtdGrammarUtil!= null && dtdGrammarUtil.isIgnorableWhiteSpace(fContentBuffer)){
if(DEBUG)System.out.println("Return SPACE EVENT");
return XMLEvent.SPACE;
@@ -3055,7 +3046,7 @@
}
fUsebuffer = true ;
//take care of character reference
- if (fEntityScanner.skipChar('#')) {
+ if (fEntityScanner.skipChar('#', NameType.REFERENCE)) {
scanCharReferenceValue(fContentBuffer, null);
fMarkupDepth--;
if(!fIsCoalesce){
@@ -3106,11 +3097,11 @@
if (fNamespaces) {
while (isValidNCName(fEntityScanner.peekChar())) {
- fStringBuffer.append((char)fEntityScanner.scanChar());
+ fStringBuffer.append((char)fEntityScanner.scanChar(null));
}
} else {
while (isValidNameChar(fEntityScanner.peekChar())) {
- fStringBuffer.append((char)fEntityScanner.scanChar());
+ fStringBuffer.append((char)fEntityScanner.scanChar(null));
}
}
String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
@@ -3163,31 +3154,6 @@
} //while loop
}//next
- /**
- * Add the count of the content buffer and check if the accumulated
- * value exceeds the limit
- * @param buffer content buffer
- */
- protected void checkLimit(XMLStringBuffer buffer) {
- if (fLimitAnalyzer.isTracking(fCurrentEntityName)) {
- fLimitAnalyzer.addValue(Limit.GENEAL_ENTITY_SIZE_LIMIT, fCurrentEntityName, buffer.length);
- if (fSecurityManager.isOverLimit(Limit.GENEAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
- fSecurityManager.debugPrint(fLimitAnalyzer);
- reportFatalError("MaxEntitySizeLimit", new Object[]{fCurrentEntityName,
- fLimitAnalyzer.getValue(Limit.GENEAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getLimit(Limit.GENEAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getStateLiteral(Limit.GENEAL_ENTITY_SIZE_LIMIT)});
- }
- if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
- fSecurityManager.debugPrint(fLimitAnalyzer);
- reportFatalError("TotalEntitySizeLimit",
- new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
- fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)});
- }
- }
- }
-
//
// Protected methods
//
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -636,7 +636,7 @@
}
// root element name
- fDoctypeName = fEntityScanner.scanName();
+ fDoctypeName = fEntityScanner.scanName(NameType.DOCTYPE);
if (fDoctypeName == null) {
reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null);
}
@@ -676,10 +676,10 @@
// is there an internal subset?
boolean internalSubset = true;
- if (!fEntityScanner.skipChar('[')) {
+ if (!fEntityScanner.skipChar('[', null)) {
internalSubset = false;
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
}
fMarkupDepth--;
@@ -758,7 +758,7 @@
fStringBuffer.clear();
fStringBuffer.append("xml");
while (XMLChar.isName(fEntityScanner.peekChar())) {
- fStringBuffer.append((char)fEntityScanner.scanChar());
+ fStringBuffer.append((char)fEntityScanner.scanChar(null));
}
String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
//this function should fill the data.. and set the fEvent object to this event.
@@ -836,9 +836,9 @@
switch (fScannerState) {
case SCANNER_STATE_PROLOG: {
fEntityScanner.skipSpaces();
- if (fEntityScanner.skipChar('<')) {
+ if (fEntityScanner.skipChar('<', null)) {
setScannerState(SCANNER_STATE_START_OF_MARKUP);
- } else if (fEntityScanner.skipChar('&')) {
+ } else if (fEntityScanner.skipChar('&', NameType.REFERENCE)) {
setScannerState(SCANNER_STATE_REFERENCE);
} else {
setScannerState(SCANNER_STATE_CONTENT);
@@ -849,11 +849,11 @@
case SCANNER_STATE_START_OF_MARKUP: {
fMarkupDepth++;
- if (fEntityScanner.skipChar('?')) {
+ if (fEntityScanner.skipChar('?', null)) {
setScannerState(SCANNER_STATE_PI);
- } else if (fEntityScanner.skipChar('!')) {
- if (fEntityScanner.skipChar('-')) {
- if (!fEntityScanner.skipChar('-')) {
+ } else if (fEntityScanner.skipChar('!', null)) {
+ if (fEntityScanner.skipChar('-', null)) {
+ if (!fEntityScanner.skipChar('-', null)) {
reportFatalError("InvalidCommentStart",
null);
}
@@ -997,7 +997,7 @@
case SCANNER_STATE_CONTENT: {
reportFatalError("ContentIllegalInProlog", null);
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
}
case SCANNER_STATE_REFERENCE: {
reportFatalError("ReferenceIllegalInProlog", null);
@@ -1096,11 +1096,14 @@
again = false;
switch (fScannerState) {
case SCANNER_STATE_DTD_INTERNAL_DECLS: {
+ boolean moreToScan = false;
+ if (!fDTDScanner.skipDTD(fSupportDTD)) {
// REVISIT: Should there be a feature for
// the "complete" parameter?
boolean completeDTD = true;
- boolean moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);
+ moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);
+ }
Entity entity = fEntityScanner.getCurrentEntity();
if(entity instanceof Entity.ScannedEntity){
fEndPos=((Entity.ScannedEntity)entity).position;
@@ -1108,12 +1111,12 @@
fReadingDTD=false;
if (!moreToScan) {
// end doctype declaration
- if (!fEntityScanner.skipChar(']')) {
+ if (!fEntityScanner.skipChar(']', null)) {
reportFatalError("EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET",
null);
}
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
}
fMarkupDepth--;
@@ -1377,7 +1380,7 @@
if(fScannerState == SCANNER_STATE_TERMINATED ){
return XMLEvent.END_DOCUMENT ;
}
- if (fEntityScanner.skipChar('<')) {
+ if (fEntityScanner.skipChar('<', null)) {
setScannerState(SCANNER_STATE_START_OF_MARKUP);
} else {
setScannerState(SCANNER_STATE_CONTENT);
@@ -1386,11 +1389,11 @@
}
case SCANNER_STATE_START_OF_MARKUP: {
fMarkupDepth++;
- if (fEntityScanner.skipChar('?')) {
+ if (fEntityScanner.skipChar('?', null)) {
setScannerState(SCANNER_STATE_PI);
- } else if (fEntityScanner.skipChar('!')) {
+ } else if (fEntityScanner.skipChar('!', null)) {
setScannerState(SCANNER_STATE_COMMENT);
- } else if (fEntityScanner.skipChar('/')) {
+ } else if (fEntityScanner.skipChar('/', null)) {
reportFatalError("MarkupNotRecognizedInMisc",
null);
} else if (XMLChar.isNameStart(fEntityScanner.peekChar())) {
@@ -1432,7 +1435,7 @@
} else{
reportFatalError("ContentIllegalInTrailingMisc",
null);
- fEntityScanner.scanChar();
+ fEntityScanner.scanChar(null);
setScannerState(SCANNER_STATE_TRAILING_MISC);
return XMLEvent.CHARACTERS;
}
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,15 +1,15 @@
/*
- * Copyright (c) 2003, 2006, 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 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
*
- * 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
- *
- * 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,
@@ -44,12 +44,11 @@
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;
@@ -365,7 +364,7 @@
// entities
/** Entities. */
- protected Hashtable fEntities = new Hashtable();
+ protected Map fEntities = new HashMap<>();
/** Entity stack. */
protected Stack fEntityStack = new Stack();
@@ -402,6 +401,8 @@
* 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);
} // ()
@@ -579,6 +580,8 @@
/**
* 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.
@@ -589,7 +592,7 @@
* 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
@@ -832,7 +835,9 @@
* 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);
@@ -852,7 +857,7 @@
*/
public boolean isExternalEntity(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -869,7 +874,7 @@
*/
public boolean isEntityDeclInExternalSubset(String entityName) {
- Entity entity = (Entity)fEntities.get(entityName);
+ Entity entity = fEntities.get(entityName);
if (entity == null) {
return false;
}
@@ -899,13 +904,13 @@
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;
}
@@ -1100,6 +1105,7 @@
/**
* 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.
@@ -1107,11 +1113,11 @@
* @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;
@@ -1231,7 +1237,7 @@
}
// start the entity
- startEntity(entityName, xmlInputSource, literal, external);
+ startEntity(isGE, entityName, xmlInputSource, literal, external);
} // startEntity(String,boolean)
@@ -1246,7 +1252,7 @@
*/
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.
@@ -1261,7 +1267,7 @@
*/
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
@@ -1280,6 +1286,7 @@
* 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
@@ -1289,12 +1296,12 @@
* @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
@@ -1306,7 +1313,7 @@
}
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?
@@ -1422,10 +1429,6 @@
// 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);
@@ -1448,6 +1451,12 @@
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();
@@ -1534,7 +1543,7 @@
// 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();
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,13 +1,13 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, 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
*
@@ -21,7 +21,7 @@
package com.sun.org.apache.xerces.internal.impl;
-
+import com.sun.org.apache.xerces.internal.impl.XMLScanner.NameType;
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;
@@ -30,10 +30,14 @@
import com.sun.org.apache.xerces.internal.util.SymbolTable;
import com.sun.org.apache.xerces.internal.util.XMLChar;
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
+import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
import com.sun.org.apache.xerces.internal.xni.*;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.xml.internal.stream.Entity;
+import com.sun.xml.internal.stream.Entity.ScannedEntity;
import com.sun.xml.internal.stream.XMLBufferListener;
import java.io.EOFException;
import java.io.IOException;
@@ -60,6 +64,12 @@
protected XMLEntityManager fEntityManager ;
+ /** Security manager. */
+ protected XMLSecurityManager fSecurityManager = null;
+
+ /** Limit analyzer. */
+ protected XMLLimitAnalyzer fLimitAnalyzer = null;
+
/** Debug switching readers for encodings. */
private static final boolean DEBUG_ENCODINGS = false;
/** Listeners which should know when load is being called */
@@ -133,6 +143,10 @@
// SAPJVM: Remember, that the XML version has explicitly been set,
// so that XMLStreamReader.getVersion() can find that out.
boolean xmlVersionSetExplicitly = false;
+
+ // indicates that the operation is for detecting XML version
+ boolean detectingVersion = false;
+
//
// Constructors
//
@@ -174,10 +188,7 @@
public void reset(PropertyManager propertyManager){
fSymbolTable = (SymbolTable)propertyManager.getProperty(SYMBOL_TABLE) ;
fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(ERROR_REPORTER) ;
- fCurrentEntity = null;
- whiteSpaceLen = 0;
- whiteSpaceInfoNeeded = true;
- listeners.clear();
+ resetCommon();
}
/**
@@ -196,18 +207,13 @@
*/
public void reset(XMLComponentManager componentManager)
throws XMLConfigurationException {
-
- //System.out.println(" this is being called");
// xerces features
fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false);
//xerces properties
fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
- fCurrentEntity = null;
- whiteSpaceLen = 0;
- whiteSpaceInfoNeeded = true;
- listeners.clear();
+ resetCommon();
} // reset(XMLComponentManager)
@@ -217,6 +223,17 @@
fSymbolTable = symbolTable;
fEntityManager = entityManager;
fErrorReporter = reporter;
+ fLimitAnalyzer = fEntityManager.fLimitAnalyzer;
+ fSecurityManager = fEntityManager.fSecurityManager;
+ }
+
+ private void resetCommon() {
+ fCurrentEntity = null;
+ whiteSpaceLen = 0;
+ whiteSpaceInfoNeeded = true;
+ listeners.clear();
+ fLimitAnalyzer = fEntityManager.fLimitAnalyzer;
+ fSecurityManager = fEntityManager.fSecurityManager;
}
/**
@@ -516,10 +533,12 @@
*
* Note: The character is consumed.
*
+ * @param nt The type of the name (element or attribute)
+ *
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanChar() throws IOException {
+ protected int scanChar(NameType nt) throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanChar: ");
print();
@@ -532,6 +551,7 @@
}
// scan character
+ int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[fCurrentEntity.position++];
if (c == '\n' ||
(c == '\r' && isExternal)) {
@@ -541,6 +561,7 @@
invokeListeners(1);
fCurrentEntity.ch[0] = (char)c;
load(1, false, false);
+ offset = 0;
}
if (c == '\r' && isExternal) {
if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') {
@@ -557,6 +578,9 @@
System.out.println(" -> '"+(char)c+"'");
}
fCurrentEntity.columnNumber++;
+ if (!detectingVersion) {
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
+ }
return c;
} // scanChar():int
@@ -576,7 +600,7 @@
* @see com.sun.org.apache.xerces.internal.util.SymbolTable
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName
*/
- public String scanNmtoken() throws IOException {
+ protected String scanNmtoken() throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanNmtoken: ");
print();
@@ -648,6 +672,8 @@
* Note: The string returned must be a symbol. The
* SymbolTable can be used for this purpose.
*
+ * @param nt The type of the name (element or attribute)
+ *
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*
@@ -655,7 +681,7 @@
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isNameStart
*/
- public String scanName() throws IOException {
+ protected String scanName(NameType nt) throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanName: ");
print();
@@ -669,6 +695,7 @@
// scan name
int offset = fCurrentEntity.position;
+ int length;
if (XMLChar.isNameStart(fCurrentEntity.ch[offset])) {
if (++fCurrentEntity.position == fCurrentEntity.count) {
invokeListeners(1);
@@ -696,20 +723,7 @@
vc = XMLChar.isName(c);
}
if(!vc)break;
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.fBufferSize) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.fBufferSize * 2];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- fCurrentEntity.fBufferSize *= 2;
- } else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, offset)) > 0) {
offset = 0;
if (load(length, false, false)) {
break;
@@ -717,12 +731,14 @@
}
}
}
- int length = fCurrentEntity.position - offset;
+ length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
// return name
String symbol;
if (length > 0) {
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
+ checkEntityLimit(nt, fCurrentEntity, offset, length);
symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
} else
symbol = null;
@@ -746,6 +762,7 @@
* this purpose.
*
* @param qname The qualified name structure to fill.
+ * @param nt The type of the name (element or attribute)
*
* @return Returns true if a qualified name appeared immediately on
* the input and was scanned, false otherwise.
@@ -757,7 +774,7 @@
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isName
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isNameStart
*/
- public boolean scanQName(QName qname) throws IOException {
+ protected boolean scanQName(QName qname, NameType nt) throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanQName, "+qname+": ");
print();
@@ -793,11 +810,13 @@
print();
System.out.println(" -> true");
}
+ checkEntityLimit(nt, fCurrentEntity, 0, 1);
return true;
}
}
int index = -1;
boolean vc = false;
+ int length;
while ( true){
//XMLChar.isName(fCurrentEntity.ch[fCurrentEntity.position])) ;
@@ -813,21 +832,10 @@
break;
}
index = fCurrentEntity.position;
+ //check prefix before further read
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, index - offset);
}
- if (++fCurrentEntity.position == fCurrentEntity.count) {
- int length = fCurrentEntity.position - offset;
- invokeListeners(length);
- if (length == fCurrentEntity.fBufferSize) {
- // bad luck we have to resize our buffer
- char[] tmp = new char[fCurrentEntity.fBufferSize * 2];
- System.arraycopy(fCurrentEntity.ch, offset,
- tmp, 0, length);
- fCurrentEntity.ch = tmp;
- fCurrentEntity.fBufferSize *= 2;
- } else {
- System.arraycopy(fCurrentEntity.ch, offset,
- fCurrentEntity.ch, 0, length);
- }
+ if ((length = checkBeforeLoad(fCurrentEntity, offset, index)) > 0) {
if (index != -1) {
index = index - offset;
}
@@ -837,7 +845,7 @@
}
}
}
- int length = fCurrentEntity.position - offset;
+ length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length;
if (length > 0) {
String prefix = null;
@@ -847,14 +855,20 @@
if (index != -1) {
int prefixLength = index - offset;
+ //check the result: prefix
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, prefixLength);
prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
offset, prefixLength);
int len = length - prefixLength - 1;
+ //check the result: localpart
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, index + 1, len);
localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
index + 1, len);
} else {
localpart = rawname;
+ //check the result: localpart
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
}
qname.setValues(prefix, localpart, rawname, null);
if (DEBUG_BUFFER) {
@@ -862,6 +876,7 @@
print();
System.out.println(" -> true");
}
+ checkEntityLimit(nt, fCurrentEntity, offset, length);
return true;
}
}
@@ -877,6 +892,109 @@
} // scanQName(QName):boolean
/**
+ * Checks whether the end of the entity buffer has been reached. If yes,
+ * checks against the limit and buffer size before loading more characters.
+ *
+ * @param entity the current entity
+ * @param offset the offset from which the current read was started
+ * @param nameOffset the offset from which the current name starts
+ * @return the length of characters scanned before the end of the buffer,
+ * zero if there is more to be read in the buffer
+ */
+ protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
+ int nameOffset) throws IOException {
+ int length = 0;
+ if (++entity.position == entity.count) {
+ length = entity.position - offset;
+ int nameLength = length;
+ if (nameOffset != -1) {
+ nameOffset = nameOffset - offset;
+ nameLength = length - nameOffset;
+ } else {
+ nameOffset = offset;
+ }
+ //check limit before loading more data
+ checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
+ invokeListeners(length);
+ if (length == entity.ch.length) {
+ // bad luck we have to resize our buffer
+ char[] tmp = new char[entity.fBufferSize * 2];
+ System.arraycopy(entity.ch, offset, tmp, 0, length);
+ entity.ch = tmp;
+ entity.fBufferSize *= 2;
+ }
+ else {
+ System.arraycopy(entity.ch, offset, entity.ch, 0, length);
+ }
+ }
+ return length;
+ }
+
+ /**
+ * If the current entity is an Entity reference, check the accumulated size
+ * against the limit.
+ *
+ * @param nt type of name (element, attribute or entity)
+ * @param entity The current entity
+ * @param offset The index of the first byte
+ * @param length The length of the entity scanned
+ */
+ protected void checkEntityLimit(NameType nt, ScannedEntity entity, int offset, int length) {
+ if (entity == null || !entity.isGE) {
+ return;
+ }
+
+ if (nt != NameType.REFERENCE) {
+ checkLimit(Limit.GENEAL_ENTITY_SIZE_LIMIT, entity, offset, length);
+ }
+ if (nt == NameType.ELEMENTSTART || nt == NameType.ATTRIBUTENAME) {
+ checkNodeCount(entity);
+ }
+ }
+
+ /**
+ * If the current entity is an Entity reference, counts the total nodes in
+ * the entity and checks the accumulated value against the limit.
+ *
+ * @param entity The current entity
+ */
+ protected void checkNodeCount(ScannedEntity entity) {
+ if (entity != null && entity.isGE) {
+ checkLimit(Limit.ENTITY_REPLACEMENT_LIMIT, entity, 0, 1);
+ }
+ }
+
+ /**
+ * Checks whether the value of the specified Limit exceeds its limit
+ *
+ * @param limit The Limit to be checked
+ * @param entity The current entity
+ * @param offset The index of the first byte
+ * @param length The length of the entity scanned
+ */
+ protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
+ fLimitAnalyzer.addValue(limit, entity.name, length);
+ if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
+ fSecurityManager.debugPrint(fLimitAnalyzer);
+ Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
+ new Object[]{fLimitAnalyzer.getValue(limit),
+ fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
+ new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
+ fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
+ e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ }
+ if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
+ fSecurityManager.debugPrint(fLimitAnalyzer);
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
+ new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
+ fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
+ fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
+ XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ }
+ }
+
+ /**
* CHANGED:
* Scans a range of parsed character data, This function appends the character data to
* the supplied buffer.
@@ -898,7 +1016,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanContent(XMLString content) throws IOException {
+ protected int scanContent(XMLString content) throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanContent: ");
print();
@@ -919,6 +1037,7 @@
int offset = fCurrentEntity.position;
int c = fCurrentEntity.ch[offset];
int newlines = 0;
+ boolean counted = false;
if (c == '\n' || (c == '\r' && isExternal)) {
if (DEBUG_BUFFER) {
System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");
@@ -932,9 +1051,11 @@
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
+ checkEntityLimit(null, fCurrentEntity, offset, newlines);
offset = 0;
fCurrentEntity.position = newlines;
if (load(newlines, false, true)) {
+ counted = true;
break;
}
}
@@ -951,9 +1072,11 @@
fCurrentEntity.lineNumber++;
fCurrentEntity.columnNumber = 1;
if (fCurrentEntity.position == fCurrentEntity.count) {
+ checkEntityLimit(null, fCurrentEntity, offset, newlines);
offset = 0;
fCurrentEntity.position = newlines;
if (load(newlines, false, true)) {
+ counted = true;
break;
}
}
@@ -967,6 +1090,7 @@
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
+ checkEntityLimit(null, fCurrentEntity, offset, length);
//CHANGED: dont replace the value.. append to the buffer. This gives control to the callee
//on buffering the data..
content.setValues(fCurrentEntity.ch, offset, length);
@@ -994,6 +1118,9 @@
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ if (!counted) {
+ checkEntityLimit(null, fCurrentEntity, offset, length);
+ }
//CHANGED: dont replace the value.. append to the buffer. This gives control to the callee
//on buffering the data..
@@ -1039,6 +1166,7 @@
* @param quote The quote character that signifies the end of the
* attribute value data.
* @param content The content structure to fill.
+ * @param isNSURI a flag indicating whether the content is a Namespace URI
*
* @return Returns the next character on the input, if known. This
* value may be -1 but this does note designate
@@ -1047,7 +1175,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public int scanLiteral(int quote, XMLString content)
+ protected int scanLiteral(int quote, XMLString content, boolean isNSURI)
throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(scanLiteral, '"+(char)quote+"': ");
@@ -1168,6 +1296,11 @@
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+
+ checkEntityLimit(null, fCurrentEntity, offset, length);
+ if (isNSURI) {
+ checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length);
+ }
content.setValues(fCurrentEntity.ch, offset, length);
// return next character
@@ -1215,7 +1348,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean scanData(String delimiter, XMLStringBuffer buffer)
+ protected boolean scanData(String delimiter, XMLStringBuffer buffer)
throws IOException {
boolean done = false;
@@ -1253,6 +1386,7 @@
if (fCurrentEntity.position > fCurrentEntity.count - delimLen) {
// something must be wrong with the input: e.g., file ends in an unterminated comment
int length = fCurrentEntity.count - fCurrentEntity.position;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, fCurrentEntity.position, length);
buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
fCurrentEntity.columnNumber += fCurrentEntity.count;
fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);
@@ -1315,6 +1449,7 @@
}
int length = fCurrentEntity.position - offset;
if (fCurrentEntity.position == fCurrentEntity.count - 1) {
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
buffer.append(fCurrentEntity.ch, offset, length);
if (DEBUG_BUFFER) {
System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");
@@ -1358,12 +1493,14 @@
fCurrentEntity.position--;
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
buffer.append(fCurrentEntity.ch, offset, length);
return true;
}
}
int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines;
+ checkEntityLimit(NameType.COMMENT, fCurrentEntity, offset, length);
if (done) {
length -= delimLen;
}
@@ -1387,13 +1524,14 @@
* the specified character.
*
* @param c The character to skip.
+ * @param nt The type of the name (element or attribute)
*
* @return Returns true if the character was skipped.
*
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean skipChar(int c) throws IOException {
+ protected boolean skipChar(int c, NameType nt) throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(skipChar, '"+(char)c+"': ");
print();
@@ -1406,6 +1544,7 @@
}
// skip character
+ int offset = fCurrentEntity.position;
int cc = fCurrentEntity.ch[fCurrentEntity.position];
if (cc == c) {
fCurrentEntity.position++;
@@ -1420,6 +1559,7 @@
print();
System.out.println(" -> true");
}
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
return true;
} else if (c == '\n' && cc == '\r' && isExternal) {
// handle newlines
@@ -1439,6 +1579,7 @@
print();
System.out.println(" -> true");
}
+ checkEntityLimit(nt, fCurrentEntity, offset, fCurrentEntity.position - offset);
return true;
}
@@ -1468,7 +1609,7 @@
*
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace
*/
- public boolean skipSpaces() throws IOException {
+ protected boolean skipSpaces() throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(skipSpaces: ");
print();
@@ -1492,6 +1633,7 @@
// skip spaces
int c = fCurrentEntity.ch[fCurrentEntity.position];
+ int offset = fCurrentEntity.position - 1;
if (XMLChar.isSpace(c)) {
do {
boolean entityChanged = false;
@@ -1521,6 +1663,11 @@
} else {
fCurrentEntity.columnNumber++;
}
+
+ //If this is a general entity, spaces within a start element should be counted
+ checkEntityLimit(null, fCurrentEntity, offset, fCurrentEntity.position - offset);
+ offset = fCurrentEntity.position;
+
// load more characters, if needed
if (!entityChanged){
fCurrentEntity.position++;
@@ -1562,7 +1709,7 @@
/**
- * @param legnth This function checks that following number of characters are available.
+ * @param length This function checks that following number of characters are available.
* to the underlying buffer.
* @return This function returns true if capacity asked is available.
*/
@@ -1571,9 +1718,9 @@
}
/**
- * @param legnth This function checks that following number of characters are available.
+ * @param length This function checks that following number of characters are available.
* to the underlying buffer.
- * @param if the underlying function should change the entity
+ * @param changeEntity a flag to indicate that the underlying function should change the entity
* @return This function returns true if capacity asked is available.
*
*/
@@ -1636,7 +1783,7 @@
* @throws IOException Thrown if i/o error occurs.
* @throws EOFException Thrown on end of file.
*/
- public boolean skipString(String s) throws IOException {
+ protected boolean skipString(String s) throws IOException {
final int length = s.length();
@@ -1656,6 +1803,9 @@
if(afterSkip-- == beforeSkip){
fCurrentEntity.position = fCurrentEntity.position + length ;
fCurrentEntity.columnNumber += length;
+ if (!detectingVersion) {
+ checkEntityLimit(null, fCurrentEntity, beforeSkip, length);
+ }
return true;
}
}
@@ -1664,7 +1814,7 @@
return false;
} // skipString(String):boolean
- public boolean skipString(char [] s) throws IOException {
+ protected boolean skipString(char [] s) throws IOException {
final int length = s.length;
//first make sure that required capacity is avaible
@@ -1684,6 +1834,9 @@
}
fCurrentEntity.position = fCurrentEntity.position + length ;
fCurrentEntity.columnNumber += length;
+ if (!detectingVersion) {
+ checkEntityLimit(null, fCurrentEntity, beforeSkip, length);
+ }
return true;
}
@@ -2081,7 +2234,7 @@
*
* @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace
*/
- public final boolean skipDeclSpaces() throws IOException {
+ protected final boolean skipDeclSpaces() throws IOException {
if (DEBUG_BUFFER) {
System.out.print("(skipDeclSpaces: ");
//XMLEntityManager.print(fCurrentEntity);
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLErrorReporter.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLErrorReporter.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLErrorReporter.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,68 +1,24 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * The Apache Software License, Version 1.1
- *
- *
- * Copyright (c) 1999-2004 The Apache Software Foundation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * 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
*
- * 4. The names "Xerces" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation and was
- * originally based on software copyright (c) 1999, International
- * Business Machines, Inc., http://www.apache.org. For more
- * information on the Apache Software Foundation, please see
- * .
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.sun.org.apache.xerces.internal.impl;
-import java.util.Hashtable;
-import java.util.Locale;
-
import com.sun.org.apache.xerces.internal.util.DefaultErrorHandler;
import com.sun.org.apache.xerces.internal.util.ErrorHandlerProxy;
import com.sun.org.apache.xerces.internal.util.MessageFormatter;
@@ -73,6 +29,9 @@
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
import org.xml.sax.ErrorHandler;
/**
@@ -189,7 +148,7 @@
protected Locale fLocale;
/** Mapping of Message formatters for domains. */
- protected Hashtable fMessageFormatters;
+ protected Map fMessageFormatters;
/** Error handler. */
protected XMLErrorHandler fErrorHandler;
@@ -233,7 +192,7 @@
// caller to specify the location of the error being
// reported. -Ac
- fMessageFormatters = new Hashtable();
+ fMessageFormatters = new HashMap<>();
} // ()
@@ -291,7 +250,7 @@
* @param domain The domain of the message formatter.
*/
public MessageFormatter getMessageFormatter(String domain) {
- return (MessageFormatter)fMessageFormatters.get(domain);
+ return fMessageFormatters.get(domain);
} // getMessageFormatter(String):MessageFormatter
/**
@@ -301,7 +260,7 @@
* @param domain The domain of the message formatter.
*/
public MessageFormatter removeMessageFormatter(String domain) {
- return (MessageFormatter) fMessageFormatters.remove(domain);
+ return fMessageFormatters.remove(domain);
} // removeMessageFormatter(String):MessageFormatter
/**
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -37,6 +37,7 @@
import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
+import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
@@ -195,9 +196,9 @@
// There are two variables,fNamespaces and fBindNamespaces
//StAX uses XMLNSDocumentScannerImpl so this distinction needs to be maintained
if (fNamespaces) {
- fEntityScanner.scanQName(fElementQName);
+ fEntityScanner.scanQName(fElementQName, NameType.ELEMENTSTART);
} else {
- String name = fEntityScanner.scanName();
+ String name = fEntityScanner.scanName(NameType.ELEMENTSTART);
fElementQName.setValues(null, name, name, null);
}
@@ -410,11 +411,11 @@
if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanAttribute()");
// name
- fEntityScanner.scanQName(fAttributeQName);
+ fEntityScanner.scanQName(fAttributeQName, NameType.ATTRIBUTE);
// equals
fEntityScanner.skipSpaces();
- if (!fEntityScanner.skipChar('=')) {
+ if (!fEntityScanner.skipChar('=', NameType.ATTRIBUTE)) {
reportFatalError("EqRequiredInAttribute",
new Object[]{fCurrentElement.rawname,fAttributeQName.rawname});
}
@@ -436,24 +437,37 @@
//since scanAttributeValue doesn't use attIndex parameter therefore we
//can safely add the attribute later..
XMLString tmpStr = getString();
- scanAttributeValue(tmpStr, fTempString2,
- fAttributeQName.rawname, attributes,
- attrIndex, isVC, fCurrentElement.rawname);
+
+ /**
+ * Determine whether this is a namespace declaration that will be subject
+ * to the name limit check in the scanAttributeValue operation.
+ * Namespace declaration format: xmlns="..." or xmlns:prefix="..."
+ * Note that prefix:xmlns="..." isn't a namespace.
+ */
+ String localpart = fAttributeQName.localpart;
+ String prefix = fAttributeQName.prefix != null
+ ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;
+ boolean isNSDecl = fBindNamespaces & (prefix == XMLSymbols.PREFIX_XMLNS ||
+ prefix == XMLSymbols.EMPTY_STRING && localpart == XMLSymbols.PREFIX_XMLNS);
+
+ scanAttributeValue(tmpStr, fTempString2, fAttributeQName.rawname, attributes,
+ attrIndex, isVC, fCurrentElement.rawname, isNSDecl);
String value = null;
//fTempString.toString();
// record namespace declarations if any.
if (fBindNamespaces) {
-
- String localpart = fAttributeQName.localpart;
- String prefix = fAttributeQName.prefix != null
- ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;
- // when it's of form xmlns="..." or xmlns:prefix="...",
- // it's a namespace declaration. but prefix:xmlns="..." isn't.
- if (prefix == XMLSymbols.PREFIX_XMLNS ||
- prefix == XMLSymbols.EMPTY_STRING && localpart == XMLSymbols.PREFIX_XMLNS) {
-
+ if (isNSDecl) {
+ //check the length of URI
+ if (tmpStr.length > fXMLNameLimit) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MaxXMLNameLimit",
+ new Object[]{new String(tmpStr.ch,tmpStr.offset,tmpStr.length),
+ tmpStr.length, fXMLNameLimit,
+ fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.MAX_NAME_LIMIT)},
+ XMLErrorReporter.SEVERITY_FATAL_ERROR);
+ }
// get the internalized value of this attribute
String uri = fSymbolTable.addSymbol(tmpStr.ch,tmpStr.offset,tmpStr.length);
value = uri;
diff -r 887a572ef17a -r 80897e67a1b3 src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java Fri Jul 29 04:24:19 2016 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java Wed Sep 07 06:06:32 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
@@ -116,6 +116,30 @@
/** Debug attribute normalization. */
protected static final boolean DEBUG_ATTR_NORMALIZATION = false;
+ /**
+ * Type of names
+ */
+ public static enum NameType {
+ ATTRIBUTE("attribute"),
+ ATTRIBUTENAME("attribute name"),
+ COMMENT("comment"),
+ DOCTYPE("doctype"),
+ ELEMENTSTART("startelement"),
+ ELEMENTEND("endelement"),
+ ENTITY("entity"),
+ NOTATION("notation"),
+ PI("pi"),
+ REFERENCE("reference");
+
+ final String literal;
+ NameType(String literal) {
+ this.literal = literal;
+ }
+
+ String literal() {
+ return literal;
+ }
+ }
//xxx: setting the default value as false, as we dont need to calculate this value
//we should have a feature when set to true computes this value
@@ -146,7 +170,7 @@
protected boolean fNotifyCharRefs = false;
/** Internal parser-settings feature */
- protected boolean fParserSettings = true;
+ protected boolean fParserSettings = true;
// properties
@@ -175,13 +199,13 @@
/** event type */
protected XMLEvent fEvent ;
- /** Entity scanner, this alwasy works on last entity that was opened. */
+ /** Entity scanner, this always works on last entity that was opened. */
protected XMLEntityScanner fEntityScanner = null;
/** Entity depth. */
protected int fEntityDepth;
- /** Literal value of the last character refence scanned. */
+ /** Literal value of the last character reference scanned. */
protected String fCharRefLiteral = null;
/** Scanning attribute. */
@@ -549,10 +573,10 @@
}
// end
- if (!fEntityScanner.skipChar('?')) {
+ if (!fEntityScanner.skipChar('?', null)) {
reportFatalError("XMLDeclUnterminated", null);
}
- if (!fEntityScanner.skipChar('>')) {
+ if (!fEntityScanner.skipChar('>', null)) {
reportFatalError("XMLDeclUnterminated", null);
}
@@ -579,7 +603,7 @@
*