jkesselm 01/10/01 08:36:18
Modified: java/src/org/apache/xml/dtm/ref DTMDefaultBase.java
DTMDefaultBaseIterators.java
DTMDefaultBaseTraversers.java
java/src/org/apache/xml/dtm/ref/dom2dtm DOM2DTM.java
java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM.java
Log:
Creating the implied Namespace Node for xml:
Revision Changes Path
1.20 +2 -5
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java
Index: DTMDefaultBase.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DTMDefaultBase.java 2001/09/05 15:46:26 1.19
+++ DTMDefaultBase.java 2001/10/01 15:36:17 1.20
@@ -111,14 +111,11 @@
/** Previous sibling values, one array element for each node. */
protected SuballocatedIntVector m_parent;
- /** Experemental. -sb */
-// protected boolean m_haveSeenNamespace = false;
-
- /** Vector of SuballocatedIntVectors of NS decl sets -jjk */
+ /** Vector of SuballocatedIntVectors of NS decl sets */
protected Vector m_namespaceDeclSets = null;
/** SuballocatedIntVector of elements at which corresponding
- * namespaceDeclSets were defined -jjk */
+ * namespaceDeclSets were defined */
protected SuballocatedIntVector m_namespaceDeclSetElements = null;
/**
1.8 +1 -1
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseIterators.java
Index: DTMDefaultBaseIterators.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseIterators.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DTMDefaultBaseIterators.java 2001/08/06 17:15:21 1.7
+++ DTMDefaultBaseIterators.java 2001/10/01 15:36:17 1.8
@@ -1225,7 +1225,7 @@
public int next()
{
- final int node = _currentNode + 1;
+ int node = _currentNode + 1;
if ((_sp >= 0) && (node < _stack[_sp]))
{
1.6 +1 -1
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseTraversers.java
Index: DTMDefaultBaseTraversers.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseTraversers.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DTMDefaultBaseTraversers.java 2001/07/28 00:25:59 1.5
+++ DTMDefaultBaseTraversers.java 2001/10/01 15:36:17 1.6
@@ -282,7 +282,7 @@
}
/**
- * Implements traversal of the Ancestor access, in reverse document order.
+ * Implements traversal of the Attribute access
*/
private class AttributeTraverser extends DTMAxisTraverser
{
1.17 +76 -3
xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java
Index: DOM2DTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DOM2DTM.java 2001/09/05 15:46:26 1.16
+++ DOM2DTM.java 2001/10/01 15:36:17 1.17
@@ -111,6 +111,10 @@
* */
transient private Node m_root;
+ /** True iff the first element has been processed. This is used to control
+ synthesis of the implied xml: namespace declaration node. */
+ boolean m_processedFirstElement=false;
+
/** true if ALL the nodes in the m_root subtree have been processed;
* false if our incremental build has not yet finished scanning the
* DOM tree. */
@@ -157,6 +161,9 @@
//
// (If it's an EntityReference node, we're probably scrod. For now
// I'm just hoping nobody is ever quite that foolish... %REVIEW%)
+ //
+ // %ISSUE% What about inherited namespaces in this case?
+ // Do we need to special-case initialize them into the DTM
model?
if(ELEMENT_NODE == m_root.getNodeType())
{
NamedNodeMap attrs=m_root.getAttributes();
@@ -513,20 +520,29 @@
// Inserting next. NOTE that we force the node type; for
// coalesced Text, this records CDATASections adjacent to
// ordinary Text as Text.
- int nextindex=addNode(next,m_last_parent,m_last_kid,
+ int nextindex=addNode(next,m_last_parent,m_last_kid,
nexttype);
m_last_kid=nextindex;
if(ELEMENT_NODE == nexttype)
{
+ int attrIndex=NULL; // start with no previous sib
+ if(!m_processedFirstElement)
+ {
+ String declURI =
"http://www.w3.org/XML/1998/namespace";
+ attrIndex=addNode(
+ new
defaultNamespaceDeclarationNode((Element)next,"xml",declURI),
+
nextindex,attrIndex,NULL);
+ m_firstch.setElementAt(DTM.NULL,attrIndex);
+
m_processedFirstElement=true;
+ }
// Process attributes _now_, rather than waiting.
// Simpler control flow, makes NS cache available immediately.
NamedNodeMap attrs=next.getAttributes();
int attrsize=(attrs==null) ? 0 : attrs.getLength();
if(attrsize>0)
{
- int attrIndex=NULL; // start with no previous sib
for(int i=0;i<attrsize;++i)
{
// No need to force nodetype in this case;
@@ -538,8 +554,9 @@
}
// Terminate list of attrs, and make sure they aren't
// considered children of the element
- m_nextsib.setElementAt(DTM.NULL,attrIndex);
} // if attrs exist
+ if(attrIndex!=NULL)
+ m_nextsib.setElementAt(DTM.NULL,attrIndex);
} //if(ELEMENT_NODE)
} // (if !suppressNode)
@@ -1648,5 +1665,61 @@
public SourceLocator getSourceLocatorFor(int node)
{
return null;
+ }
+
+ //---------------------------------------------------------------------
+ /** This is a kluge to let us shove a declaration for xml: into the model.
+ * Basically, it creates a proxy node in DOM space to carry the
+ * additional information. This is _NOT_ a full DOM implementation,
+ * and shouldn't be one since it sits alongside the DOM rather than
+ * becoming part of the DOM model.
+ *
+ * %REVIEW% An alternative solution would be to create the node _only_
+ * in DTM space, but given how DOM2DTM is currently written I think
+ * this is simplest.
+ */
+ class defaultNamespaceDeclarationNode implements Attr
+ {
+ final String NOT_SUPPORTED_ERR="Unsupported operation on pseudonode";
+
+ Element pseudoparent;
+ String prefix,uri;
+ defaultNamespaceDeclarationNode(Element peseudoparent,String
prefix,String uri)
+ {
+ this.pseudoparent=pseudoparent;
+ this.prefix=prefix;
+ this.uri=uri;
+ }
+ public String getNodeName() {return "xmlns:"+prefix;}
+ public String getName() {return getNodeName();}
+ public String getNamespaceURI() {return "http://www.w3.org/2000/xmlns/";}
+ public String getPrefix() {return prefix;}
+ public String getLocalName() {return prefix;}
+ public String getNodeValue() {return uri;}
+ public String getValue() {return uri;}
+ public Element getOwnerElement() {return pseudoparent;}
+
+ public boolean isSupported(String feature, String version) {return
false;}
+ public boolean hasChildNodes() {return false;}
+ public boolean hasAttributes() {return false;}
+ public Node getParentNode() {return null;}
+ public Node getFirstChild() {return null;}
+ public Node getLastChild() {return null;}
+ public Node getPreviousSibling() {return null;}
+ public Node getNextSibling() {return null;}
+ public boolean getSpecified() {return false;}
+ public void normalize() {return;}
+ public NodeList getChildNodes() {return null;}
+ public NamedNodeMap getAttributes() {return null;}
+ public short getNodeType() {return Node.ATTRIBUTE_NODE;}
+ public void setNodeValue(String value) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public void setValue(String value) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public void setPrefix(String value) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public Node insertBefore(Node a, Node b) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public Node replaceChild(Node a, Node b) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public Node appendChild(Node a) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public Node removeChild(Node a) {throw new
DTMException(NOT_SUPPORTED_ERR);}
+ public Document getOwnerDocument() {return
pseudoparent.getOwnerDocument();}
+ public Node cloneNode(boolean deep) {throw new
DTMException(NOT_SUPPORTED_ERR);}
}
}
1.18 +16 -3
xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Index: SAX2DTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- SAX2DTM.java 2001/09/05 15:46:26 1.17
+++ SAX2DTM.java 2001/10/01 15:36:17 1.18
@@ -1468,11 +1468,10 @@
int doc = addNode(DTM.DOCUMENT_NODE,
m_expandedNameTable.getExpandedTypeID(DTM.DOCUMENT_NODE),
DTM.NULL, DTM.NULL, 0, true);
-
+
m_parents.push(doc);
-
m_previous = DTM.NULL;
-
+
m_contextIndexes.push(m_prefixMappings.size()); // for the next element.
}
@@ -1600,6 +1599,8 @@
return false;
}
+
+ boolean m_pastFirstElement=false;
/**
* Receive notification of the start of an element.
@@ -1645,6 +1646,18 @@
int nDecls = m_prefixMappings.size();
int prev = DTM.NULL;
+ if(!m_pastFirstElement)
+ {
+ // SPECIAL CASE: Implied declaration at root element
+ prefix="xml";
+ String declURL = "http://www.w3.org/XML/1998/namespace";
+ exName = m_expandedNameTable.getExpandedTypeID(null, prefix,
DTM.NAMESPACE_NODE);
+ int val = m_valuesOrPrefixes.stringToIndex(declURL);
+ prev = addNode(DTM.NAMESPACE_NODE, exName, elemNode,
+ prev, val, false);
+ m_pastFirstElement=true;
+ }
+
for (int i = startDecls; i < nDecls; i += 2)
{
prefix = (String) m_prefixMappings.elementAt(i);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]