1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.Enumeration ; 29 import java.util.Vector ; 30 import org.apache.commons.httpclient.HttpConnection; 31 import org.apache.commons.httpclient.HttpException; 32 import org.apache.commons.httpclient.HttpState; 33 import org.apache.webdav.lib.util.WebdavStatus; 34 35 93 94 public class SearchMethod extends XMLResponseMethodBase { 95 96 97 99 100 102 103 106 public SearchMethod() { 107 } 108 109 110 113 public SearchMethod(String path) { 114 super(path); 115 } 116 117 118 126 public SearchMethod(String path, String query) { 127 this(path); 128 preloadedQuery = query; 129 } 130 131 132 134 135 138 protected String prefix = null; 139 140 private String preloadedQuery = null; 141 142 144 145 147 public String getName() { 148 return "SEARCH"; 149 } 150 151 public void recycle() { 152 super.recycle(); 153 prefix = null; 154 } 155 156 157 163 public void addRequestHeaders(HttpState state, HttpConnection conn) 164 throws IOException , HttpException { 165 166 if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 168 super.addRequestHeaders(state, conn); 169 170 } 171 172 178 protected String generateRequestBody() { 179 180 if (preloadedQuery == null || preloadedQuery.trim().length() < 1) { 181 return ""; 187 } else { 188 return preloadedQuery; 189 } 190 191 } 192 193 201 public Enumeration getAllResponseURLs() { 202 checkUsed(); 203 return getResponseURLs().elements(); 204 } 205 206 207 210 public Enumeration getResponseProperties(String urlPath) { 211 checkUsed(); 212 213 Response response = (Response) getResponseHashtable().get(urlPath); 214 if (response != null) { 215 return response.getProperties(); 216 } else { 217 return (new Vector ()).elements(); 218 } 219 220 } 221 222 227 public void parseResponse(InputStream input, HttpState state, HttpConnection conn) 228 throws IOException , HttpException { 229 try 230 { 231 int code = getStatusLine().getStatusCode(); 232 if (code == WebdavStatus.SC_BAD_REQUEST || 233 code == WebdavStatus.SC_MULTI_STATUS || 234 code == WebdavStatus.SC_FORBIDDEN || 235 code == WebdavStatus.SC_CONFLICT ) { 236 parseXMLResponse(input); 237 } 238 } 239 catch (IOException e) { 240 } 242 } 243 244 245 246 } 247 248 249 250 251 252 | Popular Tags |