001: // HttpWarning.java
002: // $Id: HttpWarning.java,v 1.10 1998/08/13 16:28:38 bmahe 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 HttpWarning extends BasicValue {
009: /**
010: * Warning status - Response is stale.
011: */
012: public static final int STALE = 110;
013: /**
014: * Warning status - Revalidation failed.
015: */
016: public static final int REVALIDATION_FAILED = 111;
017: /**
018: * Warning status - Disconnected opertaion.
019: */
020: public static final int DISCONNECTED_OPERATION = 112;
021: /**
022: * Warning status - Heuristic expiration.
023: */
024: public static final int HEURISTIC_EXPIRATION = 113;
025: /**
026: * Warning status - Miscellaneous warning
027: */
028: public static final int MISCELLANEOUS = 199;
029: /**
030: * Warning status - Transformation applied.
031: */
032: public static final int TRANSFORMATION_APPLIED = 214;
033: /**
034: * Warning status - Miscellaneous warning
035: */
036: public static final int PERSISTENT_MISCELLANEOUS = 199;
037:
038: protected HttpWarningList list = null;
039:
040: protected int status = -1;
041: protected String agent = null;
042: protected String text = null;
043:
044: /**
045: * parse.
046: * @exception HttpParserException if parsing failed.
047: */
048: protected void parse() throws HttpParserException {
049: ParseState ps = new ParseState(roff, rlen);
050: ParseState it = new ParseState();
051: // Get the status code:
052: if (HttpParser.nextItem(raw, ps) < 0)
053: error("Invalid warning, no status code.");
054: it.ioff = ps.start;
055: it.bufend = ps.end;
056: this .status = HttpParser.parseInt(raw, it);
057: // Get the agent emiting the warning
058: ps.prepare();
059: if (HttpParser.nextItem(raw, ps) < 0)
060: error("Invalid warning, no agent field.");
061: this .agent = new String(raw, 0, ps.start, ps.end - ps.start);
062: // Get the quoted message
063: ps.prepare();
064: if (HttpParser.nextItem(raw, ps) < 0)
065: error("Invalid warning, no text message.");
066: it.ioff = ps.start;
067: it.bufend = ps.end;
068: HttpParser.unquote(raw, it);
069: this .text = new String(raw, 0, it.start, it.end - it.start);
070: }
071:
072: protected void updateByteValue() {
073: HttpBuffer buf = new HttpBuffer();
074: buf.appendInt(status);
075: buf.append(' ');
076: buf.append(agent);
077: buf.append(' ');
078: buf.appendQuoted(text);
079: raw = buf.getByteCopy();
080: roff = 0;
081: rlen = raw.length;
082: }
083:
084: protected void invalidateByteValue() {
085: super .invalidateByteValue();
086: if (list != null)
087: list.invalidateByteValue();
088: }
089:
090: public Object getValue() {
091: validate();
092: return this ;
093: }
094:
095: /**
096: * Get this warning status code.
097: * @return An integer giving the warning status code.
098: */
099:
100: public int getStatus() {
101: validate();
102: return status;
103: }
104:
105: /**
106: * Set this warning status code.
107: * @param status The status code for this warning.
108: */
109:
110: public void setStatus(int status) {
111: if (this .status != status)
112: invalidateByteValue();
113: this .status = status;
114: }
115:
116: /**
117: * Get this warning agent.
118: * @return A String encoding the agent that generated the warning.
119: */
120:
121: public String getAgent() {
122: validate();
123: return agent;
124: }
125:
126: /**
127: * Set the agent that is generating the warning.
128: * @param agent The String describing the agent emitting the warning.
129: */
130:
131: public void setAgent(String agent) {
132: if ((agent != null) && !agent.equals(this .agent))
133: invalidateByteValue();
134: this .agent = agent;
135: }
136:
137: /**
138: * Get the warning text message.
139: * @return A String encoding the text message.
140: */
141:
142: public String getText() {
143: validate();
144: return text;
145: }
146:
147: /**
148: * Set the text warning message.
149: * @param text The new text of the warning message.
150: */
151:
152: public void setText(String text) {
153: if ((text != null) && !text.equals(this .text))
154: invalidateByteValue();
155: this .text = text;
156: }
157:
158: HttpWarning(HttpWarningList list, byte raw[], int roff, int rlen) {
159: this .list = list;
160: this .raw = raw;
161: this .roff = roff;
162: this .rlen = rlen;
163: this .isValid = false;
164: }
165:
166: HttpWarning(boolean isValid, int status, String agent, String text) {
167: this .isValid = isValid;
168: setStatus(status);
169: setAgent(agent);
170: setText(text);
171: }
172:
173: public HttpWarning() {
174: this .isValid = false;
175: }
176: }
|