KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > StateToken


1 package com.ibm.webdav;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * IBM will not be liable for any damages suffered by you as a result
10  * of using the Program. In no event will IBM be liable for any
11  * special, indirect or consequential damages or lost profits even if
12  * IBM has been advised of the possibility of their occurrence. IBM
13  * will not be liable for any third party claims against you.
14  */

15 import java.io.*;
16
17 /** A StateToken is a ConditionFactor describing some state of a resource represented
18  * as a URI. A typical example would be the WebDAV lock token.
19  * @author Jim Amsden <jamsden@us.ibm.com>
20  * @see com.ibm.webdav.Precondition
21  * @see com.ibm.webdav.ConditionTerm
22  * @see com.ibm.webdav.ConditionFactor
23  * @see com.ibm.webdav.EntityTag
24  * @see com.ibm.webdav.StateToken
25  */

26 public class StateToken extends ConditionFactor {
27     private String JavaDoc uri = null; // represents some state of a resource expressed as a URI
28
/** Construct a StateToken. Should never be called.
29     */

30    private StateToken()
31    {
32    }
33 /** Construct a StateToken with the given URI.
34  * @param uri the URI of the state token
35  */

36 public StateToken(String JavaDoc uri) {
37     this.uri = uri;
38 }
39 /** Create a StateToken by parsing the given If header as defined by
40  * section 9.4 in the WebDAV spec.
41  *
42  * @param tokenizer a StreamTokenizer on the contents of a WebDAV If header
43  * @return the parsed ConditionFactor (StateToken)
44  */

45 public static ConditionFactor create(StreamTokenizer tokenizer) throws WebDAVException {
46     StateToken stateToken = new StateToken();
47     try {
48         int token = tokenizer.ttype;
49         if (token == '<') {
50             token = tokenizer.nextToken();
51         } else {
52             throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Error parsing If header: saw: " + (char) token + " expected: <");
53         }
54         if (token == StreamTokenizer.TT_WORD) {
55             stateToken.setURI(tokenizer.sval);
56             token = tokenizer.nextToken();
57         } else {
58             throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Error parsing If header: saw: " + (char) token + " expected a URI");
59         }
60         if (token == '>') {
61             token = tokenizer.nextToken();
62         } else {
63             throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Error parsing If header: saw: " + (char) token + " expected: >");
64         }
65     } catch (IOException exc) {
66     }
67     return stateToken;
68 }
69 /** Compare with another StateToken.
70  * @param factor the state token to compare with
71  * @return true if this state token has the same URI as the factor
72  */

73 public boolean equals(Object JavaDoc factor) {
74     return factor != null && factor instanceof StateToken && getURI().equals(((StateToken) factor).getURI());
75 }
76 /** Get the URI of this StateToken. The URI represents some state of the
77  * resource in the containing Condition, for example, the lock token.
78  * @return the URI for this state token
79  */

80 public String JavaDoc getURI() {
81     return uri;
82 }
83 /** Set the URI of this StateToken. The URI represents some state of the
84  * resource in the containing Condition, for example, the lock token.
85  * @param value the URI for this state token
86  */

87 public void setURI(String JavaDoc value) {
88     uri = value;
89 }
90 /** Return a String representation of this StateToken as defined by the If
91  * header in section 9.4 of the WebDAV spec.
92  * @return a string representation of this state token
93  */

94 public String JavaDoc toString() {
95     StringWriter os = new StringWriter();
96     if (not()) {
97         os.write("Not ");
98     }
99     os.write('<');
100     os.write(getURI());
101     os.write('>');
102     try {
103         os.close();
104     } catch (Exception JavaDoc exc) {
105     }
106     return os.toString();
107 }
108 }
109
Popular Tags