chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfermig...@apache.org
Subject svn commit: r899665 [1/4] - in /incubator/chemistry/trunk/chemistry: ./ chemistry-shell/ chemistry-shell/scripts/ chemistry-shell/src/ chemistry-shell/src/main/ chemistry-shell/src/main/java/ chemistry-shell/src/main/java/org/ chemistry-shell/src/main/...
Date Fri, 15 Jan 2010 15:35:18 GMT
Author: sfermigier
Date: Fri Jan 15 15:35:14 2010
New Revision: 899665

URL: http://svn.apache.org/viewvc?rev=899665&view=rev
Log:
Initial import of CMIS Shell code, donated by Nuxeo.


Added:
    incubator/chemistry/trunk/chemistry/chemistry-shell/
    incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/TODO
    incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/
    incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh.bat
    incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/utils/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Cd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Connect.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Disconnect.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Exit.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Help.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Id.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/LCd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/LPopd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/LPushd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/LPwd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Ll.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Ls.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Match.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Popd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Pushd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/base/Pwd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/Cat.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/CreateFile.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/CreateFolder.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/DumpProps.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/DumpTree.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/Get.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/PropGet.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/Put.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/Remove.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/SetProp.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/cmds/cmis/SetStream.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/Cmd.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/Command.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandException.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandLine.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandParameter.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandRegistry.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandSyntax.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandSyntaxException.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/CommandToken.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/ExitException.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/command/NoSuchCommandException.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/CommandCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/CompositeCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/ContextItemCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/DirectoryCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/ItemNameCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/JLineConsole.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/jline/ParameterNameCompletor.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/ColorHelper.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/MimeTypeHelper.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/PasswordReader.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/Path.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleBrowser.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleCreator.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimplePropertyManager.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/StringUtils.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/connect.help
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/exit.help
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/help.help
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/test.help
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/usage.help
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/TestWithTestScript.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java   (with props)
    incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java   (with props)
Modified:
    incubator/chemistry/trunk/chemistry/pom.xml

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt Fri Jan 15 15:35:14 2010
@@ -0,0 +1,12 @@
+Authors
+-------
+
+- Bogdan Stefanescu: initial implementation
+- Stefane Fermigier: refactoring, maintainer
+
+Contributors
+------------
+
+- Florent Guillaume: code review
+- Olivier Grisel: feature requests
+

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/CONTRIBUTORS.txt
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile Fri Jan 15 15:35:14 2010
@@ -0,0 +1,37 @@
+VERSION:=0.5
+POM_VERSION:=$(VERSION)-SNAPSHOT
+TODAY:=$(shell date +"%Y%m%d")
+
+#RELEASE:=$(VERSION)-$(TODAY)
+#RELEASE_DIR:=cmissh-$(VERSION)-$(TODAY)
+RELEASE:=$(TODAY)
+RELEASE_DIR:=cmissh-$(TODAY)
+
+.PHONY: all clean build release
+
+all:	build test
+
+build:
+	mvn package
+
+test:
+	./run.sh -t -b testscript
+
+clean:
+	mvn clean
+	find . -name "*~" | xargs rm -f
+	find . -name "*,orig" | xargs rm -f
+	rm -rf release
+
+release: clean build
+	mkdir -p target/$(RELEASE_DIR)
+	cp scripts/* target/$(RELEASE_DIR)
+	cp README.txt target/$(RELEASE_DIR)
+	cp target/chemistry-shell-$(POM_VERSION).jar \
+		target/$(RELEASE_DIR)/chemistry-shell.jar
+	cd target ; zip -r $(RELEASE_DIR).zip $(RELEASE_DIR)
+
+push:
+	rsync -e ssh target/$(RELEASE_DIR).zip \
+		zope@gironde.nuxeo.com:static/nuxeo.org/cmis/
+

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/Makefile
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt Fri Jan 15 15:35:14 2010
@@ -0,0 +1,182 @@
+About this project
+==================
+
+This is a shell (command-line tool for you Windows people) that let you browse
+and manage content on a CMIS repository (a bit like Cadaver for WebDAV, if you
+know it).
+
+Building
+--------
+
+To build this project, just run "mvn install". You probably want to install
+first Apache Chemistry, by checking out the sources and running "mvn install"
+there, since it is not yet released.
+
+If you have make on you system, you can also use the following make targets:
+clean, build, test and release.
+
+Dependencies
+------------
+
+Here are the direct dependencies:
+
+jline
+chemistry-api
+chemistry-commons
+chemistry-atompub
+chemistry-atompub-client
+
+The packaging is an all in one jar containing all dependencies required by
+chemistry-atompub-client (like httpclient, apache-commons, apache-logging, stax
+(wstx) libs etc).
+
+Usage
+-----
+
+After building (with "mvn install"), it you can launch it using the run.sh
+command (by giving the URL where to connect), e.g.:
+
+> ./run.sh http://0.0.0.0:8082/cmis/repository
+
+or
+
+> ./run.sh -u Administrator -p Administrator \
+  http://cmis.demo.nuxeo.org/nuxeo/site/cmis/repository
+
+Some of the registered commands are not yet implemented. Commands use
+annotations and optional *.help files to provide help content (the *.help files
+must have the name of the command and be put in the same package. Ex: Ls.help)
+
+Available commands for now are:
+
+help
+id    - display info about the current object
+mkdir
+mkfile
+setp
+getp
+setStream
+getStream
+pwd
+ls
+cd
+pushd
+popd
+tree  - show repository tree
+props - show object properties
+lpwd  - local pwd (file based)
+lcd   - local cd
+ll    - list local directory content
+lpushd
+lpopd
+cmds
+exit
+
+Ls listing supports colors based on object types - I've made a default schema
+for demonstration (you can change this in color.properties).
+
+The shell has 3 modes:
+
+- single command execution (using -e flag)
+- batch execution of commands in a file (using -b)
+- interactive execution (the default one)
+
+Note that some commands are not available in all contexts (when not yet in a
+repository, calling "tree" will display nothing).
+
+I will improve this later to show only available commands depending on the
+context.
+
+One important note is that the initial context is not a repository but the APP
+service. So if you do a "ls" in the initial context you will have the list of
+repositories. To enter a repository, do a "cd repo_name". After entering a
+repository you are in a chemistry object context so all commands should be
+available.
+
+How to extend it
+----------------
+
+To add new commands, simply extend ChemistryCommand class and look how the
+other commands works.
+
+To register a new command you need to update the constructor of ChemistryApp:
+
+public ChemistryApp() {
+    registry.registerCommand(new DumpTree());
+    ...
+}
+
+Command registration will be automized in future.
+
+The most important interfaces you need to know about are Application and
+Context which are javadoc-umented.
+
+Some commands have aliases. Example: tree <=> dump. You can define aliases in
+your annotation. Example:
+
+@Cmd(syntax="dump|tree", synopsis="Dump a subtree")
+public class DumpTree extends ChemistryCommand {
+...
+
+
+Command Syntax
+--------------
+
+When defining new commands we need to add the @Cmd annotation on the command
+class.
+
+This annotation provides 2 command properties: syntax and synopsis
+
+- The synopsis is a short description that is listed on the right side of the
+  command when you print the commands list using 'cmds'
+
+- The syntax is important and define the command line structure and how
+  auto-completion will be done.
+
+Here is the syntax format:
+
+cmd_name param_spec param_spec  ...
+cmd_name: name1 | name 2 | ...  - You can have multiple names associated to a command (the first one is the command name the others are aliases)
+param_spec is a parameter specification.
+
+A parameter has a key (and 0 or more aliases), a default value, an optional flag and a type.
+
+The type is important if you need auto-completion. There are several recognized types for now:
+
+1. command  - a command (to complete with available command names)
+2. file     - a file (to complete with a file path)
+3. dir      - a directory (to complete with directory paths)
+4. item     - a remote object (to complete with remote object paths)
+
+Also a parameter can be an argument, a flag or a key/value pair. Flags are not
+yet supported (i.e. -param without a value).
+
+An optional parameter must be enclosed in brackets '[' ']'.
+
+Optional parameters can have default values that can be specified by appending
+?the_default_value after the command spec.
+
+Example: [-d|--depth?1]
+
+The type is optional and is specified after the command name list separated by
+a ':'
+
+Example: [targetFile:file?/tmp/some_file]
+
+Types parameters will be auto-completed with possible values when hiting tab
+key in shell.
+
+A complete example:
+
+> print|pr [-p|--pretty?true] [-v|--verbose?false] document:item [targetFile:file?out.txt]
+
+An instance of that command will be types on the command line like this:
+
+> print --verbose true MyDocuments/Doc1 /tmp/doc1.out
+
+Invalid characters like spaces must be escaped using backslashes ('\').
+
+Example:
+
+> print --verbose true My\ Documents/Doc1 /tmp/doc1.out
+

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/README.txt
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/TODO
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/TODO?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/TODO (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/TODO Fri Jan 15 15:35:14 2010
@@ -0,0 +1,27 @@
+P1:
+- [DONE] welcome banner
+- [DONE] refresh cache
+- [DONE] Clean up warnings
+- [DONE] fix NPE when quitting w/ ^D
+- [DONE] Make a first release + mini-announcement
+
+P2: 
+- [DONE] 'put filename.txt'
+- [DONE] Don't assume File and Workspace types exist on server
+- [DONE] move to Apache Chemistry
+- write help for all commands
+- decide on a name for executable (cmissh vs. cmis)
+- bigger announcement
+
+P3:
+- 'rm -r'
+- 'ls -l'
+- 'put -t type ...' and 'mkfile/mkdir -t type'
+- variables (or at least constants): -Dname=value -> $name
+- simple wildcards
+- multiple arguments (ex: rm toto1 toto2 toto3...)
+- better error reporting (no stracktrace unless specifically asked for)
+
+P4:
+- Specify/implement .cmisrc for global configuration
+

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml Fri Jan 15 15:35:14 2010
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.chemistry</groupId>
+    <artifactId>chemistry-parent</artifactId>
+    <version>0.5-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>chemistry-shell</artifactId>
+  <name>Chemistry Shell (aka CMIS Shell or cmissh)</name>
+  <description>Command-line client using APP protocol binding for CMIS</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>jline</groupId>
+      <artifactId>jline</artifactId>
+      <version>0.9.94</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.chemistry</groupId>
+      <artifactId>chemistry-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.chemistry</groupId>
+      <artifactId>chemistry-commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.chemistry</groupId>
+      <artifactId>chemistry-atompub</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.chemistry</groupId>
+      <artifactId>chemistry-atompub-client</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.7</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <!-- This needs a running (Nuxeo) server to pass.
+                 Run it manually with ./run.sh -b testscript -->
+            <exclude>**/TestWithTestScript.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy</id>
+            <phase>compile</phase>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.chemistry</groupId>
+                  <artifactId>chemistry-atompub-client</artifactId>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.chemistry</groupId>
+                  <artifactId>chemistry-commons</artifactId>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.chemistry</groupId>
+                  <artifactId>chemistry-api</artifactId>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.chemistry</groupId>
+                  <artifactId>chemistry-atompub</artifactId>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>commons-logging</groupId>
+                  <artifactId>commons-logging</artifactId>
+                  <version>1.1</version>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>commons-logging</groupId>
+                  <artifactId>commons-logging-api</artifactId>
+                  <version>1.1</version>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>log4j</groupId>
+                  <artifactId>log4j</artifactId>
+                  <version>1.2.15</version>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>commons-httpclient</groupId>
+                  <artifactId>commons-httpclient</artifactId>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>commons-collections</groupId>
+                  <artifactId>commons-collections</artifactId>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>commons-codec</groupId>
+                  <artifactId>commons-codec</artifactId>
+                  <version>1.3</version>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>commons-io</groupId>
+                  <artifactId>commons-io</artifactId>
+                  <version>1.3.2</version>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>stax</groupId>
+                  <artifactId>stax-api</artifactId>
+                  <version>1.0.1</version>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.codehaus.woodstox</groupId>
+                  <artifactId>wstx-asl</artifactId>
+                  <version>3.2.1</version>
+                </artifactItem>
+
+                <artifactItem>
+                  <groupId>jline</groupId>
+                  <artifactId>jline</artifactId>
+                </artifactItem>
+              </artifactItems>
+
+              <outputDirectory>target/classes</outputDirectory>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh Fri Jan 15 15:35:14 2010
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
+
+java ${JAVA_OPTS} -jar target/chemistry-shell-0.5-SNAPSHOT.jar $@

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/run.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh Fri Jan 15 15:35:14 2010
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+LIB_DIR=.
+
+java ${JAVA_OPTS} -jar "$LIB_DIR"/chemistry-shell.jar $@

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh.bat
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh.bat?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh.bat (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/cmissh.bat Fri Jan 15 15:35:14 2010
@@ -0,0 +1,12 @@
+@echo off
+
+set CMD_LINE_ARGS=
+:setArgs
+if ""%1""=="""" goto doneSetArgs
+set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
+shift
+goto setArgs
+:doneSetArgs
+
+java %JAVA_OPTS% -jar chemistry-shell.jar %CMD_LINE_ARGS%
+

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py Fri Jan 15 15:35:14 2010
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+import os, sys, shutil
+
+DEFAULT_BIN = "/usr/local/bin"
+DEFAULT_LIB = "/usr/local/lib/cmissh"
+
+if sys.platform == 'darwin':
+    PLATFORM = "Mac OS"
+elif sys.platform == 'linux2':
+    PLATFORM = "Linux"
+else:
+    PLATFORM = "Something else (%s)" % sys.platform
+
+def expandTilde(path):
+    if path.startswith("~"):
+        return os.environ['HOME'] + path[1:]
+
+print "Welcome to the CMIS Shell intaller."
+print "It should work on Linux and Mac OS."
+print "Please help with a Windows port if you can."
+print
+
+print "Note that this software is provided AS IS, with no expressed"
+print "or implied warranty."
+print
+
+print "Your OS seems to be:", PLATFORM
+print
+
+msg = "Destination directory for executables?\n(Default: %s): " % DEFAULT_BIN
+bin_dir = raw_input(msg).strip() or DEFAULT_BIN
+bin_dir = expandTilde(bin_dir)
+
+print
+
+msg = "Destination directory for libraries?\n(Default: %s): " % DEFAULT_LIB
+lib_dir = raw_input(msg).strip() or DEFAULT_LIB
+lib_dir = expandTilde(lib_dir)
+
+print "(If installation fails, you may want to rerun with sudo)."
+print
+
+print "Installing chemistry-shell.jar to %s..." % lib_dir
+shutil.copy("chemistry-shell.jar", lib_dir + "/chemistry-shell.jar")
+
+print "Installing cmissh to %s..." % bin_dir
+target = open("%s/cmissh" % bin_dir, "wc")
+for line in open("cmissh").readlines():
+    if line.startswith("LIB_DIR"):
+        target.write('LIB_DIR="%s"\n' % lib_dir)
+    else:
+        target.write(line)
+shutil.copymode("cmissh", "%s/cmissh" % bin_dir)

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/install.py
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript Fri Jan 15 15:35:14 2010
@@ -0,0 +1,109 @@
+#!./cmissh -t -b
+
+connect http://Administrator:Administrator@cmis.demo.nuxeo.org/nuxeo/site/cmis/repository
+
+# Test main commands on root
+id
+match "^CMIS server.*"
+match -r "foobar"
+ls
+match "^default$"
+
+# Local command
+help
+help ls
+lpwd
+lls
+match "testscript"
+lpushd ..
+lpopd
+lcd .
+
+# Test main commands on 'default' object (Root)
+cd default
+id
+match "^Object.*of type Root$"
+ls
+match "^default-domain$"
+tree
+propget .
+match "^cmis:objectTypeId = Root$"
+propget . cmis:objectTypeId
+match "^Root$"
+
+# navigate around
+cd default-domain
+pwd
+match "^/default/default-domain$"
+ls
+match "^workspaces$"
+cd workspaces
+pwd
+ls
+cd ..
+pwd
+cd /default/default-domain/workspaces
+pushd ..
+popd
+
+# Create an object (a folder), test commands on it
+cd /default/default-domain
+mkdir testdir
+ls
+id testdir
+ls testdir
+tree testdir
+propget testdir
+match "^dc:title = testdir$"
+match "^cmis:baseTypeId = cmis:folder$"
+propget testdir dc:title
+
+# Test mkdir more in depth
+cd /default/default-domain
+mkdir ./testdir1
+ls testdir1
+mkdir testdir1/../testdir2
+ls testdir1/../testdir2
+cd testdir1
+mkdir ../testdir3
+ls ../testdir3
+rm ../testdir3
+cd ..
+#rm testdir?
+rm testdir1
+rm testdir2
+ls
+
+# Now a file
+cd testdir
+mkfile testfile
+ls
+id testfile
+ls testfile
+propget testfile
+match "^dc:title = testfile$"
+match "^cmis:baseTypeId = cmis:document$"
+propget testfile dc:title
+match "^testfile$"
+propset testfile dc:title some_other_title
+propget testfile dc:title
+match "^some_other_title$"
+setstream testfile testscript
+cat testfile
+rm testfile
+match -r "testfile"
+
+# Put a file
+put testscript testscript
+ls
+id testscript
+cat testscript
+rm testscript
+
+# Clean up
+cd ..
+rm testdir
+match -r "testdir"
+
+disconnect
+exit

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/scripts/testscript
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,192 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.chemistry.shell.app.ChemistryApp;
+import org.apache.chemistry.shell.app.Console;
+import org.apache.chemistry.shell.command.ExitException;
+import org.apache.chemistry.shell.jline.JLineConsole;
+import org.apache.chemistry.shell.util.PasswordReader;
+
+public class Main {
+
+    String username;
+    String password;
+    String url;
+    boolean batchMode;
+    boolean execMode;
+    boolean testMode;
+    String command;
+    private ChemistryApp app;
+
+    private Main() {
+    }
+
+    public static void main(String[] args) throws Exception {
+        Main main = new Main();
+        main.parseArgs(args);
+        main.run();
+    }
+
+    public void parseArgs(String[] args) throws IOException {
+        if (args.length > 0) {
+            for (int i=0; i<args.length; i++) {
+                String arg = args[i];
+                if ("-u".equals(arg)) {
+                    if (++i == args.length) { // username
+                        error("Invalid option -u without value. Username required.");
+                    }
+                    username = args[i];
+                } else if ("-p".equals(arg)) { // password
+                    if (++i == args.length) { // username
+                        error("Invalid option -p without value. Password required.");
+                    }
+                    password = args[i];
+                } else if ("-t".equals(arg)) { // test mode
+                    testMode = true;
+                } else if ("-e".equals(arg)) { // execute mode
+                    // execute one command
+                    execMode = true;
+                    StringBuilder buf = new StringBuilder();
+                    for (i++; i<args.length; i++) {
+                        buf.append(args[i]).append(" ");
+                    }
+                    command = buf.toString();
+                    break;
+                } else if ("-b".equals(arg)) { // batch mode
+                    // execute commands in the given file or if no specified read from stdin
+                    batchMode = true;
+                    if (++i < args.length) {
+                        // read commands from a file
+                        command = args[i];
+                    }
+                    break;
+                } else if ("-h".equals(arg)) { // help
+                    // execute help command
+                    usage();
+                    System.exit(0);
+                } else if (!arg.startsWith("-")) {
+                    url = arg;
+                } else {
+                    // unknown option
+                }
+            }
+            if (username != null && password == null) {
+                password = PasswordReader.read();
+            }
+            if (url != null && !url.contains("://")) {
+                url = "http://"+url;
+            }
+        }
+    }
+
+    public void run() throws Exception {
+        app = new ChemistryApp();
+        if (username != null){
+            app.login(username, password == null ? new char[0] : password.toCharArray());
+        }
+        if (url != null) {
+            app.connect(url);
+        }
+
+        if (execMode) {
+            runInExecMode();
+        } else if (batchMode) {
+            runInBatchMode();
+        } else {
+            runInInteractiveMode();
+        }
+    }
+
+    private void runInExecMode() throws Exception {
+        Console.setDefault(new Console());
+        Console.getDefault().start(app);
+        Console.getDefault().runCommand(command);
+    }
+
+    private void runInBatchMode() throws IOException {
+        Console.setDefault(new Console());
+        Console.getDefault().start(app);
+        List<String> cmds;
+        if (command == null) {
+            cmds = IOUtils.readLines(System.in);
+        } else {
+            cmds = IOUtils.readLines(new FileInputStream(new File(command)));
+        }
+        for (String cmd : cmds) {
+            // Ignore empty lines / comments
+            if (cmd.length() == 0 || cmd.startsWith("#")) {
+                continue;
+            }
+            Console.getDefault().println("Running: " + cmd);
+            try {
+                Console.getDefault().runCommand(cmd);
+            } catch (ExitException e) {
+                Console.getDefault().println("Bye.");
+                return;
+            } catch (Exception e) {
+                Console.getDefault().error(e.getMessage());
+                if (testMode) {
+                    e.printStackTrace();
+                    Console.getDefault().println("Exiting on error.");
+                    System.exit(1);
+                    return;
+                }
+            }
+        }
+        Console.getDefault().println("Done.");
+    }
+
+    private void runInInteractiveMode() {
+        try {
+            //TODO use user profiles to setup console like prompt and default service to cd in
+            Console.setDefault(new JLineConsole());
+            Console.getDefault().println(
+                    "CMIS Shell by Nuxeo (www.nuxeo.com). Type 'help' for help.");
+            Console.getDefault().start(app);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    static void error(String msg) {
+        System.err.println(msg);
+        System.exit(1);
+    }
+
+    static void usage() throws IOException {
+        URL url = Main.class.getResource("/help/usage.help");
+        String help = IOUtils.toString(url.openStream());
+        System.out.print(help);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/Main.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,182 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+package org.apache.chemistry.shell.app;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.shell.command.CommandRegistry;
+import org.apache.chemistry.shell.util.Path;
+
+public abstract class AbstractApplication implements Application {
+
+    protected final CommandRegistry registry;
+    protected final Map<String, Object> dataMap;
+
+    protected Context ctx;
+    protected URL serverUrl;
+    protected File wd;
+    protected String username;
+    protected char[] password;
+
+
+    public AbstractApplication() {
+        registry = new CommandRegistry();
+        dataMap = new HashMap<String, Object>();
+        wd = new File(".");
+        ctx = getRootContext();
+    }
+
+    public void login(String username, char[] password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    protected void initServerURL(URL serverUrl) {
+        String userInfo = serverUrl.getUserInfo();
+        if (userInfo != null) {
+            int p = userInfo.indexOf(':');
+            if (p > -1) {
+                username = userInfo.substring(0, p);
+                password = userInfo.substring(p+1).toCharArray();
+            } else {
+                username = userInfo;
+            }
+        }
+        // do URL cleanup
+        try {
+            this.serverUrl = new URL(serverUrl.getProtocol(), serverUrl.getHost(), serverUrl.getPort(), serverUrl.getPath());
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    public String getHost() {
+        return serverUrl.getHost();
+    }
+
+    public void connect(String uri) throws IOException {
+        connect(new URL(uri));
+    }
+
+    public void connect(URL uri) throws IOException {
+        initServerURL(uri);
+        doConnect();
+    }
+
+    protected abstract void doConnect();
+
+    public CommandRegistry getCommandRegistry() {
+        return registry;
+    }
+
+    public URL getServerUrl() {
+        return serverUrl;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public File getWorkingDirectory() {
+        return wd;
+    }
+
+    public void setWorkingDirectory(File file) {
+        wd = file;
+        Console.getDefault().updatePrompt();
+    }
+
+    public Context getContext() {
+        return ctx;
+    }
+
+    public void setContext(Context ctx) {
+        this.ctx = ctx;
+        Console.getDefault().updatePrompt();
+    }
+
+    public Context resolveContext(Path path) {
+        Context c;
+        if (path.isRelative()) {
+            if (path.segmentCount() == 0) {
+                return getContext();
+            }
+            boolean dotdot = false;
+            while (path.segmentCount() > 0) {
+                String seg = path.segment(0);
+                if (seg.equals(".")) {
+                    path = path.removeFirstSegments(1);
+                } else if (seg.equals("..")) {
+                    dotdot = true;
+                    break;
+                } else {
+                    break;
+                }
+            }
+            if (dotdot) {
+                path = getContext().getPath().append(path);
+                c = getRootContext();
+            } else {
+                c = getContext();
+            }
+        } else {
+            c = getRootContext();
+        }
+        if (c == null) {
+            return null;
+        }
+        for (int i=0,cnt=path.segmentCount(); i<cnt; i++) {
+            c = c.getContext(path.segment(i));
+            if (c == null) {
+                return null;
+            }
+        }
+        return c;
+    }
+
+    public File resolveFile(String path) {
+        if (path.startsWith("/")) {
+            return new File(path);
+        } else {
+            return new File(wd, path);
+        }
+    }
+
+    public Object getData(String key) {
+        return dataMap.get(key);
+    }
+
+    public void setData(String key, Object data) {
+        if (data == null) {
+            dataMap.remove(key);
+        } else {
+            dataMap.put(key, data);
+        }
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractApplication.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import org.apache.chemistry.shell.util.Path;
+
+public abstract class AbstractContext implements Context {
+
+    protected final Application app;
+    protected final Path path;
+
+    public AbstractContext(Application app, Path path) {
+        this.app = app;
+        this.path = path;
+    }
+
+    public String pwd() {
+        return path.toString();
+    }
+
+    public Path getPath() {
+        return path;
+    }
+
+    public Application getApplication() {
+        return app;
+    }
+
+    public Path resolvePath(String path) {
+        if (!path.startsWith("/")) {
+            return new Path(path);
+        } else {
+            return this.path.append(path);
+        }
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/AbstractContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,134 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.chemistry.shell.command.CommandRegistry;
+import org.apache.chemistry.shell.util.Path;
+
+/**
+ * An application represents the global context of the shell.
+ *
+ * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
+ */
+public interface Application {
+
+    /**
+     * Login using the given account.
+     */
+    void login(String username, char[] password);
+
+    /**
+     * Gets the connection URL.
+     */
+    URL getServerUrl();
+
+    /**
+     * Gets he username used for the connection.
+     */
+    String getUsername();
+
+    /**
+     * Gets the host where the application is connected.
+     */
+    String getHost();
+
+    /**
+     * Gets the working directory.
+     */
+    File getWorkingDirectory();
+
+    /**
+     * Sets the working directory (will be used to resolve relative file paths).
+     */
+    void setWorkingDirectory(File file);
+
+    /**
+     * Gets a file given its path.
+     * <p>
+     * If the path is absolute (starts with '/') it will be resolved as an absolute path
+     * otherwise it will be resolved against the current working directory.
+     */
+    File resolveFile(String path);
+
+    /**
+     * Gets the current context.
+     */
+    Context getContext();
+
+    /**
+     * Sets the current context to the given one.
+     */
+    void setContext(Context ctx);
+
+    /**
+     * Resolves the given path to a context.
+     */
+    Context resolveContext(Path path);
+
+    /**
+     * Gets the root context.
+     */
+    Context getRootContext();
+
+    /**
+     * Gets the command registry.
+     */
+    CommandRegistry getCommandRegistry();
+
+    /**
+     * Sets a global variable. Can be used by commands to preserve their state.
+     */
+    void setData(String key, Object data);
+
+    /**
+     * Gets a global variable given its key.
+     */
+    Object getData(String key);
+
+    /**
+     * Connects to the given url. The current context will be reset.
+     */
+    void connect(String uri) throws IOException;
+
+    /**
+     * Connects to the given url. The current context will be reset.
+     */
+    void connect(URL uri) throws IOException;
+
+    /**
+     * Disconnects if already connected. The current context will be reset.
+     */
+    void disconnect();
+
+    /**
+     * Tests if connected.
+     */
+    boolean isConnected();
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Application.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,86 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import org.apache.chemistry.atompub.client.connector.APPContentManager;
+import org.apache.chemistry.shell.cmds.cmis.Cat;
+import org.apache.chemistry.shell.cmds.cmis.CreateFile;
+import org.apache.chemistry.shell.cmds.cmis.CreateFolder;
+import org.apache.chemistry.shell.cmds.cmis.DumpProps;
+import org.apache.chemistry.shell.cmds.cmis.DumpTree;
+import org.apache.chemistry.shell.cmds.cmis.Get;
+import org.apache.chemistry.shell.cmds.cmis.PropGet;
+import org.apache.chemistry.shell.cmds.cmis.Put;
+import org.apache.chemistry.shell.cmds.cmis.Remove;
+import org.apache.chemistry.shell.cmds.cmis.SetProp;
+import org.apache.chemistry.shell.cmds.cmis.SetStream;
+
+/**
+ * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
+ *
+ */
+public class ChemistryApp extends AbstractApplication {
+
+    protected APPContentManager cm;
+
+    public ChemistryApp() {
+        registry.registerCommand(new DumpTree());
+        registry.registerCommand(new SetProp());
+        registry.registerCommand(new PropGet());
+        registry.registerCommand(new DumpProps());
+        registry.registerCommand(new Get());
+        registry.registerCommand(new SetStream());
+        registry.registerCommand(new CreateFile());
+        registry.registerCommand(new CreateFolder());
+        registry.registerCommand(new Remove());
+        registry.registerCommand(new Cat());
+        registry.registerCommand(new Put());
+    }
+
+    @Override
+    protected void doConnect() {
+        cm = new APPContentManager(serverUrl.toExternalForm());
+        if (username != null) {
+            cm.login(username, new String(password));
+        }
+    }
+
+    public void disconnect() {
+        cm = null;
+    }
+
+    public boolean isConnected() {
+        return cm != null;
+    }
+
+    public Context getRootContext() {
+        return new ChemistryRootContext(this);
+    }
+
+    public APPContentManager getContentManager() {
+        return cm;
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryApp.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,46 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import org.apache.chemistry.shell.command.Command;
+import org.apache.chemistry.shell.command.CommandLine;
+
+public abstract class ChemistryCommand extends Command {
+
+    @Override
+    public void run(Application app, CommandLine cmdLine) throws Exception {
+        if (app instanceof ChemistryApp) {
+            ensureConnected(app);
+            execute((ChemistryApp) app, cmdLine);
+        } else {
+            Console.getDefault().error(
+                    "Chemistry commands cannot be run outside chemistry context");
+        }
+    }
+
+    protected abstract void execute(ChemistryApp app, CommandLine cmdLine)
+            throws Exception;
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,164 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.Folder;
+import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.atompub.client.APPConnection;
+import org.apache.chemistry.atompub.client.connector.APPContentManager;
+import org.apache.chemistry.shell.util.ColorHelper;
+import org.apache.chemistry.shell.util.Path;
+
+public class ChemistryContext extends AbstractContext {
+
+    //public static final String CONN_KEY = "chemistry.connection";
+
+    protected final APPContentManager cm;
+    protected final APPConnection conn;
+    protected final CMISObject entry;
+
+    protected String[] keys;
+    protected String[] ls;
+    protected Map<String,CMISObject> children;
+
+    public ChemistryContext(ChemistryApp app, Path path, APPConnection conn, CMISObject entry) {
+        super(app, path);
+        this.conn = conn;
+        this.entry = entry;
+        cm = app.getContentManager();
+    }
+
+    @Override
+    public ChemistryApp getApplication() {
+        return (ChemistryApp)app;
+    }
+
+    // Not used
+    public APPConnection getConnection() {
+        return conn;
+    }
+
+    // Not used
+    public CMISObject getEntry() {
+        return entry;
+    }
+
+    // Not used
+    public APPContentManager getContentManager() {
+        return cm;
+    }
+
+    // Not used
+    public Repository getRepository() {
+        return conn.getRepository();
+    }
+
+    public Context getContext(String name) {
+        load();
+        CMISObject e = children.get(name);
+        if (e != null) {
+            return new ChemistryContext((ChemistryApp) app, path.append(name), conn, e);
+        }
+        return null;
+    }
+
+    public String[] ls() {
+        load();
+        return ls;
+    }
+
+    public String[] entries() {
+        load();
+        return keys;
+    }
+
+    public void reset() {
+        children = null;
+        keys = null;
+        ls = null;
+    }
+
+    public boolean isFolder() {
+        return entry instanceof Folder;
+    }
+
+    protected void load() {
+        if (children == null) {
+            if (!isFolder()) {
+                return;
+            }
+            Folder folder = (Folder) entry;
+            List<CMISObject> feed =  folder.getChildren();
+            children = new LinkedHashMap<String, CMISObject>();
+            keys = new String[feed.size()];
+            ls = new String[keys.length];
+            int i = 0;
+            for (CMISObject entry : feed) {
+                children.put(entry.getName(), entry);
+                keys[i] = entry.getName();
+                ls[i++] = ColorHelper.decorateNameByType(entry.getName(), entry.getTypeId());
+            }
+        }
+    }
+
+    public <T> T as(Class<T> type) {
+        if (type.isAssignableFrom(entry.getClass())) {
+            return type.cast(entry);
+        }
+        return null;
+    }
+
+    // Not used
+    public CMISObject getObjectByAbsolutePath(String path) {
+        ObjectEntry entry = conn.getObjectByPath(path, null);
+        if (entry!=null) {
+            return conn.getObject(entry);
+        } else {
+            return null;
+        }
+    }
+
+    // Not used
+    public CMISObject resolveObject(String path) {
+        Path p = resolvePath(path);
+        ObjectEntry entry = conn.getObjectByPath(p.toString(), null);
+        if (entry!=null) {
+            return conn.getObject(entry);
+        } else {
+            return null;
+        }
+    }
+
+    public String id() {
+        return "Object "+entry.getId()+" of type "+entry.getTypeId();
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,125 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.Repository;
+import org.apache.chemistry.atompub.client.APPConnection;
+import org.apache.chemistry.atompub.client.ContentManager;
+import org.apache.chemistry.atompub.client.connector.APPContentManager;
+import org.apache.chemistry.shell.util.ColorHelper;
+import org.apache.chemistry.shell.util.Path;
+
+public class ChemistryRootContext extends AbstractContext {
+
+    protected Map<String, Repository> repos;
+    protected String[] keys;
+    protected String[] ls;
+
+    public ChemistryRootContext(ChemistryApp app) {
+        super(app, Path.ROOT);
+    }
+
+    public APPContentManager getContentManager() {
+        return ((ChemistryApp) app).getContentManager();
+    }
+
+    @Override
+    public ChemistryApp getApplication() {
+        return (ChemistryApp) app;
+    }
+
+    public <T> T as(Class<T> type) {
+        return null;
+    }
+
+    public Context getContext(String name) {
+        load();
+        ContentManager cm = getContentManager();
+        if (cm == null) {
+            Console.getDefault().error("Not connected: cannot browse repository");
+            return null;
+        }
+        Repository r = repos.get(name); // TODO  atompub client is using IDs to get repositories ...
+        Repository repo = cm.getRepository(r.getId());
+        if (repo != null) {
+            APPConnection conn = (APPConnection) repo.getConnection(null);
+            CMISObject entry = conn.getRootFolder();
+            return new ChemistryContext((ChemistryApp) app, path.append(name), conn, entry);
+        }
+        return null;
+    }
+
+    public String[] ls() {
+        if (load()) {
+            return ls;
+        }
+        return new String[0];
+    }
+
+    public String[] entries() {
+        if (load()) {
+            return keys;
+        }
+        return new String[0];
+    }
+
+    protected boolean load() {
+        if (keys == null) {
+            ContentManager cm = getContentManager();
+            if (cm == null) {
+                Console.getDefault().error("Not connected: cannot browse repository");
+                return false;
+            }
+            Repository[] repos = cm.getRepositories();
+            this.repos = new HashMap<String, Repository>();
+            keys = new String[repos.length];
+            ls = new String[repos.length];
+            for (int i=0; i<repos.length; i++) {
+                keys[i] = repos[i].getName();
+                this.repos.put(repos[i].getName(), repos[i]);
+                ls[i] = ColorHelper.decorateNameByType(repos[i].getName(), "Repository");
+            }
+        }
+        return true;
+    }
+
+    public void reset() {
+        keys = null;
+        ls = null;
+        APPContentManager cm = getContentManager();
+        if (cm != null) {
+            cm.refresh();
+        }
+    }
+
+    public String id() {
+        return "CMIS server: "+app.getServerUrl();
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/ChemistryRootContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,129 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.chemistry.shell.command.CommandException;
+import org.apache.chemistry.shell.command.CommandLine;
+import org.apache.chemistry.shell.command.CommandRegistry;
+import org.apache.chemistry.shell.util.PasswordReader;
+
+public class Console {
+
+    protected static Console instance;
+
+    protected Application app;
+
+    protected StringBuffer buffer = new StringBuffer();
+    protected String lastResult;
+
+    public static Console getDefault() {
+        return instance;
+    }
+
+    public static void setDefault(Console console) {
+        instance = console;
+    }
+
+    /**
+     * Starts the console.
+     */
+    public void start(Application app) throws IOException {
+        if (this.app != null) {
+            throw new IllegalStateException("Console already started");
+        }
+        this.app = app;
+    }
+
+    /**
+     * Gets the current client
+     */
+    public Application getApplication() {
+        return app;
+    }
+
+    /**
+     * Gets the result of the last command.
+     */
+    public String getLastResult() {
+        return lastResult;
+    }
+
+    public void runCommand(String line) throws Exception {
+        CommandLine commandLine = parseCommandLine(app.getCommandRegistry(), line);
+        lastResult = buffer.toString();
+        buffer = new StringBuffer();
+        commandLine.run(app);
+        if ("match".equals(commandLine.getCommand().getName())) {
+            // Keep previous result in case we have several 'match' commands
+            buffer = new StringBuffer(lastResult);
+        }
+    }
+
+    public static CommandLine parseCommandLine(CommandRegistry reg, String line) throws CommandException {
+        return new CommandLine(reg, line);
+    }
+
+    /**
+     * Update the current context of the console.
+     * Overridden in the JLine console.
+     */
+    public void updatePrompt() {
+        // do nothing
+    }
+
+    /**
+     * Reads the stream an prints the result on the screen.
+     */
+    public void print(InputStream in) throws IOException {
+        IOUtils.copy(in, System.out);
+        System.out.flush();
+    }
+
+    public void println(String str) {
+        buffer.append(str + "\n");
+        System.out.println(str);
+    }
+
+    /**
+     * Print a new line.
+     * On non text console does nothing
+     */
+    public void println() throws IOException {
+        System.out.println();
+    }
+
+    public void error(String message) {
+        System.err.println(message);
+    }
+
+    public String promptPassword() throws IOException {
+        return PasswordReader.read();
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Console.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,120 @@
+/*
+ * (C) Copyright 2009-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ *   Bogdan Stefanescu (bs@nuxeo.com), Nuxeo
+ *   Stefane Fermigier (sf@nuxeo.com), Nuxeo
+ *   Florent Guillaume (fg@nuxeo.com), Nuxeo
+ */
+
+package org.apache.chemistry.shell.app;
+
+import org.apache.chemistry.shell.util.Path;
+
+/**
+ * A context represents the current state of the shell application and is usually wrapping
+ * the current selected remote object.
+ * <p>
+ * The context can be adapted to the wrapped object by calling {@link Context#as(Class)}
+ * and providing the desired type.
+ * If the context cannot be represented as the given type it will return null,
+ * otherwise will return the instance of the desired object.
+ * <p>
+ * A context may wrap a "folder" object (thus may contain sub contexts) or it may be a leaf context.
+ * To change a context to another remote object the Context#cd
+ * <p>
+ * A context is providing several basic operations like:
+ * <ul>
+ * <li> ls  - list available sub contexts
+ * <li> pwd - get the context absolute path
+ * <li> id  - show more information about the current context
+ * <li> cd  - change the context to another context given a context path.
+ * If the path starts with a '/' it will be assumed to be an absolute path otherwise it will be resolved relative to the current context
+ * </ul>
+ */
+public interface Context {
+
+    /**
+     * Gets the current application.
+     *
+     * @return
+     */
+    Application getApplication();
+
+    /**
+     * Gets the context path.
+     *
+     * @return
+     */
+    Path getPath();
+
+    /**
+     * Gets the context absolute path as a string.
+     *
+     * @return
+     */
+    String pwd();
+
+    /**
+     * Lists the keys of the available sub contexts.
+     * This is used by the command line completor.
+     *
+     * @return an empty array if no sub contexts are available, otherwise return the array of sub context names
+     */
+    String[] entries();
+
+    /**
+     * Lists sub contexts names. The returned names are colored (may contain color code characters).
+     *
+     * @return
+     */
+    String[] ls(); //colored entries
+
+    /**
+     * Gets a child context given its name.
+     *
+     * @param name
+     * @return null if no such sub context exists, otherwise returns the sub context
+     */
+    Context getContext(String name);
+
+    Path resolvePath(String path);
+
+    /**
+     * Clears any cache associated with the context.
+     */
+    void reset();
+
+    /**
+     * Adapts the context to the given type.
+     *
+     * @param <T>
+     * @param type
+     * @return null if the context cannot be adapted, otherwise an instance of the given type
+     */
+    <T> T as(Class<T> type);
+
+    /**
+     * Gets a string identifying this context.
+     * (Can be the object title and path or other useful information).
+     *
+     * @return
+     */
+    String id();
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/app/Context.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message