You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ib...@apache.org on 2004/01/19 10:30:02 UTC
cvs commit: jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib WebdavSession.java WebdavResources.java WebdavResource.java WebdavFile.java
ib 2004/01/19 01:30:02
Modified: webdavclient/commandline/src/java/org/apache/webdav/cmd
Client.java
webdavclient/clientlib/src/java/org/apache/webdav/lib
WebdavSession.java WebdavResources.java
WebdavResource.java WebdavFile.java
Log:
Use HttpURL from Commons Httpclient instead of org.apache.util.HttpURL
Revision Changes Path
1.2 +20 -15 jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java
Index: Client.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Client.java 9 Jan 2004 09:58:19 -0000 1.1
+++ Client.java 19 Jan 2004 09:30:01 -0000 1.2
@@ -80,7 +80,8 @@
import java.util.Vector;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
-import org.apache.util.HttpURL;
+import org.apache.commons.httpclient.HttpURL;
+import org.apache.commons.httpclient.util.URIUtil;
import org.apache.util.QName;
import org.apache.webdav.lib.Ace;
import org.apache.webdav.lib.Lock;
@@ -299,7 +300,7 @@
try {
// Set up for processing WebDAV resources
- httpURL = new HttpURL(uri);
+ httpURL = new HttpURL(uri.toCharArray());
if (webdavResource == null) {
webdavResource = new WebdavResource(httpURL);
webdavResource.setDebug(debugLevel);
@@ -333,9 +334,9 @@
httpURL = null;
webdavResource = null;
}
- httpURL = new HttpURL(uri);
+ httpURL = new HttpURL(uri.toCharArray());
// It should be used like this way.
- httpURL.setUserInfo(userName, password);
+ httpURL.setUserinfo(userName, password);
webdavResource = new WebdavResource(httpURL);
webdavResource.setDebug(debugLevel);
setPath(webdavResource.getPath());
@@ -383,7 +384,7 @@
boolean succeeded = false;
if (param != null) {
if (!param.startsWith("/")) {
- httpURL = new HttpURL(param);
+ httpURL = new HttpURL(param.toCharArray());
Enumeration enum = null;
try {
// OPTIONS business logic
@@ -413,7 +414,7 @@
password= password.trim();
try {
// OPTIONS business logic
- httpURL.setUserInfo(userName,
+ httpURL.setUserinfo(userName,
password);
enum = webdavResource.
optionsMethod(httpURL);
@@ -770,7 +771,7 @@
out.print("Putting property(" + name + ", " + value +
") to '" + path + "': ");
if (webdavResource.proppatchMethod(
- path, new PropertyName("DAV:",name), value)) {
+ path, new PropertyName("DAV:",name), value, true)) {
out.println("succeeded.");
} else {
out.println("failed.");
@@ -788,7 +789,11 @@
// The resource on the remote.
String src = checkUri(path);
// The file on the local.
- String dest = (filename!=null) ? filename : HttpURL.getName(src);
+ String dest = (filename!=null)
+ ? filename
+ : URIUtil.getName(src.endsWith("/")
+ ? src.substring(0, src.length() - 1)
+ : src);
out.println("get " + src + " " + dest);
@@ -1203,11 +1208,11 @@
if ((properties!=null) && (properties.size()>0)) {
propertyValues =
- webdavResource.reportMethod(new HttpURL(path), properties, 1);
+ webdavResource.reportMethod(new HttpURL(path.toCharArray()), properties, 1);
}
else {
propertyValues =
- webdavResource.reportMethod(new HttpURL(path), 1);
+ webdavResource.reportMethod(new HttpURL(path.toCharArray()), 1);
}
if (propertyValues.hasMoreElements()){
@@ -1254,7 +1259,7 @@
out.println("expand-property Report of '" + path + "':");
Enumeration propertyValues =
- webdavResource.reportMethod(new HttpURL(path), sQuery, 1);
+ webdavResource.reportMethod(new HttpURL(path.toCharArray()), sQuery, 1);
if (propertyValues.hasMoreElements()){
while (propertyValues.hasMoreElements()){
out.println(displayXML(propertyValues.nextElement().toString(), 0));
@@ -1280,7 +1285,7 @@
out.println("Getting version-tree Report of '" + path + "':");
Enumeration propertyValues =
- webdavResource.reportMethod(new HttpURL(path), properties, historyUris, 1);
+ webdavResource.reportMethod(new HttpURL(path.toCharArray()), properties, historyUris, 1);
if (propertyValues.hasMoreElements()) {
while (propertyValues.hasMoreElements()) {
out.println(propertyValues.nextElement().toString());
1.2 +6 -7 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavSession.java
Index: WebdavSession.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavSession.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavSession.java 9 Jan 2004 09:56:04 -0000 1.1
+++ WebdavSession.java 19 Jan 2004 09:30:01 -0000 1.2
@@ -69,7 +69,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.util.HttpURL;
+import org.apache.commons.httpclient.HttpURL;
/**
* This WebdavSession class is for the session management of WebDAV clients.
@@ -182,12 +182,11 @@
// Set a state which allows lock tracking
client.setState(new WebdavState());
HostConfiguration hostConfig = client.getHostConfiguration();
- hostConfig.setHost(httpURL.getHost(), httpURL.getPort(),
- httpURL.getScheme());
+ hostConfig.setHost(httpURL);
if (proxyHost != null && proxyPort > 0)
hostConfig.setProxy(proxyHost, proxyPort);
- String userName = httpURL.getUserName();
+ String userName = httpURL.getUser();
if (userName != null && userName.length() > 0) {
String password = httpURL.getPassword();
HttpState clientState = client.getState();
1.2 +4 -4 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResources.java
Index: WebdavResources.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResources.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavResources.java 9 Jan 2004 09:56:04 -0000 1.1
+++ WebdavResources.java 19 Jan 2004 09:30:01 -0000 1.2
@@ -233,7 +233,7 @@
public void addResource(WebdavResource resource) {
String displayName = resource.getDisplayName();
if (displayName == null || displayName.trim().equals("")) {
- displayName = resource.getHttpURL().getName();
+ displayName = resource.getName();
}
hrefTable.put(displayName, resource);
}
1.2 +56 -26 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavResource.java 9 Jan 2004 09:56:04 -0000 1.1
+++ WebdavResource.java 19 Jan 2004 09:30:01 -0000 1.2
@@ -69,7 +69,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.ParseException;
@@ -92,8 +91,9 @@
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.util.DOMUtils;
-import org.apache.util.HttpURL;
-import org.apache.util.HttpsURL;
+import org.apache.commons.httpclient.HttpURL;
+import org.apache.commons.httpclient.HttpsURL;
+import org.apache.commons.httpclient.URIException;
import org.apache.util.WebdavStatus;
import org.apache.webdav.lib.methods.AclMethod;
import org.apache.webdav.lib.methods.AclReportMethod;
@@ -132,10 +132,10 @@
* File(String) | WebdavResource(HttpURL)
* File(String, String) | X (need to escape)
* File(File, String) | WebdavResource(HttpURL, String)
- * getName() | *see getHttpURL() and HttpURL
+ * getName() | getName()
* getParent() | *see getHttpURL() and HttpURL
* getParentFile() | X (not yet)
- * getPath() | *see getHttpURL() and HttpURL
+ * getPath() | getPath()
* isAbsolute() | X
* getAbsolutePath() |
* getAbsoluteFile() | X
@@ -919,7 +919,7 @@
boolean itself = false;
String href = response.getHref();
if (!href.startsWith("/"))
- href = HttpURL.getEscapedPath(href);
+ href = URIUtil.getPath(href);
String httpURLPath = httpURL.getEscapedPath();
int compared = httpURLPath.compareTo(href);
// Compare with the href path and requested-path itself.
@@ -958,7 +958,7 @@
String displayName = workingResource.getDisplayName();
if (displayName == null || displayName.trim().equals("")) {
- displayName = HttpURL.getName(href);
+ displayName = getName(href);
}
if (!itself) {
String myURI = httpURL.getEscapedURI();
@@ -1086,7 +1086,7 @@
*
* @return true if the given httpURL is the client for this resource.
*/
- protected synchronized boolean isTheClient() throws MalformedURLException {
+ protected synchronized boolean isTheClient() throws URIException {
Credentials creds = client.getState().getCredentials(null,
client.getHost());
@@ -1288,9 +1288,9 @@
* @return httpURL the http URL.
*/
public HttpURL getHttpURLExceptForUserInfo()
- throws MalformedURLException {
+ throws URIException {
- return httpURL.getHttpURLExceptForUserInfo();
+ return new HttpURL(httpURL.getRawURI());
}
@@ -1314,12 +1314,32 @@
/**
* Get the path part of this WebdavResource.
+ * If the decoding of the path fails, this method will not throw an
+ * exception but return the escaped path instead.
*
* @return the path for this WebdavResource.
+ * @see org.apache.commons.httpclient.HttpURL#getPath()
* @see #setPath(java.lang.String)
*/
public String getPath() {
- return httpURL.getPath();
+ try {
+ return httpURL.getPath();
+ } catch (URIException e) {
+ return httpURL.getEscapedPath();
+ }
+ }
+
+
+ /**
+ * Get the name of this WebdavResource.
+ * If the decoding of the name fails, this method will not throw an
+ * exception but return the escaped name instead.
+ *
+ * @return the name of this WebdavResource.
+ * @see org.apache.commons.httpclient.HttpURL#getName()
+ */
+ public String getName() {
+ return getName(httpURL.getEscapedPath());
}
@@ -1327,9 +1347,9 @@
* Get the hostname of this WebdavResource.
*
* @return the hostname.
- * @exception MalformedURLException
+ * @exception URIException
*/
- public String getHost() throws MalformedURLException {
+ public String getHost() throws URIException {
return httpURL.getHost();
}
@@ -1337,7 +1357,7 @@
/**
* Set the userinfo part of this WebdavResource.
*
- * @exception MalformedURLException
+ * @exception HttpException
* @exception IOException
* @see #setHttpURL(HttpURL)
* @see #setHttpURL(java.lang.String)
@@ -1346,7 +1366,7 @@
public void setUserInfo(String userName, String password)
throws HttpException, IOException {
- httpURL.setUserInfo(userName, password);
+ httpURL.setUserinfo(userName, password);
setHttpURL(httpURL);
}
@@ -3783,8 +3803,8 @@
public boolean lockMethod()
throws HttpException, IOException {
- String owner = (httpURL.getUserName() != null) ?
- httpURL.getUserName() : defaultOwner;
+ String owner = (httpURL.getUser() != null) ?
+ httpURL.getUser() : defaultOwner;
boolean result = lockMethod(httpURL.getPath(), owner, 120);
if (result) refresh();
@@ -3826,8 +3846,8 @@
public boolean lockMethod(String path)
throws HttpException, IOException {
- String owner = (httpURL.getUserName() != null) ?
- httpURL.getUserName() : defaultOwner;
+ String owner = (httpURL.getUser() != null) ?
+ httpURL.getUser() : defaultOwner;
return lockMethod(path, owner, 120);
}
@@ -3904,8 +3924,8 @@
*/
public boolean unlockMethod() throws HttpException, IOException {
- String owner = (httpURL.getUserName() != null) ?
- httpURL.getUserName() : defaultOwner;
+ String owner = (httpURL.getUser() != null) ?
+ httpURL.getUser() : defaultOwner;
boolean result = unlockMethod(httpURL.getPath(), owner);
if (result) refresh();
@@ -3925,8 +3945,8 @@
public boolean unlockMethod(String path)
throws HttpException, IOException {
- String owner = (httpURL.getUserName() != null) ?
- httpURL.getUserName() : defaultOwner;
+ String owner = (httpURL.getUser() != null) ?
+ httpURL.getUser() : defaultOwner;
return unlockMethod(path, owner);
}
@@ -4421,4 +4441,14 @@
return method.getResponses();
}
+
+ private static String getName(String uri) {
+ String escapedName = URIUtil.getName(
+ uri.endsWith("/") ? uri.substring(0, uri.length() - 1): uri);
+ try {
+ return URIUtil.decode(escapedName);
+ } catch (URIException e) {
+ return escapedName;
+ }
+ }
}
1.2 +48 -23 jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavFile.java
Index: WebdavFile.java
===================================================================
RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavFile.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavFile.java 9 Jan 2004 09:56:04 -0000 1.1
+++ WebdavFile.java 19 Jan 2004 09:30:01 -0000 1.2
@@ -71,7 +71,9 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.util.HttpURL;
+import org.apache.commons.httpclient.HttpURL;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.util.URIUtil;
/**
* Implements a file for WebDav
@@ -93,7 +95,7 @@
* @param parent directory
* @param child element in parent
*/
- public WebdavFile(WebdavFile parent, String child) throws MalformedURLException {
+ public WebdavFile(WebdavFile parent, String child) throws URIException {
this(
parent.getAbsolutePath() + davSeparator + child,
parent.getUser(),
@@ -106,8 +108,8 @@
* @param user user name
* @param pass password
*/
- public WebdavFile(String pathname, String user, String pass) throws MalformedURLException {
- this(new URL(pathname), user, pass);
+ public WebdavFile(String pathname, String user, String pass) throws URIException {
+ this(new HttpURL(user, pass, null, -1, pathname));
}
/**
@@ -115,7 +117,7 @@
* @param user user name
* @param pass password
*/
- public WebdavFile(URL url, String user, String pass) throws MalformedURLException {
+ public WebdavFile(URL url, String user, String pass) throws URIException {
this(new HttpURL(user, pass, url.getHost(), url.getPort(), url.getPath()));
}
/**
@@ -124,15 +126,15 @@
* @param user user name
* @param pass password
*/
- public WebdavFile(String parent, String child, String user, String pass) throws MalformedURLException {
+ public WebdavFile(String parent, String child, String user, String pass) throws URIException {
this(parent + davSeparator + child, user, pass);
}
/**
* @param httpUrl Webdav URL
*/
- public WebdavFile(HttpURL httpUrl) {
- super(httpUrl.getUnescapedHttpURL());
+ public WebdavFile(HttpURL httpUrl) throws URIException {
+ super(httpUrl.getURI());
this.httpUrl = httpUrl;
}
@@ -174,13 +176,13 @@
return files;
}
- public String getUser() throws MalformedURLException {
+ public String getUser() throws URIException {
if(relPath!=null)
return null;
- return httpUrl.getUserName();
+ return httpUrl.getUser();
}
- public String getPass() throws MalformedURLException {
+ public String getPass() throws URIException {
if(relPath!=null)
return null;
return httpUrl.getPassword();
@@ -189,16 +191,31 @@
public String getName() {
if(relPath!=null)
return relPath;
- return httpUrl.getName();
+ String escapedPath = httpUrl.getEscapedPath();
+ String escapedName =
+ URIUtil.getName(escapedPath.endsWith("/")
+ ? escapedPath.substring(0, escapedPath.length() - 1)
+ : escapedPath);
+ try {
+ return URIUtil.decode(escapedName);
+ } catch (URIException e) {
+ return escapedName;
+ }
}
public String getParent() {
if(relPath!=null)
return null;
- String parent = httpUrl.getParent();
- if("/".equals(parent))
+ String escapedPath = httpUrl.getEscapedPath();
+ String parent = escapedPath.substring(
+ 0, escapedPath.lastIndexOf('/', escapedPath.length() - 2) + 1);
+ if (parent.length() <= 1)
return null;
- return parent;
+ try {
+ return URIUtil.decode(parent);
+ } catch (URIException e) {
+ return parent;
+ }
}
public File getParentFile() {
@@ -207,8 +224,8 @@
return null;
try {
- return new WebdavFile(getParent(), getUser(), getPass());
- } catch(MalformedURLException e) {
+ return new WebdavFile(parent, getUser(), getPass());
+ } catch(URIException e) {
throw new WebdavException(e);
}
}
@@ -216,7 +233,11 @@
public String getPath() {
if(relPath!=null)
return relPath;
- return httpUrl.getUnescapedHttpURL();
+ try {
+ return httpUrl.getURI();
+ } catch (URIException e) {
+ throw new WebdavException(e);
+ }
}
public boolean isAbsolute() {
@@ -242,7 +263,11 @@
public URL toURL() throws MalformedURLException {
if(relPath!=null)
return null;
- return httpUrl.toURL();
+ try {
+ return new URL(httpUrl.getURI());
+ } catch (URIException e) {
+ throw new MalformedURLException(e.getMessage());
+ }
}
public boolean canRead() {
@@ -481,7 +506,7 @@
public String toString() {
if(relPath!=null)
return relPath;
- return httpUrl.getUnescapedHttpURL();
+ return httpUrl.getEscapedURI();
}
public int compareTo(File pathname) {
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org