1 19 package org.openharmonise.webdav.client; 20 21 import java.applet.*; 22 import java.io.*; 23 import java.net.*; 24 import java.util.*; 25 26 import HTTPClient.*; 27 import HTTPClient.URI; 28 29 37 public class WebDAVConnection extends HTTPConnection { 38 39 private static int TIMEOUT = 90000; 40 41 44 public static final String WEBDAV_NAMESPACE = "DAV:"; 45 46 49 private WebDAVFileSystem m_vfs = null; 50 51 public WebDAVConnection(WebDAVFileSystem vfs, Applet arg0) throws ProtocolNotSuppException { 52 super(arg0); 53 this.m_vfs = vfs; 54 this.setup(); 55 } 56 57 public WebDAVConnection(WebDAVFileSystem vfs, String arg0) { 58 super(arg0); 59 this.m_vfs = vfs; 60 this.setup(); 61 } 62 63 public WebDAVConnection(WebDAVFileSystem vfs, String arg0, int arg1) { 64 super(arg0, arg1); 65 this.m_vfs = vfs; 66 this.setup(); 67 } 68 69 public WebDAVConnection(WebDAVFileSystem vfs, String arg0, String arg1, int arg2) 70 throws ProtocolNotSuppException { 71 super(arg0, arg1, arg2); 72 this.m_vfs = vfs; 73 this.setup(); 74 } 75 76 public WebDAVConnection(WebDAVFileSystem vfs, 77 String arg0, 78 String arg1, 79 int arg2, 80 InetAddress arg3, 81 int arg4) 82 throws ProtocolNotSuppException { 83 super(arg0, arg1, arg2, arg3, arg4); 84 this.m_vfs = vfs; 85 this.setup(); 86 } 87 88 public WebDAVConnection(WebDAVFileSystem vfs, URL arg0) throws ProtocolNotSuppException { 89 super(arg0); 90 this.m_vfs = vfs; 91 this.setup(); 92 } 93 94 98 public WebDAVConnection(WebDAVFileSystem vfs, URI arg0) throws ProtocolNotSuppException { 99 super(arg0); 100 this.m_vfs = vfs; 101 this.setup(); 102 } 103 104 public void setup() { 105 WebDAVConnection.setDefaultTimeout(TIMEOUT); 106 } 107 108 public static void main(String [] args) { 109 110 } 111 112 122 public WebDAVResponse execute(AbstractWebDAVMethod method) throws IOException, ModuleException { 123 124 WebDAVResponse davResponse = null; 125 126 try { 127 HTTPResponse response = this.ExtensionMethod(method.getName(), 128 URLEncode(method.getURL()), 129 method.getData(), 130 method.getAllHeaders()); 131 davResponse = new WebDAVResponse( response ); 132 davResponse.setURL( method.getURL() ); 133 } catch(SocketException se) { 134 HTTPResponse response = this.ExtensionMethod(method.getName(), 135 URLEncode(method.getURL()), 136 method.getData(), 137 method.getAllHeaders()); 138 davResponse = new WebDAVResponse( response ); 139 davResponse.setURL( method.getURL() ); 140 } catch(IOException io) { 141 HTTPResponse response = this.ExtensionMethod(method.getName(), 142 URLEncode(method.getURL()), 143 method.getData(), 144 method.getAllHeaders()); 145 davResponse = new WebDAVResponse( response ); 146 davResponse.setURL( method.getURL() ); 147 } 148 149 return davResponse; 150 } 151 152 158 public static String URLEncode(String sURL) { 159 StringBuffer sBuff = new StringBuffer (); 160 161 StringTokenizer sTok = new StringTokenizer(sURL, " /:", true); 162 while(sTok.hasMoreTokens()) { 163 try { 164 String sToken = sTok.nextToken(); 165 if( !sToken.equals(":") && !sToken.equals("/") && !sToken.equals(" ") ) { 166 sBuff.append( URLEncoder.encode(sToken, "UTF-8") ); 167 } else if(sToken.equals(" ")) { 168 sBuff.append("%20"); 169 } else if(sToken.equals(":")) { 170 sBuff.append(":"); 171 } else { 172 sBuff.append(sToken); 173 } 174 } catch (UnsupportedEncodingException e) { 175 e.printStackTrace(); 176 } 177 178 } 179 180 return sBuff.toString(); 181 } 182 183 189 public static String URLDencode(String sURL) { 190 sURL.replaceAll("%20", " "); 191 StringBuffer sBuff = new StringBuffer (); 192 193 StringTokenizer sTok = new StringTokenizer(sURL, "/", true); 194 while(sTok.hasMoreTokens()) { 195 try { 196 String sToken = sTok.nextToken(); 197 if( !sToken.equals("/") ) { 198 sBuff.append( URLDecoder.decode(sToken, "UTF-8") ); 199 } else { 200 sBuff.append(sToken); 201 } 202 } catch (UnsupportedEncodingException e) { 203 e.printStackTrace(); 204 } 205 206 } 207 208 return sBuff.toString(); 209 } 210 } 211 | Popular Tags |