On Tuesday, January 15, 2002, at 09:37 PM, Timothy M. Dean wrote:
I've temporarily copied the patch file to a place where it can be accessed
via the web: You should be able to get it at:
http://www.visi.com/~tdean/patchfile.txt. If that doesn't work, let me know
and I will email you a GZIP'd version. (not sure if this email list accepts
attachments or not!)
- Tim
this----- Original Message ----- From: "Kimbro Staken" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 15, 2002 8:18 AM Subject: Re: [PATCH] XIndice namespace mapping enhancements
Hi Tim, your Lexus patch just made it in so I'm finally able to applyandpatch. Unfortunately, somewhere in the mail chain the file was wrappedthiscorrupted. I tried to reconcile it but with no success. Can you make/home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/seravailable from the web or just send it again gzipped? I'd really like to get this in before we finally release 1.0rc1.
On Thursday, January 3, 2002, at 02:18 PM, Timothy M. Dean wrote:
Index: XUpdateQueryServiceImpl.java =================================================================== RCS file:
{vices/XUpdateQueryServiceImpl.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 XUpdateQueryServiceImpl.java --- XUpdateQueryServiceImpl.java 6 Dec 2001 19:33:54 -0000 1.1.1.1 +++ XUpdateQueryServiceImpl.java 3 Jan 2002 20:07:58 -0000 @@ -74,11 +74,13 @@ import org.xmldb.api.base.*; import org.xmldb.api.modules.*;
+import java.util.*; + public class XUpdateQueryServiceImpl extends CommonConfigurable implements org.xmldb.api.modules.XUpdateQueryService { - private static final NamedVal[] EmptyNamedVals = new NamedVal[0]; protected org.xmldb.api.base.Collection collection = null; + private NamespaceMap nsMap = new NamespaceMap();
public XUpdateQueryServiceImpl() { } @@ -96,12 +98,71 @@ this.collection = col; }
+ + public void setDefaultNamespace(String uri) throws XMLDBExceptioncollection).getServerObject();+ if ( uri != null ) + nsMap.setDefaultNamespace(uri); + else + nsMap.removeDefaultNamespace(); + } + + public void removeDefaultNamespace() { + nsMap.removeDefaultNamespace(); + } + + public void setNamespace(String prefix, String uri) throws XMLDBException { + if ( ( prefix == null ) || prefix.equals("") ) { + setDefaultNamespace(uri); + } + else { + if ( uri != null ) { + nsMap.setNamespace(prefix, uri); + } + } + } + + public void removeNamespace(String prefix) { + if ( ( prefix == null ) || prefix.equals("") ) { + removeDefaultNamespace(); + } + + nsMap.removeNamespace(prefix); + } + + public String getDefaultNamespace() { + return nsMap.getDefaultNamespaceURI(); + } + + public String getNamespace(String prefix) { + if ( ( prefix == null ) || prefix.equals("") ) { + return nsMap.getDefaultNamespaceURI(); + } + + return nsMap.getNamespaceURI(prefix); + } + + public void clearNamespaces() { + nsMap.clear(); + } + + private NamedVal[] getNamespaces() { + NamedVal[] nv = new NamedVal[nsMap.size()]; + Iterator iter = nsMap.keySet().iterator(); + int i = 0; + while ( iter.hasNext() ) { + String prefix = (String)iter.next(); + String uri = nsMap.getNamespaceURI(prefix); + nv[i++] = new NamedVal(prefix, uri); + } + return nv; + } + public XMLResource updateResult(String commands) throws XMLDBException { // Get the Xindice collection object from the XML:DB collection wrapper. Collection col = ((CollectionImpl)collection).getServerObject();
try { - EncodedBuffer buffer = col.queryCollection("XUpdate", commands, EmptyNamedVals, -1); + EncodedBuffer buffer = col.queryCollection("XUpdate", + commands, getNamespaces(), -1); return new XMLResourceImpl("", collection, new String(buffer.buf)); } catch (Exception e) { @@ -129,7 +190,7 @@ Collection col = ((CollectionImpl)commands,
try { - EncodedBuffer buffer = col.queryDocument("XUpdate",commands,EmptyNamedVals, id, -1); + EncodedBuffer buffer = col.queryDocument("XUpdate",/home/cvspublic/xml-xindice/java/src/org/apache/xindice/xml/NamespaceMap+ getNamespaces(), id, -1); return new XMLResourceImpl("", collection, new String(buffer.buf)); } catch (Exception e) { Index: NamespaceMap.java =================================================================== RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/xupdate/XUp.java,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 NamespaceMap.java --- NamespaceMap.java 6 Dec 2001 19:33:58 -0000 1.1.1.1 +++ NamespaceMap.java 3 Jan 2002 20:09:19 -0000 @@ -72,7 +72,7 @@
public final class NamespaceMap extends HashMap { private Element elem = null; - + public Node getContextNode() { if ( elem == null ) { Document d = new DocumentImpl(); @@ -92,8 +92,9 @@
public void clearNamespaces() { clear(); + elem = null; } - + public String getDefaultNamespaceURI() { return (String)get(""); } @@ -104,17 +105,32 @@
public void setDefaultNamespace(String uri) { put("", uri); + elem = null; }
public void setNamespace(String prefix, String uri) { put(prefix, uri); + elem = null; }
public void removeDefaultNamespace() { remove(""); + elem = null; }
public void removeNamespace(String prefix) { remove(prefix); + elem = null; + } + + public void includeNamespaces(Map nsMap, boolean override) { + Iterator newEntries = nsMap.entrySet().iterator(); + while (newEntries.hasNext()) { + Map.Entry entry = (Map.Entry) newEntries.next(); + if (!override && super.containsKey(entry.getKey())) + continue; + super.put(entry.getKey(), entry.getValue()); + } + elem = null; } } Index: XUpdateImpl.java =================================================================== RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/xupdate/XUpdateImpl.java,v retrieving revision 1.1 diff -u -r1.1 XUpdateImpl.java --- XUpdateImpl.java 6 Dec 2001 21:00:15 -0000 1.1 +++ XUpdateImpl.java 3 Jan 2002 20:12:17 -0000 @@ -64,12 +64,15 @@ import org.apache.xindice.xml.dom.*; import org.apache.xindice.xml.*;
-import org.infozone.lexus.commands.*; -import org.infozone.lexus.*; +import org.xmldb.xupdate.lexus.commands.*; +import org.xmldb.xupdate.lexus.*; +import org.infozone.tools.xml.queries.*;
import java.util.*;
import org.w3c.dom.*; +import org.xmldb.xupdate.lexus.*; +import org.xml.sax.*;
/** * Provides Collection and document based XUpdate capabilities. @@ -79,8 +82,43 @@ */ public class XUpdateImpl extends XUpdateQueryImpl { protected int nodesModified = 0; - - /** + protected NamespaceMap nsMap; + + /** + * If set to true, then namespaces set explicitly via an API call will take precendence. + * If set to false, then namespaces set implicitly within query string will take precedence. + */ + private static final boolean API_NS_PRECEDENCE = true; + + /** + * Set the namespace map to be used when resolving queries + */ + public void setNamespaceMap(NamespaceMap nsMap) { + if (nsMap == null) + return; + + if (this.nsMap == null) { + this.nsMap = nsMap; + } + else { + this.nsMap.includeNamespaces(nsMap, API_NS_PRECEDENCE); + } + } + + + /** + * Sets the query string to be used when executing update + */ + public void setQString(String query) throws SAXException { + super.setQString(query); + if (nsMap == null) { + nsMap = new NamespaceMap(); + } + nsMap.includeNamespaces(_namespaces, !API_NS_PRECEDENCE); + } + + + /** * Execute the XUpdate commands against a document. */ public void execute(Node contextNode) throws Exception { @@ -89,6 +127,7 @@ Enumeration attributes = _query[1].elements(); Enumeration characters = _query[2].elements(); Node origNode = contextNode; + CommandObject.getXPath().setNamespace(nsMap.getContextNode());
while (commands.hasMoreElements()) { int id = ((Integer) commands.nextElement()).intValue(); @@ -143,7 +182,7 @@
// If we found an XPath selector we need to execute the commands. if (selector != null) { - NodeSet ns = col.queryCollection("XPath", selector, null); + NodeSet ns = col.queryCollection("XPath", selector, + nsMap); Document lastDoc = null; while (ns != null && ns.hasMoreNodes()) { DBNode node = (DBNode)ns.getNextNode(); Index: XUpdateQueryResolver.java =================================================================== RCS file:
dateQueryResolver.java,v retrieving revision 1.1 diff -u -r1.1 XUpdateQueryResolver.java --- XUpdateQueryResolver.java 6 Dec 2001 21:00:15 -0000 1.1 +++ XUpdateQueryResolver.java 3 Jan 2002 20:14:07 -0000 @@ -127,6 +127,7 @@ try { xu = new XUpdateImpl(); xu.setQString(query); + xu.setNamespaceMap(nsMap); } catch ( Exception e ) { throw new CompilationException("Error Compiling XUpdate Query");
Kimbro Staken XML Database Software, Consulting and Writing http://www.xmldatabases.org/