001: // DAVReply.java
002: // $Id: DAVReply.java,v 1.7 2000/10/11 14:11:59 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.Request;
008: import org.w3c.jigsaw.http.Reply;
009: import org.w3c.jigsaw.http.Client;
010:
011: import org.w3c.tools.resources.ResourceFilter;
012:
013: import org.w3c.www.http.HttpFactory;
014: import org.w3c.www.http.HeaderValue;
015:
016: import org.w3c.www.webdav.WEBDAV;
017: import org.w3c.www.webdav.DAVStatusURIList;
018: import org.w3c.www.webdav.DAVStatusURI;
019:
020: /**
021: * @version $Revision: 1.7 $
022: * @author Benoît Mahé (bmahe@w3.org)
023: */
024: public class DAVReply extends Reply implements WEBDAV {
025:
026: static {
027: registerHeader(DAV_HEADER, "org.w3c.www.http.HttpString");
028: registerHeader(LOCK_TOKEN_HEADER, "org.w3c.www.http.HttpString");
029: registerHeader(STATUS_URI_HEADER,
030: "org.w3c.www.webdav.DAVStatusURIList");
031: }
032:
033: public void setLockToken(String token) {
034: setHeaderValue(LOCK_TOKEN_HEADER, HttpFactory.makeString(token));
035: }
036:
037: public String getLockToken() {
038: HeaderValue value = getHeaderValue(LOCK_TOKEN_HEADER);
039: return (value != null) ? (String) value.getValue() : null;
040: }
041:
042: public void setStatusURI(int status, String uri) {
043: DAVStatusURIList list = (DAVStatusURIList) getHeaderValue(STATUS_URI_HEADER);
044: DAVStatusURI dsu = new DAVStatusURI(status, uri);
045: if (list == null) {
046: list = new DAVStatusURIList(dsu);
047: } else {
048: list.addStatusURI(dsu);
049: }
050: setHeaderValue(STATUS_URI_HEADER, list);
051: }
052:
053: public DAVStatusURI[] getStatusURI() {
054: HeaderValue value = getHeaderValue(STATUS_URI_HEADER);
055: return (value != null) ? (DAVStatusURI[]) value.getValue()
056: : null;
057: }
058:
059: public void setDAV(String dav) {
060: setHeaderValue(DAV_HEADER, HttpFactory.makeString(dav));
061: }
062:
063: protected void setFilters(ResourceFilter filters[], int infilters) {
064: super .setFilters(filters, infilters);
065: }
066:
067: /**
068: * Get the standard HTTP & WEBDAV reason phrase for the given status code.
069: * @param status The given status code.
070: * @return A String giving the standard reason phrase, or
071: * <strong>null</strong> if the status doesn't match any knowned error.
072: */
073:
074: public String getStandardReason(int status) {
075: return getDAVReason(status);
076: }
077:
078: public static String getDAVReason(int status) {
079: int category = status / 100;
080: int catcode = status % 100;
081: switch (category) {
082: case 1:
083: if ((catcode >= 0) && (catcode < dav_msg_100.length))
084: return dav_msg_100[catcode];
085: break;
086: case 2:
087: if ((catcode >= 0) && (catcode < dav_msg_200.length))
088: return dav_msg_200[catcode];
089: break;
090: case 3:
091: if ((catcode >= 0) && (catcode < dav_msg_300.length))
092: return dav_msg_300[catcode];
093: break;
094: case 4:
095: if ((catcode >= 0) && (catcode < dav_msg_400.length))
096: return dav_msg_400[catcode];
097: break;
098: case 5:
099: if ((catcode >= 0) && (catcode < dav_msg_500.length))
100: return dav_msg_500[catcode];
101: break;
102: }
103: return null;
104: }
105:
106: /**
107: * Create a new reply for the given client.
108: * @param client The client ot who the reply is directed.
109: * @reply status The reply status code.
110: */
111: public DAVReply(Client client, Request request, short major,
112: short minor, int status) {
113: super(client, request, major, minor, status);
114: }
115:
116: }
|