001: // HttpAcceptEncoding.java
002: // $Id: HttpAcceptEncoding.java,v 1.3 2001/02/21 16:22:10 hugo Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.www.http;
007:
008: public class HttpAcceptEncoding extends BasicValue {
009: String encoding = null;
010: double quality = 1.0;
011: HttpAcceptEncodingList list = null;
012:
013: /**
014: * parse.
015: * @exception HttpParserException if parsing failed.
016: */
017: protected void parse() throws HttpParserException {
018: ParseState ps = new ParseState(roff, rlen);
019: ps.separator = (byte) ';';
020: ps.spaceIsSep = false;
021: // Get the encoding:
022: if (HttpParser.nextItem(raw, ps) < 0)
023: error("Invalid Accept-Encoding: no encoding.");
024: this .encoding = new String(raw, 0, ps.start, ps.end - ps.start);
025: // And the optional quality:
026: ps.prepare();
027: ps.separator = (byte) '=';
028: if (HttpParser.nextItem(raw, ps) < 0) {
029: this .quality = 1.0;
030: } else {
031: ps.prepare();
032: this .quality = HttpParser.parseQuality(raw, ps);
033: }
034: }
035:
036: protected void invalidateByteValue() {
037: super .invalidateByteValue();
038: if (list != null)
039: list.invalidateByteValue();
040: }
041:
042: protected void updateByteValue() {
043: HttpBuffer buf = new HttpBuffer();
044: buf.append(encoding);
045: buf.append(';');
046: buf.append(quality);
047: raw = buf.getByteCopy();
048: roff = 0;
049: rlen = raw.length;
050: }
051:
052: public Object getValue() {
053: validate();
054: return this ;
055: }
056:
057: /**
058: * Get this accept encoding clause encoding.
059: * @return A String encoding the encoding token.
060: */
061:
062: public String getEncoding() {
063: validate();
064: return encoding;
065: }
066:
067: /**
068: * Set the encoding accepted by this clause.
069: * @param encoding The accepted encoding.
070: */
071:
072: public void setEncoding(String encoding) {
073: if (this .encoding != null) {
074: if (this .encoding.equals(encoding)) {
075: return;
076: }
077: }
078: invalidateByteValue();
079: this .encoding = encoding;
080: }
081:
082: /**
083: * Get the quality at which this encoding is accepted.
084: * @return A double value, encoding the quality, or <strong>1.0</strong>
085: * if undefined.
086: */
087:
088: public double getQuality() {
089: validate();
090: return quality;
091: }
092:
093: /**
094: * Set the quality under which this encoding is accepted.
095: * @param q The quality for this encoding.
096: */
097:
098: public void setQuality(double quality) {
099: if (this .quality != quality)
100: invalidateByteValue();
101: this .quality = quality;
102: }
103:
104: HttpAcceptEncoding(HttpAcceptEncodingList list, byte raw[], int o,
105: int l) {
106: this .list = list;
107: this .raw = raw;
108: this .roff = o;
109: this .rlen = l;
110: this .isValid = false;
111: }
112:
113: HttpAcceptEncoding(boolean isValid, String enc, double quality) {
114: this .isValid = isValid;
115: setEncoding(enc);
116: setQuality(quality);
117: }
118:
119: public HttpAcceptEncoding() {
120: this .isValid = false;
121: }
122: }
|