001: // DAVIf.java
002: // $Id: DAVIf.java,v 1.3 2000/10/20 16:12:46 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.www.webdav;
006:
007: import java.util.LinkedList;
008: import java.util.ListIterator;
009:
010: import org.w3c.www.http.HttpInvalidValueException;
011:
012: /**
013: * @version $Revision: 1.3 $
014: * @author Benoît Mahé (bmahe@w3.org)
015: */
016: public class DAVIf {
017:
018: private String taggedResource = null;
019:
020: private LinkedList lists = null; // List of list
021:
022: public void addList(byte raw[], int start, int end)
023: throws HttpInvalidValueException {
024: // stuff like <...> [...] Not <...> [...]
025: LinkedList list = new LinkedList();
026: boolean isnot = false;
027: for (int i = start; i < end; i++) {
028: int idx = i + 1;
029: switch (raw[i]) {
030: case (byte) '<':
031: // State Token
032: while ((raw[i] != (byte) '>') && (i <= end)) {
033: i++;
034: }
035: String state = new String(raw, idx, i - idx);
036: DAVStateToken token = new DAVStateToken(state, isnot);
037: list.add(token);
038: isnot = false;
039: break;
040: case (byte) '[':
041: // ETag
042: while ((raw[i] != (byte) ']') && (i <= end)) {
043: i++;
044: }
045: DAVEntityTag etag = new DAVEntityTag(raw, idx, i - idx,
046: isnot);
047: list.add(etag);
048: isnot = false;
049: break;
050: case (byte) 'N':
051: // Not
052: if (i > end - 2) {
053: throw new HttpInvalidValueException(
054: "Invalid header");
055: }
056: isnot = ((raw[i + 1] == (byte) 'o') && (raw[i + 2] == (byte) 't'));
057: i += 2;
058: break;
059: case (byte) ' ':
060: case (byte) '\t':
061: //skip spaces
062: break;
063: default:
064: // error
065: String msg = "got '" + (char) raw[i] + "'";
066: throw new HttpInvalidValueException("Invalid header: "
067: + msg);
068: }
069: }
070: lists.add(list);
071: }
072:
073: public boolean hasResource() {
074: return (taggedResource != null);
075: }
076:
077: public String getResource() {
078: return taggedResource;
079: }
080:
081: public ListIterator getTokenListIterator() {
082: return lists.listIterator(0);
083: }
084:
085: DAVIf() {
086: this .lists = new LinkedList();
087: }
088:
089: DAVIf(String resource) throws HttpInvalidValueException {
090: this .taggedResource = DAVParser.decodeURL(resource);
091: this .lists = new LinkedList();
092: }
093:
094: /**
095: * Public Constructor
096: * @param resource the tagged resource (can be null)
097: * @param taglist a List of DAVStateToken and/or DAVEntityTag
098: * @see DAVStateToken
099: * @see DAVEntityTag
100: */
101: public DAVIf(String resource, LinkedList taglist) {
102: this.lists = taglist;
103: this.taggedResource = resource;
104: }
105:
106: }
|