You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by ke...@apache.org on 2003/07/10 16:43:52 UTC
cvs commit: xml-xindice/java/src/org/apache/xindice/client/xmldb XindiceCollection.java
kevinross 2003/07/10 07:43:52
Modified: java/tests/src/org/apache/xindice/integration/client
XmlDbClient.java
java/tests/src/org/apache/xindice/integration/client/basic
CollectionTest.java DocumentTest.java
java/src/org/apache/xindice/client/xmldb
XindiceCollection.java
Log:
PR: 21462
Patch Submitted by: Kevin O'Neill (kevin@rocketred.com.au)
Reviewed by: Kevin Ross
Unit tests updated and run.
If a collection is requested and it's name ends with a / then the collection
name returned from getName is "". This patch strips the / from the end of the
name when the collection object is created.
There is also an additional test for this condition and a getContentAsSAX test I
used to debug a problem elsewhere.
Revision Changes Path
1.6 +18 -2 xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
Index: XmlDbClient.java
===================================================================
RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XmlDbClient.java 3 Jun 2003 02:18:58 -0000 1.5
+++ XmlDbClient.java 10 Jul 2003 14:43:51 -0000 1.6
@@ -63,6 +63,7 @@
import org.apache.xindice.util.XindiceException;
import org.apache.xindice.xml.dom.DOMParser;
import org.w3c.dom.Document;
+import org.xml.sax.ContentHandler;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.modules.XMLResource;
@@ -204,6 +205,21 @@
return document.getContent().toString();
}
+
+ public void getDocumentAsSax(String path, String name, ContentHandler handler) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ") returned null");
+ }
+ XMLResource document = (XMLResource) col.getResource(name);
+
+ if (document == null) {
+ return;
+ }
+
+ document.getContentAsSAX(handler);
+ }
+
public String[] listDocuments(String path) throws Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
1.5 +9 -2 xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java
Index: CollectionTest.java
===================================================================
RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CollectionTest.java 6 Apr 2003 05:37:16 -0000 1.4
+++ CollectionTest.java 10 Jul 2003 14:43:51 -0000 1.5
@@ -215,6 +215,13 @@
this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
}
+ public void testGetNameEndWithSlash()
+ throws Exception {
+ this.client.createCollection(TEST_COLLECTION_PATH, "getname");
+ assertEquals("getname", this.client.getName(TEST_COLLECTION_PATH + "/getname/"));
+ this.client.dropCollection(TEST_COLLECTION_PATH, "getname");
+ }
+
public void testGetParentCollection()
throws Exception {
Collection col = this.client.createCollection(TEST_COLLECTION_PATH, "childcol");
1.4 +22 -3 xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/DocumentTest.java
Index: DocumentTest.java
===================================================================
RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/DocumentTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DocumentTest.java 28 Oct 2002 08:39:20 -0000 1.3
+++ DocumentTest.java 10 Jul 2003 14:43:51 -0000 1.4
@@ -59,8 +59,10 @@
package org.apache.xindice.integration.client.basic;
-import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
+import java.io.StringWriter;
+import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
+import org.apache.xml.serialize.XMLSerializer;
import org.xmldb.api.base.XMLDBException;
/**
@@ -121,6 +123,23 @@
this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
}
+ public void testGetDocumentAsSAX() throws Exception {
+ String testDocument = "<?xml version=\"1.0\"?>\n<data><test>test data</test></data>";
+ this.client.insertDocument(TEST_COLLECTION_PATH, "doc1", testDocument);
+
+ StringWriter out = new StringWriter();
+ XMLSerializer serializer = new XMLSerializer();
+ serializer.setOutputCharStream(out);
+
+ this.client.getDocumentAsSax(TEST_COLLECTION_PATH, "doc1", serializer);
+ String doc = out.toString();
+
+ assertNotNull(doc);
+ assertEquals(testDocument, doc);
+
+ this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
+ }
+
public void testGetInexistantDocument()
throws Exception {
String doc = this.client.getDocument(TEST_COLLECTION_PATH, "ghostdoc");
1.7 +2 -2 xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java
Index: XindiceCollection.java
===================================================================
RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XindiceCollection.java 21 Nov 2002 07:44:35 -0000 1.6
+++ XindiceCollection.java 10 Jul 2003 14:43:52 -0000 1.7
@@ -104,7 +104,7 @@
*/
public XindiceCollection(String collPath) throws XMLDBException {
- this.collPath = collPath;
+ this.collPath = collPath.endsWith("/") ? collPath.substring(0, collPath.length() - 1) : collPath;
services = new Hashtable();
Re: cvs commit: xml-xindice/java/src/org/apache/xindice/client/xmldb
XindiceCollection.java
Posted by "Vladimir R. Bossicard" <vl...@apache.org>.
> Isn't that why the following line was added to XindiceCollection? The
> test seems to prove that this 'smarter' matching works.
Perfect. I misread.
-Vladimir
--
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice
RE: cvs commit: xml-xindice/java/src/org/apache/xindice/client/xmldb XindiceCollection.java
Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
Isn't that why the following line was added to XindiceCollection? The
test seems to prove that this 'smarter' matching works.
+ this.collPath = collPath.endsWith("/") ?
collPath.substring(0, collPath.length() - 1) : collPath;
-Kevin
-----Original Message-----
From: Vladimir R. Bossicard [mailto:vladimir@apache.org]
Sent: Thursday, July 10, 2003 9:07 AM
To: xindice-dev@xml.apache.org
Subject: Re: cvs commit:
xml-xindice/java/src/org/apache/xindice/client/xmldb
XindiceCollection.java
> If a collection is requested and it's name ends with a / then the
collection
> name returned from getName is "". This patch strips the / from the
end of the
> name when the collection object is created.
Shouldn't Xindice handle this case (and not the tests)? If you request
a collection ending/not ending with a '/' Xindice should be smart enough
to make the difference.
-Vladimir
--
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice
Re: cvs commit: xml-xindice/java/src/org/apache/xindice/client/xmldb
XindiceCollection.java
Posted by "Vladimir R. Bossicard" <vl...@apache.org>.
> If a collection is requested and it's name ends with a / then the collection
> name returned from getName is "". This patch strips the / from the end of the
> name when the collection object is created.
Shouldn't Xindice handle this case (and not the tests)? If you request
a collection ending/not ending with a '/' Xindice should be smart enough
to make the difference.
-Vladimir
--
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice