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 re...@apache.org on 2001/02/11 22:07:55 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd Main.java
remm 01/02/11 13:07:55
Modified: src/webdav/client/src/org/apache/webdav/cmd Main.java
Log:
- Small enhancements to the command line client.
- URL is normalized after a path change, so that cd .. will
now do what is expected.
- Enhanced a bit the information dislayed by the ls command.
Revision Changes Path
1.7 +122 -21 jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Main.java 2001/01/21 20:34:56 1.6
+++ Main.java 2001/02/11 21:07:54 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v 1.6 2001/01/21 20:34:56 remm Exp $
- * $Revision: 1.6 $
- * $Date: 2001/01/21 20:34:56 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v 1.7 2001/02/11 21:07:54 remm Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/02/11 21:07:54 $
*
* ====================================================================
*
@@ -80,40 +80,46 @@
/**
* Command line WebDAV client.
*
- *
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
- * @version $Revision: 1.6 $
+ * @author Sung-Gu Park
+ * @version $Revision: 1.7 $
*/
public class Main {
// ----------------------------------------------------- Instance Variables
+
/**
* Table for startup parameters
*/
Hashtable startUp = null;
+
/**
* Client
*/
WebdavClient client = null;
-
+
+
/**
* Command prompt
*/
String commandPrompt = null;
-
+
+
/**
* Path
*/
String path = null;
-
+
+
// ------------------------------------------------------------ Constructor
+
/**
- * Constructor
+ * Constructor.
*/
public Main()
{
@@ -125,7 +131,7 @@
startUp.put("password", "guest" );
client = new WebdavClient();
- client.setDebug(1);
+ client.setDebug(0);
}
@@ -135,8 +141,8 @@
/**
* Main function.
*/
- public static void main( String args[] )
- {
+ public static void main( String args[] ) {
+
boolean ready = false;
final Main m = new Main();
@@ -162,6 +168,7 @@
);
inner.start();
}
+
}
// -------------------------------------------------------- Private Methods
@@ -346,18 +353,54 @@
property.addElement("resourcetype");
property.addElement("getlastmodified");
- PropFindMethod pf = new PropFindMethod(uri,property.elements());
+ PropFindMethod pf =
+ new PropFindMethod(uri, property.elements());
+ pf.setDepth(1);
client.executeMethod( pf );
System.out.println( "Status: " + pf.getStatusCode() );
Enumeration urls = pf.getAllResponseURLs();
- while ( urls.hasMoreElements() )
- {
+ while ( urls.hasMoreElements() ) {
String url = (String) urls.nextElement();
- String dir = url.substring(
- url.indexOf(getPath()) +
+ String dir = url.substring(url.indexOf(getPath()) +
getPath().length() );
- System.out.println(dir.length() == 0 ? "." : dir);
+ String lastModified = null;
+ String contentLength = null;
+ String resourceType = null;
+
+ Enumeration properties =
+ pf.getResponseProperties(url);
+ while (properties.hasMoreElements()) {
+ Property currentProperty =
+ (Property) properties.nextElement();
+ String propertyNamespace =
+ currentProperty.getNamespaceURI();
+ String propertyName =
+ currentProperty.getLocalName();
+
+ if (propertyNamespace.equals("DAV:")) {
+ if (propertyName.equals("getcontentlength")) {
+ contentLength =
+ currentProperty.getPropertyAsString();
+ } else if (propertyName.equals
+ ("resourcetype")) {
+ resourceType =
+ currentProperty.getPropertyAsString();
+ } else if (propertyName.equals
+ ("getlastmodified")) {
+ lastModified =
+ currentProperty.getPropertyAsString();
+ }
+ }
+
+ }
+
+ if (dir.length() == 0)
+ dir = ".";
+ String display = lastModified + " "
+ + contentLength + " " + dir;
+ System.out.println(display);
+
}
}
else if( todo.equalsIgnoreCase("cd") )
@@ -384,7 +427,7 @@
if ( gm.getStatusCode() == 200 )
{
setPath( cdpath );
- updatePrompt( cdpath );
+ updatePrompt( getPath() );
}
}
}
@@ -517,7 +560,7 @@
uri = getPath().concat(uri);
}
- return uri;
+ return normalize(uri);
}
/**
@@ -530,7 +573,7 @@
{
p = p.concat("/");
}
- this.path = p;
+ this.path = normalize(p);
}
/**
@@ -565,6 +608,64 @@
return commandPrompt;
}
+ /**
+ * Return a context-relative path, beginning with a "/", that represents
+ * the canonical version of the specified path after ".." and "." elements
+ * are resolved out. If the specified path attempts to go outside the
+ * boundaries of the current context (i.e. too many ".." path elements
+ * are present), return <code>null</code> instead.
+ *
+ * @param path Path to be normalized
+ */
+ private String normalize(String path) {
+
+ if (path == null)
+ return null;
+
+ String normalized = path;
+
+ // Normalize the slashes and add leading slash if necessary
+ if (normalized.indexOf('\\') >= 0)
+ normalized = normalized.replace('\\', '/');
+ if (!normalized.startsWith("/"))
+ normalized = "/" + normalized;
+
+ // Resolve occurrences of "/./" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("/./");
+ if (index < 0)
+ break;
+ normalized = normalized.substring(0, index) +
+ normalized.substring(index + 2);
+ }
+
+ // Resolve occurrences of "/../" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("/../");
+ if (index < 0)
+ break;
+ if (index == 0)
+ return (null); // Trying to go outside our context
+ int index2 = normalized.lastIndexOf('/', index - 1);
+ normalized = normalized.substring(0, index2) +
+ normalized.substring(index + 3);
+ }
+
+ // Resolve occurrences of "//" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("//");
+ if (index < 0)
+ break;
+ normalized = normalized.substring(0, index) +
+ normalized.substring(index + 1);
+ }
+
+ // Return the normalized path that we have completed
+ return (normalized);
+
+ }
+
+
/**
* Process the initial args passed to the Class.<br>
* Currently this should consist of:<br>