jericho 01/03/06 18:08:03
Modified: src/webdav/client/src/org/apache/webdav/cmd Slide.java
src/webdav/client/src/org/apache/webdav/util
WebdavResource.java
Log:
- Fixed authorization to be checkd on the command line.
- Added the function that the Slide options command can be used in even the off-line
status.
- Added the static options method with an argument of HttpURL for that.
Revision Changes Path
1.4 +101 -53
jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java
Index: Slide.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Slide.java 2001/03/05 10:09:01 1.3
+++ Slide.java 2001/03/07 02:07:59 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.3
2001/03/05 10:09:01 juergen Exp $
- * $Revision: 1.3 $
- * $Date: 2001/03/05 10:09:01 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Slide.java,v 1.4
2001/03/07 02:07:59 jericho Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/03/07 02:07:59 $
*
* ====================================================================
*
@@ -189,6 +189,9 @@
*/
WebdavResource webdavResource = null;
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(System.in));
+
try {
if (stringUrl != null) {
// Set up for processing WebDAV resources from command line.
@@ -197,8 +200,38 @@
webdavResource = new WebdavResource(httpUrl);
setPath(webdavResource.getPath());
} catch (WebdavException we) {
- System.err.println("Warning: " + we.getMessage());
- httpUrl = null;
+ // Check authorization and try it again.
+ if (we.getStatusCode() ==
+ WebdavStatus.SC_UNAUTHORIZED) {
+
+ System.out.print("UserName: ");
+ String userName = in.readLine();
+ if (userName != null && userName.length() > 0) {
+ System.out.print("Password: ");
+ String password = in.readLine();
+ try {
+ httpUrl.setUserInfo(userName, password);
+ if (webdavResource != null) {
+ webdavResource.setHttpUrl(httpUrl);
+ } else {
+ webdavResource =
+ new WebdavResource(httpUrl);
+ }
+ setPath(webdavResource.getPath());
+ } catch (WebdavException e) {
+ System.err.println("Warning: "
+ + e.getMessage());
+ httpUrl = null;
+ } catch (IOException e) {
+ System.err.println("Error: check! "
+ + e.getMessage());
+ httpUrl = null;
+ }
+ }
+ } else {
+ System.err.println("Warning: " + we.getMessage());
+ httpUrl = null;
+ }
} catch (IOException e) {
System.err.println("Error: check! " + e.getMessage());
httpUrl = null;
@@ -206,10 +239,7 @@
}
updatePrompt(getPath());
- BufferedReader in =
- new BufferedReader(new InputStreamReader(System.in));
String command = null;
-
do {
System.out.print(getPrompt());
command = in.readLine();
@@ -301,6 +331,64 @@
todo.equalsIgnoreCase("?")) {
printSlideClientUsage();
} else
+ if (todo.equalsIgnoreCase("options")) {
+ int count = params.size();
+ String param = null;
+ HttpURL httpUrl = null;
+ if (count > 0)
+ param = (String) params.pop();
+ try {
+ boolean succeeded = false;
+ if (param != null) {
+ if (!param.startsWith("/")) {
+ httpUrl = new HttpURL(param);
+ Enumeration enum =
+ WebdavResource.optionsMethod(httpUrl);
+ while (enum.hasMoreElements()) {
+ System.out.print(enum.nextElement());
+ if (enum.hasMoreElements())
+ System.out.print(", ");
+ }
+ continue;
+ } else
+ if (webdavResource != null) {
+ succeeded =
+ webdavResource.optionsMethod(param);
+ }
+ } else
+ if (webdavResource != null) {
+ succeeded = webdavResource.optionsMethod("*");
+ }
+
+ if (succeeded) {
+ System.out.print
+ ("Allowed methods by http OPTIONS: ");
+ Enumeration allowed =
+ webdavResource.getAllowedMethods();
+ while (allowed.hasMoreElements()) {
+ System.out.print(allowed.nextElement());
+ if (allowed.hasMoreElements())
+ System.out.print(", ");
+ }
+ Enumeration davCapabilities =
+ webdavResource.getDavCapabilities();
+ if (davCapabilities.hasMoreElements())
+ System.out.print("\nDAV: ");
+ while (davCapabilities.hasMoreElements()) {
+ System.out.print
+ (davCapabilities.nextElement());
+ if (davCapabilities.hasMoreElements())
+ System.out.print(", ");
+ }
+ System.out.println();
+ }
+ } catch (WebdavException we) {
+ System.err.println("Warning: " + we.getMessage());
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.err.println("Error: check! " + e.getMessage());
+ }
+ } else
// Check the status of connection
if (webdavResource == null) {
System.out.println("Not connected yet.");
@@ -390,7 +478,7 @@
String token = null;
String path = null;
// set default options.
- byte[] options = { (byte) '-', (byte) 'F' };
+ char[] options = { '-', 'F' };
while (!params.empty()) {
// get the input token.
@@ -401,12 +489,12 @@
// FIXME: in the case of the child-resource?
path = checkUri(token + "/");
} else {
- options = token.getBytes();
+ options = token.toCharArray();
}
}
}
for (int o = 1; o < options.length; o++) {
- switch ((char)options[o]) {
+ switch (options[o]) {
case 'l':
try {
Vector list = webdavResource.listCollection();
@@ -770,46 +858,6 @@
e.getMessage());
}
}
- } else
- if (todo.equalsIgnoreCase("options")) {
- int count = params.size();
- String path = null;
- if (count > 0)
- path = checkUri((String) params.pop());
- try {
- boolean succeeded = webdavResource.optionsMethod(
- path != null ? path : "*");
- if (succeeded) {
- System.out.print
- ("Allowed methods by http OPTIONS: ");
- Enumeration allowed =
- webdavResource.getAllowedMethods();
- while (allowed.hasMoreElements()) {
- System.out.print(allowed.nextElement());
- if (allowed.hasMoreElements())
- System.out.print(", ");
- }
- Enumeration davCapabilities =
- webdavResource.getDavCapabilities();
- if (davCapabilities.hasMoreElements())
- System.out.print("\nDAV: ");
- while (davCapabilities.hasMoreElements()) {
- System.out.print
- (davCapabilities.nextElement());
- if (davCapabilities.hasMoreElements())
- System.out.print(", ");
- }
- System.out.println();
- } else {
- System.out.println("failed.");
- System.out.println(
- webdavResource.getStatusMessage());
- }
- } catch (WebdavException we) {
- System.err.println("Warning: " + we.getMessage());
- } catch (IOException e) {
- System.err.println("Error: check! " + e.getMessage());
- }
}
} while (true);
@@ -984,6 +1032,8 @@
"Exit Slide");
System.out.println(" help " +
"Print this help message");
+ System.out.println(" options [abs_path|http_URL] " +
+ "Print available http methods");
System.out.println(" url " +
"Print working URL");
System.out.println(" status " +
@@ -1014,8 +1064,6 @@
"Lock specified resource");
System.out.println(" unlock path " +
"Unlock specified resource");
- System.out.println(" options [path] " +
- "Print available http methods");
System.out.println("\nAliases: help=?, ls=dir, pwc=pwd, cc=cd, " +
"copy=cp, move=mv, delete=del=rm,\n mkcol=mkdir, " +
"exit=quit");
1.12 +40 -3
jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WebdavResource.java 2001/03/06 13:42:27 1.11
+++ WebdavResource.java 2001/03/07 02:08:02 1.12
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.11 2001/03/06 13:42:27 jericho Exp $
- * $Revision: 1.11 $
- * $Date: 2001/03/06 13:42:27 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/util/WebdavResource.java,v
1.12 2001/03/07 02:08:02 jericho Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/03/07 02:08:02 $
*
* ====================================================================
*
@@ -1332,6 +1332,43 @@
}
return false;
+ }
+
+
+ /*
+ * Execute OPTIONS method for the given http URL.
+ *
+ * @param httpUrl the http URL.
+ * @return the allowed methods and capabilities.
+ * @exception WebdavException
+ * @exception IOException
+ */
+ public static Enumeration optionsMethod(HttpURL httpUrl)
+ throws WebdavException, IOException {
+
+ WebdavClientSession session = new WebdavClientSession();
+ WebdavClient client = session.getSessionInstance(httpUrl);
+
+ OptionsMethod method = new OptionsMethod(httpUrl.getPath());
+ client.executeMethod(method);
+
+ Vector options = new Vector();
+ int statusCode = method.getStatusCode();
+ if (statusCode >= 200 && statusCode < 300) {
+ // check if the specific method is possbile
+ Enumeration allowedMethods = method.getAllowedMethods();
+ while (allowedMethods.hasMoreElements()) {
+ options.addElement(allowedMethods.nextElement());
+ }
+ // check WebDAV capabilities.
+ Enumeration davCapabilities = method.getDavCapabilities();
+ while (davCapabilities.hasMoreElements()) {
+ options.addElement(davCapabilities.nextElement());
+ }
+ }
+ session.unsetSession(httpUrl);
+
+ return options.elements();
}