001: // DAVRequest.java
002: // $Id: DAVRequest.java,v 1.9 2000/10/24 16:25:26 bmahe Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.jigsaw.webdav;
006:
007: import org.w3c.jigsaw.http.Client;
008: import org.w3c.jigsaw.http.Request;
009: import org.w3c.jigsaw.http.Reply;
010:
011: import org.w3c.tools.resources.ReplyInterface;
012: import org.w3c.tools.resources.ResourceFilter;
013:
014: import org.w3c.www.http.HTTP;
015: import org.w3c.www.http.HeaderValue;
016: import org.w3c.www.mime.MimeParser;
017:
018: import org.w3c.www.webdav.DAVIf;
019: import org.w3c.www.webdav.DAVIfList;
020: import org.w3c.www.webdav.WEBDAV;
021:
022: /**
023: * @version $Revision: 1.9 $
024: * @author Benoît Mahé (bmahe@w3.org)
025: */
026: public class DAVRequest extends Request implements WEBDAV {
027:
028: static {
029: registerHeader(DEPTH_HEADER, "org.w3c.www.http.HttpString");
030: registerHeader(DESTINATION_HEADER,
031: "org.w3c.www.http.HttpString");
032: registerHeader(IF_HEADER, "org.w3c.www.webdav.DAVIfList");
033: registerHeader(LOCK_TOKEN_HEADER, "org.w3c.www.http.HttpString");
034: registerHeader(OVERWRITE_HEADER, "org.w3c.www.http.HttpString");
035: registerHeader(TIMEOUT_HEADER, "org.w3c.www.http.HttpTokenList");
036: }
037:
038: public final static String depthToString(int depth) {
039: switch (depth) {
040: case DEPTH_0:
041: return "0";
042: case DEPTH_1:
043: return "1";
044: default:
045: return "Infinity";
046: }
047: }
048:
049: public int getDepth() {
050: HeaderValue value = getHeaderValue(DEPTH_HEADER);
051: if (value == null) {
052: return DEPTH_INFINITY;
053: }
054: String s = (String) value.getValue();
055: if (s.equals("0")) {
056: return DEPTH_0;
057: } else if (s.equals("1")) {
058: return DEPTH_1;
059: } else { // default
060: return DEPTH_INFINITY;
061: }
062: }
063:
064: public String getDestination() {
065: HeaderValue value = getHeaderValue(DESTINATION_HEADER);
066: return (value != null) ? (String) value.getValue() : null;
067: }
068:
069: public DAVIf[] getIf() {
070: HeaderValue value = getHeaderValue(IF_HEADER);
071: return (value != null) ? (DAVIf[]) value.getValue() : null;
072: }
073:
074: public boolean isTaggedListIfHeader() {
075: DAVIfList value = (DAVIfList) getHeaderValue(IF_HEADER);
076: return value.isTaggedList();
077: }
078:
079: public String getLockToken() {
080: HeaderValue value = getHeaderValue(LOCK_TOKEN_HEADER);
081: return (value != null) ? (String) value.getValue() : null;
082: }
083:
084: public boolean getOverwrite() {
085: HeaderValue value = getHeaderValue(OVERWRITE_HEADER);
086: String overwrite = (value != null) ? (String) value.getValue()
087: : null;
088: return (!"F".equals(overwrite));
089: }
090:
091: public String[] getTimeout() {
092: HeaderValue value = getHeaderValue(TIMEOUT_HEADER);
093: return (value != null) ? (String[]) value.getValue() : null;
094: }
095:
096: public ReplyInterface makeBadRequestReply() {
097: return makeReply(HTTP.BAD_REQUEST);
098: }
099:
100: /**
101: * Make an empty Reply object matching this request version.
102: * @param status The status of the reply.
103: */
104:
105: public Reply makeReply(int status) {
106: return (Reply) makeDAVReply(status);
107: }
108:
109: /**
110: * Make an empty DAV Reply object matching this request version.
111: * @param status The status of the reply.
112: */
113:
114: public DAVReply makeDAVReply(int status) {
115: DAVReply reply = new DAVReply(client, this , getMajorVersion(),
116: getMinorVersion(), status);
117: if ((filters != null) && (infilters > 0))
118: reply.setFilters(filters, infilters);
119: return reply;
120: }
121:
122: /**
123: * Constructor
124: */
125: public DAVRequest(Client client, MimeParser parser) {
126: super(client, parser);
127: this.parser = parser;
128: this.client = client;
129: }
130:
131: }
|