001: // DAVIfList.java
002: // $Id: DAVIfList.java,v 1.1 2000/09/20 15:07:47 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.Vector;
008: import java.util.LinkedList;
009: import java.util.ListIterator;
010:
011: import org.w3c.www.http.BasicValue;
012:
013: /**
014: * @version $Revision: 1.1 $
015: * @author Benoît Mahé (bmahe@w3.org)
016: */
017: public class DAVIfList extends BasicValue {
018:
019: public static final boolean debug = false;
020:
021: DAVIf davifs[] = null;
022:
023: boolean tagged = false;
024:
025: protected void parse() {
026: Vector vdavifs = new Vector();
027:
028: if (debug) {
029: System.out.println("PARSING IF HEADER");
030: }
031: // for end of list ( ... )
032: ParseState list = new ParseState(0, raw.length);
033: list.separator = (byte) ')';
034: list.spaceIsSep = false;
035: // for beginning of list
036: ParseState blist = new ParseState(0, 0);
037: blist.separator = (byte) '(';
038: blist.spaceIsSep = false;
039: // for state token <...>
040: ParseState st = new ParseState(0, 0);
041: st.separator = (byte) '>';
042: st.spaceIsSep = false;
043:
044: DAVIf davif = null;
045: if (DAVParser.nextItem(raw, list) >= 0) {
046: if (DAVParser.startsWith(raw, list, '<')) {
047: tagged = true;
048: do {
049: if (DAVParser.startsWith(raw, list, '<')) {
050: davif = null;
051: }
052: blist.prepare(list);
053: while (DAVParser.nextItem(raw, blist) >= 0) {
054: // the tagged resource
055: if ((DAVParser.startsWith(raw, blist, '<'))
056: && (davif == null)) {
057: davif = new DAVIf(blist.toString(raw));
058: vdavifs.addElement(davif);
059: if (debug) {
060: System.out.println("Res : "
061: + davif.getResource());
062: }
063: //list.start = st.end;
064: } else {
065: // another list for our tagged resource
066: if (debug) {
067: String slist = blist.toString(raw);
068: System.out.println("LIST : " + slist);
069: }
070: davif.addList(raw, blist.start, blist.end);
071: }
072: }
073: } while (DAVParser.nextItem(raw, list) >= 0);
074: } else {
075: // (... ... ...) (... ... ...)
076: tagged = false;
077: davif = new DAVIf();
078: vdavifs.addElement(davif);
079: do {
080: blist.prepare(list);
081: while (DAVParser.nextItem(raw, blist) >= 0) {
082: if (debug) {
083: System.out.println(blist.toString(raw));
084: }
085: davif.addList(raw, blist.start, blist.end);
086: }
087: } while (DAVParser.nextItem(raw, list) >= 0);
088: }
089: }
090: // Ok good
091: davifs = new DAVIf[vdavifs.size()];
092: vdavifs.copyInto(davifs);
093: }
094:
095: protected void updateByteValue() {
096: if (davifs != null) {
097: StringBuffer buf = new StringBuffer();
098: for (int i = 0; i < davifs.length; i++) {
099: DAVIf davif = davifs[i];
100: if (davif.hasResource()) {
101: buf.append("<").append(davif.getResource()).append(
102: "> ");
103: }
104: ListIterator iterator = davif.getTokenListIterator();
105: while (iterator.hasNext()) {
106: LinkedList list = (LinkedList) iterator.next();
107: ListIterator it = list.listIterator(0);
108: buf.append("(");
109: while (it.hasNext()) {
110: Object token = (String) it.next();
111: String item = token.toString();
112: if (it.hasNext()) {
113: buf.append(item).append(" ");
114: } else {
115: buf.append(item);
116: }
117: }
118: buf.append(")");
119: }
120: }
121: raw = buf.toString().getBytes();
122: roff = 0;
123: rlen = raw.length;
124: } else {
125: raw = new byte[0];
126: roff = 0;
127: rlen = 0;
128: }
129: }
130:
131: public Object getValue() {
132: validate();
133: return davifs;
134: }
135:
136: public boolean isTaggedList() {
137: return tagged;
138: }
139:
140: public DAVIfList() {
141: this .isValid = false;
142: }
143:
144: }
|