msmith 2002/09/03 22:07:12
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavResource.java
src/webdav/client/src/org/apache/webdav/lib/methods
LabelMethod.java
Log:
Client-side implementation of LabelMethod.
Revision Changes Path
1.48 +42 -5
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- WebdavResource.java 2 Sep 2002 07:58:31 -0000 1.47
+++ WebdavResource.java 4 Sep 2002 05:07:12 -0000 1.48
@@ -424,6 +424,11 @@
*
*/
public static final int OPTIONS_VERSION_HISTORY = 9;
+
+ public static final int LABEL_SET = 10;
+ public static final int LABEL_REMOVE = 11;
+ public static final int LABEL_ADD = 12;
+
/**
* Owner information for locking and unlocking.
@@ -2599,8 +2604,40 @@
return optionsMethod(HttpURL.getPath(path),type);
}
-
-
+
+ /**
+ * Execute a LABEL method on the current path, setting the given label
+ */
+ public boolean labelMethod(String labelname, int type)
+ throws HttpException, IOException
+ {
+ int labeltype=0;
+
+ switch(type) {
+ case LABEL_SET:
+ labeltype = LabelMethod.LABEL_SET;
+ break;
+ case LABEL_REMOVE:
+ labeltype = LabelMethod.LABEL_REMOVE;
+ break;
+ case LABEL_ADD:
+ labeltype = LabelMethod.LABEL_ADD;
+ break;
+ }
+
+ setClient();
+ LabelMethod method = new LabelMethod(httpURL.getPath(), labeltype,
+ labelname);
+
+ method.setDebug(debug);
+ client.executeMethod(method);
+
+ int statusCode = method.getStatusCode();
+ setStatusCode(statusCode);
+
+ return (statusCode >= 200 && statusCode < 300) ? true : false;
+ }
+
/**
* Execute the REPORT method.
*/
1.5 +87 -35
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/LabelMethod.java
Index: LabelMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/LabelMethod.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LabelMethod.java 14 Aug 2002 15:22:24 -0000 1.4
+++ LabelMethod.java 4 Sep 2002 05:07:12 -0000 1.5
@@ -68,35 +68,49 @@
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.State;
import org.apache.util.WebdavStatus;
+import org.apache.util.XMLPrinter;
/**
- * The MkWorkspace method is used to create a new workspace. New workspaces
- * can only be created in the workspace collection of the server. A workspace
- * can contain version controled resources and any other. Each resource
- * must identify its workspace.
- *
- * It is not allowed to create a new workspace inside an exiting workspace.
- *
+ * The Label method is used to manipulate labels on resources on the server.
*
* <h3>Example Request</h3>
* <pre>
- * MKWORKSPACE /ws/myWs/ HTTP/1.1
- * Host: www.server.org
+ * LABEL /files/testfile.xml HTTP/1.1
+ * Host: www.webdav.org
+ * Content-Type: text/xml; charset="utf-8"
+ *
+ * <?xml version="1.0" encoding="utf-8"?>
+ * <D:label xmlns:D="DAV:">
+ * <D:set>
+ * <D:label-name>newlabel</D:label-name>
+ * </D:set>
+ * </D:label>
* </pre>
*
* <h3>Example Response</h3>
* <pre>
- * HTTP/1.1 201 Created
+ * HTTP/1.1 200 OK
+ * Cache-Control: no-cache
* </pre>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Mathias Luber</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Smith</a>
*/
public class LabelMethod
extends XMLResponseMethodBase {
+ /** Constant for setting a label */
+ public static final int LABEL_SET = 1;
+ /** Constant for adding a label */
+ public static final int LABEL_ADD = 2;
+ /** Constant for removing a label */
+ public static final int LABEL_REMOVE = 3;
+
+ String labelname = null;
+ int type = 0;
// ----------------------------------------------------------- Constructors
@@ -112,36 +126,74 @@
/**
* Method constructor.
*/
- public LabelMethod(String path) {
+ public LabelMethod(String path, int action, String labelname) {
super(path);
name = "LABEL";
+ this.labelname = labelname;
+ this.type = action;
+ }
+
+ /** Set the type of label action to take */
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ /** Get the label type which has been set */
+ public int getType() {
+ return type;
+ }
+
+ /** Set the label-name this action will manipulate */
+ public void setLabelName(String labelname) {
+ this.labelname = labelname;
+ }
+
+ /** Get the label-name this action will manipulate */
+ public String getLabelName() {
+ return labelname;
+ }
+
+ public void generateHeaders(String host, State state) {
+ super.generateHeaders(host, state);
+ super.setHeader("Content-Type", "text/xml; charset=utf-8");
}
/**
- * Parse response.
+ * Generate the query body.
*
- * @param input Input stream
+ * @return String query
*/
- public void parseResponse(InputStream input)
- throws IOException, HttpException {
- try
- {
- if (getStatusCode() == WebdavStatus.SC_CONFLICT ||
- getStatusCode() == WebdavStatus.SC_MULTI_STATUS ||
- getStatusCode() == WebdavStatus.SC_FORBIDDEN ) {
- parseXMLResponse(input);
- }
+ public String generateQuery() {
+ if(type <= 0 || labelname == null)
+ throw new IllegalStateException
+ ("Action type and label name must be set before "+
+ "calling this function");
+
+ XMLPrinter printer = new XMLPrinter();
+ printer.writeXMLHeader();
+ printer.writeElement("D", "DAV:", "label", XMLPrinter.OPENING);
+
+ String typeelement = null;
+ switch (type) {
+ case LABEL_SET:
+ typeelement = "set";
+ break;
+ case LABEL_REMOVE:
+ typeelement = "remove";
+ break;
+ case LABEL_ADD:
+ typeelement = "add";
+ break;
}
- catch (IOException e) {
- // FIX ME: provide a way to deliver non xml data
- }
- }
-
-
-
- // --------------------------------------------------- WebdavMethod Methods
-
+ printer.writeElement("D", typeelement, XMLPrinter.OPENING);
+ printer.writeElement("D", "label-name", XMLPrinter.OPENING);
+ printer.writeText(labelname);
+ printer.writeElement("D", "label-name", XMLPrinter.CLOSING);
+ printer.writeElement("D", typeelement, XMLPrinter.CLOSING);
+ printer.writeElement("D", "label", XMLPrinter.CLOSING);
+ return printer.toString();
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>