7133220: Additional patches to JAXP 1.4.5 update 1 for 7u4
Reviewed-by: alanb
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java
index c41918e..d717d8d 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java
@@ -97,7 +97,7 @@
// In a few cases, the time zone may be +/-hh:30.
int min = offset%(60*60*1000);
char posneg = hrs < 0? '-': '+';
- buff.append(posneg + formatDigits(hrs) + ':' + formatDigits(min));
+ buff.append(posneg).append(formatDigits(hrs)).append(':').append(formatDigits(min));
}
return buff.toString();
}
@@ -164,7 +164,7 @@
*/
public static String date()
{
- String datetime = dateTime();
+ String datetime = dateTime().toString();
String date = datetime.substring(0, datetime.indexOf("T"));
String zone = datetime.substring(getZoneStart(datetime));
return (date + zone);
@@ -215,7 +215,7 @@
*/
public static String time()
{
- String datetime = dateTime();
+ String datetime = dateTime().toString();
String time = datetime.substring(datetime.indexOf("T")+1);
// The datetime() function returns the zone on the datetime string. If we
@@ -659,6 +659,7 @@
*/
public static String monthName()
{
+ Calendar cal = Calendar.getInstance();
String format = "MMMM";
return getNameOrAbbrev(format);
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java
index 6d760fc..6066832 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java
@@ -381,7 +381,7 @@
if (bits <= value.length())
value = value.substring(0, bits);
- return new Double(value).doubleValue();
+ return Double.parseDouble(value);
}
else
return Double.NaN;
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java
index 3b12000..b6cdff0 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java
@@ -55,11 +55,10 @@
public static void printUsage() {
- StringBuffer vers = new StringBuffer("XSLTC version " +
- VERSION_MAJOR + "." + VERSION_MINOR +
- ((VERSION_DELTA > 0) ? ("."+VERSION_DELTA) : ("")));
- System.err.println(vers + "\n" +
- new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
+ System.err.println("XSLTC version " +
+ VERSION_MAJOR + "." + VERSION_MINOR +
+ ((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")) + "\n" +
+ new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
if (_allowExit) System.exit(-1);
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ApplyImports.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ApplyImports.java
index 84022a2..ceba568 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ApplyImports.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ApplyImports.java
@@ -23,9 +23,13 @@
package com.sun.org.apache.xalan.internal.xsltc.compiler;
+import java.util.Enumeration;
+
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
+import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
+import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
@@ -85,6 +89,9 @@
_modeName = template.getModeName();
_precedence = template.getImportPrecedence();
+ // Get the method name for <xsl:apply-imports/> in this mode
+ stylesheet = parser.getTopLevelStylesheet();
+
parseChildren(parser); // with-params
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java
index 7e50181..6dd5c14 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java
@@ -378,12 +378,6 @@
= "namespaceArray";
public static final String NAMESPACE_INDEX_SIG
= "[" + STRING_SIG;
- public static final String NS_ANCESTORS_INDEX_SIG
- = "[I";
- public static final String PREFIX_URIS_IDX_SIG
- = "[I";
- public static final String PREFIX_URIS_ARRAY_SIG
- = "[" + STRING_SIG;
public static final String HASIDCALL_INDEX
= "_hasIdCall";
public static final String HASIDCALL_INDEX_SIG
@@ -392,24 +386,6 @@
= "transletVersion";
public static final String TRANSLET_VERSION_INDEX_SIG
= "I";
- public static final String LOOKUP_STYLESHEET_QNAME_NS_REF
- = "lookupStylesheetQNameNamespace";
- public static final String LOOKUP_STYLESHEET_QNAME_NS_SIG
- = "(" + STRING_SIG
- + "I"
- + NS_ANCESTORS_INDEX_SIG
- + PREFIX_URIS_IDX_SIG
- + PREFIX_URIS_ARRAY_SIG
- + "Z)" + STRING_SIG;
- public static final String EXPAND_STYLESHEET_QNAME_REF
- = "expandStylesheetQNameRef";
- public static final String EXPAND_STYLESHEET_QNAME_SIG
- = "(" + STRING_SIG
- + "I"
- + NS_ANCESTORS_INDEX_SIG
- + PREFIX_URIS_IDX_SIG
- + PREFIX_URIS_ARRAY_SIG
- + "Z)" + STRING_SIG;
public static final String DOM_FIELD
= "_dom";
@@ -421,12 +397,6 @@
= "_sTypesArray";
public static final String STATIC_NAMESPACE_ARRAY_FIELD
= "_sNamespaceArray";
- public static final String STATIC_NS_ANCESTORS_ARRAY_FIELD
- = "_sNamespaceAncestorsArray";
- public static final String STATIC_PREFIX_URIS_IDX_ARRAY_FIELD
- = "_sPrefixURIsIdxArray";
- public static final String STATIC_PREFIX_URIS_ARRAY_FIELD
- = "_sPrefixURIPairsArray";
public static final String STATIC_CHAR_DATA_FIELD
= "_scharData";
public static final String STATIC_CHAR_DATA_FIELD_SIG
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java
index 5654d36..8cad427 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java
@@ -100,6 +100,7 @@
* the specified method is found in the specifed class.
*/
private boolean hasMethods() {
+ LiteralExpr arg = (LiteralExpr)_arg;
// Get the class name from the namespace uri
String className = getClassNameFromUri(_namespaceOfFunct);
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java
index b7147d6..2c244e1 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java
@@ -113,8 +113,6 @@
*/
private Vector _allValidTemplates = null;
- private Vector _elementsWithNamespacesUsedDynamically = null;
-
/**
* Counter to generate unique mode suffixes.
*/
@@ -747,59 +745,10 @@
}
/**
- * <p>Compile the namesArray, urisArray, typesArray, namespaceArray,
- * namespaceAncestorsArray, prefixURIsIdxArray and prefixURIPairsArray into
+ * Compile the namesArray, urisArray and typesArray into
* the static initializer. They are read-only from the
* translet. All translet instances can share a single
- * copy of this informtion.</p>
- * <p>The <code>namespaceAncestorsArray</code>,
- * <code>prefixURIsIdxArray</code> and <code>prefixURIPairsArray</code>
- * contain namespace information accessible from the stylesheet:
- * <dl>
- * <dt><code>namespaceAncestorsArray</code></dt>
- * <dd>Array indexed by integer stylesheet node IDs containing node IDs of
- * the nearest ancestor node in the stylesheet with namespace
- * declarations or <code>-1</code> if there is no such ancestor. There
- * can be more than one disjoint tree of nodes - one for each stylesheet
- * module</dd>
- * <dt><code>prefixURIsIdxArray</code></dt>
- * <dd>Array indexed by integer stylesheet node IDs containing the index
- * into <code>prefixURIPairsArray</code> of the first namespace prefix
- * declared for the node. The values are stored in ascending order, so
- * the next value in this array (if any) can be used to find the last such
- * prefix-URI pair</dd>
- * <dt>prefixURIPairsArray</dt>
- * <dd>Array of pairs of namespace prefixes and URIs. A zero-length
- * string represents the default namespace if it appears as a prefix and
- * a namespace undeclaration if it appears as a URI.</dd>
- * </dl>
- * </p>
- * <p>For this stylesheet
- * <pre><code>
- * <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- * <xsl:template match="/">
- * <xsl:for-each select="*" xmlns:foo="foouri">
- * <xsl:element name="{n}" xmlns:foo="baruri">
- * </xsl:for-each>
- * <out xmlns="lumpit"/>
- * <xsl:element name="{n}" xmlns="foouri"/>
- * <xsl:element name="{n}" namespace="{ns}" xmlns="limpit"/gt;
- * </xsl:template>
- * </xsl:stylesheet>
- * </code></pre>
- * there will be four stylesheet nodes whose namespace information is
- * needed, and
- * <ul>
- * <li><code>namespaceAncestorsArray</code> will have the value
- * <code>[-1,0,1,0]</code>;</li>
- * <li><code>prefixURIsIdxArray</code> will have the value
- * <code>[0,4,6,8]</code>; and</li>
- * <li><code>prefixURIPairsArray</code> will have the value
- * <code>["xml","http://www.w3.org/XML/1998/namespace",
- * "xsl","http://www.w3.org/1999/XSL/Transform"
- * "foo","foouri","foo","baruri","","foouri"].</code></li>
- * </ul>
- * </p>
+ * copy of this informtion.
*/
private void compileStaticInitializer(ClassGenerator classGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
@@ -933,83 +882,6 @@
staticConst.markChunkEnd();
}
- // Put the tree of stylesheet namespace declarations into the translet
- final Vector namespaceAncestors = getXSLTC().getNSAncestorPointers();
- if (namespaceAncestors != null && namespaceAncestors.size() != 0) {
- addStaticField(classGen, NS_ANCESTORS_INDEX_SIG,
- STATIC_NS_ANCESTORS_ARRAY_FIELD);
- staticConst.markChunkStart();
- il.append(new PUSH(cpg, namespaceAncestors.size()));
- il.append(new NEWARRAY(BasicType.INT));
- int namespaceAncestorsArrayRef =
- cpg.addFieldref(_className, STATIC_NS_ANCESTORS_ARRAY_FIELD,
- NS_ANCESTORS_INDEX_SIG);
- il.append(new PUTSTATIC(namespaceAncestorsArrayRef));
- staticConst.markChunkEnd();
- for (int i = 0; i < namespaceAncestors.size(); i++) {
- int ancestor = ((Integer) namespaceAncestors.get(i)).intValue();
- staticConst.markChunkStart();
- il.append(new GETSTATIC(namespaceAncestorsArrayRef));
- il.append(new PUSH(cpg, i));
- il.append(new PUSH(cpg, ancestor));
- il.append(IASTORE);
- staticConst.markChunkEnd();
- }
- }
- // Put the array of indices into the namespace prefix/URI pairs array
- // into the translet
- final Vector prefixURIPairsIdx = getXSLTC().getPrefixURIPairsIdx();
- if (prefixURIPairsIdx != null && prefixURIPairsIdx.size() != 0) {
- addStaticField(classGen, PREFIX_URIS_IDX_SIG,
- STATIC_PREFIX_URIS_IDX_ARRAY_FIELD);
- staticConst.markChunkStart();
- il.append(new PUSH(cpg, prefixURIPairsIdx.size()));
- il.append(new NEWARRAY(BasicType.INT));
- int prefixURIPairsIdxArrayRef =
- cpg.addFieldref(_className,
- STATIC_PREFIX_URIS_IDX_ARRAY_FIELD,
- PREFIX_URIS_IDX_SIG);
- il.append(new PUTSTATIC(prefixURIPairsIdxArrayRef));
- staticConst.markChunkEnd();
- for (int i = 0; i < prefixURIPairsIdx.size(); i++) {
- int idx = ((Integer) prefixURIPairsIdx.get(i)).intValue();
- staticConst.markChunkStart();
- il.append(new GETSTATIC(prefixURIPairsIdxArrayRef));
- il.append(new PUSH(cpg, i));
- il.append(new PUSH(cpg, idx));
- il.append(IASTORE);
- staticConst.markChunkEnd();
- }
- }
-
- // Put the array of pairs of namespace prefixes and URIs into the
- // translet
- final Vector prefixURIPairs = getXSLTC().getPrefixURIPairs();
- if (prefixURIPairs != null && prefixURIPairs.size() != 0) {
- addStaticField(classGen, PREFIX_URIS_ARRAY_SIG,
- STATIC_PREFIX_URIS_ARRAY_FIELD);
-
- staticConst.markChunkStart();
- il.append(new PUSH(cpg, prefixURIPairs.size()));
- il.append(new ANEWARRAY(cpg.addClass(STRING)));
- int prefixURIPairsRef =
- cpg.addFieldref(_className,
- STATIC_PREFIX_URIS_ARRAY_FIELD,
- PREFIX_URIS_ARRAY_SIG);
- il.append(new PUTSTATIC(prefixURIPairsRef));
- staticConst.markChunkEnd();
- for (int i = 0; i < prefixURIPairs.size(); i++) {
- String prefixOrURI = (String) prefixURIPairs.get(i);
- staticConst.markChunkStart();
- il.append(new GETSTATIC(prefixURIPairsRef));
- il.append(new PUSH(cpg, i));
- il.append(new PUSH(cpg, prefixOrURI));
- il.append(AASTORE);
- staticConst.markChunkEnd();
- }
- }
-
-
// Grab all the literal text in the stylesheet and put it in a char[]
final int charDataCount = getXSLTC().getCharacterDataCount();
final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java
index 0ffcd21..9a59fe2 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java
@@ -160,7 +160,7 @@
private int _nsCounter = 0;
public String generateNamespacePrefix() {
- return(new String("ns"+(_nsCounter++)));
+ return("ns"+(_nsCounter++));
}
/**
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java
index 6a73406..a14aac6 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java
@@ -77,11 +77,6 @@
private int _line; // Source file line number
protected AttributesImpl _attributes = null; // Attributes of this element
private Hashtable _prefixMapping = null; // Namespace declarations
- public static final int UNKNOWN_STYLESHEET_NODE_ID = -1;
-
- // Records whether this node or any descendant needs to know the
- // in-scope namespaces at transform-time
- private int _nodeIDForStylesheetNSLookup = UNKNOWN_STYLESHEET_NODE_ID;
// Sentinel - used to denote unrecognised syntaxt tree nodes.
protected static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
@@ -756,35 +751,6 @@
il.append(SWAP);
il.append(methodGen.storeHandler());
}
- /**
- * Retrieve an ID to identify the namespaces in scope at this point in the
- * stylesheet
- * @return An <code>int</code> representing the node ID or <code>-1</code>
- * if no namespace declarations are in scope
- */
- protected final int getNodeIDForStylesheetNSLookup() {
- if (_nodeIDForStylesheetNSLookup == UNKNOWN_STYLESHEET_NODE_ID) {
- Hashtable prefixMapping = getPrefixMapping();
- int parentNodeID =
- (_parent != null) ? _parent.getNodeIDForStylesheetNSLookup()
- : UNKNOWN_STYLESHEET_NODE_ID;
-
- // If this node in the stylesheet has no namespace declarations of
- // its own, use the ID of the nearest ancestor element that does
- // have namespace declarations.
- if (prefixMapping == null) {
- _nodeIDForStylesheetNSLookup = parentNodeID;
- } else {
- // Inform the XSLTC object that we'll need to know about this
- // node's namespace declarations.
- _nodeIDForStylesheetNSLookup =
- getXSLTC().registerStylesheetPrefixMappingForRuntime(
- prefixMapping, parentNodeID);
- }
- }
-
- return _nodeIDForStylesheetNSLookup;
- }
/**
* Returns true if this expression/instruction depends on the context. By
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java
index 3f06a36..72164de 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java
@@ -108,10 +108,10 @@
(LocationPathPattern) _patterns.elementAt(i);
if (i == 0) {
- result.append("Testseq for kernel " + _kernelType)
+ result.append("Testseq for kernel ").append(_kernelType)
.append('\n');
}
- result.append(" pattern " + i + ": ")
+ result.append(" pattern ").append(i).append(": ")
.append(pattern.toString())
.append('\n');
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java
index 63549c2..edfa5a8 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java
@@ -157,8 +157,7 @@
if (col != -1) {
namespace = lookupNamespace(token.substring(0,col));
if (namespace != null) {
- elements.append(namespace+":"+
- token.substring(col+1,token.length()));
+ elements.append(namespace).append(':').append(token.substring(col + 1));
} else {
elements.append(token);
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java
index cbd32cb..e29915c 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java
@@ -33,7 +33,6 @@
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
@@ -118,9 +117,7 @@
private boolean _callsNodeset = false;
private boolean _multiDocument = false;
private boolean _hasIdCall = false;
- private Vector _stylesheetNSAncestorPointers;
- private Vector _prefixURIPairs;
- private Vector _prefixURIPairsIdx;
+
/**
* Set to true if template inlining is requested. Template
* inlining used to be the default, but we have found that
@@ -223,9 +220,6 @@
_attributeSetSerial = 0;
_multiDocument = false;
_hasIdCall = false;
- _stylesheetNSAncestorPointers = null;
- _prefixURIPairs = null;
- _prefixURIPairsIdx = null;
_numberFieldIndexes = new int[] {
-1, // LEVEL_SINGLE
-1, // LEVEL_MULTIPLE
@@ -714,20 +708,6 @@
* Registers a namespace and gives it a type so that it can be mapped to
* DOM namespace types at run-time.
*/
- public int registerNamespacePrefix(String name) {
- Integer code = (Integer)_namespacePrefixes.get(name);
- if (code == null) {
- code = new Integer(_nextGType++);
- _namespacePrefixes.put(name, code);
- _namesIndex.addElement("?"+name);
- }
- return code.intValue();
- }
-
- /**
- * Registers a namespace and gives it a type so that it can be mapped to
- * DOM namespace types at run-time.
- */
public int registerNamespace(String namespaceURI) {
Integer code = (Integer)_namespaces.get(namespaceURI);
if (code == null) {
@@ -738,66 +718,6 @@
return code.intValue();
}
- /**
- * Registers namespace declarations that the stylesheet might need to
- * look up dynamically - for instance, if an <code>xsl:element</code> has a
- * a <code>name</code> attribute with variable parts and has no
- * <code>namespace</code> attribute.
- *
- * @param prefixMap a <code>Hashtable</code> mapping namespace prefixes to
- * URIs. Must not be <code>null</code>. The default
- * namespace and namespace undeclarations are represented
- * by a zero-length string.
- * @param ancestorID The <code>int</code> node ID of the nearest ancestor in
- * the stylesheet that declares namespaces, or a value less
- * than zero if there is no such ancestor
- * @return A new node ID for the stylesheet element
- */
- public int registerStylesheetPrefixMappingForRuntime(Hashtable prefixMap,
- int ancestorID) {
- if (_stylesheetNSAncestorPointers == null) {
- _stylesheetNSAncestorPointers = new Vector();
- }
-
- if (_prefixURIPairs == null) {
- _prefixURIPairs = new Vector();
- }
-
- if (_prefixURIPairsIdx == null) {
- _prefixURIPairsIdx = new Vector();
- }
-
- int currentNodeID = _stylesheetNSAncestorPointers.size();
- _stylesheetNSAncestorPointers.add(new Integer(ancestorID));
-
- Iterator prefixMapIterator = prefixMap.entrySet().iterator();
- int prefixNSPairStartIdx = _prefixURIPairs.size();
- _prefixURIPairsIdx.add(new Integer(prefixNSPairStartIdx));
-
- while (prefixMapIterator.hasNext()) {
- Map.Entry entry = (Map.Entry) prefixMapIterator.next();
- String prefix = (String) entry.getKey();
- String uri = (String) entry.getValue();
- _prefixURIPairs.add(prefix);
- _prefixURIPairs.add(uri);
- }
-
- return currentNodeID;
- }
-
- public Vector getNSAncestorPointers() {
- return _stylesheetNSAncestorPointers;
- }
-
- public Vector getPrefixURIPairs() {
- return _prefixURIPairs;
- }
-
- public Vector getPrefixURIPairsIdx() {
- return _prefixURIPairsIdx;
- }
-
-
public int nextModeSerial() {
return _modeSerial++;
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java
index a4aa8c7..429cccd 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java
@@ -26,7 +26,6 @@
import com.sun.org.apache.bcel.internal.generic.ALOAD;
import com.sun.org.apache.bcel.internal.generic.ASTORE;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
-import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
import com.sun.org.apache.bcel.internal.generic.ICONST;
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
@@ -141,9 +140,6 @@
}
}
else {
- // name attribute contains variable parts. If there is no namespace
- // attribute, the generated code needs to be prepared to look up
- // any prefix in the stylesheet at run-time.
_namespace = (namespace == EMPTYSTRING) ? null :
new AttributeValueTemplate(namespace, parser, this);
}
@@ -255,34 +251,7 @@
_namespace.translate(classGen, methodGen);
}
else {
- // If name is an AVT and namespace is not specified, need to
- // look up any prefix in the stylesheet by calling
- // BasisLibrary.lookupStylesheetQNameNamespace(
- // name, stylesheetNode, ancestorsArray,
- // prefixURIsIndexArray, prefixURIPairsArray,
- // !ignoreDefaultNamespace)
- String transletClassName = getXSLTC().getClassName();
- il.append(DUP);
- il.append(new PUSH(cpg, getNodeIDForStylesheetNSLookup()));
- il.append(new GETSTATIC(cpg.addFieldref(
- transletClassName,
- STATIC_NS_ANCESTORS_ARRAY_FIELD,
- NS_ANCESTORS_INDEX_SIG)));
- il.append(new GETSTATIC(cpg.addFieldref(
- transletClassName,
- STATIC_PREFIX_URIS_IDX_ARRAY_FIELD,
- PREFIX_URIS_IDX_SIG)));
- il.append(new GETSTATIC(cpg.addFieldref(
- transletClassName,
- STATIC_PREFIX_URIS_ARRAY_FIELD,
- PREFIX_URIS_ARRAY_SIG)));
- // Default namespace is significant
- il.append(ICONST_0);
- il.append(
- new INVOKESTATIC(
- cpg.addMethodref(BASIS_LIBRARY_CLASS,
- LOOKUP_STYLESHEET_QNAME_NS_REF,
- LOOKUP_STYLESHEET_QNAME_NS_SIG)));
+ il.append(ACONST_NULL);
}
// Push additional arguments
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java
index a3c216a..1b1a80d 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java
@@ -269,7 +269,7 @@
*/
public String toString() {
String suffix = (_params == null) ?
- (null != _code ? new String(getErrorMessage()) : _message)
+ (null != _code ? getErrorMessage() : _message)
: MessageFormat.format(getErrorMessage(), _params);
return formatLine() + suffix;
}
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java
index c6f6119..9ba426f 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java
@@ -688,6 +688,7 @@
// Get the current number of local variable slots
int maxLocals = super.getMaxLocals();
+ int prevLocals = maxLocals;
// Get numer of actual variables
final LocalVariableGen[] localVars = super.getLocalVariables();
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
index 5973664..fc388d9 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
@@ -53,6 +53,7 @@
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;
@@ -1473,7 +1474,18 @@
// Handle case when prefix is not known at compile time
if (namespace == null || namespace.length() == 0) {
- runTimeError(NAMESPACE_PREFIX_ERR,prefix);
+ try {
+ // not sure if this line of code ever works
+ namespace = dom.lookupNamespace(node, prefix);
+ }
+ catch(RuntimeException e) {
+ handler.flushPending(); // need to flush or else can't get namespacemappings
+ NamespaceMappings nm = handler.getNamespaceMappings();
+ namespace = nm.lookupNamespace(prefix);
+ if (namespace == null) {
+ runTimeError(NAMESPACE_PREFIX_ERR,prefix);
+ }
+ }
}
handler.startElement(namespace, qname.substring(index+1),
@@ -1501,141 +1513,6 @@
}
/**
- * <p>Look up the namespace for a lexical QName using the namespace
- * declarations available at a particular location in the stylesheet.</p>
- * <p>See {@link org.apache.xalan.xsltc.compiler.Stylesheet#compileStaticInitializer(org.apache.xalan.xsltc.compiler.util.ClassGenerator)}
- * for more information about the <code>ancestorNodeIDs</code>,
- * <code>prefixURIsIndex</code> and <code>prefixURIPairs</code arrays.</p>
- *
- * @param lexicalQName The QName as a <code>java.lang.String</code>
- * @param stylesheetNodeID An <code>int</code> representing the element in
- * the stylesheet relative to which the namespace of
- * the lexical QName is to be determined
- * @param ancestorNodeIDs An <code>int</code> array, indexed by stylesheet
- * node IDs, containing the ID of the nearest ancestor
- * node in the stylesheet that has namespace
- * declarations, or <code>-1</code> if there is no
- * such ancestor
- * @param prefixURIsIndex An <code>int</code> array, indexed by stylesheet
- * node IDs, containing the index into the
- * <code>prefixURIPairs</code> array of the first
- * prefix declared on that stylesheet node
- * @param prefixURIPairs A <code>java.lang.String</code> array that contains
- * pairs of
- * @param ignoreDefault A <code>boolean</code> indicating whether any
- * default namespace decarlation should be considered
- * @return The namespace of the lexical QName or a zero-length string if
- * the QName is in no namespace or no namespace declaration for the
- * prefix of the QName was found
- */
- public static String lookupStylesheetQNameNamespace(String lexicalQName,
- int stylesheetNodeID,
- int[] ancestorNodeIDs,
- int[] prefixURIsIndex,
- String[] prefixURIPairs,
- boolean ignoreDefault) {
- String prefix = getPrefix(lexicalQName);
- String uri = "";
-
- if (prefix == null && !ignoreDefault) {
- prefix = "";
- }
-
- if (prefix != null) {
- // Loop from current node in the stylesheet to its ancestors
- nodeLoop:
- for (int currentNodeID = stylesheetNodeID;
- currentNodeID >= 0;
- currentNodeID = ancestorNodeIDs[currentNodeID]) {
- // Look at all declarations on the current stylesheet node
- // The prefixURIsIndex is an array of indices into the
- // prefixURIPairs array that are stored in ascending order.
- // The declarations for a node I are in elements
- // prefixURIsIndex[I] to prefixURIsIndex[I+1]-1 (or
- // prefixURIPairs.length-1 if I is the last node)
- int prefixStartIdx = prefixURIsIndex[currentNodeID];
- int prefixLimitIdx = (currentNodeID+1 < prefixURIsIndex.length)
- ? prefixURIsIndex[currentNodeID + 1]
- : prefixURIPairs.length;
-
- for (int prefixIdx = prefixStartIdx;
- prefixIdx < prefixLimitIdx;
- prefixIdx = prefixIdx + 2) {
- // Did we find the declaration of our prefix
- if (prefix.equals(prefixURIPairs[prefixIdx])) {
- uri = prefixURIPairs[prefixIdx+1];
- break nodeLoop;
- }
- }
- }
- }
-
- return uri;
- }
-
- /**
- * <p>Look up the namespace for a lexical QName using the namespace
- * declarations available at a particular location in the stylesheet and
- * return the expanded QName</p>
- * <p>See {@link org.apache.xalan.xsltc.compiler.Stylesheet#compileStaticInitializer(org.apache.xalan.xsltc.compiler.util.ClassGenerator)}
- * for more information about the <code>ancestorNodeIDs</code>,
- * <code>prefixURIsIndex</code> and <code>prefixURIPairs</code arrays.</p>
- *
- * @param lexicalQName The QName as a <code>java.lang.String</code>
- * @param stylesheetNodeID An <code>int</code> representing the element in
- * the stylesheet relative to which the namespace of
- * the lexical QName is to be determined
- * @param ancestorNodeIDs An <code>int</code> array, indexed by stylesheet
- * node IDs, containing the ID of the nearest ancestor
- * node in the stylesheet that has namespace
- * declarations, or <code>-1</code> if there is no
- * such ancestor
- * @param prefixURIsIndex An <code>int</code> array, indexed by stylesheet
- * node IDs, containing the index into the
- * <code>prefixURIPairs</code> array of the first
- * prefix declared on that stylesheet node
- * @param prefixURIPairs A <code>java.lang.String</code> array that contains
- * pairs of
- * @param ignoreDefault A <code>boolean</code> indicating whether any
- * default namespace decarlation should be considered
- * @return The expanded QName in the form "uri:localName" or just
- * "localName" if the QName is in no namespace or no namespace
- * declaration for the prefix of the QName was found
- */
- public static String expandStylesheetQNameRef(String lexicalQName,
- int stylesheetNodeID,
- int[] ancestorNodeIDs,
- int[] prefixURIsIndex,
- String[] prefixURIPairs,
- boolean ignoreDefault) {
- String expandedQName;
- String prefix = getPrefix(lexicalQName);
- String localName = (prefix != null)
- ? lexicalQName.substring(prefix.length()+1)
- : lexicalQName;
- String uri = lookupStylesheetQNameNamespace(lexicalQName,
- stylesheetNodeID,
- ancestorNodeIDs,
- prefixURIsIndex,
- prefixURIPairs,
- ignoreDefault);
-
- // Handle case when prefix is not resolved
- if (prefix != null && prefix.length() != 0
- && (uri == null || uri.length() == 0)) {
- runTimeError(NAMESPACE_PREFIX_ERR, prefix);
- }
-
- if (uri.length() == 0) {
- expandedQName = localName;
- } else {
- expandedQName = uri + ':' + localName;
- }
-
- return expandedQName;
- }
-
- /**
* This function is used in the execution of xsl:element
*/
public static String getPrefix(String qname) {
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java
index 12c9b51..e222e47 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java
@@ -294,7 +294,7 @@
for (i = 0; i <= max; i++) {
String s1 = k.nextElement().toString();
String s2 = e.nextElement().toString();
- buf.append(s1 + "=" + s2);
+ buf.append(s1).append('=').append(s2);
if (i < max) buf.append(", ");
}
buf.append("}");
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java
index 99a13e6..8308352 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/StringValueHandler.java
@@ -94,6 +94,7 @@
// Override the setEscaping method just to indicate that this class is
// aware that that method might be called.
public boolean setEscaping(boolean bool) {
+ boolean oldEscaping = m_escaping;
m_escaping = bool;
return bool;
diff --git a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java
index 8e1a6d8..568ed68 100644
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java
@@ -1268,7 +1268,7 @@
try {
// Argument to document function was: document('');
if (href.length() == 0) {
- href = new String(baseURI);
+ href = baseURI;
}
/*
diff --git a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
index 3bff3c8..c1ddeb6 100644
--- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
@@ -365,11 +365,6 @@
// shared context
- /** Shared declared entities.
- * XXX understand it more deeply, why are we doing this ?? Is it really required ?
- */
- protected Hashtable fDeclaredEntities;
-
protected XMLEntityStorage fEntityStorage ;
protected final Object [] defaultEncoding = new Object[]{"UTF-8", null};
@@ -409,24 +404,6 @@
} // <init>()
/**
- * Constructs an entity manager that shares the specified entity
- * declarations during each parse.
- * <p>
- * <strong>REVISIT:</strong> We might want to think about the "right"
- * way to expose the list of declared entities. For now, the knowledge
- * how to access the entity declarations is implicit.
- */
- public XMLEntityManager(XMLEntityManager entityManager) {
-
-
- // save shared entity declarations
- fDeclaredEntities = entityManager != null
- ? entityManager.getEntityStore().getDeclaredEntities() : null;
-
- setScannerVersion(Constants.XML_VERSION_1_0);
- } // <init>(XMLEntityManager)
-
- /**
* Adds an internal entity declaration.
* <p>
* <strong>Note:</strong> This method ignores subsequent entity
@@ -1111,7 +1088,7 @@
throws IOException, XNIException {
// was entity declared?
- Entity entity = (Entity)fEntityStorage.getDeclaredEntities().get(entityName);
+ Entity entity = (Entity)fEntityStorage.getEntity(entityName);
if (entity == null) {
if (fEntityHandler != null) {
String encoding = null;
@@ -1533,15 +1510,6 @@
}
}
- // copy declared entities
- if (fDeclaredEntities != null) {
- java.util.Enumeration keys = fDeclaredEntities.keys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- Object value = fDeclaredEntities.get(key);
- fEntities.put(key, value);
- }
- }
fEntityHandler = null;
// reset scanner
diff --git a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java
index d86209a..a0c999d 100644
--- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java
@@ -1051,11 +1051,10 @@
return fScanner.getCharacterData().toString();
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
- Hashtable ht = entityStore.getDeclaredEntities();
- Entity en = (Entity)ht.get(name);
- if(en == null)
- return null;
- if(en.isExternal())
+ Entity en = entityStore.getEntity(name);
+ if(en == null)
+ return null;
+ if(en.isExternal())
return ((Entity.ExternalEntity)en).entityLocation.getExpandedSystemId();
else
return ((Entity.InternalEntity)en).text;
@@ -1182,8 +1181,7 @@
return true;
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
- Hashtable ht = entityStore.getDeclaredEntities();
- Entity en =(Entity)ht.get(name);
+ Entity en = entityStore.getEntity(name);
if(en == null)
return false;
if(en.isExternal()){
@@ -1324,15 +1322,14 @@
protected List getEntityDecls(){
if(fEventType == XMLStreamConstants.DTD){
XMLEntityStorage entityStore = fEntityManager.getEntityStore();
- Hashtable ht = entityStore.getDeclaredEntities();
ArrayList list = null;
- if(ht != null){
+ if(entityStore.hasEntities()){
EntityDeclarationImpl decl = null;
- list = new ArrayList(ht.size());
- Enumeration enu = ht.keys();
+ list = new ArrayList(entityStore.getEntitySize());
+ Enumeration enu = entityStore.getEntityKeys();
while(enu.hasMoreElements()){
String key = (String)enu.nextElement();
- Entity en = (Entity)ht.get(key);
+ Entity en = (Entity)entityStore.getEntity(key);
decl = new EntityDeclarationImpl();
decl.setEntityName(key);
if(en.isExternal()){
diff --git a/jaxp/src/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java b/jaxp/src/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java
index 3f0f52e..a13d815 100644
--- a/jaxp/src/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java
+++ b/jaxp/src/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java
@@ -112,8 +112,16 @@
* to be recognized.
*/
public void addRecognizedFeatures(String[] featureIds) {
- if (featureIds == null) return;
- fRecognizedFeatures.addAll(Arrays.asList(featureIds));
+
+ // add recognized features
+ int featureIdsCount = featureIds != null ? featureIds.length : 0;
+ for (int i = 0; i < featureIdsCount; i++) {
+ String featureId = featureIds[i];
+ if (!fRecognizedFeatures.contains(featureId)) {
+ fRecognizedFeatures.add(featureId);
+ }
+ }
+
} // addRecognizedFeatures(String[])
/**
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java
index 82b9c26..58fae69 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java
@@ -844,12 +844,10 @@
break;
}
- StringBuffer sb=new StringBuffer();
- sb.append("["+nodeHandle+": "+typestring+
- "(0x"+Integer.toHexString(getExpandedTypeID(nodeHandle))+") "+
- getNodeNameX(nodeHandle)+" {"+getNamespaceURI(nodeHandle)+"}"+
- "=\""+ getNodeValue(nodeHandle)+"\"]");
- return sb.toString();
+ return "[" + nodeHandle + ": " + typestring +
+ "(0x" + Integer.toHexString(getExpandedTypeID(nodeHandle)) + ") " +
+ getNodeNameX(nodeHandle) + " {" + getNamespaceURI(nodeHandle) + "}" +
+ "=\"" + getNodeValue(nodeHandle) + "\"]";
}
// ========= DTM Implementation Control Functions. ==============
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java
index cee8474..0e871e0 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java
@@ -1725,7 +1725,7 @@
try
{
Node node = getNode(nodeHandle);
- treeWalker.traverse(node);
+ treeWalker.traverseFragment(node);
}
finally
{
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java
index ab138ef..99c05b9 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java
@@ -55,7 +55,7 @@
final class CharInfo
{
/** Given a character, lookup a String to output (e.g. a decorated entity reference). */
- private HashMap m_charToString = new HashMap();
+ private HashMap m_charToString;
/**
* The name of the HTML entities file.
@@ -72,42 +72,50 @@
"com.sun.org.apache.xml.internal.serializer.XMLEntities";
/** The horizontal tab character, which the parser should always normalize. */
- public static final char S_HORIZONAL_TAB = 0x09;
+ static final char S_HORIZONAL_TAB = 0x09;
/** The linefeed character, which the parser should always normalize. */
- public static final char S_LINEFEED = 0x0A;
+ static final char S_LINEFEED = 0x0A;
/** The carriage return character, which the parser should always normalize. */
- public static final char S_CARRIAGERETURN = 0x0D;
+ static final char S_CARRIAGERETURN = 0x0D;
+ static final char S_SPACE = 0x20;
+ static final char S_QUOTE = 0x22;
+ static final char S_LT = 0x3C;
+ static final char S_GT = 0x3E;
+ static final char S_NEL = 0x85;
+ static final char S_LINE_SEPARATOR = 0x2028;
/** This flag is an optimization for HTML entities. It false if entities
* other than quot (34), amp (38), lt (60) and gt (62) are defined
* in the range 0 to 127.
* @xsl.usage internal
*/
- final boolean onlyQuotAmpLtGt;
+ boolean onlyQuotAmpLtGt;
/** Copy the first 0,1 ... ASCII_MAX values into an array */
- private static final int ASCII_MAX = 128;
+ static final int ASCII_MAX = 128;
/** Array of values is faster access than a set of bits
- * to quickly check ASCII characters in attribute values.
+ * to quickly check ASCII characters in attribute values,
+ * the value is true if the character in an attribute value
+ * should be mapped to a String.
*/
- private boolean[] isSpecialAttrASCII = new boolean[ASCII_MAX];
+ private final boolean[] shouldMapAttrChar_ASCII;
/** Array of values is faster access than a set of bits
- * to quickly check ASCII characters in text nodes.
+ * to quickly check ASCII characters in text nodes,
+ * the value is true if the character in a text node
+ * should be mapped to a String.
*/
- private boolean[] isSpecialTextASCII = new boolean[ASCII_MAX];
-
- private boolean[] isCleanTextASCII = new boolean[ASCII_MAX];
+ private final boolean[] shouldMapTextChar_ASCII;
/** An array of bits to record if the character is in the set.
* Although information in this array is complete, the
* isSpecialAttrASCII array is used first because access to its values
* is common and faster.
*/
- private int array_of_bits[] = createEmptySetOfIntegers(65535);
+ private final int array_of_bits[];
// 5 for 32 bit words, 6 for 64 bit words ...
@@ -138,33 +146,38 @@
/**
- * Constructor that reads in a resource file that describes the mapping of
- * characters to entity references.
- * This constructor is private, just to force the use
- * of the getCharInfo(entitiesResource) factory
+ * A base constructor just to explicitly create the fields,
+ * with the exception of m_charToString which is handled
+ * by the constructor that delegates base construction to this one.
+ * <p>
+ * m_charToString is not created here only for performance reasons,
+ * to avoid creating a Hashtable that will be replaced when
+ * making a mutable copy, {@link #mutableCopyOf(CharInfo)}.
*
- * Resource files must be encoded in UTF-8 and can either be properties
- * files with a .properties extension assumed. Alternatively, they can
- * have the following form, with no particular extension assumed:
- *
- * <pre>
- * # First char # is a comment
- * Entity numericValue
- * quot 34
- * amp 38
- * </pre>
- *
- * @param entitiesResource Name of properties or resource file that should
- * be loaded, which describes that mapping of characters to entity
- * references.
*/
- private CharInfo(String entitiesResource, String method)
+ private CharInfo()
{
- this(entitiesResource, method, false);
+ this.array_of_bits = createEmptySetOfIntegers(65535);
+ this.firstWordNotUsed = 0;
+ this.shouldMapAttrChar_ASCII = new boolean[ASCII_MAX];
+ this.shouldMapTextChar_ASCII = new boolean[ASCII_MAX];
+ this.m_charKey = new CharKey();
+
+ // Not set here, but in a constructor that uses this one
+ // this.m_charToString = new Hashtable();
+
+ this.onlyQuotAmpLtGt = true;
+
+
+ return;
}
private CharInfo(String entitiesResource, String method, boolean internal)
{
+ // call the default constructor to create the fields
+ this();
+ m_charToString = new HashMap();
+
ResourceBundle entities = null;
boolean noExtraEntities = true;
@@ -190,12 +203,10 @@
String name = (String) keys.nextElement();
String value = entities.getString(name);
int code = Integer.parseInt(value);
- defineEntity(name, (char) code);
- if (extraEntity(code))
+ boolean extra = defineEntity(name, (char) code);
+ if (extra)
noExtraEntities = false;
}
- set(S_LINEFEED);
- set(S_CARRIAGERETURN);
} else {
InputStream is = null;
@@ -279,8 +290,8 @@
int code = Integer.parseInt(value);
- defineEntity(name, (char) code);
- if (extraEntity(code))
+ boolean extra = defineEntity(name, (char) code);
+ if (extra)
noExtraEntities = false;
}
}
@@ -289,8 +300,6 @@
}
is.close();
- set(S_LINEFEED);
- set(S_CARRIAGERETURN);
} catch (Exception e) {
throw new RuntimeException(
Utils.messages.createMessage(
@@ -308,31 +317,8 @@
}
}
- /* initialize the array isCleanTextASCII[] with a cache of values
- * for use by ToStream.character(char[], int , int)
- * and the array isSpecialTextASCII[] with the opposite values
- * (all in the name of performance!)
- */
- for (int ch = 0; ch <ASCII_MAX; ch++)
- if((((0x20 <= ch || (0x0A == ch || 0x0D == ch || 0x09 == ch)))
- && (!get(ch))) || ('"' == ch))
- {
- isCleanTextASCII[ch] = true;
- isSpecialTextASCII[ch] = false;
- }
- else {
- isCleanTextASCII[ch] = false;
- isSpecialTextASCII[ch] = true;
- }
-
-
-
onlyQuotAmpLtGt = noExtraEntities;
- // initialize the array with a cache of the BitSet values
- for (int i=0; i<ASCII_MAX; i++)
- isSpecialAttrASCII[i] = get(i);
-
/* Now that we've used get(ch) just above to initialize the
* two arrays we will change by adding a tab to the set of
* special chars for XML (but not HTML!).
@@ -344,8 +330,19 @@
*/
if (Method.XML.equals(method))
{
- isSpecialAttrASCII[S_HORIZONAL_TAB] = true;
+ // We choose not to escape the quotation mark as " in text nodes
+ shouldMapTextChar_ASCII[S_QUOTE] = false;
}
+
+ if (Method.HTML.equals(method)) {
+ // The XSLT 1.0 recommendation says
+ // "The html output method should not escape < characters occurring in attribute values."
+ // So we don't escape '<' in an attribute for HTML
+ shouldMapAttrChar_ASCII['<'] = false;
+
+ // We choose not to escape the quotation mark as " in text nodes.
+ shouldMapTextChar_ASCII[S_QUOTE] = false;
+ }
}
/**
@@ -353,23 +350,39 @@
* supplied. Nothing happens if the character reference is already defined.
* <p>Unlike internal entities, character references are a string to single
* character mapping. They are used to map non-ASCII characters both on
- * parsing and printing, primarily for HTML documents. '<amp;' is an
+ * parsing and printing, primarily for HTML documents. '&lt;' is an
* example of a character reference.</p>
*
* @param name The entity's name
* @param value The entity's value
+ * @return true if the mapping is not one of:
+ * <ul>
+ * <li> '<' to "<"
+ * <li> '>' to ">"
+ * <li> '&' to "&"
+ * <li> '"' to """
+ * </ul>
*/
- private void defineEntity(String name, char value)
+ private boolean defineEntity(String name, char value)
{
StringBuilder sb = new StringBuilder("&");
sb.append(name);
sb.append(';');
String entityString = sb.toString();
- defineChar2StringMapping(entityString, value);
+ boolean extra = defineChar2StringMapping(entityString, value);
+ return extra;
}
/**
+ * A utility object, just used to map characters to output Strings,
+ * needed because a HashMap needs to map an object as a key, not a
+ * Java primitive type, like a char, so this object gets around that
+ * and it is reusable.
+ */
+ private final CharKey m_charKey;
+
+ /**
* Map a character to a String. For example given
* the character '>' this method would return the fully decorated
* entity name "<".
@@ -400,21 +413,21 @@
/**
* Tell if the character argument that is from
- * an attribute value should have special treatment.
+ * an attribute value has a mapping to a String.
*
* @param value the value of a character that is in an attribute value
* @return true if the character should have any special treatment,
* such as when writing out attribute values,
- * or entity references.
+ * such as when writing out entity references.
* @xsl.usage internal
*/
- final boolean isSpecialAttrChar(int value)
+ final boolean shouldMapAttrChar(int value)
{
// for performance try the values in the boolean array first,
// this is faster access than the BitSet for common ASCII values
if (value < ASCII_MAX)
- return isSpecialAttrASCII[value];
+ return shouldMapAttrChar_ASCII[value];
// rather than java.util.BitSet, our private
// implementation is faster (and less general).
@@ -423,48 +436,27 @@
/**
* Tell if the character argument that is from a
- * text node should have special treatment.
+ * text node has a mapping to a String, for example
+ * to map '<' to "<".
*
* @param value the value of a character that is in a text node
- * @return true if the character should have any special treatment,
- * such as when writing out attribute values,
- * or entity references.
+ * @return true if the character has a mapping to a String,
+ * such as when writing out entity references.
* @xsl.usage internal
*/
- final boolean isSpecialTextChar(int value)
+ final boolean shouldMapTextChar(int value)
{
// for performance try the values in the boolean array first,
// this is faster access than the BitSet for common ASCII values
if (value < ASCII_MAX)
- return isSpecialTextASCII[value];
+ return shouldMapTextChar_ASCII[value];
// rather than java.util.BitSet, our private
// implementation is faster (and less general).
return get(value);
}
- /**
- * This method is used to determine if an ASCII character in
- * a text node (not an attribute value) is "clean".
- * @param value the character to check (0 to 127).
- * @return true if the character can go to the writer as-is
- * @xsl.usage internal
- */
- final boolean isTextASCIIClean(int value)
- {
- return isCleanTextASCII[value];
- }
-
-// In the future one might want to use the array directly and avoid
-// the method call, but I think the JIT alreay inlines this well enough
-// so don't do it (for now) - bjm
-// public final boolean[] getASCIIClean()
-// {
-// return isCleanTextASCII;
-// }
-
-
private static CharInfo getCharInfoBasedOnPrivilege(
final String entitiesFileName, final String method,
final boolean internal){
@@ -499,15 +491,17 @@
{
CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName);
if (charInfo != null) {
- return charInfo;
+ return mutableCopyOf(charInfo);
}
// try to load it internally - cache
try {
charInfo = getCharInfoBasedOnPrivilege(entitiesFileName,
method, true);
+ // Put the common copy of charInfo in the cache, but return
+ // a copy of it.
m_getCharInfoCache.put(entitiesFileName, charInfo);
- return charInfo;
+ return mutableCopyOf(charInfo);
} catch (Exception e) {}
// try to load it externally - do not cache
@@ -534,7 +528,41 @@
method, false);
}
- /** Table of user-specified char infos. */
+ /**
+ * Create a mutable copy of the cached one.
+ * @param charInfo The cached one.
+ * @return
+ */
+ private static CharInfo mutableCopyOf(CharInfo charInfo) {
+ CharInfo copy = new CharInfo();
+
+ int max = charInfo.array_of_bits.length;
+ System.arraycopy(charInfo.array_of_bits,0,copy.array_of_bits,0,max);
+
+ copy.firstWordNotUsed = charInfo.firstWordNotUsed;
+
+ max = charInfo.shouldMapAttrChar_ASCII.length;
+ System.arraycopy(charInfo.shouldMapAttrChar_ASCII,0,copy.shouldMapAttrChar_ASCII,0,max);
+
+ max = charInfo.shouldMapTextChar_ASCII.length;
+ System.arraycopy(charInfo.shouldMapTextChar_ASCII,0,copy.shouldMapTextChar_ASCII,0,max);
+
+ // utility field copy.m_charKey is already created in the default constructor
+
+ copy.m_charToString = (HashMap) charInfo.m_charToString.clone();
+
+ copy.onlyQuotAmpLtGt = charInfo.onlyQuotAmpLtGt;
+
+ return copy;
+ }
+
+ /**
+ * Table of user-specified char infos.
+ * The table maps entify file names (the name of the
+ * property file without the .properties extension)
+ * to CharInfo objects populated with entities defined in
+ * corresponding property file.
+ */
private static HashMap m_getCharInfoCache = new HashMap();
/**
@@ -576,7 +604,8 @@
* the creation of the set.
*/
private final void set(int i) {
- setASCIIdirty(i);
+ setASCIItextDirty(i);
+ setASCIIattrDirty(i);
int j = (i >> SHIFT_PER_WORD); // this word is used
int k = j + 1;
@@ -611,24 +640,43 @@
return in_the_set;
}
- // record if there are any entities other than
- // quot, amp, lt, gt (probably user defined)
/**
- * @return true if the entity
- * @param code The value of the character that has an entity defined
- * for it.
+ * This method returns true if there are some non-standard mappings to
+ * entities other than quot, amp, lt, gt, and its only purpose is for
+ * performance.
+ * @param charToMap The value of the character that is mapped to a String
+ * @param outputString The String to which the character is mapped, usually
+ * an entity reference such as "<".
+ * @return true if the mapping is not one of:
+ * <ul>
+ * <li> '<' to "<"
+ * <li> '>' to ">"
+ * <li> '&' to "&"
+ * <li> '"' to """
+ * </ul>
*/
- private boolean extraEntity(int entityValue)
+ private boolean extraEntity(String outputString, int charToMap)
{
boolean extra = false;
- if (entityValue < 128)
+ if (charToMap < ASCII_MAX)
{
- switch (entityValue)
+ switch (charToMap)
{
- case 34 : // quot
- case 38 : // amp
- case 60 : // lt
- case 62 : // gt
+ case '"' : // quot
+ if (!outputString.equals("""))
+ extra = true;
+ break;
+ case '&' : // amp
+ if (!outputString.equals("&"))
+ extra = true;
+ break;
+ case '<' : // lt
+ if (!outputString.equals("<"))
+ extra = true;
+ break;
+ case '>' : // gt
+ if (!outputString.equals(">"))
+ extra = true;
break;
default : // other entity in range 0 to 127
extra = true;
@@ -638,49 +686,61 @@
}
/**
- * If the character is a printable ASCII character then
- * mark it as not clean and needing replacement with
- * a String on output.
+ * If the character is in the ASCII range then
+ * mark it as needing replacement with
+ * a String on output if it occurs in a text node.
* @param ch
*/
- private void setASCIIdirty(int j)
+ private void setASCIItextDirty(int j)
{
if (0 <= j && j < ASCII_MAX)
{
- isCleanTextASCII[j] = false;
- isSpecialTextASCII[j] = true;
+ shouldMapTextChar_ASCII[j] = true;
}
}
/**
- * If the character is a printable ASCII character then
- * mark it as and not needing replacement with
- * a String on output.
+ * If the character is in the ASCII range then
+ * mark it as needing replacement with
+ * a String on output if it occurs in a attribute value.
* @param ch
*/
- private void setASCIIclean(int j)
+ private void setASCIIattrDirty(int j)
{
if (0 <= j && j < ASCII_MAX)
{
- isCleanTextASCII[j] = true;
- isSpecialTextASCII[j] = false;
+ shouldMapAttrChar_ASCII[j] = true;
}
}
- private void defineChar2StringMapping(String outputString, char inputChar)
+ /**
+ * Call this method to register a char to String mapping, for example
+ * to map '<' to "<".
+ * @param outputString The String to map to.
+ * @param inputChar The char to map from.
+ * @return true if the mapping is not one of:
+ * <ul>
+ * <li> '<' to "<"
+ * <li> '>' to ">"
+ * <li> '&' to "&"
+ * <li> '"' to """
+ * </ul>
+ */
+ boolean defineChar2StringMapping(String outputString, char inputChar)
{
CharKey character = new CharKey(inputChar);
m_charToString.put(character, outputString);
- set(inputChar);
+ set(inputChar); // mark the character has having a mapping to a String
+
+ boolean extraMapping = extraEntity(outputString, inputChar);
+ return extraMapping;
+
}
/**
* Simple class for fast lookup of char values, when used with
* hashtables. You can set the char, then use it as a key.
*
- * This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
- * It exists to cut the serializers dependancy on that package.
- *
* @xsl.usage internal
*/
private static class CharKey extends Object
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLSAXHandler.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLSAXHandler.java
index fd4801e..596a641 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLSAXHandler.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLSAXHandler.java
@@ -56,7 +56,7 @@
/**
* Keeps track of whether output escaping is currently enabled
*/
- protected boolean m_escapeSetting = false;
+ protected boolean m_escapeSetting = true;
/**
* Returns null.
@@ -742,6 +742,6 @@
*/
private void resetToHTMLSAXHandler()
{
- this.m_escapeSetting = false;
+ this.m_escapeSetting = true;
}
}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
index aa48eae..94fbce6 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
@@ -58,7 +58,7 @@
* Map that tells which XML characters should have special treatment, and it
* provides character to entity name lookup.
*/
- private static final CharInfo m_htmlcharInfo =
+ private final CharInfo m_htmlcharInfo =
// new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
CharInfo.getCharInfo(CharInfo.HTML_ENTITIES_RESOURCE, Method.HTML);
@@ -1369,7 +1369,7 @@
// System.out.println("ch: "+(int)ch);
// System.out.println("m_maxCharacter: "+(int)m_maxCharacter);
// System.out.println("m_attrCharsMap[ch]: "+(int)m_attrCharsMap[ch]);
- if (escapingNotNeeded(ch) && (!m_charInfo.isSpecialAttrChar(ch)))
+ if (escapingNotNeeded(ch) && (!m_charInfo.shouldMapAttrChar(ch)))
{
cleanLength++;
}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
index e09f680..16fb0bf 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java
@@ -919,7 +919,8 @@
{
// This is the old/fast code here, but is this
// correct for all encodings?
- if (ch >= 0x20 || (0x0A == ch || 0x0D == ch || 0x09 == ch))
+ if (ch >= CharInfo.S_SPACE || (CharInfo.S_LINEFEED == ch ||
+ CharInfo.S_CARRIAGERETURN == ch || CharInfo.S_HORIZONAL_TAB == ch))
ret= true;
else
ret = false;
@@ -1028,7 +1029,7 @@
*
* @throws java.io.IOException
*/
- protected int accumDefaultEntity(
+ int accumDefaultEntity(
java.io.Writer writer,
char ch,
int i,
@@ -1047,7 +1048,7 @@
{
// if this is text node character and a special one of those,
// or if this is a character from attribute value and a special one of those
- if ((fromTextNode && m_charInfo.isSpecialTextChar(ch)) || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch)))
+ if ((fromTextNode && m_charInfo.shouldMapTextChar(ch)) || (!fromTextNode && m_charInfo.shouldMapAttrChar(ch)))
{
String outputStringForChar = m_charInfo.getOutputStringForChar(ch);
@@ -1398,7 +1399,6 @@
if (m_cdataTagOpen)
closeCDATA();
- // the check with _escaping is a bit of a hack for XLSTC
if (m_disableOutputEscapingStates.peekOrFalse() || (!m_escaping))
{
@@ -1421,82 +1421,173 @@
try
{
int i;
- char ch1;
int startClean;
// skip any leading whitspace
// don't go off the end and use a hand inlined version
// of isWhitespace(ch)
final int end = start + length;
- int lastDirty = start - 1; // last character that needed processing
- for (i = start;
- ((i < end)
- && ((ch1 = chars[i]) == 0x20
- || (ch1 == 0xA && m_lineSepUse)
- || ch1 == 0xD
- || ch1 == 0x09));
- i++)
- {
- /*
- * We are processing leading whitespace, but are doing the same
- * processing for dirty characters here as for non-whitespace.
- *
- */
- if (!m_charInfo.isTextASCIIClean(ch1))
- {
- lastDirty = processDirty(chars,end, i,ch1, lastDirty, true);
- i = lastDirty;
+ int lastDirtyCharProcessed = start - 1; // last non-clean character that was processed
+ // that was processed
+ final Writer writer = m_writer;
+ boolean isAllWhitespace = true;
+
+ // process any leading whitspace
+ i = start;
+ while (i < end && isAllWhitespace) {
+ char ch1 = chars[i];
+
+ if (m_charInfo.shouldMapTextChar(ch1)) {
+ // The character is supposed to be replaced by a String
+ // so write out the clean whitespace characters accumulated
+ // so far
+ // then the String.
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ String outputStringForChar = m_charInfo
+ .getOutputStringForChar(ch1);
+ writer.write(outputStringForChar);
+ // We can't say that everything we are writing out is
+ // all whitespace, we just wrote out a String.
+ isAllWhitespace = false;
+ lastDirtyCharProcessed = i; // mark the last non-clean
+ // character processed
+ i++;
+ } else {
+ // The character is clean, but is it a whitespace ?
+ switch (ch1) {
+ // TODO: Any other whitespace to consider?
+ case CharInfo.S_SPACE:
+ // Just accumulate the clean whitespace
+ i++;
+ break;
+ case CharInfo.S_LINEFEED:
+ lastDirtyCharProcessed = processLineFeed(chars, i,
+ lastDirtyCharProcessed, writer);
+ i++;
+ break;
+ case CharInfo.S_CARRIAGERETURN:
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write(" ");
+ lastDirtyCharProcessed = i;
+ i++;
+ break;
+ case CharInfo.S_HORIZONAL_TAB:
+ // Just accumulate the clean whitespace
+ i++;
+ break;
+ default:
+ // The character was clean, but not a whitespace
+ // so break the loop to continue with this character
+ // (we don't increment index i !!)
+ isAllWhitespace = false;
+ break;
}
}
+ }
/* If there is some non-whitespace, mark that we may need
* to preserve this. This is only important if we have indentation on.
*/
- if (i < end)
+ if (i < end || !isAllWhitespace)
m_ispreserve = true;
-
-// int lengthClean; // number of clean characters in a row
-// final boolean[] isAsciiClean = m_charInfo.getASCIIClean();
-
- final boolean isXML10 = XMLVERSION10.equals(getVersion());
- // we've skipped the leading whitespace, now deal with the rest
for (; i < end; i++)
{
- {
- // A tight loop to skip over common clean chars
- // This tight loop makes it easier for the JIT
- // to optimize.
- char ch2;
- while (i<end
- && ((ch2 = chars[i])<127)
- && m_charInfo.isTextASCIIClean(ch2))
- i++;
- if (i == end)
- break;
- }
+ char ch = chars[i];
- final char ch = chars[i];
- /* The check for isCharacterInC0orC1Ranger and
- * isNELorLSEPCharacter has been added
- * to support Control Characters in XML 1.1
- */
- if (!isCharacterInC0orC1Range(ch) &&
- (isXML10 || !isNELorLSEPCharacter(ch)) &&
- (escapingNotNeeded(ch) && (!m_charInfo.isSpecialTextChar(ch)))
- || ('"' == ch))
- {
- ; // a character needing no special processing
+ if (m_charInfo.shouldMapTextChar(ch)) {
+ // The character is supposed to be replaced by a String
+ // e.g. '&' --> "&"
+ // e.g. '<' --> "<"
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ String outputStringForChar = m_charInfo.getOutputStringForChar(ch);
+ writer.write(outputStringForChar);
+ lastDirtyCharProcessed = i;
}
- else
- {
- lastDirty = processDirty(chars,end, i, ch, lastDirty, true);
- i = lastDirty;
+ else {
+ if (ch <= 0x1F) {
+ // Range 0x00 through 0x1F inclusive
+ //
+ // This covers the non-whitespace control characters
+ // in the range 0x1 to 0x1F inclusive.
+ // It also covers the whitespace control characters in the same way:
+ // 0x9 TAB
+ // 0xA NEW LINE
+ // 0xD CARRIAGE RETURN
+ //
+ // We also cover 0x0 ... It isn't valid
+ // but we will output "�"
+
+ // The default will handle this just fine, but this
+ // is a little performance boost to handle the more
+ // common TAB, NEW-LINE, CARRIAGE-RETURN
+ switch (ch) {
+
+ case CharInfo.S_HORIZONAL_TAB:
+ // Leave whitespace TAB as a real character
+ break;
+ case CharInfo.S_LINEFEED:
+ lastDirtyCharProcessed = processLineFeed(chars, i, lastDirtyCharProcessed, writer);
+ break;
+ case CharInfo.S_CARRIAGERETURN:
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write(" ");
+ lastDirtyCharProcessed = i;
+ // Leave whitespace carriage return as a real character
+ break;
+ default:
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ lastDirtyCharProcessed = i;
+ break;
+
+ }
+ }
+ else if (ch < 0x7F) {
+ // Range 0x20 through 0x7E inclusive
+ // Normal ASCII chars, do nothing, just add it to
+ // the clean characters
+
+ }
+ else if (ch <= 0x9F){
+ // Range 0x7F through 0x9F inclusive
+ // More control characters, including NEL (0x85)
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ lastDirtyCharProcessed = i;
+ }
+ else if (ch == CharInfo.S_LINE_SEPARATOR) {
+ // LINE SEPARATOR
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write("
");
+ lastDirtyCharProcessed = i;
+ }
+ else if (m_encodingInfo.isInEncoding(ch)) {
+ // If the character is in the encoding, and
+ // not in the normal ASCII range, we also
+ // just leave it get added on to the clean characters
+
+ }
+ else {
+ // This is a fallback plan, we should never get here
+ // but if the character wasn't previously handled
+ // (i.e. isn't in the encoding, etc.) then what
+ // should we do? We choose to write out an entity
+ writeOutCleanChars(chars, i, lastDirtyCharProcessed);
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ lastDirtyCharProcessed = i;
+ }
}
}
// we've reached the end. Any clean characters at the
// end of the array than need to be written out?
- startClean = lastDirty + 1;
+ startClean = lastDirtyCharProcessed + 1;
if (i > startClean)
{
int lengthClean = i - startClean;
@@ -1515,6 +1606,32 @@
if (m_tracer != null)
super.fireCharEvent(chars, start, length);
}
+
+ private int processLineFeed(final char[] chars, int i, int lastProcessed, final Writer writer) throws IOException {
+ if (!m_lineSepUse
+ || (m_lineSepLen ==1 && m_lineSep[0] == CharInfo.S_LINEFEED)){
+ // We are leaving the new-line alone, and it is just
+ // being added to the 'clean' characters,
+ // so the last dirty character processed remains unchanged
+ }
+ else {
+ writeOutCleanChars(chars, i, lastProcessed);
+ writer.write(m_lineSep, 0, m_lineSepLen);
+ lastProcessed = i;
+ }
+ return lastProcessed;
+ }
+
+ private void writeOutCleanChars(final char[] chars, int i, int lastProcessed) throws IOException {
+ int startClean;
+ startClean = lastProcessed + 1;
+ if (startClean < i)
+ {
+ int lengthClean = i - startClean;
+ m_writer.write(chars, startClean, lengthClean);
+ }
+ }
+
/**
* This method checks if a given character is between C0 or C1 range
* of Control characters.
@@ -1634,7 +1751,7 @@
*
* @throws org.xml.sax.SAXException
*/
- protected int accumDefaultEscape(
+ private int accumDefaultEscape(
Writer writer,
char ch,
int i,
@@ -1698,16 +1815,15 @@
* to write it out as Numeric Character Reference(NCR) regardless of XML Version
* being used for output document.
*/
- if (isCharacterInC0orC1Range(ch) ||
- (XMLVERSION11.equals(getVersion()) && isNELorLSEPCharacter(ch)))
+ if (isCharacterInC0orC1Range(ch) || isNELorLSEPCharacter(ch))
{
writer.write("&#");
writer.write(Integer.toString(ch));
writer.write(';');
}
else if ((!escapingNotNeeded(ch) ||
- ( (fromTextNode && m_charInfo.isSpecialTextChar(ch))
- || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch))))
+ ( (fromTextNode && m_charInfo.shouldMapTextChar(ch))
+ || (!fromTextNode && m_charInfo.shouldMapAttrChar(ch))))
&& m_elemContext.m_currentElemDepth > 0)
{
writer.write("&#");
@@ -1971,28 +2087,86 @@
string.getChars(0,len, m_attrBuff, 0);
final char[] stringChars = m_attrBuff;
- for (int i = 0; i < len; )
+ for (int i = 0; i < len;)
{
char ch = stringChars[i];
- if (escapingNotNeeded(ch) && (!m_charInfo.isSpecialAttrChar(ch)))
- {
- writer.write(ch);
- i++;
- }
- else
- { // I guess the parser doesn't normalize cr/lf in attributes. -sb
-// if ((CharInfo.S_CARRIAGERETURN == ch)
-// && ((i + 1) < len)
-// && (CharInfo.S_LINEFEED == stringChars[i + 1]))
-// {
-// i++;
-// ch = CharInfo.S_LINEFEED;
-// }
+ if (m_charInfo.shouldMapAttrChar(ch) || !(escapingNotNeeded(ch))) {
+ // The character is supposed to be replaced by a String
+ // e.g. '&' --> "&"
+ // e.g. '<' --> "<"
i = accumDefaultEscape(writer, ch, i, stringChars, len, false, true);
}
- }
+ else {
+ i++;
+ if (0x0 <= ch && ch <= 0x1F) {
+ // Range 0x00 through 0x1F inclusive
+ // This covers the non-whitespace control characters
+ // in the range 0x1 to 0x1F inclusive.
+ // It also covers the whitespace control characters in the same way:
+ // 0x9 TAB
+ // 0xA NEW LINE
+ // 0xD CARRIAGE RETURN
+ //
+ // We also cover 0x0 ... It isn't valid
+ // but we will output "�"
+ // The default will handle this just fine, but this
+ // is a little performance boost to handle the more
+ // common TAB, NEW-LINE, CARRIAGE-RETURN
+ switch (ch) {
+
+ case CharInfo.S_HORIZONAL_TAB:
+ writer.write("	");
+ break;
+ case CharInfo.S_LINEFEED:
+ writer.write(" ");
+ break;
+ case CharInfo.S_CARRIAGERETURN:
+ writer.write(" ");
+ break;
+ default:
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ break;
+
+ }
+ }
+ else if (ch < 0x7F) {
+ // Range 0x20 through 0x7E inclusive
+ // Normal ASCII chars
+ writer.write(ch);
+ }
+ else if (ch <= 0x9F){
+ // Range 0x7F through 0x9F inclusive
+ // More control characters
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ }
+ else if (ch == CharInfo.S_LINE_SEPARATOR) {
+ // LINE SEPARATOR
+ writer.write("
");
+ }
+ else if (m_encodingInfo.isInEncoding(ch)) {
+ // If the character is in the encoding, and
+ // not in the normal ASCII range, we also
+ // just write it out
+ writer.write(ch);
+ }
+ else {
+ // This is a fallback plan, we should never get here
+ // but if the character wasn't previously handled
+ // (i.e. isn't in the encoding, etc.) then what
+ // should we do? We choose to write out a character ref
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ }
+
+ }
+ }
}
/**
@@ -2219,13 +2393,14 @@
try
{
- if (shouldIndent())
- indent();
-
final int limit = start + length;
boolean wasDash = false;
if (m_cdataTagOpen)
closeCDATA();
+
+ if (shouldIndent())
+ indent();
+
final java.io.Writer writer = m_writer;
writer.write(COMMENT_BEGIN);
// Detect occurrences of two consecutive dashes, handle as necessary.
@@ -2258,6 +2433,15 @@
throw new SAXException(e);
}
+ /*
+ * Don't write out any indentation whitespace now,
+ * because there may be non-whitespace text after this.
+ *
+ * Simply mark that at this point if we do decide
+ * to indent that we should
+ * add a newline on the end of the current line before
+ * the indentation at the start of the next line.
+ */
m_startNewLine = true;
// time to generate comment event
if (m_tracer != null)
@@ -2506,7 +2690,7 @@
*/
protected boolean shouldIndent()
{
- return m_doIndent && (!m_ispreserve && !m_isprevtext);
+ return m_doIndent && (!m_ispreserve && !m_isprevtext) && m_elemContext.m_currentElemDepth > 0;
}
/**
@@ -2749,6 +2933,14 @@
closeCDATA();
m_cdataTagOpen = false;
}
+ if (m_writer != null) {
+ try {
+ m_writer.flush();
+ }
+ catch(IOException e) {
+ // what? me worry?
+ }
+ }
}
public void setContentHandler(ContentHandler ch)
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLSAXHandler.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLSAXHandler.java
index 6cdb591..7b165e4 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLSAXHandler.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLSAXHandler.java
@@ -50,7 +50,7 @@
/**
* Keeps track of whether output escaping is currently enabled
*/
- protected boolean m_escapeSetting = false;
+ protected boolean m_escapeSetting = true;
public ToXMLSAXHandler()
{
@@ -772,7 +772,7 @@
*/
private void resetToXMLSAXHandler()
{
- this.m_escapeSetting = false;
+ this.m_escapeSetting = true;
}
}
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
index b70e9e3..5263e91 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
@@ -56,7 +56,7 @@
* Map that tells which XML characters should have special treatment, and it
* provides character to entity name lookup.
*/
- private static CharInfo m_xmlcharInfo =
+ private CharInfo m_xmlcharInfo =
// new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
CharInfo.getCharInfo(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
@@ -160,8 +160,22 @@
writer.write('\"');
writer.write(standalone);
writer.write("?>");
- if (m_doIndent)
- writer.write(m_lineSep, 0, m_lineSepLen);
+ if (m_doIndent) {
+ if (m_standaloneWasSpecified
+ || getDoctypePublic() != null
+ || getDoctypeSystem() != null) {
+ // We almost never put a newline after the XML
+ // header because this XML could be used as
+ // an extenal general parsed entity
+ // and we don't know the context into which it
+ // will be used in the future. Only when
+ // standalone, or a doctype system or public is
+ // specified are we free to insert a new line
+ // after the header. Is it even worth bothering
+ // in these rare cases?
+ writer.write(m_lineSep, 0, m_lineSepLen);
+ }
+ }
}
catch(IOException e)
{
@@ -312,12 +326,15 @@
writer.write('?');
writer.write('>');
- // Always output a newline char if not inside of an
- // element. The whitespace is not significant in that
- // case.
- if (m_elemContext.m_currentElemDepth <= 0)
- writer.write(m_lineSep, 0, m_lineSepLen);
-
+ /*
+ * Don't write out any indentation whitespace now,
+ * because there may be non-whitespace text after this.
+ *
+ * Simply mark that at this point if we do decide
+ * to indent that we should
+ * add a newline on the end of the current line before
+ * the indentation at the start of the next line.
+ */
m_startNewLine = true;
}
catch(IOException e)
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/WriterToUTF8Buffered.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/WriterToUTF8Buffered.java
index f6b8bd8..b9291cc 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/WriterToUTF8Buffered.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/WriterToUTF8Buffered.java
@@ -204,10 +204,10 @@
*/
int split = length/CHARS_MAX;
final int chunks;
- if (split > 1)
- chunks = split;
+ if (length % CHARS_MAX > 0)
+ chunks = split + 1;
else
- chunks = 2;
+ chunks = split;
int end_chunk = start;
for (int chunk = 1; chunk <= chunks; chunk++)
{
@@ -339,10 +339,10 @@
final int start = 0;
int split = length/CHARS_MAX;
final int chunks;
- if (split > 1)
- chunks = split;
+ if (length % CHARS_MAX > 0)
+ chunks = split + 1;
else
- chunks = 2;
+ chunks = split;
int end_chunk = 0;
for (int chunk = 1; chunk <= chunks; chunk++)
{
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/serializer/utils/URI.java b/jaxp/src/com/sun/org/apache/xml/internal/serializer/utils/URI.java
index 0aa1307..8af2fd8 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/serializer/utils/URI.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/serializer/utils/URI.java
@@ -502,7 +502,7 @@
// if we get to this point, we need to resolve relative path
// RFC 2396 5.2 #6
- String path = new String();
+ String path = "";
String basePath = p_base.getPath();
// 6a - get all but the last segment of the base URI path
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/FastStringBuffer.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/FastStringBuffer.java
index 5a52304..b8b9a51 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/FastStringBuffer.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/FastStringBuffer.java
@@ -422,6 +422,7 @@
// We may have preallocated chunks. If so, all but last should
// be at full size.
+ boolean lastchunk = (m_lastChunk + 1 == m_array.length);
if (m_firstFree < m_chunkSize) // Simplified test single-character-fits
chunk = m_array[m_lastChunk];
@@ -1135,7 +1136,8 @@
boolean processingLeadingWhitespace =
((edgeTreatmentFlags & SUPPRESS_LEADING_WS) != 0);
boolean seenWhitespace = ((edgeTreatmentFlags & CARRY_WS) != 0);
-
+ boolean suppressTrailingWhitespace =
+ ((edgeTreatmentFlags & SUPPRESS_TRAILING_WS) != 0);
int currPos = start;
int limit = start+length;
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectPool.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectPool.java
index 79a5410..fb75bc4 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectPool.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectPool.java
@@ -22,7 +22,7 @@
*/
package com.sun.org.apache.xml.internal.utils;
-import java.util.Vector;
+import java.util.ArrayList;
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
import com.sun.org.apache.xml.internal.res.XMLMessages;
@@ -41,9 +41,9 @@
* @serial */
private final Class objectType;
- /** Vector of given objects this points to.
+ /** Stack of given objects this points to.
* @serial */
- private final Vector freeStack;
+ private final ArrayList freeStack;
/**
* Constructor ObjectPool
@@ -53,7 +53,7 @@
public ObjectPool(Class type)
{
objectType = type;
- freeStack = new Vector();
+ freeStack = new ArrayList();
}
/**
@@ -71,7 +71,7 @@
{
throw new WrappedRuntimeException(cnfe);
}
- freeStack = new Vector();
+ freeStack = new ArrayList();
}
@@ -85,7 +85,7 @@
public ObjectPool(Class type, int size)
{
objectType = type;
- freeStack = new Vector(size);
+ freeStack = new ArrayList(size);
}
/**
@@ -95,7 +95,7 @@
public ObjectPool()
{
objectType = null;
- freeStack = new Vector();
+ freeStack = new ArrayList();
}
/**
@@ -112,10 +112,7 @@
{
// Remove object from end of free pool.
- Object result = freeStack.lastElement();
-
- freeStack.setSize(freeStack.size() - 1);
-
+ Object result = freeStack.remove(freeStack.size() - 1);
return result;
}
@@ -150,10 +147,7 @@
{
// Remove object from end of free pool.
- Object result = freeStack.lastElement();
-
- freeStack.setSize(freeStack.size() - 1);
-
+ Object result = freeStack.remove(freeStack.size() - 1);
return result;
}
}
@@ -171,7 +165,7 @@
// Remove safety. -sb
// if (objectType.isInstance(obj))
// {
- freeStack.addElement(obj);
+ freeStack.add(obj);
// }
// else
// {
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java
index 3bfc1be..a26a006 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java
@@ -153,9 +153,25 @@
*/
public void traverse(Node pos) throws org.xml.sax.SAXException
{
-
this.m_contentHandler.startDocument();
+ traverseFragment(pos);
+
+ this.m_contentHandler.endDocument();
+ }
+
+ /**
+ * Perform a pre-order traversal non-recursive style.
+ *
+ * In contrast to the traverse() method this method will not issue
+ * startDocument() and endDocument() events to the SAX listener.
+ *
+ * @param pos Node in the tree where to start traversal
+ *
+ * @throws TransformerException
+ */
+ public void traverseFragment(Node pos) throws org.xml.sax.SAXException
+ {
Node top = pos;
while (null != pos)
@@ -191,7 +207,6 @@
pos = nextNode;
}
- this.m_contentHandler.endDocument();
}
/**
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/URI.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/URI.java
index 7ae2579..b2606a7 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/URI.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/URI.java
@@ -522,7 +522,7 @@
// if we get to this point, we need to resolve relative path
// RFC 2396 5.2 #6
- String path = new String();
+ String path = "";
String basePath = p_base.getPath();
// 6a - get all but the last segment of the base URI path
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLString.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLString.java
index ac96a6b..e8de6f3 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLString.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLString.java
@@ -127,7 +127,7 @@
/**
* Compares this string to the specified object.
* The result is <code>true</code> if and only if the argument is not
- * <code>null</code> and is a <code>String</code> object that represents
+ * <code>null</code> and is an <code>XMLString</code> object that represents
* the same sequence of characters as this object.
*
* @param anObject the object to compare this <code>String</code>
@@ -139,6 +139,20 @@
*/
public abstract boolean equals(XMLString anObject);
+ /**
+ * Compares this string to the specified <code>String</code>.
+ * The result is <code>true</code> if and only if the argument is not
+ * <code>null</code> and is a <code>String</code> object that represents
+ * the same sequence of characters as this object.
+ *
+ * @param anotherString the object to compare this <code>String</code>
+ * against.
+ * @return <code>true</code> if the <code>String</code>s are equal;
+ * <code>false</code> otherwise.
+ * @see java.lang.String#compareTo(java.lang.String)
+ * @see java.lang.String#equalsIgnoreCase(java.lang.String)
+ */
+ public abstract boolean equals(String anotherString);
/**
* Compares this string to the specified object.
diff --git a/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLStringDefault.java b/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLStringDefault.java
index e681aea..3953c86 100644
--- a/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLStringDefault.java
+++ b/jaxp/src/com/sun/org/apache/xml/internal/utils/XMLStringDefault.java
@@ -152,6 +152,22 @@
}
}
+ /**
+ * Compares this string to the specified <code>String</code>.
+ * The result is <code>true</code> if and only if the argument is not
+ * <code>null</code> and is a <code>String</code> object that represents
+ * the same sequence of characters as this object.
+ *
+ * @param obj2 the object to compare this <code>String</code> against.
+ * @return <code>true</code> if the <code>String</code>s are equal;
+ * <code>false</code> otherwise.
+ * @see java.lang.String#compareTo(java.lang.String)
+ * @see java.lang.String#equalsIgnoreCase(java.lang.String)
+ */
+ public boolean equals(String obj2) {
+ return m_str.equals(obj2);
+ }
+
/**
* Compares this string to the specified object.
* The result is <code>true</code> if and only if the argument is not
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/AxesWalker.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/AxesWalker.java
index 0369779..1834264 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/AxesWalker.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/AxesWalker.java
@@ -427,7 +427,7 @@
return -1;
}
- walker.setPredicateCount(walker.getPredicateCount() - 1);
+ walker.setPredicateCount(m_predicateIndex);
walker.setNextWalker(null);
walker.setPrevWalker(null);
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/BasicTestIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/BasicTestIterator.java
index 5740aff..cbea6db 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/BasicTestIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/BasicTestIterator.java
@@ -27,6 +27,7 @@
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
/**
* Base for iterators that handle predicates. Does the basic next
@@ -76,7 +77,7 @@
{
super(compiler, opPos, analysis, false);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
int whatToShow = compiler.getWhatToShow(firstStepPos);
if ((0 == (whatToShow
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java
index d8990af..729f89d 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java
@@ -31,7 +31,9 @@
import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
import com.sun.org.apache.xpath.internal.compiler.OpCodes;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
+import org.w3c.dom.DOMException;
/**
* This class implements an optimized iterator for
@@ -57,7 +59,7 @@
super(compiler, opPos, analysis, false);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
int stepType = compiler.getOp(firstStepPos);
boolean orSelf = (OpCodes.FROM_DESCENDANTS_OR_SELF == stepType);
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/IteratorPool.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/IteratorPool.java
index 4c8094d..ccaca31 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/IteratorPool.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/IteratorPool.java
@@ -22,7 +22,7 @@
*/
package com.sun.org.apache.xpath.internal.axes;
-import java.util.Vector;
+import java.util.ArrayList;
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
import com.sun.org.apache.xml.internal.utils.WrappedRuntimeException;
@@ -31,17 +31,19 @@
* Pool of object of a given type to pick from to help memory usage
* @xsl.usage internal
*/
-public class IteratorPool implements java.io.Serializable
+public final class IteratorPool implements java.io.Serializable
{
static final long serialVersionUID = -460927331149566998L;
- /** Type of objects in this pool.
- * @serial */
+ /**
+ * Type of objects in this pool.
+ */
private final DTMIterator m_orig;
- /** Vector of given objects this points to.
- * @serial */
- private final Vector m_freeStack;
+ /**
+ * Stack of given objects this points to.
+ */
+ private final ArrayList m_freeStack;
/**
* Constructor IteratorPool
@@ -51,7 +53,7 @@
public IteratorPool(DTMIterator original)
{
m_orig = original;
- m_freeStack = new Vector();
+ m_freeStack = new ArrayList();
}
/**
@@ -72,10 +74,7 @@
else
{
// Remove object from end of free pool.
- DTMIterator result = (DTMIterator)m_freeStack.lastElement();
-
- m_freeStack.setSize(m_freeStack.size() - 1);
-
+ DTMIterator result = (DTMIterator)m_freeStack.remove(m_freeStack.size() - 1);
return result;
}
}
@@ -104,10 +103,7 @@
else
{
// Remove object from end of free pool.
- DTMIterator result = (DTMIterator)m_freeStack.lastElement();
-
- m_freeStack.setSize(m_freeStack.size() - 1);
-
+ DTMIterator result = (DTMIterator)m_freeStack.remove(m_freeStack.size() - 1);
return result;
}
}
@@ -120,6 +116,6 @@
*/
public synchronized void freeInstance(DTMIterator obj)
{
- m_freeStack.addElement(obj);
+ m_freeStack.add(obj);
}
}
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/MatchPatternIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/MatchPatternIterator.java
index b7e3649..edba3a2 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/MatchPatternIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/MatchPatternIterator.java
@@ -28,6 +28,7 @@
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
import com.sun.org.apache.xpath.internal.objects.XObject;
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
import com.sun.org.apache.xpath.internal.patterns.StepPattern;
@@ -78,7 +79,7 @@
super(compiler, opPos, analysis, false);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0);
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIterator.java
index 9ec79e8..5390684 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIterator.java
@@ -29,6 +29,7 @@
import com.sun.org.apache.xpath.internal.Expression;
import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
/**
* This class implements a general iterator for
@@ -58,7 +59,7 @@
throws javax.xml.transform.TransformerException
{
super(compiler, opPos, analysis);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIteratorForward.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIteratorForward.java
index eb78eee..ea1a829 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIteratorForward.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIteratorForward.java
@@ -26,6 +26,7 @@
import com.sun.org.apache.xml.internal.dtm.DTMFilter;
import com.sun.org.apache.xpath.internal.Expression;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
/**
* This class implements a general iterator for
@@ -54,7 +55,7 @@
throws javax.xml.transform.TransformerException
{
super(compiler, opPos, analysis);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
m_axis = WalkerFactory.getAxisFromStep(compiler, firstStepPos);
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/SelfIteratorNoPredicate.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/SelfIteratorNoPredicate.java
index 55ec39a..f15c69f 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/SelfIteratorNoPredicate.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/SelfIteratorNoPredicate.java
@@ -78,6 +78,7 @@
return DTM.NULL;
int next;
+ DTM dtm = m_cdtm;
m_lastFetched = next = (DTM.NULL == m_lastFetched)
? m_context
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java
index ee448b0..c83f4e5 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java
@@ -30,6 +30,7 @@
import com.sun.org.apache.xpath.internal.XPathVisitor;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
import com.sun.org.apache.xpath.internal.compiler.OpCodes;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
/**
* This class extends NodeSetDTM, which implements DTMIterator,
@@ -160,7 +161,7 @@
super();
- opPos = compiler.getFirstChildPos(opPos);
+ opPos = OpMap.getFirstChildPos(opPos);
loadLocationPaths(compiler, opPos, 0);
}
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
index d406690..2f05535 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java
@@ -30,6 +30,7 @@
import com.sun.org.apache.xpath.internal.compiler.Compiler;
import com.sun.org.apache.xpath.internal.compiler.FunctionTable;
import com.sun.org.apache.xpath.internal.compiler.OpCodes;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
import com.sun.org.apache.xpath.internal.objects.XNumber;
import com.sun.org.apache.xpath.internal.patterns.ContextMatchStepPattern;
import com.sun.org.apache.xpath.internal.patterns.FunctionPattern;
@@ -162,7 +163,7 @@
throws javax.xml.transform.TransformerException
{
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
int analysis = analyze(compiler, firstStepPos, 0);
boolean isOneStep = isOneStep(analysis);
DTMIterator iter;
@@ -402,7 +403,7 @@
int opPos)
{
int endFunc = opPos + compiler.getOp(opPos + 1) - 1;
- opPos = compiler.getFirstChildPos(opPos);
+ opPos = OpMap.getFirstChildPos(opPos);
int funcID = compiler.getOp(opPos);
// System.out.println("funcID: "+funcID);
// System.out.println("opPos: "+opPos);
@@ -453,7 +454,7 @@
case OpCodes.OP_LT:
case OpCodes.OP_LTE:
case OpCodes.OP_EQUALS:
- int leftPos = compiler.getFirstChildPos(op);
+ int leftPos = OpMap.getFirstChildPos(op);
int rightPos = compiler.getNextOpPos(leftPos);
isProx = isProximateInnerExpr(compiler, leftPos);
if(isProx)
@@ -521,7 +522,7 @@
case OpCodes.OP_LT:
case OpCodes.OP_LTE:
case OpCodes.OP_EQUALS:
- int leftPos = compiler.getFirstChildPos(innerExprOpPos);
+ int leftPos = OpMap.getFirstChildPos(innerExprOpPos);
int rightPos = compiler.getNextOpPos(leftPos);
isProx = isProximateInnerExpr(compiler, leftPos);
if(isProx)
@@ -984,9 +985,7 @@
int stepType = compiler.getOp(opPos);
boolean simpleInit = false;
- int totalNumberWalkers = (analysis & BITS_COUNT);
boolean prevIsOneStepDown = true;
- int firstStepPos = compiler.getFirstChildPos(opPos);
int whatToShow = compiler.getWhatToShow(opPos);
StepPattern ai = null;
@@ -1286,7 +1285,7 @@
public static String getAnalysisString(int analysis)
{
StringBuffer buf = new StringBuffer();
- buf.append("count: "+getStepCount(analysis)+" ");
+ buf.append("count: ").append(getStepCount(analysis)).append(' ');
if((analysis & BIT_NODETEST_ANY) != 0)
{
buf.append("NTANY|");
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkingIterator.java b/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkingIterator.java
index c78fc96..08502fe 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkingIterator.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkingIterator.java
@@ -29,6 +29,7 @@
import com.sun.org.apache.xpath.internal.VariableStack;
import com.sun.org.apache.xpath.internal.XPathVisitor;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
+import com.sun.org.apache.xpath.internal.compiler.OpMap;
/**
* Location path iterator that uses Walkers.
@@ -58,7 +59,7 @@
{
super(compiler, opPos, analysis, shouldLoadWalkers);
- int firstStepPos = compiler.getFirstChildPos(opPos);
+ int firstStepPos = OpMap.getFirstChildPos(opPos);
if (shouldLoadWalkers)
{
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java b/jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java
index 88b4c8b..f0cfa94 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java
@@ -242,7 +242,7 @@
else
{
throw new RuntimeException(
- XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object[]{new Integer(stepType).toString()}));
+ XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNKNOWN_STEP, new Object[]{String.valueOf(stepType)}));
//"Programmer's assertion in getNextStepPos: unknown stepType: " + stepType);
}
}
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/objects/XString.java b/jaxp/src/com/sun/org/apache/xpath/internal/objects/XString.java
index 19db24a..0ff2b55 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/objects/XString.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/objects/XString.java
@@ -321,6 +321,22 @@
return xstr().equals(obj2.xstr());
}
+ /**
+ * Compares this string to the specified <code>String</code>.
+ * The result is <code>true</code> if and only if the argument is not
+ * <code>null</code> and is a <code>String</code> object that represents
+ * the same sequence of characters as this object.
+ *
+ * @param obj2 the object to compare this <code>String</code> against.
+ * @return <code>true</code> if the <code>String</code>s are equal;
+ * <code>false</code> otherwise.
+ * @see java.lang.String#compareTo(java.lang.String)
+ * @see java.lang.String#equalsIgnoreCase(java.lang.String)
+ */
+ public boolean equals(String obj2) {
+ return str().equals(obj2);
+ }
+
/**
* Compares this string to the specified object.
* The result is <code>true</code> if and only if the argument is not
@@ -336,11 +352,14 @@
*/
public boolean equals(XMLString obj2)
{
-
- if (!obj2.hasString())
- return obj2.equals(this);
- else
- return str().equals(obj2.toString());
+ if (obj2 != null) {
+ if (!obj2.hasString()) {
+ return obj2.equals(str());
+ } else {
+ return str().equals(obj2.toString());
+ }
+ }
+ return false;
}
/**
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/objects/XStringForFSB.java b/jaxp/src/com/sun/org/apache/xpath/internal/objects/XStringForFSB.java
index 34535d7..d631064 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/objects/XStringForFSB.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/objects/XStringForFSB.java
@@ -979,7 +979,7 @@
return Double.NaN;
try {
- return new Double(valueString).doubleValue();
+ return Double.parseDouble(valueString);
} catch (NumberFormatException nfe) {
// This should catch double periods, empty strings.
return Double.NaN;
diff --git a/jaxp/src/com/sun/org/apache/xpath/internal/patterns/StepPattern.java b/jaxp/src/com/sun/org/apache/xpath/internal/patterns/StepPattern.java
index 1290859..ce4b3af 100644
--- a/jaxp/src/com/sun/org/apache/xpath/internal/patterns/StepPattern.java
+++ b/jaxp/src/com/sun/org/apache/xpath/internal/patterns/StepPattern.java
@@ -857,7 +857,7 @@
}
else
{
- buf.append("?" + Integer.toHexString(pat.m_whatToShow));
+ buf.append('?').append(Integer.toHexString(pat.m_whatToShow));
}
if (null != pat.m_predicates)
diff --git a/jaxp/src/com/sun/xml/internal/stream/XMLEntityStorage.java b/jaxp/src/com/sun/xml/internal/stream/XMLEntityStorage.java
index fd85c30..8343d9b 100644
--- a/jaxp/src/com/sun/xml/internal/stream/XMLEntityStorage.java
+++ b/jaxp/src/com/sun/xml/internal/stream/XMLEntityStorage.java
@@ -36,6 +36,7 @@
import com.sun.org.apache.xerces.internal.impl.PropertyManager;
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
import com.sun.org.apache.xerces.internal.impl.Constants;
+import java.util.Enumeration;
/**
*
@@ -129,19 +130,27 @@
} // reset(XMLComponentManager)
/**
- * Returns the hashtable of declared entities.
- * <p>
- * <strong>REVISIT:</strong>
- * This should be done the "right" way by designing a better way to
- * enumerate the declared entities. For now, this method is needed
- * by the constructor that takes an XMLEntityManager parameter.
- * XXX Making this method public, return all the declared entities.
- * @return Hashtable hastable containing all the declared entities.
+ * Returns entity declaration.
+ *
+ * @param name The name of the entity.
+ *
+ * @see SymbolTable
*/
- public Hashtable getDeclaredEntities() {
- return fEntities;
- } // getDeclaredEntities():Hashtable
+ public Entity getEntity(String name) {
+ return (Entity)fEntities.get(name);
+ } // getEntity(String)
+ public boolean hasEntities() {
+ return (fEntities!=null);
+ } // getEntity(String)
+
+ public int getEntitySize() {
+ return fEntities.size();
+ } // getEntity(String)
+
+ public Enumeration getEntityKeys() {
+ return fEntities.keys();
+ }
/**
* Adds an internal entity declaration.
* <p>
diff --git a/jaxp/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java b/jaxp/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java
index 9a64859..30bee23 100644
--- a/jaxp/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java
+++ b/jaxp/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java
@@ -384,6 +384,8 @@
fElementStack.clear();
fInternalNamespaceContext.reset();
fReuse = true;
+ fStartTagOpened = false;
+ fNamespaceContext.userContext = null;
}
/**
diff --git a/jaxp/src/javax/xml/parsers/FactoryFinder.java b/jaxp/src/javax/xml/parsers/FactoryFinder.java
index 970820e..43a6e02 100644
--- a/jaxp/src/javax/xml/parsers/FactoryFinder.java
+++ b/jaxp/src/javax/xml/parsers/FactoryFinder.java
@@ -25,15 +25,12 @@
package javax.xml.parsers;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.net.URL;
+import java.util.Properties;
/**
* <p>Implements pluggable Datatypes.</p>
@@ -42,6 +39,7 @@
* sync. It is package private for secure class loading.</p>
*
* @author Santiago.PericasGeertsen@sun.com
+ * @author Huizhe.Wang@oracle.com
*/
class FactoryFinder {
@@ -95,18 +93,24 @@
* If the class loader supplied is <code>null</code>, first try using the
* context class loader followed by the current (i.e. bootstrap) class
* loader.
+ *
+ * Use bootstrap classLoader if cl = null and useBSClsLoader is true
*/
static private Class getProviderClass(String className, ClassLoader cl,
- boolean doFallback) throws ClassNotFoundException
+ boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException
{
try {
if (cl == null) {
- cl = ss.getContextClassLoader();
- if (cl == null) {
- throw new ClassNotFoundException();
- }
- else {
- return cl.loadClass(className);
+ if (useBSClsLoader) {
+ return Class.forName(className, true, FactoryFinder.class.getClassLoader());
+ } else {
+ cl = ss.getContextClassLoader();
+ if (cl == null) {
+ throw new ClassNotFoundException();
+ }
+ else {
+ return cl.loadClass(className);
+ }
}
}
else {
@@ -131,8 +135,8 @@
* @param className Name of the concrete class corresponding to the
* service provider
*
- * @param cl ClassLoader to use to load the class, null means to use
- * the bootstrap ClassLoader
+ * @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
+ * current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @param doFallback True if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
@@ -140,8 +144,30 @@
static Object newInstance(String className, ClassLoader cl, boolean doFallback)
throws ConfigurationError
{
+ return newInstance(className, cl, doFallback, false);
+ }
+
+ /**
+ * Create an instance of a class. Delegates to method
+ * <code>getProviderClass()</code> in order to load the class.
+ *
+ * @param className Name of the concrete class corresponding to the
+ * service provider
+ *
+ * @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
+ * current <code>Thread</code>'s context classLoader is used to load the factory class.
+ *
+ * @param doFallback True if the current ClassLoader should be tried as
+ * a fallback if the class is not found using cl
+ *
+ * @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter
+ * is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader.
+ */
+ static Object newInstance(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader)
+ throws ConfigurationError
+ {
try {
- Class providerClass = getProviderClass(className, cl, doFallback);
+ Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader);
Object instance = providerClass.newInstance();
if (debug) { // Extra check to avoid computing cl strings
dPrint("created new instance of " + providerClass +
@@ -244,6 +270,7 @@
// First try the Context ClassLoader
ClassLoader cl = ss.getContextClassLoader();
+ boolean useBSClsLoader = false;
if (cl != null) {
is = ss.getResourceAsStream(cl, serviceId);
@@ -251,11 +278,13 @@
if (is == null) {
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
+ useBSClsLoader = true;
}
} else {
// No Context ClassLoader, try the current ClassLoader
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
+ useBSClsLoader = true;
}
if (is == null) {
@@ -293,7 +322,7 @@
// ClassLoader because we want to avoid the case where the
// resource file was found using one ClassLoader and the
// provider class was instantiated using a different one.
- return newInstance(factoryClassName, cl, false);
+ return newInstance(factoryClassName, cl, false, useBSClsLoader);
}
// No provider found
diff --git a/jaxp/src/javax/xml/transform/FactoryFinder.java b/jaxp/src/javax/xml/transform/FactoryFinder.java
index 8abe2a4..b0c6d9a 100644
--- a/jaxp/src/javax/xml/transform/FactoryFinder.java
+++ b/jaxp/src/javax/xml/transform/FactoryFinder.java
@@ -25,16 +25,13 @@
package javax.xml.transform;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
-import java.net.URL;
+import java.util.Properties;
/**
* <p>Implements pluggable Datatypes.</p>
@@ -43,6 +40,7 @@
* sync. It is package private for secure class loading.</p>
*
* @author Santiago.PericasGeertsen@sun.com
+ * @author Huizhe.Wang@oracle.com
*/
class FactoryFinder {
@@ -96,18 +94,24 @@
* If the class loader supplied is <code>null</code>, first try using the
* context class loader followed by the current (i.e. bootstrap) class
* loader.
+ *
+ * Use bootstrap classLoader if cl = null and useBSClsLoader is true
*/
static private Class getProviderClass(String className, ClassLoader cl,
- boolean doFallback) throws ClassNotFoundException
+ boolean doFallback, boolean useBSClsLoader) throws ClassNotFoundException
{
try {
if (cl == null) {
- cl = ss.getContextClassLoader();
- if (cl == null) {
- throw new ClassNotFoundException();
- }
- else {
- return cl.loadClass(className);
+ if (useBSClsLoader) {
+ return Class.forName(className, true, FactoryFinder.class.getClassLoader());
+ } else {
+ cl = ss.getContextClassLoader();
+ if (cl == null) {
+ throw new ClassNotFoundException();
+ }
+ else {
+ return cl.loadClass(className);
+ }
}
}
else {
@@ -132,8 +136,8 @@
* @param className Name of the concrete class corresponding to the
* service provider
*
- * @param cl ClassLoader to use to load the class, null means to use
- * the bootstrap ClassLoader
+ * @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
+ * current <code>Thread</code>'s context classLoader is used to load the factory class.
*
* @param doFallback True if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
@@ -141,13 +145,32 @@
static Object newInstance(String className, ClassLoader cl, boolean doFallback)
throws ConfigurationError
{
- return newInstance(className, cl, doFallback, false);
+ return newInstance(className, cl, doFallback, false, false);
}
- static Object newInstance(String className, ClassLoader cl, boolean doFallback, boolean useServicesMechanism)
+
+ /**
+ * Create an instance of a class. Delegates to method
+ * <code>getProviderClass()</code> in order to load the class.
+ *
+ * @param className Name of the concrete class corresponding to the
+ * service provider
+ *
+ * @param cl <code>ClassLoader</code> used to load the factory class. If <code>null</code>
+ * current <code>Thread</code>'s context classLoader is used to load the factory class.
+ *
+ * @param doFallback True if the current ClassLoader should be tried as
+ * a fallback if the class is not found using cl
+ *
+ * @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter
+ * is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader.
+ *
+ * @param useServicesMechanism True use services mechanism
+ */
+ static Object newInstance(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader, boolean useServicesMechanism)
throws ConfigurationError
{
try {
- Class providerClass = getProviderClass(className, cl, doFallback);
+ Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader);
Object instance = null;
if (!useServicesMechanism) {
instance = newInstanceNoServiceLoader(providerClass);
@@ -215,7 +238,7 @@
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
dPrint("found system property, value=" + systemProp);
- return newInstance(systemProp, null, true, true);
+ return newInstance(systemProp, null, true, false, true);
}
}
catch (SecurityException se) {
@@ -243,7 +266,7 @@
if (factoryClassName != null) {
dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
- return newInstance(factoryClassName, null, true, true);
+ return newInstance(factoryClassName, null, true, false, true);
}
}
catch (Exception ex) {
@@ -261,7 +284,7 @@
}
dPrint("loaded from fallback value: " + fallbackClassName);
- return newInstance(fallbackClassName, null, true, true);
+ return newInstance(fallbackClassName, null, true, false, true);
}
/*
@@ -277,6 +300,7 @@
// First try the Context ClassLoader
ClassLoader cl = ss.getContextClassLoader();
+ boolean useBSClsLoader = false;
if (cl != null) {
is = ss.getResourceAsStream(cl, serviceId);
@@ -284,11 +308,13 @@
if (is == null) {
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
- }
+ useBSClsLoader = true;
+ }
} else {
// No Context ClassLoader, try the current ClassLoader
cl = FactoryFinder.class.getClassLoader();
is = ss.getResourceAsStream(cl, serviceId);
+ useBSClsLoader = true;
}
if (is == null) {
@@ -326,7 +352,7 @@
// ClassLoader because we want to avoid the case where the
// resource file was found using one ClassLoader and the
// provider class was instantiated using a different one.
- return newInstance(factoryClassName, cl, false, true);
+ return newInstance(factoryClassName, cl, false, useBSClsLoader, true);
}
// No provider found