You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@locus.apache.org on 2000/06/28 19:02:52 UTC
cvs commit: jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods PropFindMethod.java PropPatchMethod.java WebdavMethod.java WebdavMethodBase.java
remm 00/06/28 10:02:48
Modified: docs index.htsrc
src/clients/webdav/src/org/apache/webdav/lib
WebdavClient.java
src/clients/webdav/src/org/apache/webdav/lib/methods
PropFindMethod.java PropPatchMethod.java
WebdavMethod.java WebdavMethodBase.java
Log:
- Added new functions in WebdavMethod, to handle validation
of requests and recycling of request objects
- WebdavClient now uses those functions
- PROPATCH and PROPFIND support (but both don't parse the response sent by the server)
Revision Changes Path
1.3 +1 -1 jakarta-slide/docs/index.htsrc
Index: index.htsrc
===================================================================
RCS file: /home/cvs/jakarta-slide/docs/index.htsrc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- index.htsrc 2000/06/05 05:55:24 1.2
+++ index.htsrc 2000/06/28 17:02:28 1.3
@@ -29,7 +29,7 @@
</p>
<p>
-You can also <a href="http://jakarta.apache.org/slide/doc/">read some online documentation</a> (included in the CVS tree).
+You can learn more about Slide, and read general considerations about content management by visiting the <a href="http://www.interlog.com/~bcholmes/geek/slide-home.html">Slide Guide</a>. This website is maintained by <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>.
</p>
<p>
1.5 +28 -12 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java
Index: WebdavClient.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebdavClient.java 2000/06/26 22:37:50 1.4
+++ WebdavClient.java 2000/06/28 17:02:33 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v 1.4 2000/06/26 22:37:50 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2000/06/26 22:37:50 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v 1.5 2000/06/28 17:02:33 remm Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/06/28 17:02:33 $
*
* ====================================================================
*
@@ -258,20 +258,29 @@
private void sendRequest(WebdavMethod method)
throws IOException, WebdavException {
+ if (method.hasBeenUsed())
+ throw new WebdavException("Method has already been used");
+
+ if (!method.validate())
+ throw new WebdavException("Invalid method");
+
String requestLine = method.generateRequestLine();
method.generateHeaders(state);
Enumeration headersList = method.getHeaders();
- String query = method.generateQuery();
- if (query == null)
- query = new String();
// Sending request line
-
output.write(requestLine.getBytes());
- // TEMP CODE : Writing content length
- output.write(("Content-Length: "
- + query.length() + "\r\n").getBytes());
+ // Sending headers
+ String query = null;
+ if (!method.isStreamedQuery()) {
+ query = method.generateQuery();
+ if (query == null)
+ query = new String();
+ output.write(("Content-Length: "
+ + query.length() + "\r\n").getBytes());
+ }
+
if (state.getAuthenticateToken() != null) {
String challengeResponse = Authenticator.challengeResponse
@@ -289,9 +298,16 @@
output.write("\r\n".getBytes());
- // Writing query
+ // Writing request body
- output.write(query.getBytes());
+ if (method.isStreamedQuery()) {
+ // TODO : Streamed query
+ // Requires chunking on output
+ InputStream queryStream = method.streamQuery();
+
+ } else {
+ output.write(query.getBytes());
+ }
}
1.3 +24 -7 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropFindMethod.java
Index: PropFindMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropFindMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PropFindMethod.java 2000/06/28 00:57:37 1.2
+++ PropFindMethod.java 2000/06/28 17:02:38 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropFindMethod.java,v 1.2 2000/06/28 00:57:37 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2000/06/28 00:57:37 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropFindMethod.java,v 1.3 2000/06/28 17:02:38 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/06/28 17:02:38 $
*
* ====================================================================
*
@@ -159,7 +159,7 @@
private int depth = DEPTH_INFINITY;
- // --------------------------------------------------------- Public Methods
+ // ------------------------------------------------------------- Properties
/**
@@ -247,11 +247,28 @@
public String generateQuery() {
WebdavXMLPrinter printer = new WebdavXMLPrinter();
- printer.writeElement("DAV", "D", "propfind", WebdavXMLPrinter.OPENING);
+ printer.writeElement("D", "DAV", "propfind", WebdavXMLPrinter.OPENING);
-
+ switch (type) {
+ case ALL:
+ printer.writeElement("D", "allprop", WebdavXMLPrinter.NO_CONTENT);
+ break;
+ case NAMES:
+ printer.writeElement("D", "propname",
+ WebdavXMLPrinter.NO_CONTENT);
+ break;
+ case BY_NAME:
+ printer.writeElement("D", "prop", WebdavXMLPrinter.OPENING);
+ while (propertyNames.hasMoreElements()) {
+ String propertyName = (String) propertyNames.nextElement();
+ printer.writeElement(null, propertyName,
+ WebdavXMLPrinter.NO_CONTENT);
+ }
+ printer.writeElement("D", "prop", WebdavXMLPrinter.CLOSING);
+ break;
+ }
- printer.writeElement("DAV", "D", "propfind", WebdavXMLPrinter.CLOSING);
+ printer.writeElement("D", "DAV", "propfind", WebdavXMLPrinter.CLOSING);
return printer.toString();
}
1.2 +157 -4 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropPatchMethod.java
Index: PropPatchMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropPatchMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PropPatchMethod.java 2000/06/19 07:31:14 1.1
+++ PropPatchMethod.java 2000/06/28 17:02:40 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropPatchMethod.java,v 1.1 2000/06/19 07:31:14 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/06/19 07:31:14 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PropPatchMethod.java,v 1.2 2000/06/28 17:02:40 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/06/28 17:02:40 $
*
* ====================================================================
*
@@ -74,6 +74,7 @@
import org.apache.webdav.lib.State;
import org.apache.webdav.lib.Header;
import org.apache.webdav.lib.WebdavStatus;
+import org.apache.webdav.lib.util.WebdavXMLPrinter;
/**
@@ -98,6 +99,100 @@
}
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * Hashtable of the properties to set.
+ */
+ protected Hashtable toSet = new Hashtable();
+
+
+ /**
+ * Hashtable of the properties to remove.
+ */
+ protected Hashtable toRemove = new Hashtable();
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Add a new property to set.
+ *
+ * @param name Property name
+ * @param value Property value
+ */
+ public void addPropertyToSet(String name, String value) {
+ Property propertyToSet = new Property();
+ if (name != null) {
+ propertyToSet.name = name;
+ if (value != null)
+ propertyToSet.value = value;
+ else
+ propertyToSet.value = "";
+ toSet.put(name, propertyToSet);
+ }
+ }
+
+
+ /**
+ * Add a new property to set.
+ *
+ * @param name Property name
+ * @param value Property value
+ * @param namespace Namespace abbreviation
+ * @param namespaceInfo Namespace information
+ */
+ public void addPropertyToSet(String name, String value, String namespace,
+ String namespaceInfo) {
+ Property propertyToSet = new Property();
+ if (name != null) {
+ propertyToSet.name = name;
+ if (value != null)
+ propertyToSet.value = value;
+ else
+ propertyToSet.value = "";
+ propertyToSet.namespace = namespace;
+ propertyToSet.namespaceInfo = namespaceInfo;
+ toSet.put(namespace + ":" + name, propertyToSet);
+ }
+ }
+
+
+ /**
+ * Add property to remove.
+ *
+ * @param name Property name
+ */
+ public void addPropertyToRemove(String name) {
+ Property propertyToRemove = new Property();
+ if (name != null) {
+ propertyToRemove.name = name;
+ toRemove.put(name, propertyToRemove);
+ }
+ }
+
+
+ /**
+ * Add property to remove.
+ *
+ * @param name Property name
+ * @param namespace Namespace abbreviation
+ * @param namespaceInfo Namespace information
+ */
+ public void addPropertyToRemove(String name, String namespace,
+ String namespaceInfo) {
+ Property propertyToRemove = new Property();
+ if (name != null) {
+ propertyToRemove.name = name;
+ propertyToRemove.namespace = namespace;
+ propertyToRemove.namespaceInfo = namespaceInfo;
+ toRemove.put(name, propertyToRemove);
+ }
+ }
+
+
// --------------------------------------------------- WebdavMethod Methods
@@ -107,7 +202,49 @@
* @return String query
*/
public String generateQuery() {
- return null;
+
+ WebdavXMLPrinter printer = new WebdavXMLPrinter();
+ printer.writeElement("D", "DAV", "propertyupdate",
+ WebdavXMLPrinter.OPENING);
+
+ if (toSet.size() > 0) {
+
+ printer.writeElement("D", null, "set",
+ WebdavXMLPrinter.OPENING);
+
+ Enumeration toSetList = toSet.elements();
+ while (toSetList.hasMoreElements()) {
+ Property current = (Property) toSetList.nextElement();
+ printer.writeProperty(current.namespace, current.namespaceInfo,
+ current.name, current.value);
+ }
+
+ printer.writeElement("D", null, "set",
+ WebdavXMLPrinter.CLOSING);
+
+ }
+
+ if (toRemove.size() > 0) {
+
+ printer.writeElement("D", null, "remove",
+ WebdavXMLPrinter.OPENING);
+
+ Enumeration toRemoveList = toRemove.elements();
+ while (toRemoveList.hasMoreElements()) {
+ Property current = (Property) toRemoveList.nextElement();
+ printer.writeElement(current.namespace, current.namespaceInfo,
+ current.name,
+ WebdavXMLPrinter.NO_CONTENT);
+ }
+
+ printer.writeElement("D", null, "remove",
+ WebdavXMLPrinter.CLOSING);
+
+ }
+
+ printer.writeElement("D", "DAV", "propertyupdate",
+ WebdavXMLPrinter.CLOSING);
+ return printer.toString();
}
@@ -118,6 +255,22 @@
*/
public void parseResponse(InputStream is)
throws IOException {
+
+ // Parse the 207 - Multistatus
+
+ }
+
+
+ // --------------------------------------------------- Property Inner Class
+
+
+ private class Property {
+
+ public String name = "";
+ public String namespace;
+ public String namespaceInfo;
+ public String value;
+
}
1.4 +48 -3 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java
Index: WebdavMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebdavMethod.java 2000/06/27 06:44:02 1.3
+++ WebdavMethod.java 2000/06/28 17:02:41 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.3 2000/06/27 06:44:02 remm Exp $
- * $Revision: 1.3 $
- * $Date: 2000/06/27 06:44:02 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.4 2000/06/28 17:02:41 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/06/28 17:02:41 $
*
* ====================================================================
*
@@ -176,10 +176,35 @@
public void removeHeader(String headerName);
+ /**
+ * Checks if this method's instance has already been used, and has not been
+ * recycled.
+ *
+ * @return boolean True if the method's instance has already been used
+ */
+ public boolean hasBeenUsed();
+
+
// ------------------------------------------------------ Interface Methods
/**
+ * Ensures the correctness of the request according to criterions which are
+ * method dependent.
+ *
+ * @return boolean True if the method is valid
+ */
+ public boolean validate();
+
+
+ /**
+ * Recycle the method object, so that it can be reused again. Any attempt
+ * to reuse an object without recycling it will throw a WebdavException.
+ */
+ public void recycle();
+
+
+ /**
* Get headers.
*
* @return Enumeration
@@ -196,6 +221,15 @@
/**
+ * Is the query body submitted through an InputStream of with a String.
+ * If an InputStream is available, it's used.
+ *
+ * @return boolean True if the content is avalable in an InputStream
+ */
+ public boolean isStreamedQuery();
+
+
+ /**
* Generate the query.
*
* @return String query
@@ -204,6 +238,15 @@
/**
+ * Stream the body of the query. This function should be used to send large
+ * request bodies.
+ *
+ * @return InputStream Body of the query
+ */
+ public InputStream streamQuery();
+
+
+ /**
* Process response headers. The contract of this method is that it only
* parses the response headers.
*
@@ -227,6 +270,8 @@
* @return String request line
*/
public String generateRequestLine();
+
+
}
1.4 +74 -5 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java
Index: WebdavMethodBase.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebdavMethodBase.java 2000/06/27 06:44:03 1.3
+++ WebdavMethodBase.java 2000/06/28 17:02:43 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.3 2000/06/27 06:44:03 remm Exp $
- * $Revision: 1.3 $
- * $Date: 2000/06/27 06:44:03 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.4 2000/06/28 17:02:43 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/06/28 17:02:43 $
*
* ====================================================================
*
@@ -89,6 +89,12 @@
/**
+ * True if this method has already been executed.
+ */
+ private boolean used = false;
+
+
+ /**
* Debug.
*/
protected int debug = 0;
@@ -246,10 +252,47 @@
}
+ /**
+ * Checks if this method's instance has already been used, and has not been
+ * recycled.
+ *
+ * @return boolean True if the method's instance has already been used
+ */
+ public final boolean hasBeenUsed() {
+ return (used);
+ }
+
+
// --------------------------------------------------- WebdavMethod Methods
/**
+ * Ensures the correctness of the request according to criterions which are
+ * method dependent.
+ *
+ * @return boolean True if the method is valid
+ */
+ public boolean validate() {
+ // By default, the request is valid.
+ return (true);
+ }
+
+
+ /**
+ * Recycle the method object, so that it can be reused again. Any attempt
+ * to reuse an object without recycling it will throw a WebdavException.
+ */
+ public void recycle() {
+ path = "/";
+ statusCode = WebdavStatus.SC_OK;
+ statusText = "OK";
+ headers.clear();
+ state = null;
+ used = false;
+ }
+
+
+ /**
* Get headers.
*
* @return Enumeration
@@ -273,11 +316,36 @@
/**
+ * Is the query body submitted through an InputStream of with a String.
+ * If an InputStream is available, it's used.
+ *
+ * @return boolean True if the content is avalable in an InputStream
+ */
+ public boolean isStreamedQuery() {
+ // By default, the query is NOT streamed.
+ return false;
+ }
+
+
+ /**
* Generate the query body.
*
* @return String query
+ */
+ public String generateQuery() {
+ return "";
+ }
+
+
+ /**
+ * Stream the body of the query. This function should be used to send large
+ * request bodies.
+ *
+ * @return InputStream Body of the query
*/
- public abstract String generateQuery();
+ public InputStream streamQuery() {
+ return null;
+ }
/**
@@ -318,8 +386,9 @@
*
* @return String request line
*/
- public String generateRequestLine() {
+ public final String generateRequestLine() {
+ used = true;
return (name + " " + path + " " + PROTOCOL + "\r\n");
}