1 23 package org.apache.webdav.lib.methods; 24 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.StringTokenizer ; 30 31 import org.apache.commons.httpclient.HttpConnection; 32 import org.apache.commons.httpclient.HttpException; 33 import org.apache.commons.httpclient.HttpState; 34 35 36 41 public class UnsubscribeMethod extends XMLResponseMethodBase 42 { 43 private static final String HEADER_SUBSCRIPTION_ID = "Subscription-Id"; 44 45 private List subscriptionIds = new ArrayList (); 46 47 public UnsubscribeMethod() { 48 } 49 50 public UnsubscribeMethod(String path) { 51 super(path); 52 } 53 54 57 public void addSubscriptionId(int id) { 58 this.subscriptionIds.add(new Integer (id)); 59 } 60 61 63 public String getName() 64 { 65 return "UNSUBSCRIBE"; 66 } 67 68 public void recycle() 69 { 70 super.recycle(); 71 this.subscriptionIds.clear(); 72 } 73 74 protected void addRequestHeaders(HttpState state, HttpConnection conn) 75 throws IOException , HttpException 76 { 77 super.addRequestHeaders(state, conn); 78 if (this.subscriptionIds.size() > 0) { 79 StringBuffer b = new StringBuffer (); 80 boolean first = true; 81 for (Iterator i = this.subscriptionIds.iterator(); i.hasNext();) { 82 if (first) first = false; else b.append(", "); 83 b.append(i.next()); 84 } 85 super.addRequestHeader(HEADER_SUBSCRIPTION_ID, b.toString()); 86 } 87 } 88 89 93 public void setRequestHeader(String headerName, String headerValue) 94 { 95 if (headerName.equalsIgnoreCase(HEADER_SUBSCRIPTION_ID)){ 96 StringTokenizer t = new StringTokenizer (headerValue, ", "); 97 try { 98 for(;t.hasMoreTokens();) { 99 addSubscriptionId(Integer.parseInt(t.nextToken())); 100 } 101 } catch (NumberFormatException e) { 102 throw new IllegalArgumentException ("Invalid header value '" + 103 headerValue + "' for header " + headerName + "!"); 104 } 105 } else { 106 super.setRequestHeader(headerName, headerValue); 107 } 108 } 109 } 110 | Popular Tags |