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 pn...@apache.org on 2004/09/16 21:38:26 UTC
cvs commit: jakarta-slide/proposals/wvcm/src/org/apache/wvcm LocationImpl.java
pnever 2004/09/16 12:38:26
Modified: proposals/wvcm/src/org/apache/wvcm/sample
BasicCmdClient.java sample.properties
proposals/wvcm/src/org/apache/wvcm LocationImpl.java
Log:
Enhanced "BasicCmdClient' contributed by Michael Gesmann.
Some changes to make mod_dav compliant.
Revision Changes Path
1.9 +752 -105 jakarta-slide/proposals/wvcm/src/org/apache/wvcm/sample/BasicCmdClient.java
Index: BasicCmdClient.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/wvcm/src/org/apache/wvcm/sample/BasicCmdClient.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BasicCmdClient.java 30 Jul 2004 06:52:26 -0000 1.8
+++ BasicCmdClient.java 16 Sep 2004 19:38:26 -0000 1.9
@@ -63,6 +63,7 @@
package org.apache.wvcm.sample;
import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
@@ -72,6 +73,7 @@
import java.util.Properties;
import java.util.StringTokenizer;
import javax.wvcm.ControllableResource;
+import javax.wvcm.Folder;
import javax.wvcm.ControllableFolder;
import javax.wvcm.Location;
import javax.wvcm.PropertyNameList;
@@ -91,10 +93,14 @@
* Sample WVCM Application: Basic Command-line Client.
*
* @author <a href="mailto:peter.nevermann@softwareag.com">Peter Nevermann</a>
+ * @author <a href="mailto:michael.gesmann@softwareag.com">Michael Gesmann</a>
* @version $Revision$
*/
public class BasicCmdClient {
+ private static String PATH_SEPARATOR = "/";
+ private static String _VALUE_UNAVAILABLE = ".";
+
private static Properties javaprops = new Properties();
static {
try {
@@ -102,8 +108,8 @@
} catch (java.io.IOException e) {}
}
- private String command;
- private Provider provider;
+ private String command = null;
+ private Provider provider = null;
private FolderNode rootNode = createRootNode();
private ResourceNode currentNode = rootNode;
private String host;
@@ -114,6 +120,8 @@
private SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
private ReportFormat dirRf = new ReportFormat( new int[]{20,20,17}, 1 );
private String[] dirRHeaders = {"Binding Name", "Type", "Last Modified"};
+ private ReportFormat dirRfNoProperties = new ReportFormat( new int[]{30}, 1);
+ private String[] dirRHeadersNoProperties = {"BindingName"};
private ReportFormat propsRf = new ReportFormat( new int[]{30,30}, 1 );
private String[] propsRHeaders = {"Property Name", "Value"};
@@ -124,11 +132,12 @@
new BasicCmdClient().run( args );
}
- public FolderNode createRootNode() {
+ private FolderNode createRootNode() {
return new FolderNode(null, null, null);
}
- public ResourceNode createResourceNode(String uri) throws Exception {
+ // create representative for file or folder in ResourceNode tree
+ private ResourceNode createResourceNode(String uri) throws Exception {
Path p = new Path(uri);
if (p.isRoot()) {
return rootNode;
@@ -137,12 +146,26 @@
ResourceNode n = rootNode;
for ( int i = 0; i < p.tokens.length; i++) {
if (n.getChild(p.tokens[i]) != null) {
+ // has been read earlier
n = n.getChild(p.tokens[i]);
}
else {
- Location location = provider.location( new Path(p.tokens,i+1).toString() );
- Resource r = location.resource();
- r = r.doReadProperties(null); // determine type;
+ Resource r = null;
+ // not yet read, do it now
+ try {
+ Location folderLocation = provider.location( new Path(p.tokens,i+1, p.isRoot()).toString() );
+ Folder folder = folderLocation.folder();
+ r = folder.doReadProperties(null); // determine type of folder;
+ } catch (WvcmException e){
+ // this might not be a folder
+ try {
+ Location fileLocation = provider.location( new Path(p.tokens,i+1, p.isRoot()).toString() );
+ Resource file = fileLocation.resource();
+ r = file.doReadProperties(null); // determine type of file;
+ } catch (WvcmException ex){
+ return null;
+ }
+ }
n.addChild(p.tokens[i], WvcmTypes.type(r));
n = n.getChild(p.tokens[i]);
}
@@ -150,7 +173,8 @@
return n;
}
- public ResourceNode createResourceNode( ResourceNode parent, String seg, Class type ) {
+ // create a representative for file or folder in ResourceNode tree
+ private ResourceNode createResourceNode( ResourceNode parent, String seg, Class type ) {
if (type == Resource.class) {
return new ResourceNode(parent, seg, type);
}
@@ -169,16 +193,26 @@
return null;
}
+ private boolean alreadyConnected(){
+ if (provider != null){
+ return true;
+ } else {
+ System.out.println("not yet connected");
+ return false;
+ }
+ }
+
/**
* This method is called after start up.
*/
- public void run(String[] args) {
+ private void run(String[] args) {
// Print application prompt to console.
System.out.println("Basic Command-line Client");
while (true) {
String prompt = currentNode.toString();
+ // get next command to be executed
command = readInput(prompt, ">", null);
if (command == null || command.length() == 0) {
continue;
@@ -192,23 +226,202 @@
show();
}
else if (command.startsWith("con")) {
+ // connect to server
connect();
}
- else if (command.startsWith("mem")) {
- members();
- }
else if (command.startsWith("prop")) {
- properties();
+ // list properties of current resource (folder or file)
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens()){
+ // return properties of specified path
+ properties(new Path(t.nextToken()));
+ } else {
+ // return properties of current node
+ properties();
+ }
+ }
+ }
}
else if (command.startsWith("vc")) {
- versionControl();
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ vc(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("cd")) {
+ // move to a folder resource
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ cd(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("lls")) {
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens()){
+ // return properties of specified path
+ ls(new Path(t.nextToken()), true);
+ } else {
+ // return properties of current node
+ ls(true);
+ }
+ }
+ }
+ }
+ else if (command.startsWith("ls")) {
+ // list members of current folder without properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens()){
+ // return properties of specified path
+ ls(new Path(t.nextToken()), false);
+ } else {
+ // return properties of current node
+ ls(false);
+ }
+ }
+ }
}
- else if (command.startsWith("sel")) {
- StringTokenizer t = new StringTokenizer(command, " ");
- t.nextToken();
- select(t.nextToken());
+ else if (command.startsWith("read")) {
+ // move to a file resource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ readFile(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("save")) {
+ // move to a file resource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ saveFile(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("checkout")) {
+ // move to a file resource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ checkout(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("uncheckout")) {
+ // move to a file resource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ uncheckout(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("checkin")) {
+ // move to a file dresource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ checkin(new Path(t.nextToken()));
+ }
+ }
+ }
+ else if (command.startsWith("mkdir")) {
+ // list members of current folder without properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ mkdir(t.nextToken());
+ }
+ }
+ }
+ else if (command.startsWith("rmdir")) {
+ // list members of current folder without properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens()){
+ // return properties of specified path
+ rmdir(new Path(t.nextToken()));
+ } else {
+ // return properties of current node
+ rmdir();
+ }
+ }
+ }
+ }
+ else if (command.startsWith("rm")) {
+ // move to a file resource
+ // list members of current folder with their properties
+ if (alreadyConnected()){
+ if (command != null){
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens())
+ rm(new Path(t.nextToken()));
+ }
+ }
+ }
+
+ else if (command.startsWith("move")) {
+ // list members of current folder without properties
+ if (alreadyConnected()){
+ if (command != null){
+ Path from = null;
+ Path to = null;
+ StringTokenizer t = new StringTokenizer(command, " ");
+ t.nextToken();
+ if (t.hasMoreTokens()){
+ from = new Path(t.nextToken());
+ }
+ if (t.hasMoreTokens()){
+ to = new Path(t.nextToken());
+ }
+ move(from, to);
+ }
+ }
+ }
+ else if (command.startsWith("test")) {
+ // list members of current folder without properties
+ if (alreadyConnected()){
+ testIt();
+ }
}
else if (command.startsWith("exit")) {
+ // leave application
System.out.println("Bye!");
break;
}
@@ -222,6 +435,33 @@
}
}
+ private void help() {
+ System.out.println("available calls:");
+ System.out.println("- help - This information");
+ System.out.println("- show - Show environment");
+ System.out.println("- con[nect] - Connect to server; parameters will be asked for");
+ System.out.println("- prop [path] - Show properties; without path for current folder");
+ System.out.println("- read [path] - read a file into current working directory");
+ System.out.println("- save [path] - save a file from current working directory");
+ System.out.println("- vc [path] - set file under version control");
+ System.out.println("- checkout [path] - checkout a file");
+ System.out.println("- checkin [path] - checkin a file");
+ System.out.println("- uncheckout [path] - uncheckout a file, i.e. redo checkout without checkin");
+ System.out.println("- rm [path] - remove a file");
+ System.out.println("- cd [path] - change directory");
+ System.out.println("- ls [path] - Show members; without path for current folder");
+ System.out.println("- lls [path] - Show members with their properties; without path for current folder");
+ System.out.println("- mkdir [folderName] - create a new folder");
+ System.out.println("- rmdir [path] - remove folder; without path for current folder and move to parent");
+ System.out.println("- move frompath topath - move file/folder from \"from\" to \"to\"");
+ System.out.println("- exit - exit this application");
+ System.out.println();
+ System.out.println("Parameters not specified here will be ignored.");
+// System.out.println("This sample cannot handle the situation where a file and");
+// System.out.println(" a folder have the same name in the same parent.");
+ System.out.println("\"working directory\" is a folder in your file system where you have started this program.");
+ }
+
private void show() {
System.out.println("- Host: "+host);
System.out.println("- Port: "+port);
@@ -229,16 +469,33 @@
System.out.println("- Realm: "+realm);
}
- private void help() {
- System.out.println("- help - This information");
- System.out.println("- con - Connect to server");
- System.out.println("- show - Show environment");
- System.out.println("- sel - Select resource");
- System.out.println("- mem - Show members");
- System.out.println("- prop - Show properties");
- System.out.println("- exit - Leave the application");
+ private void testIt() throws Exception {
+ // prepare
+
+ Location loc = provider.location("/slide/files");
+ ControllableFolder rootFolder = (ControllableFolder)loc.folder();
+ ControllableFolder f = (ControllableFolder)rootFolder.location().child("foo").folder();
+ f.doUnbind();
+ f.doCreateResource();
+ System.out.println("\nCreated folder 'f': "+f);
+ ControllableFolder f2 = (ControllableFolder)rootFolder.location().child("to_move").folder();
+ f2.doUnbind();
+ f2.doCreateResource();
+ System.out.println("Created folder 'f2': "+f2);
+ ControllableResource r = rootFolder.location().child("to_move.txt").controllableResource();
+ r.doUnbind();
+ r.doCreateResource();
+ r.doWriteContent(new ByteArrayInputStream("Test Content\n".getBytes("utf-8")), null);
+ System.out.println("Created file 'r': "+r);
+ // move r into f2
+ Location f3 = provider.location("/slide/files");
+ r.doRebind(f2.location().child("to_move.txt"), false);
+ System.out.println("Moved file 'r' to 'f2': "+r);
+ f2.doRebind(f.location().child("to_move"), false);
+ System.out.println("Moved folder 'f2' to 'f': "+f2);
}
+
private void connect() throws Exception {
// Read user input from console.
host = readInput("Host", ": ", host != null ? host : (String)javaprops.get("host"));
@@ -255,69 +512,267 @@
if( context != null ) h.put( "context", context );
provider = ProviderFactory.createProvider(
"org.apache.wvcm.ProviderImpl", callback, h );
+ currentNode = rootNode;
+ currentNode.resetChildren();
+ currentNode.resetReferences();
currentNode.addChild(context, ControllableFolder.class);
currentNode = (FolderNode)currentNode.getChild(context);
}
- private void members() throws Exception {
+ private void properties() throws Exception {
+ System.out.println( propsRf.format(propsRHeaders) );
+ System.out.println( propsRf.separator('-') );
+ currentNode.showProperties();
+ }
+
+ private void properties(Path path) throws Exception {
+ ResourceNode saveIt = currentNode;
+ if (currentNode instanceof FolderNode){
+ if (walkThroughPath(path)){
+ properties();
+ }
+ currentNode = saveIt;
+ } else {
+ System.out.println("current node is not a folder");
+ }
+ }
+
+ private void ls(boolean withProperties) throws Exception {
if (!(currentNode instanceof FolderNode)) {
System.out.println(currentNode.toString()+" is not a folder");
+ } else
+ ((FolderNode)currentNode).showMembers(withProperties);
+ }
+
+ private void ls(Path path, boolean withProperties) throws Exception {
+ ResourceNode saveIt = currentNode;
+ if (cd(path)){
+ ((FolderNode)currentNode).showMembers(withProperties);
}
- ((FolderNode)currentNode).showMembers();
+ currentNode = saveIt;
}
- private void versionControl() throws Exception {
- if (!(currentNode instanceof ControllableResourceNode)) {
- System.out.println(currentNode.toString()+" is not controllable");
+ private void vc(Path path) throws Exception {
+
+ if (makeFileCurrent(path)){
+ if (!(currentNode instanceof ControllableResourceNode)) {
+ System.out.println(currentNode.toString()+" is not controllable");
+ }
+ ((ControllableResourceNode)currentNode).versionControl();
+ currentNode = currentNode.getParent();
}
- ((ControllableResourceNode)currentNode).versionControl();
+
}
- private void select(String path) throws Exception {
- if (path == null || path.length() == 0) {
- return;
+ private boolean walkThroughPath (Path path) throws Exception {
+
+ if (path == null || path.isRoot()) {
+ return true;
}
- if( path.startsWith("/") )
+
+ // instantiates all possible ResourceNodes for path
+ createResourceNode(currentNode.toString()+"/"+path);
+
+ if( path.startsAtRoot() )
currentNode = currentNode.getRoot();
- StringTokenizer t = new StringTokenizer(path, "/");
- while (t.hasMoreTokens()) {
- String seg = t.nextToken();
+ String [] pathTokens = path.tokens;
+ for (int i=0; i<path.tokens.length; i++){
+ String seg = pathTokens[i];
if ("..".equals(seg)) {
- currentNode = currentNode.getParent();
+ if (currentNode.getParent() != null){
+ currentNode = currentNode.getParent();
+ }
}
else if (".".equals(seg)) {
//ignore
}
else {
ResourceNode cand = currentNode.getChild(seg);
- if (cand == null) {
- Location location = provider.location( new Path(currentNode.path, seg).toString() );
- Resource r = location.resource();
- try {
- // determine type;
- r = r.doReadProperties(null);
- currentNode.addChild(seg, WvcmTypes.type(r));
- cand = currentNode.getChild(seg);
- } catch (WvcmException e) {}
- }
+
if (cand == null) {
cand = currentNode.getRef(seg);
}
if (cand == null) {
- System.out.println(seg+" not found");
+ return false;
+ } else {
+ currentNode = cand;
}
- currentNode = cand;
}
}
+ return (true);
}
- private void properties() throws Exception {
- System.out.println( propsRf.format(propsRHeaders) );
- System.out.println( propsRf.separator('-') );
- currentNode.showProperties();
+ private boolean cd (Path path) throws Exception {
+
+ ResourceNode saveIt = currentNode;
+ if (walkThroughPath(path)){
+ if (!(currentNode instanceof FolderNode)){
+ System.out.println("path does not point to a folder");
+ currentNode = saveIt;
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ System.out.println("not a valid path");
+ currentNode = saveIt;
+ return false;
+ }
+ }
+
+ private boolean makeFileCurrent(Path path) throws Exception {
+
+ ResourceNode saveIt = currentNode;
+ if (walkThroughPath(path)){
+ if ((currentNode instanceof FolderNode)){
+ System.out.println("path does not point to a file");
+ currentNode = saveIt;
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+// System.out.println("file does not exist");
+ currentNode = saveIt;
+ return false;
+ }
+ }
+
+
+ private void saveFile(Path path) throws Exception {
+
+ boolean created = false;
+ if (!makeFileCurrent(path)){
+ ((FolderNode)currentNode).createFile(path.toString());
+ created = true;
+ makeFileCurrent(path);
+ }
+ if (!currentNode.saveContent(path.toString()) && created){
+ currentNode = currentNode.getParent();
+ rm(path);
+ }
+ currentNode = currentNode.getParent();
+ }
+
+ private void readFile(Path path) throws Exception {
+
+ if (makeFileCurrent(path)){
+ currentNode.readContent();
+ currentNode = currentNode.getParent();
+ }
+ }
+
+
+ private void checkin(Path path) throws Exception {
+
+ if (!makeFileCurrent(path)){
+ ((FolderNode)currentNode).createFile(path.toString());
+ makeFileCurrent(path);
+ }
+ currentNode.checkin();
+ currentNode = currentNode.getParent();
+ }
+
+ private void checkout(Path path) throws Exception {
+
+ if (makeFileCurrent(path)){
+ currentNode.checkout();
+ currentNode = currentNode.getParent();
+ }
+ }
+
+
+ private void uncheckout(Path path) throws Exception {
+
+ if (makeFileCurrent(path)){
+ currentNode.checkout();
+ currentNode = currentNode.getParent();
+ }
+ }
+
+
+ private void rm(Path path) throws Exception {
+
+ ResourceNode saveIt = currentNode;
+ if (walkThroughPath(path)){
+ if (currentNode instanceof FolderNode){
+ System.out.println("path does not point to a file");
+ currentNode = saveIt;
+ } else {
+ String fileName = path.getLastSegment();
+ if (fileName.length() > 0){
+ currentNode = currentNode.getParent();
+ ((FolderNode)currentNode).deleteFile(fileName);
+ }
+ }
+ } else {
+ System.out.println("not a valid path");
+ }
+ currentNode = saveIt;
}
+ private void mkdir(String newFolderName) throws Exception {
+ if (!(currentNode instanceof FolderNode)) {
+ System.out.println(currentNode.toString()+" is not a folder");
+ } else {
+ Resource r = ((FolderNode)currentNode).createFolder(newFolderName);
+ r.doReadProperties(null);
+ currentNode.addChild(newFolderName, WvcmTypes.type(r));
+ }
+ }
+
+ private void rmdir() throws Exception {
+
+ if (!(currentNode instanceof FolderNode)) {
+ System.out.println(currentNode.toString()+" is not a folder");
+ } else
+ ((FolderNode)currentNode).deleteFolder();
+ currentNode = currentNode.getParent();
+ currentNode.resetChildren();
+ currentNode.resetReferences();
+ }
+
+ private void rmdir(Path path) throws Exception {
+
+ ResourceNode saveIt = currentNode;
+ if (path != null){
+ if (cd(path)){
+ rmdir();
+ }
+ }
+ currentNode = saveIt;
+ }
+
+ private void move(Path fromPath, Path toPath) throws Exception {
+
+ ResourceNode saveIt = currentNode;
+ ResourceNode rFrom = null;
+ ResourceNode rTo = null;
+
+ if (fromPath == null)
+ return;
+ if (toPath == null)
+ return;
+
+ if (walkThroughPath(fromPath)){
+ rFrom = currentNode;
+ }
+ currentNode = saveIt;
+ if (walkThroughPath(new Path(toPath.getPathFront()))){
+ rTo = currentNode;
+ }
+ if ((rFrom != null) && (rTo != null)){
+ rFrom.move(rTo, toPath.getLastSegment());
+ } else {
+ System.out.println("one of the paths does not exist");
+ }
+
+ currentNode = saveIt;
+
+ }
+
+
/**
* This method reads user input from console.
*/
@@ -366,7 +821,7 @@
return authentication;
}
- class AuthenticationImpl implements Authentication {
+ private class AuthenticationImpl implements Authentication {
private String username = null;
private String password = null;
@@ -391,11 +846,16 @@
**/
private static class Path {
+ private static String PATH_SEPARATOR = "/";
+
/** The path tokens */
- String[] tokens = null;
+ public String[] tokens = null;
+ private boolean startsAtRoot;
+
Path( String uri ) {
- StringTokenizer ut = new StringTokenizer( uri, "/" );
+ startsAtRoot = uri.startsWith(PATH_SEPARATOR);
+ StringTokenizer ut = new StringTokenizer( uri, PATH_SEPARATOR );
int ntok = ut.countTokens();
this.tokens = new String[ntok];
for( int i = 0; i < ntok; i++ )
@@ -403,6 +863,7 @@
}
Path( Path parent, String seg ) {
+ startsAtRoot = parent.isRoot() && seg.startsWith(PATH_SEPARATOR);
String[] toks = parent.tokens;
this.tokens = new String[toks.length+1];
for( int i = 0; i < toks.length; i++ )
@@ -410,18 +871,15 @@
tokens[toks.length] = seg;
}
- Path( String[] toks ) {
- this.tokens = new String[toks.length];
- for( int i = 0; i < toks.length; i++ )
- tokens[i] = toks[i];
- }
- Path( String[] toks, int number ) {
+ Path( String[] toks, int number, boolean isRoot ) {
+ startsAtRoot = isRoot;
this.tokens = new String[number];
for( int i = 0; i < number; i++ )
tokens[i] = toks[i];
}
+
/**
** Check whether the path is valid.
** @return true if the URI is valid
@@ -437,6 +895,11 @@
return (tokens.length == 0);
}
+
+ boolean startsAtRoot() {
+ return startsAtRoot;
+ }
+
/**
* Return the parent.
* Example: for /a/b/c returns: /a/b
@@ -468,12 +931,26 @@
*/
public String toString() {
StringBuffer b = new StringBuffer();
- if( tokens.length == 0 )
- b.append( "/" );
- for( int i = 0; i < tokens.length; i++ )
+ b.append((startsAtRoot)?"/":"").append((tokens.length==0)?"":tokens[0]);
+
+ for( int i = 1; i < tokens.length; i++ )
+ b.append( "/" ).append( tokens[i] );
+ return b.toString();
+ }
+
+ /**
+ * get Path except of last element
+ */
+ public String getPathFront(){
+ StringBuffer b = new StringBuffer();
+
+ b.append((startsAtRoot)?"/":"").append((tokens.length<=1)?"":tokens[0]);
+
+ for( int i = 1; i < tokens.length - 1 ; i++ )
b.append( "/" ).append( tokens[i] );
return b.toString();
}
+
}
private class ResourceNode {
@@ -499,6 +976,7 @@
}
}
+
/**
* Return the parent.
* Example: for /a/b/c returns: /a/b
@@ -551,28 +1029,126 @@
references.put(name, ref);
}
+ void readContent() throws Exception {
+ // only called for files, but not for folders
+ Location location = provider.location( toString());
+ if (this instanceof FolderNode){
+ System.out.println("read not allowed, use ls or lls");
+ } else {
+ Resource resource = location.resource();
+ java.io.OutputStream o = new java.io.FileOutputStream(location.lastSegment());
+ resource.doReadContent(null, o);
+ }
+ }
+
+ boolean saveContent(String fileName) throws Exception {
+ Location location = provider.location( toString());
+ if (this instanceof FolderNode){
+ System.out.println("read not allowed, use ls or lls");
+ } else {
+ Resource resource = location.resource();
+ try {
+ java.io.InputStream i = new java.io.FileInputStream(fileName);
+ resource.doWriteContent(i, null);
+ } catch (Exception e){
+ System.out.println("saving content failed with: " + e.toString());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ void checkin() throws Exception {
+ // only called for files, but not for folders
+ Location location = provider.location( toString());
+ if (this instanceof FolderNode){
+ System.out.println("checkin not allowed on folder");
+ } else {
+ try {
+ ControllableResource resource = location.controllableResource();
+ resource.doCheckin();
+ } catch (WvcmException e){
+ System.out.println(e.toString());
+ }
+ }
+ }
+
+ void checkout() throws Exception {
+ Location location = provider.location( toString());
+ if (this instanceof FolderNode){
+ System.out.println("checkout not allowed on folder");
+ } else {
+ try {
+ ControllableResource resource = location.controllableResource();
+ resource.doCheckout(false, null, false, false);
+ } catch (WvcmException e){
+ System.out.println(e.toString());
+ }
+ }
+ }
+
+
+ void uncheckout() throws Exception {
+ Location location = provider.location( toString());
+ if (this instanceof FolderNode){
+ System.out.println("uncheckout not allowed on folder");
+ } else {
+ try {
+ ControllableResource resource = location.controllableResource();
+ resource.doUncheckout();
+ } catch (WvcmException e){
+ System.out.println(e.toString());
+ }
+ }
+ }
+
Resource readProperties() throws Exception {
Location location = provider.location( toString() );
- Resource resource = location.resource();
+ Resource resource = null;
+ if (type == ControllableFolder.class || type == Folder.class) {
+ resource = location.folder();
+ }
+ else {
+ resource = location.resource();
+ }
resource = resource.doReadProperties(null); // to determine the type
resource = resource.doReadProperties( WvcmProperties.allProperties(WvcmTypes.type(resource), true) );
return resource;
}
+
+ void move(ResourceNode to, String name) throws Exception {
+
+ if (!(to instanceof FolderNode)){
+ System.out.println("target of move operation is not a folder");
+ } else {
+ Location lFrom = provider.location( toString() );
+ Location lTo = provider.location( to.toString() + PATH_SEPARATOR + name );
+ // this is a file, otherwise move() from FolderNode would apply.
+ ControllableResource rFrom = lFrom.controllableResource();
+
+ try {
+ rFrom.doRebind(lTo, false);
+ } catch (WvcmException e){
+ System.out.println(e.toString());
+ }
+ }
+ }
+
Resource showProperties() throws Exception {
resetReferences();
Resource resource = readProperties();
- String comment = "<value unavailable>";
- String contentCharacterSet = "<value unavailable>";
- String contentIdentifier = "<value unavailable>";
- String contentLanguage = "<value unavailable>";
- String contentLength = "<value unavailable>";
- String contentType = "<value unavailable>";
- String creationDate = "<value unavailable>";
- String creatorDisplayName = "<value unavailable>";
- String displayName = "<value unavailable>";
- String lastModified = "<value unavailable>";
+ String comment = _VALUE_UNAVAILABLE;
+ String contentCharacterSet = _VALUE_UNAVAILABLE;
+ String contentIdentifier = _VALUE_UNAVAILABLE;
+ String contentLanguage = _VALUE_UNAVAILABLE;
+ String contentLength = _VALUE_UNAVAILABLE;
+ String contentType = _VALUE_UNAVAILABLE;
+ String creationDate = _VALUE_UNAVAILABLE;
+ String creatorDisplayName = _VALUE_UNAVAILABLE;
+ String displayName = _VALUE_UNAVAILABLE;
+ String lastModified = _VALUE_UNAVAILABLE;
try {comment = resource.getComment();} catch (Exception e) {}
try {contentCharacterSet = resource.getContentCharacterSet();} catch (Exception e) {}
@@ -640,23 +1216,23 @@
Resource showProperties() throws Exception {
ControllableResource resource = (ControllableResource)super.showProperties();
- String activityList = "<value unavailable>";
- String autoMergeList = "<value unavailable>";
- String checkedIn = "<value unavailable>";
- String checkedOut = "<value unavailable>";
- String dirtyPropertyList = "<value unavailable>";
- String isCheckedOut = "<value unavailable>";
- String isDirtyContent = "<value unavailable>";
- String isStaleContent = "<value unavailable>";
- String mergeList = "<value unavailable>";
- String predecessorList = "<value unavailable>";
- String serverState = "<value unavailable>";
- String stalePropertyList = "<value unavailable>";
- String unreserved = "<value unavailable>";
- String versionControllable = "<value unavailable>";
- String versionControlledConfiguration = "<value unavailable>";
- String versionHistory = "<value unavailable>";
- String workspace = "<value unavailable>";
+ String activityList = _VALUE_UNAVAILABLE;
+ String autoMergeList = _VALUE_UNAVAILABLE;
+ String checkedIn = _VALUE_UNAVAILABLE;
+ String checkedOut = _VALUE_UNAVAILABLE;
+ String dirtyPropertyList = _VALUE_UNAVAILABLE;
+ String isCheckedOut = _VALUE_UNAVAILABLE;
+ String isDirtyContent = _VALUE_UNAVAILABLE;
+ String isStaleContent = _VALUE_UNAVAILABLE;
+ String mergeList = _VALUE_UNAVAILABLE;
+ String predecessorList = _VALUE_UNAVAILABLE;
+ String serverState = _VALUE_UNAVAILABLE;
+ String stalePropertyList = _VALUE_UNAVAILABLE;
+ String unreserved = _VALUE_UNAVAILABLE;
+ String versionControllable = _VALUE_UNAVAILABLE;
+ String versionControlledConfiguration = _VALUE_UNAVAILABLE;
+ String versionHistory = _VALUE_UNAVAILABLE;
+ String workspace = _VALUE_UNAVAILABLE;
try {
Version checkedInV = resource.getCheckedIn();
@@ -665,7 +1241,8 @@
try {activityList = resource.getActivityList().toString();} catch (Exception e) {};
try {autoMergeList = resource.getAutoMergeList().toString();} catch (Exception e) {};
- try {checkedIn = getRef(PropertyName.CHECKED_IN.getString()).toString();} catch (Exception e) {};
+// try {checkedIn = getRef(PropertyName.CHECKED_IN.getString()).toString();} catch (Exception e) {};
+ try {checkedIn = resource.getCheckedIn().location().string();} catch (Exception e) {};
try {checkedOut = resource.getCheckedOut().location().string();} catch (Exception e) {};
try {dirtyPropertyList = resource.getDirtyPropertyList().toString();} catch (Exception e) {};
try {isCheckedOut = String.valueOf(resource.getIsCheckedOut());} catch (Exception e) {};
@@ -716,13 +1293,74 @@
}
}
+
+ //
+ // folder representative
+ //
private class FolderNode extends ControllableResourceNode {
FolderNode( ResourceNode parent, String seg, Class type ) {
super( parent, seg, type );
}
- void showMembers() throws Exception {
+ void createFile(String newFileName) throws Exception {
+ Location newLocation = provider.location(toString()+"/"+newFileName);
+ ControllableResource newResource = newLocation.controllableResource();
+ newResource.doCreateResource();
+// try {
+// newResource.doControl();
+// } catch (WvcmException e){
+// // ignore is not controllable
+// }
+ Resource r = newResource.doReadProperties(null);
+ this.addChild(newFileName, WvcmTypes.type(r));
+ }
+
+ void deleteFile(String filename) throws Exception{
+ Location location = provider.location(toString()+"/"+filename);
+ Resource file = location.resource();
+ if ((file instanceof Folder) || (file instanceof ControllableFolder)){
+ System.out.println(filename + " is a folder and not a file!");
+ } else {
+ file.doUnbind();
+ resetChildren();
+ resetReferences();
+ }
+ }
+
+ Resource createFolder(String newFolderName) throws Exception {
+ Location newLocation = provider.location(toString()+"/"+newFolderName);
+ ControllableFolder newFolder = (ControllableFolder)newLocation.folder();
+ newFolder.doCreateResource();
+ return newFolder;
+ }
+
+ void deleteFolder() throws Exception {
+ Location location = provider.location(toString());
+ ControllableFolder folder = (ControllableFolder)location.folder();
+ folder.doUnbind();
+ }
+
+ void move(ResourceNode to) throws Exception {
+
+ if (!(to instanceof FolderNode)){
+ System.out.println("target of move operation is not a folder");
+ } else {
+ Location lSource = provider.location( toString() );
+ Location lTo = provider.location( to.toString() );
+ // this is a folder!
+ Resource rSource = lSource.folder();
+
+ try {
+ rSource.doRebind(lTo, false);
+ } catch (WvcmException e){
+ System.out.println(e.toString());
+ }
+ }
+ }
+
+
+ void showMembers(boolean withProperties) throws Exception {
Location location = provider.location( toString() );
ControllableFolder folder = (ControllableFolder)location.folder();
PropertyNameList pnl = new PropertyNameList(
@@ -730,14 +1368,23 @@
{PropertyName.LAST_MODIFIED}
);
Iterator mlIter = folder.doReadMemberList( pnl, false );
- System.out.println( dirRf.format(dirRHeaders) );
- System.out.println( dirRf.separator('-') );
+ if (withProperties){
+ System.out.println( dirRf.format(dirRHeaders) );
+ System.out.println( dirRf.separator('-') );
+ } else {
+ System.out.println( dirRfNoProperties.format(dirRHeadersNoProperties) );
+ System.out.println( dirRfNoProperties.separator('-') );
+ }
resetChildren();
while (mlIter.hasNext()) {
Resource r = (Resource)mlIter.next();
Path p = new Path(r.location().string());
addChild(p.getLastSegment(), WvcmTypes.type(r));
- System.out.println( dirRf.format(p.getLastSegment(), WvcmTypes.typeName(r), df.format(r.getLastModified())) );
+ if (withProperties){
+ System.out.println( dirRf.format(p.getLastSegment(), WvcmTypes.typeName(r), df.format(r.getLastModified())) );
+ } else {
+ System.out.println( dirRfNoProperties.format(p.getLastSegment()) );
+ }
}
}
}
1.7 +4 -2 jakarta-slide/proposals/wvcm/src/org/apache/wvcm/sample/sample.properties
Index: sample.properties
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/wvcm/src/org/apache/wvcm/sample/sample.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sample.properties 8 Dec 2003 17:14:27 -0000 1.6
+++ sample.properties 16 Sep 2004 19:38:26 -0000 1.7
@@ -1,4 +1,6 @@
host=localhost
port=8080
-context=taminowebdavserver
-realm=Tamino WebDAV Server
+# context=taminowebdavserver
+context=slide
+# realm=Tamino WebDAV Server
+realm=Slide DAV Server
1.16 +29 -6 jakarta-slide/proposals/wvcm/src/org/apache/wvcm/LocationImpl.java
Index: LocationImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/wvcm/src/org/apache/wvcm/LocationImpl.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- LocationImpl.java 30 Jul 2004 06:52:25 -0000 1.15
+++ LocationImpl.java 16 Sep 2004 19:38:26 -0000 1.16
@@ -154,7 +154,7 @@
"Illegal location syntax", string, ReasonCode.ILLEGAL_LOCATION_SYNTAX, new Exception[]{e});
}
}
-
+
private URI initPaths(String string, ProviderImpl provider, boolean escaped) throws WvcmException, NullPointerException, URIException {
URI uri = null;
String urlenc = (String)provider.initParameter("urlencoding");
@@ -198,6 +198,7 @@
* Return a proxy for the folder at this Location.
*/
public Folder folder() {
+ path.isFolder = true;
return new ControllableFolderImpl( this );
}
@@ -349,6 +350,9 @@
if( cls == null || !isSubtypeOfResourceImpl(cls) )
throw new WvcmException( "Cannot create instance for "+cls,
string(), ReasonCode.CANNOT_CREATE_NEW_RESOURCE, null );
+ if (isSubtypeOfControllableFolderImpl(cls)) {
+ path.isFolder = true;
+ }
try {
Class[] parmtypes = {Location.class};
Object[] initargs = {this};
@@ -368,6 +372,16 @@
return isSubtypeOfResourceImpl( cls.getSuperclass() );
}
+ private boolean isSubtypeOfControllableFolderImpl( Class cls ) {
+ if (cls == null) {
+ return false;
+ }
+ if( cls == ControllableFolderImpl.class )
+ return true;
+ else
+ return isSubtypeOfControllableFolderImpl( cls.getSuperclass() );
+ }
+
/**
* Get the path of this location
*
@@ -426,11 +440,15 @@
/** The path tokens */
String[] tokens = null;
+ boolean isFolder = false;
/**
** Default constructor.
**/
Path( String uri ) throws WvcmException {
+ if (uri != null && uri.endsWith("/")) {
+ isFolder = true;
+ }
StringTokenizer ut = new StringTokenizer( uri, "/" );
int ntok = ut.countTokens();
this.tokens = new String[ntok];
@@ -499,7 +517,9 @@
return null;
}
else {
- return new Path( tokens, tokens.length - 1 );
+ Path result = new Path(tokens, tokens.length - 1);
+ result.isFolder = true;
+ return result;
}
}
catch (WvcmException e) {
@@ -543,6 +563,9 @@
b.append( "/" );
for( int i = 0; i < tokens.length; i++ )
b.append( "/" ).append( tokens[i] );
+ if (isFolder && !b.toString().endsWith("/")) {
+ b.append("/");
+ }
return b.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org