kstaken 2002/07/02 01:03:07
Modified: java/src/org/apache/xindice/tools XMLTools.java
java/src/org/apache/xindice/tools/command XPathQuery.java
Log:
Adding patch to add namespace support for queries at the command line.
Submitted by: Vanessa Williams
Reviewed by: Kimbro Staken
Revision Changes Path
1.4 +6 -1
xml-xindice/java/src/org/apache/xindice/tools/XMLTools.java
Index: XMLTools.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/tools/XMLTools.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLTools.java 3 May 2002 16:35:11 -0000 1.3
+++ XMLTools.java 2 Jul 2002 08:03:07 -0000 1.4
@@ -114,6 +114,7 @@
public static final String USER = "user";
public static final String PASSWORD = "password";
public static final String AUTO_KEY = "autoKey";
+ public static final String NAMESPACES = "namespaces";
@@ -236,6 +237,8 @@
table.put( VERBOSE, "true");
} else if ( token.equalsIgnoreCase("-y") ||
token.equalsIgnoreCase("--yes_force") ) {
table.put( FORCE, "yes");
+ } else if ( token.equalsIgnoreCase("-s") ||
token.equalsIgnoreCase("--namespaces") ) {
+ table.put(NAMESPACES, at.nextSwitchToken());
// Index specific options
} else if ( token.equalsIgnoreCase("-t") ||
token.equalsIgnoreCase("--type") ) {
table.put( TYPE, at.nextSwitchToken());
@@ -632,6 +635,7 @@
System.out.println(" -q " + "Query string");
System.out.println(" -u " + "Database URI");
System.out.println(" -y " + "Force Deletion process");
+ System.out.println(" -s " + "Semi-colon delimited list of
namespaces for query in the form prefix=namespace-uri");
System.out.println(" -t " + "Specify the data type in
collection index");
System.out.println(" --pagesize " + "Page size for file pages
(default: 4096)");
System.out.println(" --maxkeysize " + "The maximum size for file
keys (default: 0=none)");
@@ -670,6 +674,7 @@
System.out.println(" xindice dd -c /db/test -n myxmldocument");
System.out.println(" xindice rd -c /db/test/ocs -f a:\\file.xml -n
file.xml");
System.out.println(" xindice xpath -c /db/test/ocs -q test");
+ System.out.println(" xindice xpath -c /db/test -s
a=http://somedomain.com/schema.xsd -q /a:foo");
System.out.println();
System.out.println("For more information, please read the Xindice -
Tools Reference Guide");
System.out.println();
1.2 +17 -1
xml-xindice/java/src/org/apache/xindice/tools/command/XPathQuery.java
Index: XPathQuery.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/tools/command/XPathQuery.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XPathQuery.java 6 Dec 2001 19:33:57 -0000 1.1
+++ XPathQuery.java 2 Jul 2002 08:03:07 -0000 1.2
@@ -60,6 +60,7 @@
*/
import java.util.Hashtable;
+import java.util.StringTokenizer;
import java.io.*;
import org.xmldb.api.modules.*;
@@ -93,6 +94,7 @@
return false;
}
+
String colstring = normalizeCollectionURI(
(String)table.get("collection") );
String querystring = (String)table.get("query");
XPathQueryService service = null;
@@ -106,6 +108,8 @@
}
service =
(XPathQueryService)col.getService("XPathQueryService","1.0");
+ addNamespaces(service, (String)table.get("namespaces"));
+
ResourceSet resultSet = service.query(querystring);
results = resultSet.getIterator();
@@ -131,6 +135,18 @@
return true;
}
+ private void addNamespaces(XPathQueryService service, String
namespacesString) throws XMLDBException {
+ if ((namespacesString != "") && (namespacesString != null)) {
+ StringTokenizer st = new
StringTokenizer(namespacesString, "=;");
+ if (st.countTokens() % 2 != 0) {
+ System.out.println("ERROR : mismatched
namespace prefixes and uris");
+ return;
+ }
+ while (st.hasMoreTokens()) {
+ service.setNamespace(st.nextToken(),
st.nextToken());
+ }
+ }
+ }
}