You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ed...@apache.org on 2005/08/11 20:06:07 UTC

svn commit: r231495 [6/7] - in /incubator/jackrabbit/trunk/contrib/jcr-commands: ./ applications/test/ applications/test/fs/ applications/test/fs/dummy folder/ benchmarking/ src/java/ src/java/org/apache/jackrabbit/chain/ src/java/org/apache/jackrabbit...

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/AbstractLsProperties.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/AbstractLsProperties.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/AbstractLsProperties.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/AbstractLsProperties.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * List properties superclass
+ */
+public abstract class AbstractLsProperties extends AbstractLs
+{
+    /** name width */
+    private int nameWidth = 35;
+
+    /** node type width */
+    private int typeWidth = 15;
+
+    /**
+     * @inheritDoc
+     */
+    public final boolean execute(Context ctx) throws Exception
+    {
+        int[] width = new int[]
+        {
+                35, longWidth, longWidth, longWidth
+        };
+
+        String header[] = new String[]
+        {
+                bundle.getString("name"), bundle.getString("multiple"),
+                bundle.getString("type"), bundle.getString("length")
+        };
+
+        PrintHelper.printRow(ctx, width, header);
+        PrintHelper.printSeparatorRow(ctx, width, '-');
+
+        int index = 0;
+        Iterator iter = getProperties(ctx);
+
+        int maxItems = getMaxItems(ctx) ;
+        
+        while (iter.hasNext() && index < maxItems)
+        {
+            Property p = (Property) iter.next();
+
+            long length = 0;
+
+            if (p.getDefinition().isMultiple())
+            {
+                long[] lengths = p.getLengths();
+                for (int i = 0; i < lengths.length; i++)
+                {
+                    length += lengths[i];
+                }
+            } else
+            {
+                length = p.getLength();
+            }
+
+            String multiple = Boolean.toString(p.getDefinition().isMultiple());
+            if (p.getDefinition().isMultiple())
+            {
+                multiple += "[" + p.getValues().length + "]";
+            }
+
+            String[] row = new String[]
+            {
+                    p.getName(), multiple,
+                    PropertyType.nameFromValue(p.getType()),
+                    Long.toString(length)
+            };
+            PrintHelper.printRow(ctx, width, row);
+            index++;
+        }
+
+        CtxHelper.getOutput(ctx).println();
+
+        // Write footer
+        printFooter(ctx, (PropertyIterator) iter);
+
+        return false;
+    }
+
+    /**
+     * Subclasses are responsible of collecting the properties to display
+     * 
+     * @param ctx
+     * @return
+     */
+    protected abstract Iterator getProperties(Context ctx) throws Exception;
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/AbstractLsProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Cat.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Cat.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Cat.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Cat.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Displays the content of a property or a node of type nt:file or nt:resource
+ */
+public class Cat implements Command
+{
+    /** property name */
+    private String path;
+
+    /** index. [optional] argument to display multivalue properties */
+    private int index;
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        Item item = CtxHelper.getItem(ctx, path);
+        if (item.isNode())
+        {
+            printNode(ctx, (Node) item);
+        } else
+        {
+            printProperty(ctx, (Property) item);
+        }
+        return false;
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+
+    /**
+     * 
+     * @param ctx
+     * @param n
+     * @throws PathNotFoundException
+     * @throws JcrCommandException
+     * @throws RepositoryException
+     * @throws IllegalStateException
+     * @throws IOException
+     */
+    private void printNode(Context ctx, Node n) throws PathNotFoundException,
+            JcrCommandException, RepositoryException, IllegalStateException,
+            IOException
+    {
+        if (n.isNodeType("nt:file"))
+        {
+            printValue(ctx, n.getNode("jcr:content").getProperty("jcr:data")
+                .getValue());
+        } else if (n.isNodeType("nt:resource"))
+        {
+            printValue(ctx, n.getProperty("jcr:data").getValue());
+        } else
+        {
+            throw new JcrCommandException("cat.unsupported.type", new String[]
+            {
+                n.getPrimaryNodeType().getName()
+            });
+        }
+    }
+
+    /**
+     * 
+     * @param ctx
+     * @param p
+     * @throws JcrCommandException
+     * @throws ValueFormatException
+     * @throws IllegalStateException
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    private void printProperty(Context ctx, Property p)
+            throws JcrCommandException, ValueFormatException,
+            IllegalStateException, RepositoryException, IOException
+    {
+        if (p.getDefinition().isMultiple())
+        {
+            printValue(ctx, p.getValues()[index]);
+        } else
+        {
+            printValue(ctx, p.getValue());
+        }
+    }
+
+    /**
+     * Read the value
+     * 
+     * @param ctx
+     * @param value
+     * @throws ValueFormatException
+     * @throws IllegalStateException
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    private void printValue(Context ctx, Value value)
+            throws ValueFormatException, IllegalStateException,
+            RepositoryException, IOException
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+        out.println();
+        BufferedReader in = new BufferedReader(new StringReader(value
+            .getString()));
+        String str = null;
+        while ((str = in.readLine()) != null)
+        {
+            out.println(str);
+        }
+    }
+
+    /**
+     * @return Returns the index.
+     */
+    public int getIndex()
+    {
+        return index;
+    }
+
+    /**
+     * @param index
+     *            The index to set.
+     */
+    public void setIndex(int index)
+    {
+        this.index = index;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Cat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Dump.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Dump.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Dump.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Dump.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.io.PrintWriter;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Dumps stored data from the current working node
+ */
+public class Dump implements Command
+{
+
+    public boolean execute(Context ctx) throws Exception
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx) ;
+        dump(out, CtxHelper.getCurrentNode(ctx));
+        return false;
+    }
+
+    public void dump(PrintWriter out, Node n) throws RepositoryException
+    {
+        out.println(n.getPath()) ;
+        PropertyIterator pit = n.getProperties();
+        while (pit.hasNext())
+        {
+            Property p = pit.nextProperty();
+            out.print(p.getPath() + "=");
+            if (p.getDefinition().isMultiple())
+            {
+                Value[] values = p.getValues();
+                for (int i = 0; i < values.length; i++)
+                {
+                    if (i > 0)
+                        out.println(",");
+                    out.println(values[i].getString());
+                }
+            } else
+            {
+                out.print(p.getString());
+            }
+            out.println();
+        }
+        NodeIterator nit = n.getNodes();
+        while (nit.hasNext())
+        {
+            Node cn = nit.nextNode();
+            dump(out, cn);
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Dump.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Help.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Help.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Help.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Help.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.chain.Context;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+import org.apache.jackrabbit.chain.cli.AbstractParameter;
+import org.apache.jackrabbit.chain.cli.Argument;
+import org.apache.jackrabbit.chain.cli.CommandLine;
+import org.apache.jackrabbit.chain.cli.CommandLineFactory;
+import org.apache.jackrabbit.chain.cli.Flag;
+import org.apache.jackrabbit.chain.cli.Option;
+
+/**
+ * Help on available commands
+ */
+public class Help extends AbstractInfoCommand
+{
+    /** Command factory */
+    private CommandLineFactory factory = CommandLineFactory.getInstance();
+
+    /** Help formatter */
+    private HelpFormatter hf = new HelpFormatter();
+
+    private String command;
+
+    public boolean execute(Context ctx) throws Exception
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+        out.println();
+        if (command == null)
+        {
+            helpAll(ctx);
+        } else
+        {
+            helpCommand(ctx);
+        }
+        return false;
+    }
+
+    /**
+     * Writes help for all the commands
+     * 
+     * @param ctx
+     * @throws JcrCommandException
+     */
+    private void helpAll(Context ctx) throws JcrCommandException
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+        Collection descriptors = factory.getCommandLines();
+        Iterator iter = descriptors.iterator();
+
+        // Tab position
+        int tabPos = 20;
+        while (iter.hasNext())
+        {
+            CommandLine desc = (CommandLine) iter.next();
+            if (desc.getName().length() > tabPos)
+            {
+                tabPos = desc.getName().length() + 1;
+            }
+        }
+
+        iter = descriptors.iterator();
+        while (iter.hasNext())
+        {
+            CommandLine desc = (CommandLine) iter.next();
+            StringBuffer buf = new StringBuffer(desc.getName());
+            buf.setLength(tabPos);
+            for (int i = desc.getName().length(); i < buf.length(); i++)
+            {
+                buf.setCharAt(i, ' ');
+            }
+            buf.append(desc.getLocalizedDescription());
+            hf.printWrapped(out, 74, tabPos, buf.toString());
+        }
+    }
+
+    /**
+     * Writes detailed help for the given command
+     * 
+     * @param ctx
+     * @throws JcrCommandException
+     */
+    private void helpCommand(Context ctx) throws JcrCommandException
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+
+        CommandLine desc = factory.getCommandLine(this.command);
+
+        out.println(bundle.getString("description") + ": ");
+        out.println(desc.getLocalizedDescription());
+        out.println();
+
+        // Usage
+        out.print(bundle.getString("usage") + ":");
+        out.print(desc.getName() + " ");
+
+        // Arguments
+        Iterator iter = desc.getArguments().values().iterator();
+        while (iter.hasNext())
+        {
+            Argument arg = (Argument) iter.next();
+            out.print("<" + arg.getLocalizedArgName() + "> ");
+        }
+
+        // Options
+        iter = desc.getOptions().values().iterator();
+        while (iter.hasNext())
+        {
+            Option arg = (Option) iter.next();
+            out.print("-" + arg.getName() + " <" + arg.getLocalizedArgName()
+                    + "> ");
+        }
+
+        // flags
+        iter = desc.getFlags().values().iterator();
+        while (iter.hasNext())
+        {
+            Flag arg = (Flag) iter.next();
+            out.print("-" + arg.getName() + " ");
+        }
+        out.println();
+
+
+        // Alias
+        if (desc.getAlias().size()>0) {
+            out.print(bundle.getString("alias") + ":");
+            iter = desc.getAlias().iterator();
+            while (iter.hasNext())
+            {
+                out.print((String) iter.next() + " ");
+
+            }
+            out.println();
+        }
+        out.println();
+
+        // Arguments details
+        if (desc.getArguments().size() > 0)
+        {
+            out.println("<" + bundle.getString("arguments") + ">");
+            printParam(ctx, desc.getArguments().values());
+        }
+
+        // Options details
+        if (desc.getOptions().values().size() > 0)
+        {
+            out.println();
+            out.println("<" + bundle.getString("options") + ">");
+            printParam(ctx, desc.getOptions().values());
+        }
+
+        // flag details
+        if (desc.getFlags().values().size() > 0)
+        {
+            out.println();
+            out.println("<" + bundle.getString("flags") + ">");
+            printParam(ctx, desc.getFlags().values());
+        }
+
+    }
+
+private void printParam(Context ctx, Collection params)
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+        int[] width = new int[]
+        {
+                10, 10, 10, 40
+        };
+
+        String[] header = new String[]
+        {
+                bundle.getString("name"), bundle.getString("arg.name"),
+                bundle.getString("required"), bundle.getString("description")
+        };
+
+        PrintHelper.printRow(ctx, width, header);
+        PrintHelper.printSeparatorRow(ctx, width, '-');
+
+        Iterator iter = params.iterator();
+        while (iter.hasNext())
+        {
+            AbstractParameter p = (AbstractParameter) iter.next();
+            String[] item = new String[]
+            {
+                    p.getName(), p.getLocalizedArgName(),
+                    Boolean.toString(p.isRequired()),
+                    p.getLocalizedDescription()
+            };
+            PrintHelper.printRow(ctx, width, item);
+        }
+
+    }    public String getCommand()
+    {
+        return command;
+    }
+
+    public void setCommand(String command)
+    {
+        this.command = command;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/Help.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/JcrInfoCommandException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/JcrInfoCommandException.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/JcrInfoCommandException.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/JcrInfoCommandException.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Exception thrown by Info Commands
+ */
+public class JcrInfoCommandException extends JcrCommandException
+{
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3257854259679866933L;
+
+    /**
+     * @param message
+     */
+    public JcrInfoCommandException(String message)
+    {
+        super(message);
+    }
+
+    /**
+     * @param message
+     * @param arguments
+     */
+    public JcrInfoCommandException(String message, Object[] arguments)
+    {
+        super(message, arguments);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public JcrInfoCommandException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    /**
+     * @param message
+     * @param cause
+     * @param arguments
+     */
+    public JcrInfoCommandException(String message, Throwable cause,
+        Object[] arguments)
+    {
+        super(message, cause, arguments);
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/JcrInfoCommandException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedItems.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedItems.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedItems.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedItems.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Lists collected nodes. This Command looks for an Iterator under the given
+ * context variable and lists its items.
+ */
+public class LsCollectedItems extends AbstractLsItems
+{
+    /** Context variable that holds the Iterator */
+    private String fromKey = "collected";
+
+    /**
+     * @return the context variable
+     */
+    public String getFromKey()
+    {
+        return fromKey;
+    }
+
+    /**
+     * Sets the context variable
+     * @param context variable name
+     */
+    public void setFromKey(String contextVariable)
+    {
+        this.fromKey = contextVariable;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getItems(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        // Always show the path
+        this.setPath(true);
+        Object o = ctx.get(this.fromKey);
+        if (o == null || !(o instanceof Iterator))
+        {
+            throw new JcrInfoCommandException(
+                "illegalargument.no.iterator.under", new String[]
+                {
+                    fromKey
+                });
+        }
+        return (Iterator) o;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedItems.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedNodes.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedNodes.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedNodes.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedNodes.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Lists collected nodes. This Command looks for an Iterator under the given
+ * context variable and lists its nodes.
+ */
+public class LsCollectedNodes extends AbstractLsNodes
+{
+    /** Context variable that holds the Iterator */
+    private String fromKey = "collected";
+
+    /**
+     * @return the context variable
+     */
+    public String getFromKey()
+    {
+        return fromKey;
+    }
+
+    /**
+     * Sets the context variable
+     * @param context variable name
+     */
+    public void setFromKey(String contextVariable)
+    {
+        this.fromKey = contextVariable;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getNodes(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        this.setPath(true);
+        Object o = ctx.get(this.fromKey);
+        if (o == null || !(o instanceof Iterator))
+        {
+            throw new JcrInfoCommandException(
+                "illegalargument.no.iterator.under", new String[]
+                {
+                    fromKey
+                });
+        }
+        return (Iterator) o;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedNodes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedProperties.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedProperties.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedProperties.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedProperties.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Lists collected properties.<br> 
+ * This Command looks for an Iterator under the given
+ * context variable and lists its properties.
+ */
+public class LsCollectedProperties extends AbstractLsProperties
+{
+    /** Context variable that holds the Iterator */
+    private String fromKey = "collected";
+
+    /**
+     * @return the context variable
+     */
+    public String getFromKey()
+    {
+        return fromKey;
+    }
+
+    /**
+     * Sets the context variable
+     * @param context variable name
+     */
+    public void setFromKey(String contextVariable)
+    {
+        this.fromKey = contextVariable;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getProperties(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        // show the path
+        this.setPath(true);
+        Object o = ctx.get(this.fromKey);
+        if (o == null || !(o instanceof Iterator))
+        {
+            throw new JcrInfoCommandException(
+                "illegalargument.no.iterator.under", new String[]
+                {
+                    fromKey
+                });
+        }
+        return (Iterator) o;
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsCollectedProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsItems.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsItems.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsItems.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsItems.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * List items
+ * 
+ * <p>
+ * <ul>
+ * <li>name</li>
+ * <li>type</li>
+ * <li>isNode</li>
+ * <li>isNew</li>
+ * <li>isModified</li>
+ * </ul>
+ * </p>
+ */
+public class LsItems extends AbstractLsItems
+{
+
+    /** name pattern key */
+    private String patternKey;
+
+    /** name pattern */
+    private String pattern;
+
+    /**
+     * @return the name pattern
+     */
+    public String getPatternKey()
+    {
+        return patternKey;
+    }
+
+    /**
+     * Sets the name pattern
+     * 
+     * @param name
+     *            pattern
+     */
+    public void setPatternKey(String pattern)
+    {
+        this.patternKey = pattern;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getItems(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        String pattern = CtxHelper.getAttr(this.pattern, patternKey, "*", ctx);
+        return CtxHelper.getItems(ctx, pattern);
+    }
+
+    /**
+     * @return Returns the pattern.
+     */
+    public String getPattern()
+    {
+        return pattern;
+    }
+
+    /**
+     * @param pattern
+     *            The pattern to set.
+     */
+    public void setPattern(String pattern)
+    {
+        this.pattern = pattern;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsItems.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsNodes.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsNodes.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsNodes.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsNodes.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Lists the nodes under the current working node that match the given pattern.
+ */
+public class LsNodes extends AbstractLsNodes
+{
+    /** name pattern */
+    private String pattern;
+
+    /** name pattern key */
+    private String patternKey;
+
+    /**
+     * @return name pattern
+     */
+    public String getPattern()
+    {
+        return pattern;
+    }
+
+    /**
+     * Sets the name pattern
+     * 
+     * @param pattern
+     */
+    public void setPattern(String pattern)
+    {
+        this.pattern = pattern;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getNodes(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        String pattern = CtxHelper.getAttr(this.pattern, patternKey, "*", ctx);
+        return CtxHelper.getNodes(ctx, pattern);
+    }
+
+    /**
+     * @return Returns the patternKey.
+     */
+    public String getPatternKey()
+    {
+        return patternKey;
+    }
+
+    /**
+     * @param patternKey
+     *            The patternKey to set.
+     */
+    public void setPatternKey(String patternKey)
+    {
+        this.patternKey = patternKey;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsNodes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsProperties.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsProperties.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsProperties.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsProperties.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * <p>
+ * Property fields:
+ * <ul>
+ * <li>name</li>
+ * <li>multiple</li>
+ * <li>type</li>
+ * <li>length</li>
+ * </ul>
+ * </p>
+ */
+public class LsProperties extends AbstractLsProperties
+{
+    /** property name pattern */
+    private String pattern;
+
+    /** property name pattern key */
+    private String patternKey;
+
+    /**
+     * @return name pattern
+     */
+    public String getPatternKey()
+    {
+        return patternKey;
+    }
+
+    /**
+     * Sets the name pattern
+     * 
+     * @param pattern
+     */
+    public void setPatternKey(String pattern)
+    {
+        this.patternKey = pattern;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected Iterator getProperties(Context ctx) throws JcrCommandException,
+            RepositoryException
+    {
+        String pattern = CtxHelper.getAttr(this.pattern, patternKey, "*", ctx);
+        return CtxHelper.getProperties(ctx, pattern);
+    }
+
+    /**
+     * @return Returns the pattern.
+     */
+    public String getPattern()
+    {
+        return pattern;
+    }
+
+    /**
+     * @param pattern
+     *            The pattern to set.
+     */
+    public void setPattern(String pattern)
+    {
+        this.pattern = pattern;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsReferences.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsReferences.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsReferences.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsReferences.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Displays references to the given Node
+ */
+public class LsReferences extends AbstractInfoCommand
+{
+    /** path to the node */
+    private String path;
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        Node n = CtxHelper.getNode(ctx, path);
+
+        // header
+        int[] width = new int[]
+        {
+            60
+        };
+        String[] header = new String[]
+        {
+            bundle.getString("path")
+        };
+
+        // print header
+        PrintHelper.printRow(ctx, width, header);
+
+        // print separator
+        PrintHelper.printSeparatorRow(ctx, width, '-');
+
+        PropertyIterator iter = n.getReferences();
+        while (iter.hasNext())
+        {
+            Property p = iter.nextProperty();
+            // print header
+            PrintHelper.printRow(ctx, width, new String[]
+            {
+                p.getPath()
+            });
+        }
+
+        CtxHelper.getOutput(ctx).println();
+        CtxHelper.getOutput(ctx).println(
+            iter.getSize() + " " + bundle.getString("references"));
+
+        return false;
+    }
+
+    /**
+     * @return Returns the path.
+     */
+    public String getPath()
+    {
+        return path;
+    }
+
+    /**
+     * @param path
+     *            The path to set.
+     */
+    public void setPath(String path)
+    {
+        this.path = path;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/LsReferences.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/PrintHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/PrintHelper.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/PrintHelper.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/PrintHelper.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,212 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.info;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Helper methods to print
+ */
+class PrintHelper
+{
+
+    /**
+     * 
+     * @param ctx
+     * @param width
+     * @param text
+     */
+    public static void printRow(Context ctx, int[] width, String[] text)
+    {
+        if (width.length != text.length)
+        {
+            throw new IllegalArgumentException(
+                "width[] and text[] haven't the same length");
+        }
+
+        PrintWriter out = CtxHelper.getOutput(ctx);
+
+        int rows = 1;
+
+        // Calculate rows
+        for (int i = 0; i < text.length; i++)
+        {
+            int textLength = text[i].length();
+            if (textLength == 0)
+            {
+                textLength = 1;
+            }
+            int columnWidth = width[i];
+            int neededRows = (int) Math.ceil((double) textLength
+                    / (double) columnWidth);
+            if (neededRows > rows)
+            {
+                rows = neededRows;
+            }
+        }
+
+        // Write table
+        for (int row = 0; row < rows; row++)
+        {
+            for (int column = 0; column < width.length; column++)
+            {
+                for (int pointer = 0; pointer < width[column]; pointer++)
+                {
+                    int pos = row * width[column] + pointer;
+                    if (pos < text[column].length())
+                    {
+                        out.print(text[column].charAt(pos));
+                    } else
+                    {
+                        out.print(' ');
+                    }
+                }
+                out.print(' ');                
+            }
+            out.println();
+        }
+    }
+
+    /**
+     * @param ctx
+     * @param width
+     * @param separator
+     */
+    public static void printSeparatorRow(
+        Context ctx,
+        int[] width,
+        char separator)
+    {
+        PrintWriter out = CtxHelper.getOutput(ctx);
+        for (int i = 0; i < width.length; i++)
+        {
+            for (int j = 0; j <= width[i]; j++)
+            {
+                if (j < width[i])
+                {
+                    out.print(separator);
+                } else
+                {
+                    out.print(' ');
+                }
+            }
+        }
+        out.println();
+    }
+
+    /**
+     * 
+     * @param ctx
+     * @param width
+     * @param texts
+     * @throws JcrCommandException
+     */
+    public static void printRow(Context ctx, int[] width, Collection texts)
+            throws JcrCommandException
+    {
+        String[] text = new String[width.length];
+        Iterator iter = texts.iterator();
+        int column = 0;
+        while (iter.hasNext())
+        {
+            Object o = iter.next();
+            if (o instanceof String)
+            {
+                text[column] = (String) o;
+            } else if (o instanceof Collection)
+            {
+                StringBuffer sb = new StringBuffer() ;
+                Iterator i = ((Collection) o).iterator();
+                while (i.hasNext())
+                {
+                    String str = (String) i.next();
+                    int rows = (int) Math.ceil((double) str.length()
+                            / (double) width[column]);
+                    if (rows == 0)
+                    {
+                        rows = 1;
+                    }
+                    sb.append(str) ;
+                    for (int j = 0; j < rows * width[column] - str.length(); j++)
+                    {
+                        sb.append(' ') ;
+                    }
+                }
+                text[column] = sb.toString() ;
+            } else
+            {
+                throw new JcrCommandException("illegalargument");
+            }
+            column++;
+        }
+        printRow(ctx, width, text);
+    }
+    
+    /**
+     * 
+     * @param ctx
+     * @param widths
+     * @param texts
+     * @throws JcrCommandException
+     */
+    public static void printRow(Context ctx, Collection widths, Collection texts) throws JcrCommandException {
+        printRow(ctx, convertWidth(widths), texts) ;
+    }
+    
+    /**
+     * 
+     * @param ctx
+     * @param widths
+     * @param texts
+     * @throws JcrCommandException
+     */
+    private static int[] convertWidth(Collection widths) throws JcrCommandException {
+        int[] width = new int[widths.size()] ;
+        int index=0 ;
+        Iterator iter = widths.iterator() ;
+        while (iter.hasNext())
+        {
+            Integer i = (Integer) iter.next();
+            width[index]= i.intValue() ;
+            index++ ;
+        }
+        return width ;
+    }
+    
+    /**
+     * 
+     * @param ctx
+     * @param widths
+     * @param separator
+     * @throws JcrCommandException 
+     */
+    public static void printSeparatorRow(
+        Context ctx,
+        Collection widths,
+        char separator) throws JcrCommandException
+    {
+        printSeparatorRow(ctx, convertWidth(widths), separator) ;
+    }
+    
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/PrintHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/exceptions.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/exceptions.properties?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/exceptions.properties (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/exceptions.properties Thu Aug 11 11:04:29 2005
@@ -0,0 +1,3 @@
+illegalargument.no.iterator.under=Illegal argument. There is no iterator under {0}.
+missing.arguments=missing arguments. Required = {0}, received = {1}.
+unkown.arguments=unkown arguments. Known arguments = {0}, received = {1}.
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/exceptions.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/resources.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/resources.properties?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/resources.properties (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/resources.properties Thu Aug 11 11:04:29 2005
@@ -0,0 +1,33 @@
+alias=alias
+arguments=arguments
+arg.name=content
+default=default
+description=description
+flags=flags
+has.lock=holds lock
+isnode=node
+isnew=new
+ismodified=modified
+length=length
+listed=listed
+lockable=lockable
+locked=locked
+multiple=multiple
+modified=modified
+name=name
+new=new
+node=node
+nodes=nodes
+node=node type
+nodetype=node type
+path=path
+options=options
+property=property
+properties=properties
+referenceable=referenceable
+references=references
+required=required
+type=type
+total=total
+usage=usage
+versionable=versionable
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/info/resources.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/AbstractQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/AbstractQuery.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/AbstractQuery.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/AbstractQuery.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ * 
+ */
+package org.apache.jackrabbit.chain.command.query;
+
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Query the repository through either SQL or XPATH. <br>
+ * The Command attributes are set from the specified literal values, or from the
+ * context attributes stored under the given keys.
+ */
+public abstract class AbstractQuery implements Command
+{
+    // ---------------------------- < literals >
+
+    /** query statement */
+    private String statement;
+
+    // ---------------------------- < keys >
+
+    /** query statement key */
+    private String statementKey;
+
+    /** destination key */
+    private String toKey;
+
+    /**
+     * @inheritDoc
+     */
+    public final boolean execute(Context ctx) throws Exception
+    {
+        String statement = CtxHelper.getAttr(this.statement,
+            this.statementKey, ctx);
+
+        Session session = CtxHelper.getSession(ctx);
+        javax.jcr.query.Query query = session.getWorkspace().getQueryManager()
+            .createQuery(statement, this.getLanguage());
+
+        QueryResult result = query.execute();
+
+        ctx.put(toKey, result.getNodes());
+
+        return false;
+    }
+
+    /**
+     * Query language
+     * 
+     * @return
+     */
+    protected abstract String getLanguage();
+
+    /**
+     * @return the query statement
+     */
+    public String getStatement()
+    {
+        return statement;
+    }
+
+    /**
+     * Sets the query statement
+     * 
+     * @param statement
+     */
+    public void setStatement(String statement)
+    {
+        this.statement = statement;
+    }
+
+    /**
+     * @return Returns the statementKey.
+     */
+    public String getStatementKey()
+    {
+        return statementKey;
+    }
+
+    /**
+     * @param statementKey
+     *            Set the context attribute key for the statement attribute.
+     */
+    public void setStatementKey(String statementKey)
+    {
+        this.statementKey = statementKey;
+    }
+
+    /**
+     * @return Returns the toKey.
+     */
+    public String getToKey()
+    {
+        return toKey;
+    }
+
+    /**
+     * @param toKey
+     *            Set the context attribute key for the to attribute.
+     */
+    public void setToKey(String toKey)
+    {
+        this.toKey = toKey;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/AbstractQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/SQLQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/SQLQuery.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/SQLQuery.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/SQLQuery.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ * 
+ */
+package org.apache.jackrabbit.chain.command.query;
+
+
+/**
+ * SQL query
+ */
+public class SQLQuery extends AbstractQuery
+{
+
+    protected String getLanguage()
+    {
+        return javax.jcr.query.Query.SQL;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/SQLQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/XPathQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/XPathQuery.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/XPathQuery.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/XPathQuery.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ * 
+ */
+package org.apache.jackrabbit.chain.command.query;
+
+
+/**
+ * XPath query
+ */
+public class XPathQuery extends AbstractQuery
+{
+
+    protected String getLanguage()
+    {
+        return javax.jcr.query.Query.XPATH;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/query/XPathQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/resources.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/resources.properties?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/resources.properties (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/resources.properties Thu Aug 11 11:04:29 2005
@@ -0,0 +1 @@
+collected.under=collected nodes are stored under 
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/resources.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/AbstractExportViewToFile.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/AbstractExportViewToFile.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/AbstractExportViewToFile.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/AbstractExportViewToFile.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.xml;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Export the xml view to a file<br>
+ * The Command attributes are set from the specified literal values, or from the
+ * context attributes stored under the given keys.
+ */
+public abstract class AbstractExportViewToFile implements Command
+{
+
+    // ---------------------------- < literals >
+    /** target file literal */
+    protected String from;
+
+    /** target file literal */
+    protected String to;
+
+    /** overwrite flag literal */
+    protected String overwrite;
+
+    /** skip binary flag literal */
+    protected String skipBinary;
+
+    /** no recurse flag literal */
+    protected String noRecurse;
+
+    // ---------------------------- < keys >
+    /** target file literal */
+    protected String fromKey;
+
+    /** target file key */
+    protected String toKey;
+
+    /** overwrite flag key */
+    protected String overwriteKey;
+
+    /** skip binary flag key */
+    protected String skipBinaryKey;
+
+    /** no recurse flag key */
+    protected String noRecurseKey;
+
+    /**
+     * @return the OutputStream for the given file
+     * @throws JcrCommandException
+     * @throws IOException
+     */
+    protected OutputStream getOutputStream(Context ctx)
+            throws JcrCommandException, IOException
+    {
+
+        String file = CtxHelper.getAttr(this.to, this.toKey, ctx);
+
+        boolean overwrite = CtxHelper.getBooleanAttr(this.overwrite,
+            this.overwriteKey, false, ctx);
+
+        File f = new File(file);
+
+        if (f.exists() && !overwrite)
+        {
+            throw new JcrCommandException("file.exists", new String[]
+            {
+                file
+            });
+        }
+
+        if (!f.exists())
+        {
+            f.createNewFile();
+        }
+
+        BufferedOutputStream out = new BufferedOutputStream(
+            new FileOutputStream(f));
+
+        return out;
+    }
+
+    /**
+     * @return Returns the noRecurse.
+     */
+    public String getNoRecurse()
+    {
+        return noRecurse;
+    }
+
+    /**
+     * @param noRecurse
+     *            The noRecurse to set.
+     */
+    public void setNoRecurse(String noRecurse)
+    {
+        this.noRecurse = noRecurse;
+    }
+
+    /**
+     * @return Returns the noRecurseKey.
+     */
+    public String getNoRecurseKey()
+    {
+        return noRecurseKey;
+    }
+
+    /**
+     * @param noRecurseKey
+     *            Set the context attribute key for the noRecurse attribute.
+     */
+    public void setNoRecurseKey(String noRecurseKey)
+    {
+        this.noRecurseKey = noRecurseKey;
+    }
+
+    /**
+     * @return Returns the overwrite.
+     */
+    public String getOverwrite()
+    {
+        return overwrite;
+    }
+
+    /**
+     * @param overwrite
+     *            The overwrite to set.
+     */
+    public void setOverwrite(String overwrite)
+    {
+        this.overwrite = overwrite;
+    }
+
+    /**
+     * @return Returns the overwriteKey.
+     */
+    public String getOverwriteKey()
+    {
+        return overwriteKey;
+    }
+
+    /**
+     * @param overwriteKey
+     *            Set the context attribute key for the overwrite attribute.
+     */
+    public void setOverwriteKey(String overwriteKey)
+    {
+        this.overwriteKey = overwriteKey;
+    }
+
+    /**
+     * @return Returns the skipBinary.
+     */
+    public String getSkipBinary()
+    {
+        return skipBinary;
+    }
+
+    /**
+     * @param skipBinary
+     *            The skipBinary to set.
+     */
+    public void setSkipBinary(String skipBinary)
+    {
+        this.skipBinary = skipBinary;
+    }
+
+    /**
+     * @return Returns the skipBinaryKey.
+     */
+    public String getSkipBinaryKey()
+    {
+        return skipBinaryKey;
+    }
+
+    /**
+     * @param skipBinaryKey
+     *            Set the context attribute key for the skipBinary attribute.
+     */
+    public void setSkipBinaryKey(String skipBinaryKey)
+    {
+        this.skipBinaryKey = skipBinaryKey;
+    }
+
+    /**
+     * @return Returns the from.
+     */
+    public String getFrom()
+    {
+        return from;
+    }
+
+    /**
+     * @param from
+     *            The from to set.
+     */
+    public void setFrom(String from)
+    {
+        this.from = from;
+    }
+
+    /**
+     * @return Returns the fromKey.
+     */
+    public String getFromKey()
+    {
+        return fromKey;
+    }
+
+    /**
+     * @param fromKey
+     *            The fromKey to set.
+     */
+    public void setFromKey(String fromKey)
+    {
+        this.fromKey = fromKey;
+    }
+
+    /**
+     * @return Returns the to.
+     */
+    public String getTo()
+    {
+        return to;
+    }
+
+    /**
+     * @param to
+     *            The to to set.
+     */
+    public void setTo(String to)
+    {
+        this.to = to;
+    }
+
+    /**
+     * @return Returns the toKey.
+     */
+    public String getToKey()
+    {
+        return toKey;
+    }
+
+    /**
+     * @param toKey
+     *            The toKey to set.
+     */
+    public void setToKey(String toKey)
+    {
+        this.toKey = toKey;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/AbstractExportViewToFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportDocViewToFile.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportDocViewToFile.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportDocViewToFile.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportDocViewToFile.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,40 @@
+package org.apache.jackrabbit.chain.command.xml;
+
+import java.io.OutputStream;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Serializes the node to the given file using the Document View Format
+ */
+public class ExportDocViewToFile extends AbstractExportViewToFile
+{
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        boolean skipBinary = CtxHelper.getBooleanAttr(this.skipBinary,
+            this.skipBinaryKey, false, ctx);
+
+        boolean noRecurse = CtxHelper.getBooleanAttr(this.noRecurse,
+            this.noRecurseKey, false, ctx);
+
+        Session s = CtxHelper.getSession(ctx);
+        Node current = CtxHelper.getCurrentNode(ctx);
+        Node from = CtxHelper.getNode(ctx, CtxHelper.getAttr(this.from,
+            this.fromKey, current.getPath(), ctx));
+
+        OutputStream out = getOutputStream(ctx);
+        s.exportDocumentView(from.getPath(), out, skipBinary, noRecurse);
+        out.close();
+
+        return false;
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportDocViewToFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportSysViewToFile.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportSysViewToFile.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportSysViewToFile.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportSysViewToFile.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,40 @@
+package org.apache.jackrabbit.chain.command.xml;
+
+import java.io.OutputStream;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Serializes the node to the given file using the System View Format
+ */
+public class ExportSysViewToFile extends AbstractExportViewToFile
+{
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        boolean skipBinary = CtxHelper.getBooleanAttr(this.skipBinary,
+            this.skipBinaryKey, false, ctx);
+
+        boolean noRecurse = CtxHelper.getBooleanAttr(this.noRecurse,
+            this.noRecurseKey, false, ctx);
+
+        Session s = CtxHelper.getSession(ctx);
+        Node current = CtxHelper.getCurrentNode(ctx);
+        Node from = CtxHelper.getNode(ctx, CtxHelper.getAttr(this.from,
+            this.fromKey, current.getPath(), ctx));
+
+        OutputStream out = getOutputStream(ctx);
+        s.exportSystemView(from.getPath(), out, skipBinary, noRecurse);
+        out.close();
+
+        return false;
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ExportSysViewToFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ImportXmlFromFile.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ImportXmlFromFile.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ImportXmlFromFile.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ImportXmlFromFile.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.command.xml;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+
+/**
+ * Imports the xml view from the given file to the current working node. <br>
+ * The Command attributes are set from the specified literal values, or from the
+ * context attributes stored under the given keys.
+ */
+public class ImportXmlFromFile implements Command
+{
+
+    // ---------------------------- < literals >
+
+    /** doc view file */
+    private String from;
+
+    /** uuid behaviour */
+    private String uuidBehaviour;
+
+    // ---------------------------- < keys >
+
+    /** doc view file key */
+    private String fromKey;
+
+    /** uuid behaviour key */
+    private String uuidBehaviourKey;
+
+    /**
+     * @inheritDoc
+     */
+    public boolean execute(Context ctx) throws Exception
+    {
+        String file = CtxHelper.getAttr(this.from, this.fromKey, ctx);
+
+        int uuidBehaviour = CtxHelper.getIntAttr(this.uuidBehaviour,
+            this.uuidBehaviourKey, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW,
+            ctx);
+
+        File f = new File(file);
+
+        if (!f.exists())
+        {
+            throw new JcrCommandException("file.not.found", new String[]
+            {
+                file
+            });
+        }
+        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+
+        Session s = CtxHelper.getSession(ctx);
+        Node n = CtxHelper.getCurrentNode(ctx);
+        s.importXML(n.getPath(), in, uuidBehaviour);
+        return false;
+    }
+
+    /**
+     * @return Returns the from.
+     */
+    public String getFrom()
+    {
+        return from;
+    }
+
+    /**
+     * @param from
+     *            The from to set.
+     */
+    public void setFrom(String from)
+    {
+        this.from = from;
+    }
+
+    /**
+     * @return Returns the fromKey.
+     */
+    public String getFromKey()
+    {
+        return fromKey;
+    }
+
+    /**
+     * @param fromKey
+     *            Set the context attribute key for the from attribute.
+     */
+    public void setFromKey(String fromKey)
+    {
+        this.fromKey = fromKey;
+    }
+
+    /**
+     * @return Returns the uuidBehaviour.
+     */
+    public String getUuidBehaviour()
+    {
+        return uuidBehaviour;
+    }
+
+    /**
+     * @param uuidBehaviour
+     *            The uuidBehaviour to set.
+     */
+    public void setUuidBehaviour(String uuidBehaviour)
+    {
+        this.uuidBehaviour = uuidBehaviour;
+    }
+
+    /**
+     * @return Returns the uuidBehaviourKey.
+     */
+    public String getUuidBehaviourKey()
+    {
+        return uuidBehaviourKey;
+    }
+
+    /**
+     * @param uuidBehaviourKey
+     *            Set the context attribute key for the uuidBehaviour attribute.
+     */
+    public void setUuidBehaviourKey(String uuidBehaviourKey)
+    {
+        this.uuidBehaviourKey = uuidBehaviourKey;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/command/xml/ImportXmlFromFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/exceptions.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/exceptions.properties?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/exceptions.properties (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/exceptions.properties Thu Aug 11 11:04:29 2005
@@ -0,0 +1,14 @@
+illegalargument.not.a.command=Illegal argument. "{0}" is not a command.
+illegalargument.null=Null arguments are illegal. 
+repository.not.in.context=The repository can't be found in the application context. You need to start a jcr implementation before trying to login.
+no.current.node=The current working node isn't set. Please start a jcr implementation before trying to get the current working node.
+not.ntfile={0} is not nt:file.
+fspath.is.null=The file system path is unset.  
+file.flag.unset=The file flag is unset.
+file.not.found=File not found. {0}.
+file.exists=File already exists. {0}.
+not.file.or.folder=The given node is not nt:file nor nt:folder. {0}.
+file.not.created=The file was not created. {0}.
+folder.not.created=The folder was not created. {0}.
+already.logged.in=You are already logged in. Please logout.
+literal.and.key.null=Literal value and key are both null.

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/chain/exceptions.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/AbstractCommandTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/AbstractCommandTest.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/AbstractCommandTest.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/AbstractCommandTest.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.test;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.chain.Catalog;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.config.ConfigParser;
+import org.apache.commons.chain.impl.CatalogFactoryBase;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.JcrCommandException;
+import org.apache.jackrabbit.chain.command.ClearWorkspace;
+import org.apache.jackrabbit.chain.command.Login;
+import org.apache.jackrabbit.chain.command.Logout;
+import org.apache.jackrabbit.chain.command.StartOrGetJackrabbitSingleton;
+
+/**
+ * Commands Test superclass
+ */
+public abstract class AbstractCommandTest extends TestCase
+{
+    /** config */
+    private static String CONFIG = "applications/test/repository.xml";
+
+    /** home */
+    private static String HOME = "applications/test/repository";
+
+    static
+    {
+        try
+        {
+            ConfigParser parser = new ConfigParser();
+            parser.parse(AbstractCommandTest.class.getResource("chains.xml"));
+        } catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /** clear workspace */
+    private ClearWorkspace cw = new ClearWorkspace();
+
+    /** Context */
+    protected Context ctx = new ContextBase();
+
+    /** catalog */
+    protected Catalog catalog = CatalogFactoryBase.getInstance().getCatalog("test");
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        // Start
+        StartOrGetJackrabbitSingleton startCmd = new StartOrGetJackrabbitSingleton();
+        startCmd.setConfig(CONFIG);
+        startCmd.setHome(HOME);
+        startCmd.execute(ctx);
+        assertTrue(CtxHelper.getRepository(ctx) instanceof Repository);
+
+        // Login
+        Login loginCmd = new Login();
+        loginCmd.setUser("user");
+        loginCmd.setPassword("password");
+        loginCmd.execute(ctx);
+        assertTrue(CtxHelper.getSession(ctx) != null);
+        assertTrue(CtxHelper.getCurrentNode(ctx).getPath().equals("/"));
+
+        // clear workspace
+        cw.execute(ctx);
+
+    }
+    
+
+    protected void addTestNode() throws Exception
+    {
+        catalog.getCommand("addTestNode").execute(ctx);
+    }    
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        cw.execute(ctx);
+
+        // Logout
+        Logout logoutCmd = new Logout();
+        logoutCmd.execute(ctx);
+
+        ctx.clear();
+    }
+    
+    protected Node getRoot() throws PathNotFoundException, JcrCommandException, RepositoryException {
+        return CtxHelper.getNode(ctx, "/") ;
+    }
+    
+    
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/AbstractCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliParserTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliParserTest.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliParserTest.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliParserTest.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.jackrabbit.chain.test;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.chain.Command;
+import org.apache.jackrabbit.chain.cli.JcrParser;
+import org.apache.jackrabbit.chain.cli.JcrParserException;
+import org.apache.jackrabbit.chain.command.CurrentNode;
+import org.apache.jackrabbit.chain.command.StartJackrabbit;
+
+/**
+ * Command line parser tests
+ */
+public class CliParserTest extends TestCase
+{
+    
+    /**
+     * @throws Exception
+     */
+    public void testParse() throws Exception
+    {
+        JcrParser parser = new JcrParser();
+        String config = "repository.xml";
+        String home = "/repository";
+        parser.parse("startjackrabbit -config " + config + " -home " + home);
+        Command c = parser.getCommand();
+        assertTrue(c instanceof StartJackrabbit);
+        StartJackrabbit cmd = (StartJackrabbit) c;
+        assertTrue(cmd.getConfig().equals(config));
+        assertTrue(cmd.getHome().equals(home));
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void testCliParserExceptions() throws Exception
+    {
+        JcrParser parser = new JcrParser();
+        try
+        {
+            parser.parse("startjackrabbit -config ");
+            fail();
+        } catch (JcrParserException e)
+        {
+            // Do nothing
+        }
+
+    }
+    
+    /**
+     * @throws Exception
+     */
+    public void testCd() throws Exception
+    {
+        JcrParser parser = new JcrParser();
+        parser.parse("cd foo");
+        CurrentNode cmd = (CurrentNode) parser.getCommand() ;
+        assertTrue(cmd.getPath().equals("foo")) ;
+    }    
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native