morten 01/08/20 07:50:32
Modified: java/src/org/apache/xalan/xsltc TransletOutputHandler.java
java/src/org/apache/xalan/xsltc/compiler Variable.java
VariableRef.java VariableRefBase.java
java/src/org/apache/xalan/xsltc/compiler/util
MultiHashtable.java
java/src/org/apache/xalan/xsltc/dom DOMImpl.java
java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
TextOutput.java TransletOutputBase.java
Log:
Added element/attribute prefix information in the internal DOM.
This should fix some problems we have had with the copy and copy-of
elements. Added a few lines of code in an attempt to speed up the DOM builder.
PR: n/a
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.6 +1 -2
xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java
Index: TransletOutputHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/TransletOutputHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransletOutputHandler.java 2001/08/16 12:29:19 1.5
+++ TransletOutputHandler.java 2001/08/20 14:50:32 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransletOutputHandler.java,v 1.5 2001/08/16 12:29:19 morten Exp $
+ * @(#)$Id: TransletOutputHandler.java,v 1.6 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -78,7 +78,6 @@
public void attribute(String attributeName, String attributeValue)
throws TransletException;
public void namespace(String prefix, String uri) throws TransletException;
- public String getPrefix(String uri) throws TransletException;
public void comment(String comment) throws TransletException;
public void processingInstruction(String target, String data)
throws TransletException;
1.12 +5 -1 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java
Index: Variable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Variable.java 2001/07/31 09:11:51 1.11
+++ Variable.java 2001/08/20 14:50:32 1.12
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Variable.java,v 1.11 2001/07/31 09:11:51 morten Exp $
+ * @(#)$Id: Variable.java,v 1.12 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -194,6 +194,10 @@
_type = Type.ResultTree;
}
}
+
+ // The return type is void as the variable element does not leave
+ // anything on the JVM's stack. The '_type' global will be returned
+ // by the references to this variable, and not by the variable itself.
return Type.Void;
}
1.5 +15 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java
Index: VariableRef.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRef.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- VariableRef.java 2001/07/31 09:11:51 1.4
+++ VariableRef.java 2001/08/20 14:50:32 1.5
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: VariableRef.java,v 1.4 2001/07/31 09:11:51 morten Exp $
+ * @(#)$Id: VariableRef.java,v 1.5 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -78,11 +78,21 @@
}
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
- if (_variable.isLocal()) {
- if (_escaped = isEscaped())
- ((Variable)_variable).setEscapes();
+ if ( (_variable.isLocal()) && (_escaped = isEscaped()) )
+ ((Variable)_variable).setEscapes();
+
+ // Attempt to get the cached variable type
+ _type = _variable.getType();
+
+ // If that does not work we must force a type-check (this is normally
+ // only needed for globals in included/imported stylesheets
+ if (_type == null) {
+ _variable.typeCheck(stable);
+ _type = _variable.getType();
}
- return _type = _variable.getType();
+
+ // Return the type of the referenced variable
+ return _type;
}
private boolean isEscaped() {
1.2 +19 -2
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRefBase.java
Index: VariableRefBase.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableRefBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VariableRefBase.java 2001/07/31 09:13:13 1.1
+++ VariableRefBase.java 2001/08/20 14:50:32 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: VariableRefBase.java,v 1.1 2001/07/31 09:13:13 morten Exp $
+ * @(#)$Id: VariableRefBase.java,v 1.2 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,17 +68,34 @@
class VariableRefBase extends Expression {
- protected final VariableBase _variable;
+ protected final VariableBase _variable; // Reference to the associated var.
+ /**
+ * Created a new variable or parameter reference. Note that this base-
+ * class is not here mostly because variable and parameter references share
+ * a lot of functionality. The base class is needed more for having a
+ * single class to run 'if (instanceof)' on in the compiler code. The same
+ * holds for the variable base class.
+ * @param variable The referenced variable
+ */
public VariableRefBase(VariableBase variable) {
_variable = variable;
variable.addReference(this);
}
+ /**
+ * Returns a reference to the associated variable
+ * @return The referenced variable
+ */
public VariableBase getVariable() {
return(_variable);
}
+ /**
+ * Returns a string representation of this variable reference on the
+ * format 'variable-ref(<var-name>)'.
+ * @return Variable reference description
+ */
public String toString() {
return "variable-ref(" + _variable.getName() + ')';
}
1.2 +2 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MultiHashtable.java
Index: MultiHashtable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/MultiHashtable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MultiHashtable.java 2001/04/17 18:52:17 1.1
+++ MultiHashtable.java 2001/08/20 14:50:32 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: MultiHashtable.java,v 1.1 2001/04/17 18:52:17 sboag Exp $
+ * @(#)$Id: MultiHashtable.java,v 1.2 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -76,6 +76,7 @@
}
public boolean maps(Object from, Object to) {
+ if (from == null) return false;
final Vector vector = (Vector) get(from);
if (vector != null) {
final int n = vector.size();
1.20 +217 -150 xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
Index: DOMImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DOMImpl.java 2001/08/16 12:06:45 1.19
+++ DOMImpl.java 2001/08/20 14:50:32 1.20
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DOMImpl.java,v 1.19 2001/08/16 12:06:45 morten Exp $
+ * @(#)$Id: DOMImpl.java,v 1.20 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -128,8 +128,10 @@
private char[] _text;
// Namespace related stuff
- private String[] _nsNamesArray;
+ private String[] _uriArray;
+ private String[] _prefixArray;
private short[] _namespace;
+ private short[] _prefix;
private Hashtable _nsIndex = new Hashtable();
// Tracks which textnodes are whitespaces and which are not
@@ -162,7 +164,7 @@
* Returns 'true' if a specific node is an element (of any type)
*/
private boolean isElement(final int node) {
- return ((node < _treeNodeLimit) && (_type[node] >= NTYPES));
+ return ((node < _firstAttributeNode) && (_type[node] >= NTYPES));
}
/**
@@ -361,7 +363,7 @@
return Node.COMMENT_NODE;
default:
- return _index < _treeNodeLimit
+ return _index < _firstAttributeNode
? Node.ELEMENT_NODE : Node.ATTRIBUTE_NODE;
}
}
@@ -506,11 +508,11 @@
}
public String getNamespaceURI() {
- return _nsNamesArray[_namespace[_type[_index] - NTYPES]];
+ return _uriArray[_namespace[_type[_index] - NTYPES]];
}
public String getPrefix() {
- return null; // We don't know with the current DOM implementation
+ return _prefixArray[_prefix[_index]];
}
public void setPrefix(String prefix) {
@@ -518,9 +520,7 @@
}
public String getLocalName() {
- final String qname = _namesArray[_type[_index] - NTYPES];
- final int col = qname.lastIndexOf(':');
- return qname.substring(col+1);
+ return DOMImpl.this.getLocalName(_index);
}
public boolean hasAttributes() {
@@ -1736,12 +1736,25 @@
case TEXT:
return makeStringValue(node);
default:
- return node < _treeNodeLimit
- ? getElementValue(node) // element string value
- : makeStringValue(node); // attribute value
+ if (node < _firstAttributeNode)
+ return getElementValue(node); // element string value
+ else
+ return makeStringValue(node); // attribute value
}
}
+ private String getLocalName(int node) {
+ final int type = _type[node] - NTYPES;
+ final String qname = _namesArray[type];
+ final String uri = _uriArray[_namespace[type]];
+
+ if (uri != null) {
+ final int len = uri.length();
+ if (len > 0) return qname.substring(len+1);
+ }
+ return qname;
+ }
+
/**
* Sets up a translet-to-dom type mapping table
*/
@@ -1786,10 +1799,18 @@
// extended types initialized to "beyond caller's types"
// unknown element or Attr
for (i = NTYPES; i < mappingLength; i++) {
- final String name = _namesArray[i - NTYPES];
- final int atPos = name.lastIndexOf(':')+1;
- result[i] = (short)(name.charAt(atPos) == '@'
- ? ATTRIBUTE : ELEMENT);
+ final int type = i - NTYPES;
+ final String name = _namesArray[type];
+ final String uri = _uriArray[_namespace[type]];
+ int len = 0;
+ if (uri != null) {
+ len = uri.length();
+ if (len > 0) len++;
+ }
+ if (name.charAt(len) == '@')
+ result[i] = (short)ATTRIBUTE;
+ else
+ result[i] = (short)ELEMENT;
}
// actual mapping of caller requested names
@@ -1826,7 +1847,7 @@
public short[] getNamespaceMapping(String[] namespaces) {
int i;
final int nsLength = namespaces.length;
- final int mappingLength = _nsNamesArray.length;
+ final int mappingLength = _uriArray.length;
final short[] result = new short[mappingLength];
// Initialize all entries to -1
@@ -1875,8 +1896,9 @@
out.writeObject(_lengthOrAttr);
out.writeObject(_text);
out.writeObject(_namesArray);
- out.writeObject(_nsNamesArray);
+ out.writeObject(_uriArray);
out.writeObject(_whitespace);
+ out.writeObject(_prefix);
out.flush();
}
@@ -1894,8 +1916,9 @@
_lengthOrAttr = (int[])in.readObject();
_text = (char[])in.readObject();
_namesArray = (String[])in.readObject();
- _nsNamesArray = (String[])in.readObject();
+ _uriArray = (String[])in.readObject();
_whitespace = (BitArray)in.readObject();
+ _prefix = (short[])in.readObject();
_types = setupMapping(_namesArray);
}
@@ -1909,7 +1932,7 @@
/**
* Constructor - defines initial size
*/
- public DOMImpl(final int size) {
+ public DOMImpl(int size) {
_type = new short[size];
_parent = new int[size];
_nextSibling = new int[size];
@@ -1917,7 +1940,8 @@
_lengthOrAttr = new int[size];
_text = new char[size * 10];
_whitespace = new BitArray(size);
- // _namesArray[] and _nsNamesArray are allocated in endDocument
+ _prefix = new short[size];
+ // _namesArray[] and _uriArray are allocated in endDocument
}
/**
@@ -1961,22 +1985,29 @@
public String getNodeName(final int node) {
// Get the node type and make sure that it is within limits
final short type = _type[node];
- if (type == DOM.PROCESSING_INSTRUCTION)
- return("a-pi");
- else if (type < NTYPES)
+ switch(type) {
+ case DOM.ROOT:
+ case DOM.TEXT:
+ case DOM.UNUSED:
+ case DOM.ELEMENT:
+ case DOM.ATTRIBUTE:
+ case DOM.COMMENT:
return EMPTYSTRING;
-
- // Get node's name (attribute or element)
- final String rawName = _namesArray[type - NTYPES];
- // Make sure attributes are returned without the leading '@'
- if (node < _firstAttributeNode)
- return(rawName);
- else {
- final int col = rawName.lastIndexOf(':');
- if (col < 0)
- return(rawName.substring(1));
- else
- return(rawName.substring(0,col)+':'+rawName.substring(col+2));
+ case DOM.PROCESSING_INSTRUCTION:
+ return "a-pi";
+ default:
+ // Construct the local part (omit '@' for attributes)
+ String name = getLocalName(node);
+ if (node >= _firstAttributeNode)
+ name = name.substring(1);
+
+ final int pi = _prefix[node];
+ if (pi > 0) {
+ final String prefix = _prefixArray[pi];
+ if (prefix != EMPTYSTRING)
+ name = prefix+':'+name;
+ }
+ return name;
}
}
@@ -1985,7 +2016,7 @@
*/
public String getNamespaceName(final int node) {
final int type = getNamespaceType(node);
- final String name = _nsNamesArray[type];
+ final String name = _uriArray[type];
if (name == null)
return(EMPTYSTRING);
else
@@ -2001,40 +2032,36 @@
}
/**
- * Returns the value of a given attribute type of a given element
+ * Returns the attribute node of a given type (if any) for an element
*/
- public String getAttributeValue(final int type, final int element) {
+ public int getAttributeNode(final int type, final int element) {
for (int attr = _lengthOrAttr[element];
attr != NULL;
attr = _nextSibling[attr]) {
- if (_type[attr] == type) return makeStringValue(attr);
+ if (_type[attr] == type) return attr;
}
- return EMPTYSTRING;
+ return NULL;
}
/**
- * Returns the attribute node of a given type (if any) for an element
+ * Returns the value of a given attribute type of a given element
*/
- public int getAttributeNode(final int gType, final int element) {
- for (int attr = _lengthOrAttr[element];
- attr != NULL;
- attr = _nextSibling[attr]) {
- if (_type[attr] == gType) return attr;
- }
- return NULL;
+ public String getAttributeValue(final int type, final int element) {
+ final int attr = getAttributeNode(type, element);
+ if (attr != NULL)
+ return makeStringValue(attr);
+ else
+ return EMPTYSTRING;
}
/**
* Returns true if a given element has an attribute of a given type
*/
public boolean hasAttribute(final int type, final int node) {
- for (int attr = _lengthOrAttr[node]; attr != NULL;
- attr = _nextSibling[attr]) {
- if (_type[attr] == type) {
- return true;
- }
- }
- return false;
+ if (getAttributeNode(type, node) != NULL)
+ return true;
+ else
+ return false;
}
/**
@@ -2048,7 +2075,7 @@
* Returns true if the given element has any children
*/
private boolean hasChildren(final int node) {
- if (node < _treeNodeLimit) {
+ if (node < _firstAttributeNode) {
final int type = _type[node];
return(((type >= NTYPES) || (type == ROOT)) &&
(_offsetOrChild[node] != 0));
@@ -2060,12 +2087,10 @@
* Returns an iterator with all the children of a given node
*/
public NodeIterator getChildren(final int node) {
- if (hasChildren(node)) {
+ if (hasChildren(node))
return(new ChildrenIterator());
- }
- else {
+ else
return(EMPTYITERATOR);
- }
}
/**
@@ -2274,15 +2299,12 @@
public void copy(final int node, TransletOutputHandler handler)
throws TransletException {
- int attr, child, col;
+ final int type = _type[node];
- switch(_type[node]) {
+ switch(type) {
case ROOT:
- for (child = _offsetOrChild[node];
- child != NULL;
- child = _nextSibling[child]) {
- copy(child, handler);
- }
+ for (int c=_offsetOrChild[node]; c!=NULL; c=_nextSibling[c])
+ copy(c, handler);
break;
case PROCESSING_INSTRUCTION:
copyPI(node, handler);
@@ -2299,57 +2321,20 @@
break;
default:
if (isElement(node)) {
- final String name = getNodeName(node);
- // Copy element name - start tag
- col = name.lastIndexOf(':');
- if (col > 0) {
- final String uri = name.substring(0,col);
- final String prefix = handler.getPrefix(uri);
- final String local = name.substring(col+1);
- if (prefix.equals(EMPTYSTRING))
- handler.startElement(local);
- else
- handler.startElement(prefix+':'+local);
- }
- else {
- handler.startElement(name);
- }
-
+ // Start element definition
+ final String name = copyElement(node, type, handler);
// Copy element attribute
- for (attr = _lengthOrAttr[node];
- attr != NULL;
- attr = _nextSibling[attr]) {
- final String aname = getNodeName(attr);
- col = aname.lastIndexOf(':');
- if (col < 0) {
- handler.attribute(aname,makeStringValue(attr));
- }
- else {
- final String uri = aname.substring(0,col);
- final String prefix = handler.getPrefix(uri);
- final String local = aname.substring(col+1);
- final String value = makeStringValue(attr);
- final String qname = prefix+':'+local;
- if (prefix.equals(EMPTYSTRING))
- handler.attribute(local, value);
- else
- handler.attribute(prefix+':'+local, value);
- }
- }
-
+ for (int a=_lengthOrAttr[node]; a!=NULL; a=_nextSibling[a])
+ handler.attribute(getNodeName(a), makeStringValue(a));
// Copy element children
- for (child = _offsetOrChild[node];
- child != NULL;
- child = _nextSibling[child]) {
- copy(child, handler);
- }
-
- // Copy element end-tag
+ for (int c=_offsetOrChild[node]; c!=NULL; c=_nextSibling[c])
+ copy(c, handler);
+ // Close element definition
handler.endElement(name);
}
// Shallow copy of attribute to output handler
else {
- shallowCopy(node, handler);
+ handler.attribute(getNodeName(node), makeStringValue(node));
}
break;
}
@@ -2384,7 +2369,10 @@
*/
public String shallowCopy(final int node, TransletOutputHandler handler)
throws TransletException {
- switch(_type[node]) {
+
+ final int type = _type[node];
+
+ switch(type) {
case ROOT: // do nothing
return EMPTYSTRING;
case TEXT:
@@ -2397,32 +2385,43 @@
return null;
case COMMENT:
return null;
- default: // element or attribute
- final String name = getNodeName(node);
+ default:
if (isElement(node)) {
- // Copy element name - start tag
- int col = name.lastIndexOf(':');
- if (col > 0) {
- final String uri = name.substring(0,col);
- final String prefix = handler.getPrefix(uri);
- final String local = name.substring(col+1);
- if (prefix.equals(EMPTYSTRING))
- handler.startElement(local);
- else
- handler.startElement(prefix+':'+local);
- }
- else {
- handler.startElement(name);
- }
- return(name);
+ return(copyElement(node, type, handler));
}
- else { // attribute
- handler.attribute(name, makeStringValue(node));
+ else {
+ String name = getNodeName(node);
+ final String value = makeStringValue(node);
+ handler.attribute(name, value);
+ return null;
}
- return null;
}
}
+ private String copyElement(int node, int type,
+ TransletOutputHandler handler)
+ throws TransletException {
+
+ type = type - NTYPES;
+ String name = _namesArray[type];
+ final int pi = _prefix[node];
+ if (pi > 0) {
+ final String prefix = _prefixArray[pi];
+ final String uri = _uriArray[_namespace[type]];
+ final String local = getLocalName(node);
+ if (prefix.equals(EMPTYSTRING))
+ name = local;
+ else
+ name = prefix+':'+local;
+ handler.startElement(name);
+ handler.namespace(prefix, uri);
+ }
+ else {
+ handler.startElement(name);
+ }
+ return name;
+ }
+
/**
* Returns the string value of the entire tree
*/
@@ -2521,6 +2520,7 @@
/****************************************************************/
private final class DOMBuilder implements ContentHandler {
+ private final static int ATTR_ARRAY_SIZE = 32;
private final static int REUSABLE_TEXT_SIZE = 32;
private Hashtable _shortTexts = null;
@@ -2533,17 +2533,19 @@
private int _currentOffset = 0;
private int _currentNode = 0;
- // attribute node stuff
+ // Temporary structures for attribute nodes
private int _currentAttributeNode = 0;
- private short[] _type2 = new short[32];
- private int[] _parent2 = new int[32];
- private int[] _nextSibling2 = new int[32];
- private int[] _offset = new int[32];
- private int[] _length = new int[32];
+ private short[] _type2 = new short[ATTR_ARRAY_SIZE];
+ private short[] _prefix2 = new short[ATTR_ARRAY_SIZE];
+ private int[] _parent2 = new int[ATTR_ARRAY_SIZE];
+ private int[] _nextSibling2 = new int[ATTR_ARRAY_SIZE];
+ private int[] _offset = new int[ATTR_ARRAY_SIZE];
+ private int[] _length = new int[ATTR_ARRAY_SIZE];
// Namespace prefix-to-uri mapping stuff
private Hashtable _nsPrefixes = new Hashtable();
- private int _nsCount = 0;
+ private int _uriCount = 0;
+ private int _prefixCount = 0;
// Stack used to keep track of what whitespace text nodes are protected
// by xml:space="preserve" attributes and which nodes that are not.
@@ -2670,9 +2672,9 @@
/**
* Generate the internal type for an element's expanded QName
*/
- private short makeElementNode(String name) throws SAXException {
+ private short makeElementNode(String name, int col)
+ throws SAXException {
// Expand prefix:localname to full QName
- int col = name.lastIndexOf(':');
if (col > -1) {
final String uri = getNamespaceURI(name.substring(0, col));
name = uri + name.substring(col);
@@ -2691,6 +2693,18 @@
return (short)obj.intValue();
}
+ /**
+ *
+ */
+ private short registerPrefix(String prefix) {
+ Stack stack = (Stack)_nsPrefixes.get(prefix);
+ if (stack != null) {
+ Integer obj = (Integer)stack.elementAt(0);
+ return (short)obj.intValue();
+ }
+ return 0;
+ }
+
/*
* This method will check if the current text node contains text that
* is already in the text array. If the text is found in the array
@@ -2778,7 +2792,6 @@
final String qname = attList.getQName(i);
final String localname = attList.getLocalName(i);
final String value = attList.getValue(i);
-
StringBuffer namebuf = new StringBuffer(EMPTYSTRING);
// Create the internal attribute node name (uri+@+localname)
@@ -2810,6 +2823,12 @@
}
_parent2[node] = parent;
+
+ final int col = qname.lastIndexOf(':');
+ if (col > 0) {
+ _prefix2[node] = registerPrefix(qname.substring(0, col));
+ }
+
characters(attList.getValue(i));
storeAttrValRef(node);
return node;
@@ -2872,9 +2891,9 @@
appendAttributes();
_treeNodeLimit = _currentNode;
- // Fill the _namespace[] and _nsNamesArray[] array
+ // Fill the _namespace[] and _uriArray[] array
_namespace = new short[namesSize];
- _nsNamesArray = new String[_nsCount];
+ _uriArray = new String[_uriCount];
for (int i = 0; i<namesSize; i++) {
final String qname = _namesArray[i];
final int col = _namesArray[i].lastIndexOf(':');
@@ -2883,9 +2902,18 @@
final String uri = _namesArray[i].substring(0, col);
final Integer idx = (Integer)_nsIndex.get(uri);
_namespace[i] = idx.shortValue();
- _nsNamesArray[idx.intValue()] = uri;
+ _uriArray[idx.intValue()] = uri;
}
}
+
+ _prefixArray = new String[_prefixCount];
+ Enumeration p = _nsPrefixes.keys();
+ while (p.hasMoreElements()) {
+ final String prefix = (String)p.nextElement();
+ final Stack stack = (Stack)_nsPrefixes.get(prefix);
+ final Integer I = (Integer)stack.elementAt(0);
+ _prefixArray[I.shortValue()] = prefix;
+ }
}
/**
@@ -2916,11 +2944,18 @@
_lengthOrAttr[node] = DOM.NULL;
}
+ final int col = qname.lastIndexOf(':');
+
// Assign an internal type to this element (may exist)
if ((uri != null) && (localName.length() > 0))
_type[node] = makeElementNode(uri, localName);
else
- _type[node] = makeElementNode(qname);
+ _type[node] = makeElementNode(qname, col);
+
+ // Assign an internal type to the element's prefix (may exist)
+ if (col > -1) {
+ _prefix[node] = registerPrefix(qname.substring(0, col));
+ }
}
/**
@@ -2983,12 +3018,13 @@
Stack stack = (Stack)_nsPrefixes.get(prefix);
if (stack == null) {
stack = new Stack();
+ stack.push(new Integer(_prefixCount++));
_nsPrefixes.put(prefix, stack);
}
// Check if the URI already exists before pushing on stack
if (_nsIndex.get(uri) == null) {
- _nsIndex.put(uri, new Integer(_nsCount++));
+ _nsIndex.put(uri, new Integer(_uriCount++));
}
stack.push(uri);
}
@@ -3014,45 +3050,75 @@
string.getChars(0, length, _text, _currentOffset);
_currentOffset += length;
}
-
+
private void resizeArrays(final int newSize, final int length) {
if (newSize > length) {
+ // Resize the '_type' array
final short[] newType = new short[newSize];
System.arraycopy(_type, 0, newType, 0, length);
_type = newType;
+
+ // Resize the '_parent' array
final int[] newParent = new int[newSize];
System.arraycopy(_parent, 0, newParent, 0, length);
_parent = newParent;
+
+ // Resize the '_nextSibling' array
final int[] newNextSibling = new int[newSize];
System.arraycopy(_nextSibling, 0, newNextSibling, 0, length);
_nextSibling = newNextSibling;
+
+ // Resize the '_offsetOrChild' array
final int[] newOffsetOrChild = new int[newSize];
System.arraycopy(_offsetOrChild, 0, newOffsetOrChild, 0,length);
_offsetOrChild = newOffsetOrChild;
+
+ // Resize the '_lengthOrAttr' array
final int[] newLengthOrAttr = new int[newSize];
System.arraycopy(_lengthOrAttr, 0, newLengthOrAttr, 0, length);
_lengthOrAttr = newLengthOrAttr;
+
+ // Resize the '_whitespace' array (a BitArray instance)
_whitespace.resize(newSize);
+
+ // Resize the '_prefix' array
+ final short[] newPrefix = new short[newSize];
+ System.arraycopy(_prefix, 0, newPrefix, 0, length);
+ _prefix = newPrefix;
}
}
private void resizeArrays2(final int newSize, final int length) {
if (newSize > length) {
+ // Resize the '_type2' array (attribute types)
final short[] newType = new short[newSize];
System.arraycopy(_type2, 0, newType, 0, length);
_type2 = newType;
+
+ // Resize the '_parent2' array (attribute parent elements)
final int[] newParent = new int[newSize];
System.arraycopy(_parent2, 0, newParent, 0, length);
_parent2 = newParent;
+
+ // Resize the '_nextSibling2' array (you get the idea...)
final int[] newNextSibling = new int[newSize];
System.arraycopy(_nextSibling2, 0, newNextSibling, 0, length);
_nextSibling2 = newNextSibling;
+
+ // Resize the '_offset' array (attribute value start)
final int[] newOffset = new int[newSize];
System.arraycopy(_offset, 0, newOffset, 0, length);
_offset = newOffset;
+
+ // Resize the 'length' array (attribute value length)
final int[] newLength = new int[newSize];
System.arraycopy(_length, 0, newLength, 0, length);
_length = newLength;
+
+ // Resize the '_prefix2' array
+ final short[] newPrefix = new short[newSize];
+ System.arraycopy(_prefix2, 0, newPrefix, 0, length);
+ _prefix2 = newPrefix;
}
}
@@ -3077,6 +3143,7 @@
if (len > 0) {
final int dst = _currentNode;
System.arraycopy(_type2, 0, _type, dst, len);
+ System.arraycopy(_prefix2, 0, _prefix, dst, len);
System.arraycopy(_parent2, 0, _parent, dst, len);
System.arraycopy(_nextSibling2, 0, _nextSibling, dst, len);
System.arraycopy(_offset, 0, _offsetOrChild, dst, len);
1.11 +7 -5
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
Index: BasisLibrary.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- BasisLibrary.java 2001/08/20 08:13:52 1.10
+++ BasisLibrary.java 2001/08/20 14:50:32 1.11
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: BasisLibrary.java,v 1.10 2001/08/20 08:13:52 morten Exp $
+ * @(#)$Id: BasisLibrary.java,v 1.11 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -243,9 +243,9 @@
int istart = (int)Math.round(start) - 1;
if (Double.isNaN(start)) return(EMPTYSTRING);
+ if (istart > strlen) return(EMPTYSTRING);
+ if (istart < 1) istart = 0;
- if ((istart < 1) || (istart > strlen)) istart = 0;
-
return value.substring(istart);
}
catch (IndexOutOfBoundsException e) {
@@ -266,10 +266,12 @@
if (Double.isNaN(start) || Double.isNaN(length))
return(EMPTYSTRING);
+ if (istart > strlen) return(EMPTYSTRING);
+ if (isum < 0) return(EMPTYSTRING);
- if ((istart < 1) || (istart > strlen)) istart = 0;
+ if (istart < 0) istart = 0;
- if ((isum < 0) || (isum > strlen))
+ if (isum > strlen)
return value.substring(istart);
else
return value.substring(istart, isum);
1.22 +1 -38
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java
Index: TextOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TextOutput.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TextOutput.java 2001/08/20 09:54:29 1.21
+++ TextOutput.java 2001/08/20 14:50:32 1.22
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TextOutput.java,v 1.21 2001/08/20 09:54:29 morten Exp $
+ * @(#)$Id: TextOutput.java,v 1.22 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -742,43 +742,6 @@
private String lookupNamespace(String prefix) {
final Stack stack = (Stack)_namespaces.get(prefix);
return stack != null && !stack.isEmpty() ? (String)stack.peek() : null;
- }
-
- /**
- * Generates a namespace prefix for URIs that have no associated
- * prefix. Can happen quite frequently since we do not store
- * namespace prefixes in the tree (we only store the URIs).
- */
- private int _nsCounter = 0;
-
- private String generateNamespacePrefix() {
- return(new String("ns"+Integer.toString(_nsCounter++)));
- }
-
- /**
- * Returns a prefix that is currently mapped to a given URI
- */
- public String getPrefix(String uri) throws TransletException {
- try {
- String prefix = EMPTYSTRING;
- String theuri;
-
- // First a quick check for the default namespace
- if (uri.equals(lookupNamespace(prefix))) return prefix;
-
- Enumeration prefixes = _namespaces.keys();
- while (prefixes.hasMoreElements()) {
- prefix = (String)prefixes.nextElement();
- theuri = lookupNamespace(prefix);
- if ((theuri != null) && (theuri.equals(uri))) return prefix;
- }
- prefix = generateNamespacePrefix();
- pushNamespace(prefix, uri);
- return prefix;
- }
- catch (SAXException e) {
- throw new TransletException(e);
- }
}
/**
1.6 +1 -2
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java
Index: TransletOutputBase.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletOutputBase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransletOutputBase.java 2001/08/16 12:29:19 1.5
+++ TransletOutputBase.java 2001/08/20 14:50:32 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransletOutputBase.java,v 1.5 2001/08/16 12:29:19 morten Exp $
+ * @(#)$Id: TransletOutputBase.java,v 1.6 2001/08/20 14:50:32 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -79,7 +79,6 @@
throws TransletException {}
public void namespace(String prefix, String uri)
throws TransletException {}
- public String getPrefix(String uri) throws TransletException { return(""); }
public void comment(String comment) throws TransletException {}
public void processingInstruction(String target, String data)
throws TransletException {}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]