home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / servlet-api.jar / javax / servlet / http / Cookie.class (.txt) next >
Encoding:
Java Class File  |  2004-08-28  |  3.5 KB  |  113 lines

  1. package javax.servlet.http;
  2.  
  3. import java.text.MessageFormat;
  4. import java.util.ResourceBundle;
  5.  
  6. public class Cookie implements Cloneable {
  7.    private static final String LSTRING_FILE = "javax.servlet.http.LocalStrings";
  8.    private static ResourceBundle lStrings = ResourceBundle.getBundle("javax.servlet.http.LocalStrings");
  9.    private String name;
  10.    private String value;
  11.    private String comment;
  12.    private String domain;
  13.    private int maxAge = -1;
  14.    private String path;
  15.    private boolean secure;
  16.    private int version = 0;
  17.    private static final String tspecials = ",; ";
  18.  
  19.    public Cookie(String name, String value) {
  20.       if (this.isToken(name) && !name.equalsIgnoreCase("Comment") && !name.equalsIgnoreCase("Discard") && !name.equalsIgnoreCase("Domain") && !name.equalsIgnoreCase("Expires") && !name.equalsIgnoreCase("Max-Age") && !name.equalsIgnoreCase("Path") && !name.equalsIgnoreCase("Secure") && !name.equalsIgnoreCase("Version") && !name.startsWith("$")) {
  21.          this.name = name;
  22.          this.value = value;
  23.       } else {
  24.          String errMsg = lStrings.getString("err.cookie_name_is_token");
  25.          Object[] errArgs = new Object[1];
  26.          errArgs[0] = name;
  27.          errMsg = MessageFormat.format(errMsg, errArgs);
  28.          throw new IllegalArgumentException(errMsg);
  29.       }
  30.    }
  31.  
  32.    public void setComment(String purpose) {
  33.       this.comment = purpose;
  34.    }
  35.  
  36.    public String getComment() {
  37.       return this.comment;
  38.    }
  39.  
  40.    public void setDomain(String pattern) {
  41.       this.domain = pattern.toLowerCase();
  42.    }
  43.  
  44.    public String getDomain() {
  45.       return this.domain;
  46.    }
  47.  
  48.    public void setMaxAge(int expiry) {
  49.       this.maxAge = expiry;
  50.    }
  51.  
  52.    public int getMaxAge() {
  53.       return this.maxAge;
  54.    }
  55.  
  56.    public void setPath(String uri) {
  57.       this.path = uri;
  58.    }
  59.  
  60.    public String getPath() {
  61.       return this.path;
  62.    }
  63.  
  64.    public void setSecure(boolean flag) {
  65.       this.secure = flag;
  66.    }
  67.  
  68.    public boolean getSecure() {
  69.       return this.secure;
  70.    }
  71.  
  72.    public String getName() {
  73.       return this.name;
  74.    }
  75.  
  76.    public void setValue(String newValue) {
  77.       this.value = newValue;
  78.    }
  79.  
  80.    public String getValue() {
  81.       return this.value;
  82.    }
  83.  
  84.    public int getVersion() {
  85.       return this.version;
  86.    }
  87.  
  88.    public void setVersion(int v) {
  89.       this.version = v;
  90.    }
  91.  
  92.    private boolean isToken(String value) {
  93.       int len = value.length();
  94.  
  95.       for(int i = 0; i < len; ++i) {
  96.          char c = value.charAt(i);
  97.          if (c < ' ' || c >= 127 || ",; ".indexOf(c) != -1) {
  98.             return false;
  99.          }
  100.       }
  101.  
  102.       return true;
  103.    }
  104.  
  105.    public Object clone() {
  106.       try {
  107.          return super.clone();
  108.       } catch (CloneNotSupportedException e) {
  109.          throw new RuntimeException(e.getMessage());
  110.       }
  111.    }
  112. }
  113.