chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfermig...@apache.org
Subject svn commit: r899665 [4/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
Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/PasswordReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/PasswordReader.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/PasswordReader.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/PasswordReader.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,75 @@
+/*
+ * (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.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * In java 6 there is direct support for reading passwords form a console
+ * <pre>
+ *  if ((cons = System.console()) != null &&
+ *    (passwd = cons.readPassword("[%s]", "Password:")) != null) {
+ *    ...
+ *  }
+ * </pre>
+ * This can be for java &lt; 6.
+ * <p>
+ * A separate thread is used to send to the console the backspace character to erase the last-typed character.
+ */
+public class PasswordReader {
+
+    private PasswordReader() {
+    }
+
+    public static String read() throws IOException {
+        ConsoleEraser consoleEraser = new ConsoleEraser();
+        System.out.print("Password:  ");
+        BufferedReader stdin = new BufferedReader(new
+                InputStreamReader(System.in));
+        consoleEraser.start();
+        String pass = stdin.readLine();
+        consoleEraser.halt();
+        System.out.print("\b");
+        return pass;
+    }
+
+    static class ConsoleEraser extends Thread {
+
+        private boolean running = true;
+
+        @Override
+        public void run() {
+            while (running) {
+                System.out.print("\b ");
+            }
+        }
+
+        public synchronized void halt() {
+            running = false;
+        }
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/Path.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/Path.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/Path.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/Path.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,512 @@
+/*
+ * (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.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Path implements Serializable {
+
+    public static final char SEP = '/';
+
+    protected static final int HAS_LEADING = 1;
+    protected static final int HAS_TRAILING = 2;
+    protected static final int HASH_MASK = ~HAS_TRAILING;
+    protected static final int ALL_SEPARATORS = HAS_LEADING | HAS_TRAILING;
+    protected static final int USED_BITS = 2;
+    protected static final String[] NO_SEGMENTS = new String[0];
+
+    private static final long serialVersionUID = 5008948361159403627L;
+
+    public static final Path EMPTY = new Path(new String[0], 0) {
+        private static final long serialVersionUID = -1731993368728652448L;
+        @Override
+        public String toString() {
+            return "";
+        }
+    };
+
+    public static final Path ROOT = new Path(new String[0], 1) {
+        private static final long serialVersionUID = -6689687769363666578L;
+        @Override
+        public String toString() {
+            return "/";
+        }
+    };
+
+    protected String[] segments;
+    protected int flags;
+
+
+    public Path(String path) {
+        init(path);
+        updateHashCode();
+    }
+
+    public Path(String path, int flags) {
+        init(path);
+        this.flags |= flags & ALL_SEPARATORS;
+        updateHashCode();
+    }
+
+    public Path(String[] segments, int flags) {
+        this.segments = segments;
+        this.flags = flags;
+        updateHashCode();
+    }
+
+    public Path(Path path) {
+        segments = path.segments;
+        flags = path.flags;
+    }
+
+
+    private void init(String path) {
+        List<String> segments = new ArrayList<String>();
+        int len = path.length();
+        if (len == 0) {
+            flags = 0;
+            this.segments = NO_SEGMENTS;
+            return;
+        }
+        if (len == 1) {
+            char c = path.charAt(0);
+            if (c == '/') {
+                flags = HAS_LEADING;
+                this.segments = NO_SEGMENTS;
+                return;
+            } else if (c == '.'){
+                flags = 0;
+                this.segments = NO_SEGMENTS;
+                return;
+            } else {
+                flags = 0;
+                this.segments = new String[] {path};
+                return;
+            }
+        }
+        char[] chars = path.toCharArray();
+        flags = chars[0] == '/' ? HAS_LEADING : 0;
+        if (chars[len-1] == '/') {
+            flags |= HAS_TRAILING;
+        }
+
+        int slash = 0;
+        int off = 0;
+        int cnt = 0;
+        for (int i = 0; i < len; i++) {
+            char c = chars[i];
+            switch (c) {
+            case SEP:
+                if (slash == 0) { // first slash
+                    if (cnt > 0) { // segment end
+                        segments.add(new String(chars, off, cnt));
+                        cnt = 0;
+                    }
+                    off = i;
+                } else { // ignore double slashes
+                    off++;
+                }
+                slash++;
+                break;
+            case '.':
+                if (slash > 0 || i == 0) {
+                    if (i < chars.length-2) { // look ahead 2 chars
+                        char c1 = chars[i+1];
+                        char c2 = chars[i+2];
+                        if (c1 == '.' && c2 == SEP) { // a .. segment
+                            if (segments.isEmpty()) { // add a dot segment
+                                segments.add("..");
+                            } else { // remove last segment
+                                int last = segments.size()-1;
+                                if (!"..".equals(segments.get(last))) {
+                                    segments.remove(last);
+                                } else {
+                                    segments.add("..");
+                                }
+                            }
+                            i += 2;
+                            slash = 1;
+                            continue;
+                        } else if (c1 == SEP) { // a . segment - ignore it
+                            i++;
+                            slash = 1;
+                            continue;
+                        }
+                    } else if (i < chars.length -1 && chars[i+1] == '/') { // ignore . segment
+                        slash = 0;
+                        continue; //TODO - we may add here the segment to avoid rereading the char
+                    }
+                    slash = 0;
+                }
+                // do nothing (the char will be added to the segment)
+            default:
+                if (slash > 0) {
+                    slash = 0;
+                    off = i;
+                }
+                cnt++;
+                break;
+            }
+        }
+        if (cnt > 0) {
+            segments.add(new String(chars, off, cnt));
+        }
+        int size = segments.size();
+        if (size == 0) {
+            this.segments = NO_SEGMENTS;
+        } else {
+            this.segments = segments.toArray(new String[segments.size()]);
+        }
+    }
+
+    protected final void updateHashCode() {
+        flags = (flags & ALL_SEPARATORS) | (computeHashCode() << USED_BITS);
+    }
+
+    protected int computeHashCode() {
+        int hash = 17;
+        int segmentCount = segments.length;
+        for (int i = 0; i < segmentCount; i++) {
+            //this function tends to given a fairly even distribution
+            hash = hash * 37 + segments[i].hashCode();
+        }
+        return hash;
+    }
+
+    public boolean isAbsolute() {
+        return (flags & HAS_LEADING) != 0;
+    }
+
+    public boolean isRelative() {
+        return (flags & HAS_LEADING) == 0;
+    }
+
+    public boolean isRoot() {
+        return (segments.length == 0) && ((flags & HAS_LEADING) != 0);
+    }
+
+    public boolean isEmpty() {
+        return (segments.length == 0) && ((flags & HAS_LEADING) == 0);
+    }
+
+    public boolean hasTrailingSeparator() {
+        return (flags & HAS_TRAILING) != 0;
+    }
+
+    public int segmentCount() {
+        return segments.length;
+    }
+
+    public String[] segments() {
+        final String[] segmentCopy = new String[segments.length];
+        System.arraycopy(segments, 0, segmentCopy, 0, segments.length);
+        return segmentCopy;
+    }
+
+    public String segment(int index) {
+        return segments[index];
+    }
+
+    public String getLastSegment() {
+        int len = segments.length;
+        return len == 0 ? null : segments[len - 1];
+    }
+
+    public String getFileExtension() {
+        int len = segments.length;
+        if (len == 0) {
+            return null;
+        }
+        String name = segments[len - 1];
+        int p = name.lastIndexOf('.');
+        if (p > -1) {
+            return name.substring(p+1);
+        }
+        return null;
+    }
+
+    public String getFileName() {
+        int len = segments.length;
+        if (len == 0) {
+            return null;
+        }
+        String name = segments[len - 1];
+        int p = name.lastIndexOf('.');
+        if (p > -1) {
+            return name.substring(0, p);
+        }
+        return name;
+    }
+
+    public String[] getFileParts() {
+        int len = segments.length;
+        if (len == 0) {
+            return null;
+        }
+        String name = segments[len - 1];
+        int p = name.lastIndexOf('.');
+        if (p > -1) {
+            return new String[] {name.substring(0, p), name.substring(p+1)};
+        }
+        return new String[] {name, null};
+    }
+
+    public Path makeAbsolute() {
+        if (isAbsolute()) {
+            return this;
+        }
+        int k = 0;
+        for (String segment : segments) {
+            if ("..".equals(segment)) {
+                k++;
+            } else {
+                break;
+            }
+        }
+        if (k > 0) {
+            String[] newSegments = new String[segments.length-k];
+            System.arraycopy(segments, k, newSegments, 0, newSegments.length);
+           return  new Path(newSegments, flags | HAS_LEADING);
+        }
+        return new Path(segments, flags | HAS_LEADING);
+    }
+
+    public Path makeRelative() {
+        if (isRelative()) {
+            return this;
+        }
+        return new Path(segments, flags & ~HAS_LEADING);
+    }
+
+    public Path removeTrailingSeparator() {
+        if (!hasTrailingSeparator()) {
+            return this;
+        }
+        return new Path(segments, flags & ~HAS_TRAILING);
+    }
+
+    public Path addTrailingSeparator() {
+        if (hasTrailingSeparator()) {
+            return this;
+        }
+        return new Path(segments, flags | HAS_TRAILING);
+    }
+
+    public Path removeLastSegments(int count) {
+        if (count == 0) {
+            return this;
+        }
+        if (count >= segments.length) {
+            //result will have no trailing separator
+            return (flags & HAS_LEADING) != 0 ? ROOT : EMPTY;
+        }
+        assert count > 0;
+        final int newSize = segments.length - count;
+        final String[] newSegments = new String[newSize];
+        System.arraycopy(segments, 0, newSegments, 0, newSize);
+        return new Path(newSegments, flags);
+    }
+
+    public Path removeFirstSegments(int count) {
+        if (count == 0) {
+            return this;
+        }
+        if (count >= segments.length) {
+            return EMPTY;
+        }
+        assert count > 0;
+        int newSize = segments.length - count;
+        String[] newSegments = new String[newSize];
+        System.arraycopy(segments, count, newSegments, 0, newSize);
+
+        //result is always a relative path
+        return new Path(newSegments, flags & HAS_TRAILING);
+    }
+
+    public Path removeFileExtension() {
+        String extension = getFileExtension();
+        if (extension == null || extension.equals("")) { //$NON-NLS-1$
+            return this;
+        }
+        String lastSegment = getLastSegment();
+        int index = lastSegment.lastIndexOf(extension) - 1;
+        return removeLastSegments(1).append(lastSegment.substring(0, index));
+    }
+
+    public Path up() {
+        return removeLastSegments(1);
+    }
+
+    public Path getParent() {
+        return removeLastSegments(1);
+    }
+
+    public Path appendSegment(String segment) {
+        int myLen = segments.length;
+        String[] newSegments = new String[myLen + 1];
+        System.arraycopy(segments, 0, newSegments, 0, myLen);
+        newSegments[myLen] = segment;
+        return new Path(newSegments, flags);
+    }
+
+    public Path append(Path tail) {
+        //optimize some easy cases
+        if (tail == null || tail.segmentCount() == 0) {
+            return this;
+        }
+        if (isEmpty()) {
+            return tail.makeRelative();
+        }
+        if (isRoot()) {
+            return tail.makeAbsolute();
+        }
+
+        int flags = this.flags;
+
+        int myLen = segments.length;
+        int tailLen = tail.segmentCount();
+        int j = 0; int s = 0;
+        // remove ../ segments from the appended path
+        for (int i=0; i<tailLen; i++) {
+            String seg = tail.segments[i];
+            if ("..".equals(seg)) {
+                j++;
+            } else if (".".equals(seg)) {
+                if (j == 0) {
+                    s++;
+                }
+            } else {
+                break;
+            }
+        }
+        if (j > 0) {
+            s = j;
+        }
+
+        int k = myLen - j;
+        if (k < 0) {
+            myLen = -k;
+        } else {
+            myLen = k;
+        }
+
+        //concatenate the two segment arrays
+        String[] newSegments = new String[myLen + tailLen-s];
+        if (k < 0) {
+            for (int i = 0; i < myLen; i++) {
+                newSegments[i] = "..";
+            }
+            flags &= ~HAS_LEADING;
+        } else if (k > 0) {
+            System.arraycopy(segments, 0, newSegments, 0, myLen);
+        }
+        for (int i = s; i < tailLen; i++) {
+            newSegments[myLen + i-s] = tail.segment(i);
+        }
+        //use my leading separators and the tail's trailing separator
+
+        return new Path(newSegments, (flags & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0));
+    }
+
+    public Path append(String tail) {
+        //optimize addition of a single segment
+        if (tail.indexOf(SEP) == -1) {
+            int tailLength = tail.length();
+            if (tailLength < 3) {
+                //some special cases
+                if (tailLength == 0 || ".".equals(tail)) {
+                    return this;
+                }
+                if ("..".equals(tail)) {
+                    return removeLastSegments(1);
+                }
+            }
+            //just add the segment
+            int myLen = segments.length;
+            String[] newSegments = new String[myLen + 1];
+            System.arraycopy(segments, 0, newSegments, 0, myLen);
+            newSegments[myLen] = tail;
+            return new Path(newSegments, flags & ~HAS_TRAILING);
+        }
+        //go with easy implementation
+        return append(new Path(tail));
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof Path)) {
+            return false;
+        }
+        Path target = (Path) obj;
+        //check leading separators and hash code
+        if (flags != target.flags) {
+            return false;
+        }
+        String[] targetSegments = target.segments;
+        int i = segments.length;
+        //check segment count
+        if (i != targetSegments.length) {
+            return false;
+        }
+        //check segments in reverse order - later segments more likely to differ
+        while (--i >= 0) {
+            if (!segments[i].equals(targetSegments[i])) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return flags & HASH_MASK;
+    }
+
+    @Override
+    public String toString() {
+        int len = segments.length;
+        if (len == 0) {
+            return (flags & HAS_LEADING) != 0 ? "/" : "";
+        }
+        StringBuilder buf = new StringBuilder(len*16);
+        if ((flags & HAS_LEADING) != 0) {
+            buf.append(SEP);
+        }
+        buf.append(segments[0]);
+        for (int i=1; i<len; i++) {
+            buf.append(SEP).append(segments[i]);
+        }
+        if ((flags & HAS_TRAILING) != 0) {
+            buf.append(SEP);
+        }
+        return buf.toString();
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleBrowser.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleBrowser.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleBrowser.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleBrowser.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,68 @@
+/*
+ * (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.util;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.chemistry.BaseType;
+import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.Folder;
+import org.apache.chemistry.shell.app.Console;
+
+public class SimpleBrowser {
+
+    protected final Folder root;
+
+    public SimpleBrowser(Folder root) {
+        this.root = root;
+    }
+
+    public void browse() throws IOException {
+        doBrowse(root);
+    }
+
+    protected void doBrowse(Folder currentNode) throws IOException {
+        doBrowse("+", currentNode);
+    }
+
+    protected void doBrowse(String tabs, Folder currentNode) throws IOException {
+        dumpWithPath(tabs, currentNode);
+        List<CMISObject> children = currentNode.getChildren();
+        for (CMISObject child : children) {
+            if (BaseType.FOLDER.equals(child.getBaseType())) {
+                Folder folder = (Folder) child;
+                doBrowse(tabs + "--+", folder);
+            } else {
+                dumpWithPath(tabs + "---", child);
+            }
+        }
+    }
+
+    protected void dumpWithPath(String tabs, CMISObject item) {
+        Console.getDefault().println(tabs+ " "+ item.getName()+" ["+item.getType().getId()+"]");
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleCreator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleCreator.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleCreator.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimpleCreator.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,54 @@
+/*
+ * (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.util;
+
+import org.apache.chemistry.Document;
+import org.apache.chemistry.Folder;
+
+public class SimpleCreator {
+
+    protected final Folder folder;
+
+    public SimpleCreator(Folder folder) {
+        this.folder = folder;
+    }
+
+    public void createFolder(String typeName, String name) throws Exception {
+        Folder newFolder = folder.newFolder(typeName);
+        newFolder.setName(name);
+        // TODO
+        //newFolder.setValue("dc:title", name);
+        newFolder.save();
+    }
+
+    public void createFile(String typeName, String name) throws Exception {
+        Document newDoc = folder.newDocument(typeName);
+        newDoc.setName(name);
+        // TODO
+        //newDoc.setValue("dc:title", name);
+        newDoc.save();
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimplePropertyManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimplePropertyManager.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimplePropertyManager.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/SimplePropertyManager.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,94 @@
+/*
+ * (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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.ContentStream;
+import org.apache.chemistry.Document;
+import org.apache.chemistry.Property;
+import org.apache.chemistry.impl.simple.SimpleContentStream;
+import org.apache.chemistry.shell.app.Console;
+import org.apache.chemistry.shell.command.CommandException;
+
+public class SimplePropertyManager {
+
+    protected final CMISObject item;
+
+    public SimplePropertyManager(CMISObject item) {
+        this.item = item;
+    }
+
+    public String getPropertyAsString(String name) {
+        Property p = item.getProperty(name);
+        if (p == null) {
+            return "[null]";
+        }
+        Serializable val = p.getValue();
+        return val != null ? val.toString() : "[null]";
+    }
+
+    public void setProperty(String name, Serializable value) throws Exception{
+        item.setValue(name, value);
+        item.save();
+    }
+
+    public void dumpProperties() {
+        Map<String, Property> props = item.getProperties();
+
+        List<String> keys = new LinkedList<String>(props.keySet());
+        Collections.sort(keys);
+
+        for (String key : keys) {
+            Property prop = props.get(key);
+            Object value = prop.getValue();
+            Console.getDefault().println(key + " = " + (value != null ? value : "[null]"));
+        }
+    }
+
+    public ContentStream getStream() throws IOException {
+        return  item.getContentStream(null);
+    }
+
+    public void setStream(InputStream in, String name) throws Exception {
+        if (item instanceof Document) {
+            Document doc = (Document) item;
+            String mimeType = MimeTypeHelper.getMimeType(name);
+            ContentStream stream = new SimpleContentStream(in, mimeType, name);
+            doc.setContentStream(stream);
+            doc.save();
+        } else {
+            throw new CommandException("Target object is not a Document, can not set stream");
+        }
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/StringUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/StringUtils.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/StringUtils.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/java/org/apache/chemistry/shell/util/StringUtils.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,122 @@
+/*
+ * (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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class StringUtils {
+
+    private StringUtils() {
+    }
+
+    public static String[] split(String str, char delimiter, boolean trim) {
+        int s = 0;
+        int e = str.indexOf(delimiter, s);
+        if (e == -1) {
+            if (trim) {
+                str = str.trim();
+            }
+            return new String[] {str};
+        }
+        List<String> ar = new ArrayList<String>();
+        do {
+            String segment = str.substring(s, e);
+            if (trim) {
+                segment = segment.trim();
+            }
+            ar.add(segment);
+            s = e + 1;
+            e = str.indexOf(delimiter, s);
+        } while (e != -1);
+
+        int len = str.length();
+        if (s < len) {
+            String segment = str.substring(s);
+            if (trim) {
+                segment = segment.trim();
+            }
+            ar.add(segment);
+        } else {
+            ar.add("");
+        }
+
+        return ar.toArray(new String[ar.size()]);
+    }
+
+    public static String[] tokenize(String text) {
+        boolean esc = false;
+        boolean inString = false;
+        ArrayList<String> tokens = new ArrayList<String>();
+        StringBuilder buf = new StringBuilder();
+
+        char[] chars = text.toCharArray();
+        for (char c : chars) {
+            if (esc) {
+                switch (c) {
+                    case 'n':
+                        buf.append('\n');
+                        break;
+                    case 't':
+                        buf.append('\t');
+                        break;
+                    default:
+                        buf.append(c);
+                }
+                esc = false;
+                continue;
+            }
+            if (inString && c != '"') {
+                buf.append(c);
+                continue;
+            }
+            switch (c) {
+                case ' ':
+                case '\t':
+                    if (buf.length() > 0) {
+                        tokens.add(buf.toString());
+                        buf.setLength(0);
+                    }
+                    break;
+                case '\\':
+                    esc = true;
+                    break;
+                case '"':
+                    inString = !inString;
+                    break;
+                default:
+                    buf.append(c);
+                    break;
+            }
+        }
+
+        if (buf.length() > 0) {
+            tokens.add(buf.toString());
+            buf.setLength(0);
+        }
+        return tokens.toArray(new String[tokens.size()]);
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF Fri Jan 15 15:35:14 2010
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 1
+Bundle-Name: Chemistry CMIS Client
+Bundle-SymbolicName: org.apache.chemistry.shell;singleton:=true
+Main-Class: org.apache.chemistry.shell.Main

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties Fri Jan 15 15:35:14 2010
@@ -0,0 +1,8 @@
+Repository=cyan
+WorkspaceRoot=cyan
+SectionRoot=cyan
+TemplateRoot=cyan
+Folder=blue
+Workspace=magenta
+Section=yellow
+Domain=red

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/color.properties
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/connect.help
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/connect.help?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/connect.help (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/connect.help Fri Jan 15 15:35:14 2010
@@ -0,0 +1,7 @@
+Usage: connect <url>
+
+Connect to a service URL.
+
+If credentials need to be passed, embed them in the URL, e.g. use
+
+http://<login>:<password>@<host>/...
\ No newline at end of file

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/exit.help
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/exit.help?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/exit.help (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/exit.help Fri Jan 15 15:35:14 2010
@@ -0,0 +1 @@
+Exit client application.
\ No newline at end of file

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/help.help
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/help.help?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/help.help (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/help.help Fri Jan 15 15:35:14 2010
@@ -0,0 +1,5 @@
+Usage: help [command]
+
+To get help of a specific command, type 'help name_of_command'.
+
+List of available commands:

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/test.help
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/test.help?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/test.help (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/test.help Fri Jan 15 15:35:14 2010
@@ -0,0 +1 @@
+Only for testing (will be removed),

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/usage.help
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/usage.help?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/usage.help (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/help/usage.help Fri Jan 15 15:35:14 2010
@@ -0,0 +1,49 @@
+NAME
+      cmissh - interactive or batch CMIS client
+
+SYNOPSIS
+      cmissh [OPTIONS] [-b script] [-e command] [URL]
+
+DESCRIPTION
+      cmissh is a command-line tool to connect to a document
+      management server using the OASIS CMIS (Content Management
+      Interoperability Standard) protocol.
+
+      It can be used to create, retrieve, modify and delete
+      (CRUD) document and folders.
+
+OPTIONS
+      -b script
+              Enables batch mode. Runs the specified script
+              non-interactively.
+
+      -e command
+              Enable command mode. Runs a single command as
+              specified on the command-line.
+
+      -h      Reports usage information.
+
+      -p password
+              Specifies password to connect to server.
+
+      -t      Enables testing mode. In testing mode (usually
+              used conjointly with batch mode), cmissh will
+              fail as soon as a command reports an error.
+
+      -u username
+              Specifies username to connect to server.
+
+SEE ALSO
+      Type 'cmissh help' or 'help' in interactive mode for the list
+      of available commands.
+
+HISTORY
+      cmissh was written by Bogdan Stefanescu (bs@nuxeo.com), then
+      Stefane Fermigier (sf@nuxeo.com) and Florent Guillaume
+      (fg@nuxeo.com).
+
+      cmissh is based on the Apache Chemistry code.
+
+LICENSE
+      cmissh is released under the Apache Public License 2.0.
+

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties Fri Jan 15 15:35:14 2010
@@ -0,0 +1,7 @@
+log4j.rootLogger=WARN, CONSOLE
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%C{1}] %m%n
+
+# HttpClient is too verbose
+log4j.category.org.apache.commons.httpclient=ERROR
\ No newline at end of file

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/TestWithTestScript.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/TestWithTestScript.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/TestWithTestScript.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/TestWithTestScript.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,38 @@
+/*
+ * (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 org.apache.chemistry.shell.Main;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestWithTestScript extends Assert {
+
+    @Test
+    public void test() throws Exception {
+        Main.main(new String[] {"cmissh", "-t", "-b", "testscript"});
+    }
+
+}

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

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

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,60 @@
+package org.apache.chemistry.shell.command;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.chemistry.shell.app.Application;
+import org.apache.chemistry.shell.command.Cmd;
+import org.apache.chemistry.shell.command.Command;
+import org.apache.chemistry.shell.command.CommandException;
+import org.apache.chemistry.shell.command.CommandLine;
+import org.apache.chemistry.shell.command.CommandRegistry;
+
+public class TestCommandLine extends Assert {
+
+    CommandRegistry reg;
+
+    @Before
+    public void setUp() {
+        Map<String, Command> map = new HashMap<String,Command>();
+        map.put("cmd", new DummyCommand());
+        reg = new CommandRegistry(map);
+    }
+
+    @Test
+    public void testWithoutOption() throws CommandException {
+        String line = "cmd value";
+        CommandLine commandLine = new CommandLine(reg, line);
+
+        assertEquals("cmd", commandLine.getCommand().getName());
+        assertEquals("value", commandLine.getParameterValue("arg1"));
+        assertNull(commandLine.getParameter("-r"));
+        assertNull(commandLine.getParameter("-o"));
+        //assertEquals("tutu", commandLine.getParameterValue("titi"));
+    }
+
+    @Test
+    public void testWithOption() throws CommandException {
+        String line = "cmd -r -o option value";
+        CommandLine commandLine = new CommandLine(reg, line);
+
+        assertEquals("cmd", commandLine.getCommand().getName());
+        assertEquals("value", commandLine.getParameterValue("arg1"));
+        assertEquals("option", commandLine.getParameterValue("-o"));
+        assertNotNull(commandLine.getParameter("-r"));
+        //assertEquals("tutu", commandLine.getParameterValue("titi"));
+    }
+
+    @Ignore // this is not a test, you dummy Maven!
+    @Cmd(syntax="cmd [-r] [-o:*] arg1 [titi:file?tutu]", synopsis="")
+    class DummyCommand extends Command {
+        @Override
+        public void run(Application app, CommandLine cmdLine) throws Exception {}
+    }
+
+}
+

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandLine.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,140 @@
+/*
+ * (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.command;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.chemistry.shell.command.CommandSyntax;
+import org.apache.chemistry.shell.command.CommandToken;
+
+public class TestCommandSyntax extends Assert {
+
+    @Test
+    public void testNoArgument() {
+        CommandSyntax cs = CommandSyntax.parse("cmd");
+        assertEquals(0, cs.getArguments().size());
+        assertEquals(1, cs.getTokens().size());
+        assertEquals("cmd", cs.getCommandToken().getName());
+    }
+
+    @Test
+    public void testOneMandatoryArgument() {
+        CommandSyntax cs = CommandSyntax.parse("cmd arg1");
+        assertEquals(1, cs.getArguments().size());
+        assertEquals(2, cs.getTokens().size());
+
+        CommandToken cmd = cs.getCommandToken();
+        assertEquals("cmd", cmd.getName());
+        assertTrue(cmd.isCommand());
+        assertFalse(cmd.isArgument());
+
+        CommandToken arg1 = cs.getArgument(0);
+        CommandToken arg1ByName = cs.getToken("arg1");
+        assertEquals(arg1ByName, arg1);
+
+        assertEquals("arg1", arg1.getName());
+        assertTrue(arg1.isArgument());
+        assertFalse(arg1.isCommand());
+        assertFalse(arg1.isOptional());
+        assertFalse(arg1.isFlag());
+        assertNull(arg1.getValueType());
+    }
+
+    @Test
+    public void testOneMandatoryWithType() {
+        CommandSyntax cs = CommandSyntax.parse("cmd arg1:file");
+        assertEquals(1, cs.getArguments().size());
+        assertEquals(2, cs.getTokens().size());
+
+        CommandToken arg1 = cs.getArgument(0);
+        CommandToken arg1ByName = cs.getToken("arg1");
+        assertEquals(arg1ByName, arg1);
+
+        assertEquals("arg1", arg1.getName());
+        assertTrue(arg1.isArgument());
+        assertFalse(arg1.isCommand());
+        assertFalse(arg1.isFlag());
+
+        assertEquals("file", arg1.getValueType());
+    }
+
+    @Test
+    public void testOneOptionalArgument() {
+        CommandSyntax cs = CommandSyntax.parse("cmd [arg1]");
+        assertEquals(1, cs.getArguments().size());
+        assertEquals(2, cs.getTokens().size());
+
+        CommandToken cmd = cs.getCommandToken();
+        assertEquals("cmd", cmd.getName());
+        assertTrue(cmd.isCommand());
+        assertFalse(cmd.isArgument());
+
+        CommandToken arg1 = cs.getArgument(0);
+        CommandToken arg1ByName = cs.getToken("arg1");
+        assertEquals(arg1ByName, arg1);
+
+        assertEquals("arg1", arg1.getName());
+        assertTrue(arg1.isArgument());
+        assertFalse(arg1.isCommand());
+        assertTrue(arg1.isOptional());
+        assertFalse(arg1.isFlag());
+    }
+
+    @Test
+    public void testOneOptionalFlag() {
+        CommandSyntax cs = CommandSyntax.parse("cmd [-s] arg1");
+        assertEquals(1, cs.getArguments().size());
+        assertEquals(3, cs.getTokens().size());
+
+        CommandToken cmd = cs.getCommandToken();
+        assertEquals("cmd", cmd.getName());
+        assertTrue(cmd.isCommand());
+        assertFalse(cmd.isArgument());
+
+        CommandToken arg1 = cs.getToken("arg1");
+        assertEquals("arg1", arg1.getName());
+
+        CommandToken flag = cs.getToken("-s");
+
+        assertEquals("-s", flag.getName());
+        assertFalse(flag.isArgument());
+        assertFalse(flag.isCommand());
+        assertTrue(flag.isOptional());
+        assertTrue(flag.isFlag());
+    }
+
+    @Test
+    public void testDefaultValue() {
+        CommandSyntax cs = CommandSyntax.parse("cmd [arg1:file?toto]");
+        CommandToken arg1 = cs.getToken("arg1");
+        assertEquals("arg1", arg1.getName());
+        assertEquals("file", arg1.getValueType());
+        assertEquals("toto", arg1.getDefaultValue());
+        assertTrue(arg1.isArgument());
+        assertFalse(arg1.isCommand());
+        assertTrue(arg1.isOptional());
+        assertFalse(arg1.isFlag());
+    }
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/command/TestCommandSyntax.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,256 @@
+/*
+ * (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.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.chemistry.shell.util.Path;
+
+public class TestPath extends Assert {
+
+    @Test
+    public void testRelative() {
+        Path p = new Path("abc/asdf/file.ext");
+        assertEquals("abc/asdf/file.ext", p.toString());
+        assertEquals("ext", p.getFileExtension());
+        assertEquals("file", p.getFileName());
+        assertEquals("abc", p.segment(0));
+        assertEquals("asdf", p.segment(1));
+        assertEquals("file.ext", p.getLastSegment());
+
+        p = p.makeAbsolute();
+        assertEquals("/abc/asdf/file.ext", p.toString());
+
+        p = p.makeAbsolute();
+        assertEquals("/abc/asdf/file.ext", p.toString());
+
+        Path p1 = p.getParent();
+        assertEquals("/abc/asdf", p1.toString());
+
+        p1 = p.up();
+        assertEquals("/abc/asdf", p1.toString());
+    }
+
+    @Test
+    public void testAbsolute() {
+        Path p = new Path("/abc/asdf/file.ext");
+        assertEquals("/abc/asdf/file.ext", p.toString());
+
+        p = p.makeRelative();
+        assertEquals("abc/asdf/file.ext", p.toString());
+
+        p = p.makeRelative();
+        assertEquals("abc/asdf/file.ext", p.toString());
+    }
+
+    @Test
+    public void testDots() {
+        Path p = new Path("/./abc//asdf/../file.ext");
+        assertEquals("/abc/file.ext", p.toString());
+    }
+
+    @Test
+    public void testAppend() {
+        Path p = new Path("/commands");
+
+        p = p.append((Path) null);
+        assertEquals("/commands", p.toString());
+
+        p = p.append("");
+        assertEquals("/commands", p.toString());
+
+        p = p.append(Path.EMPTY);
+        assertEquals("/commands", p.toString());
+
+        p = Path.EMPTY.append(p);
+        assertEquals("commands", p.toString());
+
+        p = new Path("/commands");
+        p = p.append("test");
+        assertEquals("/commands/test", p.toString());
+
+        p = p.append("../../../test2");
+        assertEquals("../test2", p.toString());
+
+        p = p.makeAbsolute();
+        assertEquals("/test2", p.toString());
+
+        p = p.append(".");
+        assertEquals("/test2", p.toString());
+
+        p = p.append("..");
+        assertEquals("/", p.toString());
+
+        p = p.append("..");
+        assertEquals("/", p.toString());
+    }
+
+    @Test
+    public void testRoot() {
+        assertTrue(Path.ROOT.isRoot());
+        assertFalse(Path.ROOT.isEmpty());
+        assertEquals("/", Path.ROOT.toString());
+        Path p1 = new Path("/");
+        assertEquals(Path.ROOT, p1);
+        Path p2 = new Path(Path.ROOT);
+        assertEquals(Path.ROOT, p2);
+    }
+
+    @Test
+    public void testEmpty() {
+        assertTrue(Path.EMPTY.isEmpty());
+        assertFalse(Path.EMPTY.isRoot());
+        assertEquals("", Path.EMPTY.toString());
+        Path p1 = new Path("");
+        assertEquals(Path.EMPTY, p1);
+        Path p2 = new Path(Path.EMPTY);
+        assertEquals(Path.EMPTY, p2);
+    }
+
+    // Tests copied (mutatis mutandis) from the org.nuxeo.commons Path
+
+    @Test
+    public void test() {
+        Path path = new Path("/a/b/c/d");
+
+        assertFalse(path.isRoot());
+        assertFalse(path.isEmpty());
+
+        assertTrue(path.isAbsolute());
+
+        assertEquals("/a/b/c/d", path.toString());
+        assertEquals(4, path.segmentCount());
+        assertEquals(4, path.segments().length);
+        assertEquals("a", path.segment(0));
+        assertEquals("b", path.segment(1));
+        assertEquals("c", path.segment(2));
+        assertEquals("d", path.segment(3));
+        assertEquals("d", path.getLastSegment());
+
+        assertEquals(new Path("b/c/d"), path.removeFirstSegments(1));
+        assertEquals(new Path("/a/b/c"), path.removeLastSegments(1));
+    }
+
+    @Test
+    public void testEquals() {
+        Path path = new Path("/a/b/c/d");
+        Path path2 = new Path("/a/b/c/d/");
+        Path path3 = new Path("/a/b/c////d/");
+        Path path4 = new Path("/a/b/././c/./e/../d/");
+
+        assertEquals(path, path);
+
+        assertFalse(path.equals(path2));
+
+        assertEquals(path2, path3);
+        assertEquals(path2, path4);
+
+        // SF: I think this shouldn't pass...
+        assertEquals(path.hashCode(), path2.hashCode());
+        assertEquals(path.hashCode(), path3.hashCode());
+        assertEquals(path.hashCode(), path4.hashCode());
+
+        assertFalse(path.equals(null));
+
+        assertFalse(path.equals(new Path("a/b/c/d")));
+        assertFalse(path.equals(new Path("/a/b/c/e")));
+        assertFalse(path.equals(new Path("/a/b/c/d/e")));
+    }
+
+    @Test
+    public void testGetFileExtension() {
+        assertNull(new Path("/a/b/c/").getFileExtension());
+        assertNull(new Path("/a/b/c").getFileExtension());
+        assertEquals("doc", new Path("/a/b/c.doc").getFileExtension());
+    }
+
+    @Test
+    public void testBasic() {
+        final Path path = new Path("/a/b/c");
+
+        assertEquals(3, path.segmentCount());
+        assertTrue(path.isAbsolute());
+        assertFalse(path.isEmpty());
+        assertFalse(path.isRoot());
+        assertEquals(3, path.segments().length);
+        assertEquals("a", path.segment(0));
+        assertEquals("b", path.segment(1));
+        assertEquals("c", path.segment(2));
+
+        assertEquals(path, new Path("/a/b/c"));
+    }
+
+    @Test
+    public void testFileExtension() {
+        Path path = new Path("/a/b/c");
+        assertNull(path.getFileExtension());
+
+        path = new Path("/a/b/c.txt");
+        assertEquals("txt", path.getFileExtension());
+        assertEquals("/a/b/c", path.removeFileExtension().toString());
+
+        path = new Path("/a/b/c/");
+        assertNull(path.getFileExtension());
+    }
+
+    @Test
+    public void testPathNormalisation() {
+        Path path = new Path("////a/./b/../c");
+        assertEquals("/a/c", path.toString());
+    }
+
+    @Test
+    public void testEquality() {
+        assertEquals(new Path("/a/b/c"), new Path("/a/b/c"));
+        assertEquals(new Path("/a/b/c/"), new Path("/a/b/c/"));
+
+        assert !new Path("/a/b/c").equals(new Path("/a/b"));
+        assert !new Path("/a/b").equals(new Path("/a/b/c"));
+        assert !new Path("/a/b/c/").equals(new Path("/a/b/c"));
+        assert !new Path("/a/b/c").equals(new Path("/a/b/c/"));
+
+        assert !new Path("/a/b/d").equals(new Path("/a/b/c"));
+        assert !new Path("/a/d/c").equals(new Path("/a/b/c"));
+        assert !new Path("/d/b/c").equals(new Path("/a/b/c"));
+        assert !new Path("/a/b/c").equals(new Path("/a/b/d"));
+        assert !new Path("/a/b/c").equals(new Path("/a/d/c"));
+        assert !new Path("/a/b/c").equals(new Path("/d/b/c"));
+    }
+
+    @Test
+    public void testAppend1() {
+        Path path1 = new Path("/a/b/c");
+        Path path2 = new Path("/d/e/f");
+        Path path3 = new Path("/a/b/c/d/e/f");
+        assertEquals(path3, path1.append(path2));
+
+        assertEquals("/a/b/c", path1.append(".").toString());
+        assertEquals("/a/b", path1.append("..").toString());
+
+        assertEquals("/a/b/c", path1.append(new Path(".")).toString());
+        assertEquals("/a/b", path1.append(new Path("..")).toString());
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestPath.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java?rev=899665&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java Fri Jan 15 15:35:14 2010
@@ -0,0 +1,85 @@
+/*
+ * (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.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.chemistry.shell.util.StringUtils;
+
+public class TestStringUtils extends Assert {
+
+    @Test
+    public void testSplit() {
+        String[] res = StringUtils.split("abc", '|', true);
+        assertArrayEquals(new String[] {"abc"}, res);
+
+        res = StringUtils.split(" abc ", '|', true);
+        assertArrayEquals(new String[] {"abc"}, res);
+
+        res = StringUtils.split(" abc ", '|', false);
+        assertArrayEquals(new String[] {" abc "}, res);
+
+        res = StringUtils.split("a|b|c", '|', true);
+        assertArrayEquals(new String[] {"a", "b", "c"}, res);
+
+        res = StringUtils.split(" a | b |c ", '|', true);
+        assertArrayEquals(new String[] {"a", "b", "c"}, res);
+
+        res = StringUtils.split(" a | b |c ", '|', false);
+        assertArrayEquals(new String[] {" a ", " b ", "c "}, res);
+    }
+
+    @Test
+    public void testTokenizeSimple() {
+        String[] res = StringUtils.tokenize("a bc def");
+        assertArrayEquals(new String[] {"a", "bc", "def"}, res);
+    }
+
+    @Test
+    public void testTokenizeEscape() {
+        String[] res = StringUtils.tokenize("a\\ bc def");
+        assertArrayEquals(new String[] {"a bc", "def"}, res);
+
+        res = StringUtils.tokenize("a\\\\\\n\\t def");
+        assertArrayEquals(new String[] {"a\\\n\t", "def"}, res);
+
+        res = StringUtils.tokenize("a\\bc def");
+        assertArrayEquals(new String[] {"abc", "def"}, res);
+    }
+
+    @Test
+    public void testTokenizeString() {
+        String[] res = StringUtils.tokenize("a \"bc def\"");
+        assertArrayEquals(new String[] {"a", "bc def"}, res);
+    }
+
+    @Test
+    // "" is stronger than \
+    public void testTokenizeBoth() {
+        String[] res = StringUtils.tokenize("a \"bc\\ \\ndef\"");
+        assertArrayEquals(new String[] {"a", "bc\\ \\ndef"}, res);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-shell/src/test/java/org/apache/chemistry/shell/util/TestStringUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/chemistry/trunk/chemistry/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/pom.xml?rev=899665&r1=899664&r2=899665&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/pom.xml Fri Jan 15 15:35:14 2010
@@ -40,6 +40,7 @@
     <module>chemistry-ws</module>
     <module>chemistry-jcr</module>
     <module>chemistry-tck-atompub</module>
+    <module>chemistry-shell</module>
   </modules>
 
 </project>



Mime
View raw message