[prev in list] [next in list] [prev in thread] [next in thread]
List: slide-dev
Subject: cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd Main.java
From: jericho () apache ! org
Date: 2001-02-26 13:05:12
[Download RAW message or body]
jericho 01/02/26 05:05:12
Modified: src/webdav/client/src/org/apache/webdav/cmd Main.java
Log:
- Put a file on the server without writing a full uri out.
Patch submitted by Dirk Verbeeck <dirk.verbeeck at the-ecorp.com>.
Revision Changes Path
1.9 +122 -122 \
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Main.java 2001/02/21 18:56:26 1.8
+++ Main.java 2001/02/26 13:05:12 1.9
@@ -1,13 +1,13 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v \
1.8 2001/02/21 18:56:26 remm Exp $
- * $Revision: 1.8 $
- * $Date: 2001/02/21 18:56:26 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v \
1.9 2001/02/26 13:05:12 jericho Exp $ + * $Revision: 1.9 $
+ * $Date: 2001/02/26 13:05:12 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -23,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,11 +59,11 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.webdav.cmd;
-// Java
+// Java
import java.io.*;
import java.util.*;
import java.security.Principal;
@@ -79,45 +79,45 @@
/**
* 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>
* @author Sung-Gu Park
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
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.
*/
@@ -129,33 +129,33 @@
startUp.put("port", new Integer("8080"));
startUp.put("user", "guest");
startUp.put("password", "guest" );
-
+
client = new WebdavClient();
client.setDebug(0);
}
-
-
+
+
// --------------------------------------------------------- Public Methods
-
-
+
+
/**
* Main function.
*/
public static void main( String args[] ) {
-
+
boolean ready = false;
-
+
final Main m = new Main();
ready = m.processStartUp( args );
m.setPath("/");
m.updatePrompt("/");
-
+
final WebdavClient cl = m.getClient();
if ( ready )
{
// Process command line requests
// Once the client has started
- Thread inner =
+ Thread inner =
new Thread(
new Runnable()
{
@@ -163,16 +163,16 @@
{
m.processCommands( cl );
}
-
+
}
);
inner.start();
}
-
+
}
-
+
// -------------------------------------------------------- Private Methods
-
+
/**
* Parse the command line and execute the request.
* @param WeddavClient client
@@ -181,15 +181,15 @@
{
try
{
- BufferedReader in =
+ BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
String command = null;
-
+
do
{
System.out.print( getPrompt() );
command = in.readLine();
-
+
if( command == null || command.length() == 0 )
{
// Print commandLine Usage
@@ -201,14 +201,14 @@
StringTokenizer st = new StringTokenizer(command);
String todo = st.nextToken();
Stack params = new Stack();
-
+
while ( st.hasMoreTokens() )
{
params.push( st.nextToken() );
}
//System.out.println( todo );
-
+
if( todo.equalsIgnoreCase("quit") )
{
break;
@@ -220,7 +220,7 @@
else if( todo.equalsIgnoreCase("get") )
{
GetMethod gm = new GetMethod();
-
+
if( params.empty() )
{
System.out.println("get <uri of file to fetch>");
@@ -238,23 +238,23 @@
else if( todo.equalsIgnoreCase("put") )
{
PutMethod pm = new PutMethod();
-
+
if( params.empty() || params.size() < 2 )
{
System.out.println("put <uri to file to upload> <uri \
destination>"); }
else
{
- String dest = (String)params.pop();
+ String dest = checkUri( (String)params.pop() );
String toload = (String)params.pop();
-
+
System.out.println(" file to load " + toload );
System.out.println(" dest of file " + dest);
-
+
pm.setPath( dest );
pm.sendData( new File( toload ) );
client.executeMethod( pm );
-
+
System.out.println( "Status: " + pm.getStatusCode() );
System.out.println();
}
@@ -262,7 +262,7 @@
else if( todo.equalsIgnoreCase("mkcol") )
{
MkcolMethod mc = new MkcolMethod();
-
+
if( params.empty() )
{
System.out.println("mkcol <uri to make>");
@@ -279,7 +279,7 @@
else if( todo.equalsIgnoreCase("options") )
{
OptionsMethod mc = new OptionsMethod();
-
+
if( params.empty() )
{
System.out.println("options <uri>");
@@ -313,7 +313,7 @@
else if( todo.equalsIgnoreCase("propfind") )
{
PropFindMethod pf = new PropFindMethod();
-
+
if( params.empty() )
{
System.out.println("propfind <uri>");
@@ -324,20 +324,20 @@
pf.setPath( uri );
client.executeMethod( pf );
System.out.println( "Status: " + pf.getStatusCode() );
-
-
+
+
Enumeration e = pf.getResponses();
while ( e.hasMoreElements() )
{
System.out.println( e.nextElement() );
-
+
}
}
}
- else if( todo.equalsIgnoreCase("ls") )
- {
+ else if( todo.equalsIgnoreCase("ls") )
+ {
String uri = null;
-
+
if( params.empty() )
{
uri = getPath();
@@ -346,61 +346,61 @@
{
uri = checkUri( (String)params.pop() );
}
-
+
Vector property = new Vector();
property.addElement("displayname");
property.addElement("getcontentlength");
property.addElement("resourcetype");
property.addElement("getlastmodified");
-
- PropFindMethod pf =
+
+ 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() ) {
String url = (String) urls.nextElement();
- String dir = url.substring(url.indexOf(getPath()) +
+ String dir = url.substring(url.indexOf(getPath()) +
getPath().length() );
String lastModified = null;
String contentLength = null;
String resourceType = null;
-
+
Enumeration properties =
pf.getResponseProperties(url);
while (properties.hasMoreElements()) {
- Property currentProperty =
+ Property currentProperty =
(Property) properties.nextElement();
- String propertyNamespace =
+ String propertyNamespace =
currentProperty.getNamespaceURI();
- String propertyName =
+ String propertyName =
currentProperty.getLocalName();
-
+
if (propertyNamespace.equals("DAV:")) {
if (propertyName.equals("getcontentlength")) {
- contentLength =
+ contentLength =
currentProperty.getPropertyAsString();
} else if (propertyName.equals
("resourcetype")) {
- resourceType =
+ resourceType =
currentProperty.getPropertyAsString();
} else if (propertyName.equals
("getlastmodified")) {
- lastModified =
+ lastModified =
currentProperty.getPropertyAsString();
}
}
-
+
}
-
+
if (dir.length() == 0)
dir = ".";
- String display = lastModified + " "
+ String display = lastModified + " "
+ contentLength + " " + dir;
System.out.println(display);
-
+
}
}
else if( todo.equalsIgnoreCase("cd") )
@@ -411,7 +411,7 @@
// the the request is a valid URI
GetMethod gm = new GetMethod();
String cdpath = (String)params.pop();
-
+
if( cdpath.startsWith("/") )
{
gm.setPath( cdpath );
@@ -421,13 +421,13 @@
path = getPath();
cdpath = path.concat(cdpath);
}
-
+
client.executeMethod( gm );
-
+
if ( gm.getStatusCode() == 200 )
{
setPath( cdpath );
- updatePrompt( getPath() );
+ updatePrompt( getPath() );
}
}
}
@@ -435,7 +435,7 @@
{
System.out.println( getPath() );
}
- else if( todo.equalsIgnoreCase("delete") )
+ else if( todo.equalsIgnoreCase("delete") )
{
if( params.empty() )
{
@@ -446,18 +446,18 @@
String uri = checkUri( (String)params.pop() );
DeleteMethod dm = new DeleteMethod(uri);
client.executeMethod( dm );
-
+
System.out.println( "Status: " + dm.getStatusCode() );
}
}
else if( todo.equalsIgnoreCase("lock") )
{
-
+
String owner = "jericho@thinkfree.com";// user info
short lock = LockMethod.SCOPE_EXCLUSIVE;
// to make it easy to manage lock information
long timeout = 120; // 2 min.
-
+
if( params.empty() )
{
System.out.println("lock <uri>");
@@ -465,10 +465,10 @@
else
{
String uri = checkUri( (String)params.pop() );
-
+
LockMethod lm = new LockMethod(uri, owner, lock, timeout);
client.executeMethod( lm );
-
+
// TODO: to manage lock information for unlock
System.out.println( "Status: " + lm.getStatusCode() +
"\nLockToken: " + lm.getLockToken());
@@ -477,7 +477,7 @@
}
else if( todo.equalsIgnoreCase("proppatch") )
{
-
+
if( params.size() != 3 )
{
System.out.println("proppatch <uri> <property name> \
<property value>"); @@ -487,20 +487,20 @@
String propertyValue = (String) params.pop();
String propertyName = (String) params.pop();
String uri = checkUri( (String)params.pop() );
-
+
PropPatchMethod pp = new PropPatchMethod(uri);
pp.addPropertyToSet(propertyName, propertyValue);
// pp.addPropertyToSet("password", "jericho");
-
+
client.executeMethod( pp );
-
+
System.out.println( "Status: " + pp.getStatusCode() );
// pp.recycle();
}
}
else if( todo.equalsIgnoreCase("copy") )
{
-
+
if( params.size() != 2 )
{
System.out.println("copy <source uri> <destination \
uri>"); @@ -509,17 +509,17 @@
{
String destination = checkUri( (String)params.pop() );
String source = checkUri( (String)params.pop() );
-
+
CopyMethod cm = new CopyMethod(source, destination);
client.executeMethod( cm );
-
+
System.out.println( "Status: " + cm.getStatusCode() );
// cm.recycle();
}
}
else if( todo.equalsIgnoreCase("move") )
{
-
+
if( params.size() != 2)
{
System.out.println("move <source uri> <destination uri> \
"); @@ -528,10 +528,10 @@
{
String destination = checkUri( (String)params.pop() );
String source = checkUri( (String)params.pop() );
-
+
MoveMethod mm = new MoveMethod(source, destination);
client.executeMethod( mm );
-
+
System.out.println( "Status: " + mm.getStatusCode() );
// mm.recycle();
}
@@ -541,13 +541,13 @@
}
catch( Exception pce )
{
- System.out.println("Error processing a command: " + pce );
+ System.out.println("Error processing a command: " + pce );
}
}
-
+
/**
* Determine which URI to use at the prompt.
- * For example if your use "GET test", GET
+ * For example if your use "GET test", GET
* will look for test at the current path. However,
* if you use "GET /webdav/test" then GET will disregard the
* current path and use /webdav/test
@@ -559,10 +559,10 @@
{
uri = getPath().concat(uri);
}
-
+
return normalize(uri);
}
-
+
/**
* Set the path
* @param String the path
@@ -575,7 +575,7 @@
}
this.path = normalize(p);
}
-
+
/**
* Get the path
* @return String the path
@@ -586,7 +586,7 @@
}
/**
- * Update the command prompt
+ * Update the command prompt
* based on a CD
* @param String path
*/
@@ -596,18 +596,18 @@
buff.append("[Slide ");
buff.append(path);
buff.append(" ]$ ");
- commandPrompt = buff.toString();
+ commandPrompt = buff.toString();
}
-
+
/**
* Get the prompt
- * @param String
+ * @param String
*/
private String getPrompt()
{
- return commandPrompt;
+ return commandPrompt;
}
-
+
/**
* Return a context-relative path, beginning with a "/", that represents
* the canonical version of the specified path after ".." and "." elements
@@ -623,7 +623,7 @@
return null;
String normalized = path;
-
+
// Normalize the slashes and add leading slash if necessary
if (normalized.indexOf('\\') >= 0)
normalized = normalized.replace('\\', '/');
@@ -667,16 +667,16 @@
/**
- * Process the initial args passed to the Class.<br>
+ * Process the initial args passed to the Class.<br>
* Currently this should consist of:<br>
- *
+ *
* -host [the host to connect to]</br>
* -port [the port the host is running webdav on]<br>
* -u [username]<br>
* -p [password]<br>
*
* There are default set if anything is missing.<br>
- *
+ *
* If all goes well, a session will be created and credentials set.
*/
private boolean processStartUp( String[] args )
@@ -688,7 +688,7 @@
while ( argsIndex < args.length )
{
String input = args[ argsIndex ++ ];
-
+
if ( input.equalsIgnoreCase( "-help" ) )
{
printStartUsage();
@@ -696,7 +696,7 @@
}
else if ( input.equalsIgnoreCase( "-host" ) )
{
- startUp.put("host", args[ argsIndex++ ]);
+ startUp.put("host", args[ argsIndex++ ]);
}
else if ( input.equalsIgnoreCase( "-port" ) )
{
@@ -726,21 +726,21 @@
return false;
}
}
-
- // Start session with client
+
+ // Start session with client
String h = (String)startUp.get("host");
int p = ( (Integer)startUp.get("port") ).intValue();
client.startSession(h, p);
-
+
// Set the credentials to use
String un = (String)startUp.get("user");
String pn = (String)startUp.get("password");
Credentials credentials = new Credentials(un,pn);
client.setCredentials(credentials);
-
+
// Ready for interactive commandline
ready = true;
-
+
} catch (IllegalArgumentException iae) {
iae.getMessage();
System.err.println
@@ -753,7 +753,7 @@
}
return ready;
}
-
+
/**
* Print the commands options from startup
*/
@@ -766,13 +766,13 @@
System.out.println(" -p <password>");
System.out.println(" -help");
}
-
+
/**
* Print the commands for use
*/
private static void printCommandUsage()
{
- System.out.println("WebDAV Client commands:");
+ System.out.println("WebDAV Client commands:");
System.out.println(" quit");
System.out.println(" help/?");
System.out.println(" get [uri] Get \
a file"); @@ -790,12 +790,12 @@
System.out.println(" lock [uri] \
Lock a collection or a file");
System.out.println(" unlock [uri] \
Unlock a collection or a file"); }
-
+
private WebdavClient getClient()
{
return client;
}
-
+
private static void pause(int secs)
{
try
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic