001: // HttpEntityTag.java
002: // $Id: HttpEntityTag.java,v 1.10 2002/07/17 14:22:10 ylafon Exp $$
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.www.http;
007:
008: public class HttpEntityTag extends BasicValue {
009: boolean weak = false;
010: String tag = null;
011:
012: HttpEntityTagList list = null;
013:
014: /**
015: * parse the byte value as an entity tag.
016: * @exception HttpParserException if parsing failed.
017: */
018: protected void parse() throws HttpParserException {
019: ParseState ps = new ParseState();
020: ps.ioff = roff;
021: ps.bufend = rlen;
022: ps.separator = (byte) '/';
023: if (HttpParser.nextItem(raw, ps) < 0)
024: error("Invalid entity tag.");
025: if ((raw[ps.start] == 'W') || (raw[ps.start] == 'w')) {
026: weak = true;
027: ps.prepare();
028: if (HttpParser.nextItem(raw, ps) < 0)
029: error("Invalid weak entity tag.");
030: ps.ioff = ps.start;
031: ps.bufend = ps.end;
032: HttpParser.unquote(raw, ps);
033: tag = ps.toString(raw);
034: } else {
035: weak = false;
036: ps.ioff = ps.start;
037: ps.bufend = ps.end;
038: HttpParser.unquote(raw, ps);
039: tag = ps.toString(raw);
040: }
041: }
042:
043: protected void invalidateByteValue() {
044: super .invalidateByteValue();
045: if (list != null)
046: list.invalidateByteValue();
047: }
048:
049: /**
050: * Update the byte value to reflect any changes in the parsed value.
051: */
052:
053: protected void updateByteValue() {
054: validate();
055: HttpBuffer buf = new HttpBuffer(20);
056: if (weak) {
057: buf.append('W');
058: buf.append('/');
059: }
060: buf.appendQuoted(tag);
061: raw = buf.getByteCopy();
062: roff = 0;
063: rlen = raw.length;
064: }
065:
066: public Object getValue() {
067: return this ;
068: }
069:
070: /**
071: * Is this a weak entity tag ?
072: * @return A boolean <strong>true</strong> if the tag is weak.
073: */
074:
075: public boolean isWeak() {
076: validate();
077: return weak;
078: }
079:
080: /**
081: * Set this tag weakness.
082: * @param onoff A boolean, tag is weak if <strong>true</strong>.
083: */
084:
085: public void setWeak(boolean onoff) {
086: if (onoff != weak)
087: invalidateByteValue();
088: weak = onoff;
089: }
090:
091: /**
092: * Get this tag value.
093: * @return A String giving the entity tag value.
094: */
095:
096: public String getTag() {
097: validate();
098: return tag;
099: }
100:
101: /**
102: * Set this tag value.
103: * @param tag The new tag value.
104: */
105:
106: public void setTag(String tag) {
107: if (!tag.equals(this .tag))
108: invalidateByteValue();
109: this .tag = tag;
110: }
111:
112: HttpEntityTag(HttpEntityTagList list, byte raw[], int roff, int rlen) {
113: this .list = list;
114: this .raw = raw;
115: this .isValid = false;
116: this .roff = roff;
117: this .rlen = rlen;
118: }
119:
120: HttpEntityTag(boolean isValid, boolean weak, String tag) {
121: this .isValid = isValid;
122: this .weak = weak;
123: this .tag = tag;
124: }
125:
126: public HttpEntityTag() {
127: this .isValid = false;
128: }
129:
130: }
|