[exo-jcr-commits] exo-jcr SVN: r1279 - jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 4 11:00:57 EST 2010


Author: nzamosenchuk
Date: 2010-01-04 11:00:57 -0500 (Mon, 04 Jan 2010)
New Revision: 1279

Modified:
   jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
Log:
EXOJCR-340: Added SQL and XPATH query methods.

Modified: jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java	2010-01-04 14:19:33 UTC (rev 1278)
+++ jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java	2010-01-04 16:00:57 UTC (rev 1279)
@@ -16,19 +16,18 @@
  */
 package org.exoplatform.services.jcr.cluster;
 
-import java.io.IOException;
-
-import javax.ws.rs.core.HttpHeaders;
-
 import org.exoplatform.common.http.client.CookieModule;
 import org.exoplatform.common.http.client.HTTPConnection;
 import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.common.http.client.HttpHeaderElement;
 import org.exoplatform.common.http.client.HttpOutputStream;
 import org.exoplatform.common.http.client.ModuleException;
 import org.exoplatform.common.http.client.NVPair;
 import org.exoplatform.services.rest.ExtHttpHeaders;
 
+import java.io.IOException;
+
+import javax.ws.rs.core.HttpHeaders;
+
 /**
  * Created by The eXo Platform SAS.
  * 
@@ -52,7 +51,7 @@
       super(host, port);
 
       CookieModule.setCookiePolicyHandler(null);
-      
+
       this.user = user;
       this.pass = password;
       this.realm = realm;
@@ -60,7 +59,7 @@
 
       addBasicAuthorization(this.realm, this.user, this.pass);
    }
-   
+
    public HTTPResponse addNode(String name, byte[] data) throws IOException, ModuleException
    {
       HTTPResponse response = Put(workspacePath + name, data);
@@ -84,7 +83,7 @@
    {
       HTTPResponse response = Delete(workspacePath + name);
       response.getStatusCode();
-      
+
       return response;
    }
 
@@ -92,7 +91,7 @@
    {
       Get(workspacePath + name).getStatusCode();
    }*/
-   
+
    public HTTPResponse getNode(String name) throws IOException, ModuleException
    {
       HTTPResponse response = Get(workspacePath + name);
@@ -100,7 +99,6 @@
       return response;
    }
 
-
    public HTTPResponse addProperty(String nodeName, String property) throws IOException, ModuleException
    {
       String xmlBody =
@@ -113,7 +111,7 @@
 
       HTTPResponse response = ExtensionMethod("PROPPATCH", workspacePath + nodeName, xmlBody.getBytes(), headers);
       response.getStatusCode();
-      
+
       return response;
    }
 
@@ -132,14 +130,12 @@
 
       return response;
    }
-   
+
    public HTTPResponse getProperty(String nodeName, String property) throws IOException, ModuleException
    {
       String xmlBody =
-         "<?xml version='1.0' encoding='utf-8' ?>"
-            + "<D:propfind xmlns:D='DAV:' >" 
-            + "<D:prop><" + property + "/></D:prop>" 
-            + "</D:propfind>";
+         "<?xml version='1.0' encoding='utf-8' ?>" + "<D:propfind xmlns:D='DAV:' >" + "<D:prop><" + property
+            + "/></D:prop>" + "</D:propfind>";
 
       NVPair[] headers = new NVPair[2];
       headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/xml; charset='utf-8'");
@@ -147,7 +143,7 @@
 
       HTTPResponse response = ExtensionMethod("PROPFIND", workspacePath + nodeName, xmlBody.getBytes(), headers);
       response.getStatusCode();
-      
+
       return response;
    }
 
@@ -164,7 +160,7 @@
 
       HTTPResponse response = ExtensionMethod("PROPPATCH", workspacePath + nodeName, xmlBody.getBytes(), headers);
       response.getStatusCode();
-      
+
       return response;
    }
 
@@ -236,7 +232,7 @@
    {
       MkCol(workspacePath + path).getStatusCode();
    }
-   
+
    public HTTPResponse restore(String node, String version) throws IOException, ModuleException
    {
       NVPair[] query = new NVPair[1];
@@ -244,20 +240,71 @@
 
       HTTPResponse response = Get(workspacePath + node, query);
       response.getStatusCode();
-      
+
       return response;
    }
-   
+
    public HTTPResponse moveNode(String path, String destination) throws IOException, ModuleException
    {
       NVPair[] headers = new NVPair[2];
-      headers[0] = new NVPair(ExtHttpHeaders.DESTINATION, this.getProtocol() + "://" + this.getHost() + ":" + this.getPort() + workspacePath + destination);
+      headers[0] =
+         new NVPair(ExtHttpHeaders.DESTINATION, this.getProtocol() + "://" + this.getHost() + ":" + this.getPort()
+            + workspacePath + destination);
       headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString("".length()));
 
       HTTPResponse response = ExtensionMethod("MOVE", workspacePath + path, "".getBytes(), headers);
       response.getStatusCode();
-      
+
       return response;
    }
 
+   /**
+    * Performs XPath query on workspace and returns plain HTTPResponse. It should be returned with status 207 
+    * and must contain the XML with node collection. 
+    * 
+    * @param query
+    * @return
+    * @throws IOException
+    * @throws ModuleException
+    */
+   public HTTPResponse xpathQuery(String query) throws IOException, ModuleException
+   {
+      String xmlBody =
+         "<?xml version='1.0' encoding='utf-8' ?><D:searchrequest xmlns:D='DAV:'>" + "<D:xpath>" + query + "</D:xpath>"
+            + "</D:searchrequest>";
+
+      NVPair[] headers = new NVPair[2];
+      headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/xml; charset='utf-8'");
+      headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString(xmlBody.length()));
+
+      HTTPResponse response = ExtensionMethod("SEARCH", workspacePath, xmlBody.getBytes(), headers);
+      response.getStatusCode();
+
+      return response;
+   }
+
+   /**
+    * Performs SQL query on workspace and returns plain HTTPResponse. It should be returned with status 207 
+    * and must contain the XML with node collection. 
+    * @param query
+    * @return
+    * @throws IOException
+    * @throws ModuleException
+    */
+   public HTTPResponse sqlQuery(String query) throws IOException, ModuleException
+   {
+      String xmlBody =
+         "<?xml version='1.0' encoding='utf-8' ?><D:searchrequest xmlns:D='DAV:'>" + "<D:sql>" + query + "</D:sql>"
+            + "</D:searchrequest>";
+
+      NVPair[] headers = new NVPair[2];
+      headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/xml; charset='utf-8'");
+      headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString(xmlBody.length()));
+
+      HTTPResponse response = ExtensionMethod("SEARCH", workspacePath, xmlBody.getBytes(), headers);
+      response.getStatusCode();
+
+      return response;
+   }
+
 }
\ No newline at end of file



More information about the exo-jcr-commits mailing list