1 package com.ibm.webdav; 2 3 15 import java.io.*; 16 17 26 public class StateToken extends ConditionFactor { 27 private String uri = null; 30 private StateToken() 31 { 32 } 33 36 public StateToken(String uri) { 37 this.uri = uri; 38 } 39 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 73 public boolean equals(Object factor) { 74 return factor != null && factor instanceof StateToken && getURI().equals(((StateToken) factor).getURI()); 75 } 76 80 public String getURI() { 81 return uri; 82 } 83 87 public void setURI(String value) { 88 uri = value; 89 } 90 94 public String 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 exc) { 105 } 106 return os.toString(); 107 } 108 } 109 | Popular Tags |