jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1855719 [2/6] - in /jackrabbit/trunk: ./ jackrabbit-standalone-components/ jackrabbit-standalone-components/src/ jackrabbit-standalone-components/src/main/ jackrabbit-standalone-components/src/main/java/ jackrabbit-standalone-components/sr...
Date Sun, 17 Mar 2019 21:44:47 GMT
Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrClient.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrClient.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrClient.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrClient.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,388 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import jline.ArgumentCompletor;
+import jline.Completor;
+import jline.ConsoleReader;
+import jline.History;
+import jline.SimpleCompletor;
+
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.Parser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+import org.apache.jackrabbit.util.ChildrenCollectorFilter;
+
+/**
+ * Command line interface client
+ */
+public class JcrClient {
+    /** logger */
+    private static Log log = LogFactory.getLog(JcrClient.class);
+
+    /** Resource bundle */
+    private ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** exit control variable */
+    private boolean exit = false;
+
+    /** Execution context */
+    private Context ctx;
+
+    /** run options */
+    private Options options;
+
+    /**
+     * Constructor
+     */
+    JcrClient() {
+        super();
+        ctx = new ContextBase();
+        initOptions();
+        initContext();
+    }
+
+    /**
+     * Constructor
+     * @param ctx
+     *        the <code>Context</code>
+     */
+    public JcrClient(Context ctx) {
+        super();
+        this.ctx = ctx;
+    }
+
+    /**
+     * @param args
+     *        the arguments
+     */
+    public static void main(String[] args) {
+        JcrClient client = new JcrClient();
+        client.run(args);
+    }
+
+    /**
+     * Run client
+     * @param args
+     *        the arguments
+     */
+    private void run(String[] args) {
+        try {
+            // parse arguments
+            Parser parser = new BasicParser();
+            org.apache.commons.cli.CommandLine cl = parser.parse(options, args);
+
+            // Set locale
+            this.setLocale(cl);
+
+            // Welcome message
+            System.out.println(bundle.getString("word.welcome"));
+
+            // check interactive mode
+            if (cl.hasOption("source")) {
+                this.runNonInteractive(cl);
+            } else {
+                this.runInteractive();
+            }
+        } catch (Exception e) {
+            HelpFormatter hf = new HelpFormatter();
+            hf.printHelp("jcrclient", options);
+            e.printStackTrace();
+            return;
+        }
+    }
+    
+    /**
+     * jline ConsoleReader tab completor that completes on the children of the
+     * current jcr node (both nodes and properties).
+     * 
+     * @author <a href="mailto:alexander(dot)klimetschek(at)mindquarry(dot)com">
+     *         Alexander Klimetschek</a>
+     *
+     */
+    private class JcrChildrenCompletor implements Completor {
+
+        public int complete(String buffer, int cursor, List clist) {
+            String start = (buffer == null) ? "" : buffer;
+            
+            Node node;
+            try {
+                node = CommandHelper.getNode(ctx, ".");
+                Collection items = new ArrayList();
+                ChildrenCollectorFilter collector = new ChildrenCollectorFilter(
+                    "*", items, true, true, 1);
+                collector.visit(node);
+                for (Object item : items) {
+                    String can = ((Item) item).getName();
+                    if (can.startsWith(start)) {
+                        clist.add(can);
+                    }
+                }
+                
+                return 0;
+            } catch (CommandException e) {
+                e.printStackTrace();
+            } catch (RepositoryException e) {
+                e.printStackTrace();
+            }
+            
+            return -1;
+        }
+        
+    }
+
+    /**
+     * Run in interactive mode
+     * @throws Exception
+     *         if an Exception occurs
+     */
+    public void runInteractive() throws Exception {
+        // built jline console reader with history + tab completion
+        ConsoleReader reader = new ConsoleReader();
+        reader.setHistory(new History());
+        reader.setUseHistory(true);
+        
+        // get all available commands for command tab completion
+        Collection<CommandLine> commands =
+            CommandLineFactory.getInstance().getCommandLines();
+        List<String> commandNames = new ArrayList<String>();
+        for (CommandLine c : commands) {
+            commandNames.add(c.getName());
+            for (Object alias : c.getAlias()) {
+                commandNames.add((String) alias);
+            }
+        }
+        commandNames.add("exit");
+        commandNames.add("quit");
+        
+        // first part is the command, then all arguments will get children tab completion
+        reader.addCompletor(new ArgumentCompletor( new Completor[] {
+                new SimpleCompletor(commandNames.toArray(new String[] {} )),
+                new JcrChildrenCompletor()
+        }));
+        
+        while (!exit) {
+            try {
+                String input = reader.readLine("[" + this.getPrompt() + "] > ");
+                if (input == null) {
+                    input = "exit";
+                } else {
+                    input = input.trim();
+                }
+                log.debug("running: " + input);
+                if (input.equals("exit") || input.equals("quit")) { // exit?
+                    exit = true;
+                    System.out.println("Good bye...");
+                } else if (input.length() > 0) {
+                    this.runCommand(input);
+                }
+            } catch (JcrParserException e) {
+                System.out.println(e.getLocalizedMessage());
+                System.out.println();
+            } catch (Exception e) {
+                handleException(reader, e);
+            }
+        }
+    }
+
+    /**
+     * Run in non interactive mode
+     * @param cl
+     *        the <code>CommandLine</code>
+     * @throws Exception
+     *         if an <code>Exception</code> occurs while running the
+     *         <code>Command</code>
+     */
+    private void runNonInteractive(org.apache.commons.cli.CommandLine cl) throws Exception {
+        this.runCommand("source " + cl.getOptionValue("source"));
+    }
+
+    /**
+     * Parses the input and runs the specified command
+     * @param input
+     *        the user's input
+     * @throws Exception
+     *         if an <code>Exception</code> occurs while running the
+     *         <code>Command</code>
+     */
+    void runCommand(String input) throws Exception {
+        if (input.startsWith("#") || input.length() == 0) {
+            return;
+        }
+
+        // Process user input
+        JcrParser parser = new JcrParser();
+        parser.parse(input);
+
+        // populate ctx
+        parser.populateContext(ctx);
+
+        // Execute command
+        long start = System.currentTimeMillis();
+        parser.getCommand().execute(ctx);
+        long elapsed = System.currentTimeMillis() - start;
+
+        // depopulate ctx
+        parser.depopulateContext(ctx);
+
+        // Display elapsed timed
+        System.out.println();
+        System.out.println(bundle.getString("phrase.elapsedtime") + ": "
+                + elapsed + " ms.");
+        System.out.println();
+    }
+
+    /**
+     * Handle the Exception. <br>
+     * Shows a short message and prompt the user to show the entire stacktrace.
+     * @param ex
+     *        the <code>Exception</code> to handle
+     */
+    private void handleException(ConsoleReader cr, Exception ex) {
+        System.out.println();
+        System.out.println(bundle.getString("exception.occurred"));
+        System.out.println();
+        System.out.println(bundle.getString("exception") + ": "
+                + ex.getClass().getName());
+        System.out.println(bundle.getString("word.message") + ": "
+                + ex.getLocalizedMessage());
+        System.out.println();
+        String prompt = bundle.getString("phrase.display.stacktrace")
+                + "? [y/n]";
+
+        String str = "";
+        int tries = 0;
+        while (!str.equals("y") && !str.equals("n") && tries < 3) {
+            tries++;
+
+            try {
+                str = cr.readLine(prompt);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        if (str.equals("y")) {
+            ex.printStackTrace();
+        }
+    }
+
+    /**
+     * Prompt message
+     * @return prompt the prompt message
+     * @throws RepositoryException
+     *         if the current <code>Repository</code> throws a
+     *         <code>RepositoryException</code>
+     */
+    private String getPrompt() throws RepositoryException {
+
+        try {
+            CommandHelper.getRepository(ctx);
+        } catch (CommandException e) {
+            return bundle.getString("phrase.not.connected");
+        }
+
+        boolean unsaved = false;
+        try {
+            unsaved = CommandHelper.getSession(ctx).hasPendingChanges();
+        } catch (CommandException e) {
+            return bundle.getString("phrase.not.logged.in");
+        }
+
+        try {
+            Node n = CommandHelper.getCurrentNode(ctx);
+            // the current node might be Invalid
+            String path;
+            try {
+                path = n.getPath();
+            } catch (InvalidItemStateException e) {
+                CommandHelper.setCurrentNode(ctx, CommandHelper.getSession(ctx)
+                    .getRootNode());
+                path = CommandHelper.getCurrentNode(ctx).getPath();
+            }
+            if (unsaved) {
+                return path + "*";
+            } else {
+                return path;
+            }
+        } catch (CommandException e) {
+            return bundle.getString("phrase.not.logged.in");
+        }
+
+    }
+
+    /**
+     * Init allowed CommandLine options
+     */
+    private void initOptions() {
+        options = new Options();
+        options.addOption("lang", "code", true, "Language code");
+        options.addOption("country", "code", true, "Country code");
+        options.addOption("source", "path", true,
+            "Script for noninteractive mode");
+    }
+
+    /**
+     * Sets the default Locale for the given CommandLine
+     * @param cl
+     *        the CLI <code>CommandLine</code>
+     * @throws ParseException
+     *         if cl can't be parsed
+     */
+    private void setLocale(org.apache.commons.cli.CommandLine cl) throws ParseException {
+        Locale locale = null;
+        if (cl.hasOption("lang") && cl.hasOption("country")) {
+            locale = new Locale(cl.getOptionValue("lang"), cl
+                .getOptionValue("country"));
+        }
+        if (cl.hasOption("lang") && !cl.hasOption("country")) {
+            locale = new Locale(cl.getOptionValue("lang"));
+        }
+        if (locale != null) {
+            Locale.setDefault(locale);
+        }
+    }
+
+    /**
+     * Init context. <br>
+     * Sets the Context Output to the console
+     */
+    private void initContext() {
+        CommandHelper.setOutput(ctx, new PrintWriter(System.out, true));
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParser.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParser.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParser.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,293 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.chain.Catalog;
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.config.ConfigParser;
+import org.apache.commons.chain.impl.CatalogFactoryBase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Input Parser
+ */
+public class JcrParser {
+    /** parser */
+    private static Log log = LogFactory.getLog(JcrParser.class);
+
+    static {
+        try {
+            ConfigParser parser = new ConfigParser();
+            parser.parse(JcrParser.class.getResource("command.xml"));
+        } catch (Exception e) {
+            log.error("Failed to parse command.xml", e);
+        }
+    }
+
+    /** catalog */
+    private Catalog catalog = CatalogFactoryBase.getInstance().getCatalog();
+
+    /** Command */
+    private Command cmd;
+
+    /** Command Line */
+    private CommandLine cl;
+
+    /**
+     * Constructor
+     */
+    public JcrParser() {
+        super();
+    }
+
+    /**
+     * Parse the user's input.
+     * @param input
+     *        user's input
+     * @throws JcrParserException
+     *         if the input is illegal
+     * @throws ConfigurationException
+     *         if the mapped command can't be mapped to a Commons Chain Command
+     */
+    public void parse(String input) throws JcrParserException,
+            ConfigurationException {
+        this.cl = null;
+        this.cmd = null;
+
+        // Validate input
+        if (input == null || input.length() == 0) {
+            throw new JcrParserException("exception.parse.input.empty");
+        }
+
+        // Extract arguments
+        LinkedList args = this.getArguments(input);
+
+        // The first arg is the command name
+        String cmdName = (String) args.getFirst();
+        args.removeFirst();
+
+        // Get the command line descriptor
+        cl = CommandLineFactory.getInstance().getCommandLine(cmdName);
+
+        // populate with the given params
+        populate(cl, args);
+
+        // validate the command line
+        validate(cl);
+
+        // Create Chain Command
+        String impl = cl.getImpl();
+        if (impl == null) {
+            impl = cl.getName();
+        }
+        cmd = catalog.getCommand(impl);
+
+        if (cmd == null) {
+            throw new JcrParserException("no chain command for name " + impl);
+        }
+
+    }
+
+    /**
+     * Tokenize user's input
+     * @param input
+     *        the user's input
+     * @return a <code>List</code> containing the arguments
+     */
+    private LinkedList getArguments(String input) {
+        LinkedList args = new LinkedList();
+        int length = input.length();
+
+        boolean insideSingleQuote = false;
+        boolean insideDoubleQuote = false;
+        int escape = -1;
+
+        StringBuffer arg = new StringBuffer();
+
+        for (int i = 0; i < length; ++i) {
+            char c = input.charAt(i);
+
+            // end of argument?
+            if ((!insideSingleQuote && !insideDoubleQuote && Character
+                .isWhitespace(c))) {
+                if (arg.toString().trim().length() > 0) {
+                    args.add(arg.toString().trim());
+                    arg = new StringBuffer();
+                }
+                continue;
+            }
+
+            if (i == escape) { // escaped char
+                arg.append(c);
+            } else { // unescaped char
+                switch (c) {
+                case '\\':
+                    escape = i + 1;
+                    break;
+                case '"':
+                    insideDoubleQuote = !insideDoubleQuote;
+                    break;
+                case '\'':
+                    insideSingleQuote = !insideSingleQuote;
+                    break;
+                default:
+                    arg.append(c);
+                    break;
+                }
+            }
+        }
+
+        if (arg.toString().trim().length() > 0) {
+            args.add(arg.toString());
+        }
+
+        return args;
+    }
+
+    /**
+     * Populate the <code>Context</code> with the attributes needed by the
+     * <code>Command</code>
+     * @param ctx
+     *        the <code>Context</code>
+     */
+    public void populateContext(Context ctx) {
+        Iterator iter = cl.getAllParameters();
+        while (iter.hasNext()) {
+            AbstractParameter param = (AbstractParameter) iter.next();
+            log.debug("add ctx attr: " + param.getContextKey() + "="
+                    + param.getValue());
+            ctx.put(param.getContextKey(), param.getValue());
+        }
+    }
+
+    /**
+     * Remove <code>Context</code> attribute specific to the parsed
+     * <code>Command</code>
+     * @param ctx
+     *        the <code>Context</code>
+     */
+    public void depopulateContext(Context ctx) {
+        Iterator iter = cl.getAllParameters();
+        while (iter.hasNext()) {
+            AbstractParameter param = (AbstractParameter) iter.next();
+            String ctxKey = param.getContextKey();
+            log.debug("remove ctx attr: " + ctxKey + "=" + param.getValue());
+            ctx.remove(ctxKey);
+        }
+    }
+
+    /**
+     * @return the <code>Command</code>
+     */
+    public Command getCommand() {
+        return cmd;
+    }
+
+    /**
+     * Populate the <code>CommandLine</code> with the given parameters
+     * @param cl
+     *        the <code>CommandLine</code>
+     * @param valList
+     *        the arguments
+     * @throws JcrParserException
+     *         if the user's input is illegal
+     */
+    private void populate(CommandLine cl, List valList)
+            throws JcrParserException {
+        String[] values = (String[]) valList
+            .toArray(new String[valList.size()]);
+
+        // Command Line parameters
+        Map options = cl.getOptions();
+        Map flags = cl.getFlags();
+        Map clArgs = cl.getArguments();
+
+        // Input arguments
+        List args = new ArrayList();
+
+        for (int i = 0; i < values.length; i++) {
+            String value = values[i];
+
+            if (value.startsWith("-")) {
+                // option
+                if (i + 1 < values.length && !values[i + 1].startsWith("-")) {
+                    Option opt = (Option) options.get(value.substring(1));
+                    if (opt == null) {
+                        throw new JcrParserException("exception.no.opt.for.name",
+                            new String[] {
+                                value.substring(1)
+                            });
+                    }
+                    opt.setValue(values[i + 1]);
+                    i++;
+                } else {
+                    // flag
+                    Flag flag = (Flag) flags.get(value.substring(1));
+                    if (flag == null) {
+                        throw new JcrParserException("exception.no.flag.for.name",
+                            new String[] {
+                                value
+                            });
+                    }
+                    flag.setPresent(true);
+                }
+            } else {
+                // collect arguments
+                args.add(value);
+            }
+        }
+
+        // set arguments
+        String[] argValues = (String[]) args.toArray(new String[args.size()]);
+        for (int j = 0; j < argValues.length; j++) {
+            Argument arg = (Argument) clArgs.get(new Integer(j));
+            if (arg == null) {
+                throw new JcrParserException("exception.more.arguments.than.expected");
+            }
+            arg.setValue(argValues[j]);
+        }
+
+    }
+
+    /**
+     * Validate the <code>CommandLine</code>
+     * @param cl
+     *        the <code>CommandLine</code>
+     * @throws JcrParserException
+     *         if a required parameter is not present in the user's input
+     */
+    private void validate(CommandLine cl) throws JcrParserException {
+        Iterator iter = cl.getRequiredParameters();
+        while (iter.hasNext()) {
+            AbstractParameter param = (AbstractParameter) iter.next();
+            if (param.getValue() == null) {
+                throw new JcrParserException("exception.missing.paramater", new String[] {
+                    param.getName()
+                });
+            }
+        }
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParserException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParserException.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParserException.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/JcrParserException.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli;
+
+import org.apache.jackrabbit.standalone.cli.CommandException;
+
+/**
+ * Exception thrown if any error occurs while parsing the user's input.
+ */
+public class JcrParserException extends CommandException {
+
+    /**
+     * <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3761694498056713525L;
+
+    /**
+     * @param message the message
+     * @param arguments the arguments
+     */
+    public JcrParserException(String message, Object[] arguments) {
+        super(message, arguments);
+    }
+
+    /**
+     * @param message the message
+     * @param cause the cause
+     * @param arguments the arguments
+     */
+    public JcrParserException(String message, Throwable cause,
+        Object[] arguments) {
+        super(message, cause, arguments);
+    }
+
+    /**
+     * @param message the message
+     */
+    public JcrParserException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message the message
+     * @param cause the cause
+     */
+    public JcrParserException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/Option.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/Option.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/Option.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/Option.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli;
+
+/**
+ * Command Line option. <br>
+ * An option is a pair with the following pattern -[option name] [option value]
+ */
+public class Option extends AbstractParameter {
+
+    /** argument name */
+    private String argName;
+
+    /** required */
+    private boolean required = false;
+
+    /**
+     * @return true if this <code>Option</code> is required
+     */
+    public boolean isRequired() {
+        return required;
+    }
+
+    /**
+     * @param required
+     *        set required
+     */
+    public void setRequired(boolean required) {
+        this.required = required;
+    }
+
+    /**
+     * @return the argument name
+     */
+    public String getArgName() {
+        return argName;
+    }
+
+    /**
+     * @return the localized argument name
+     */
+    public String getLocalizedArgName() {
+        return bundle.getString(this.getArgName());
+    }
+
+    /**
+     * @param argName
+     *        the argument name to set
+     */
+    public void setArgName(String argName) {
+        this.argName = argName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object clone() {
+        Option o = new Option();
+        this.clone(o);
+        return o;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void clone(Option opt) {
+        super.clone(opt);
+        opt.argName = this.argName;
+        opt.required = this.required;
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getLocalizedDescription() {
+        return bundle.getString(this.getDescription());
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/SourceCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/SourceCommand.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/SourceCommand.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/SourceCommand.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.util.ResourceBundle;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Executes a script from the given file
+ */
+public class SourceCommand implements Command {
+    /** Resource bundle */
+    private ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** file */
+    private String fileKey = "file";
+
+    /**
+     * @return Returns the file.
+     */
+    public String getFileKey() {
+        return fileKey;
+    }
+
+    /**
+     * @param file
+     *        The file to set.
+     */
+    public void setFileKey(String file) {
+        this.fileKey = file;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        File f = new File((String) ctx.get(this.fileKey));
+        if (!f.exists()) {
+            throw new CommandException("exception.file.not.found",
+                new String[] {
+                    f.getAbsolutePath()
+                });
+        }
+        // client
+        JcrClient client = new JcrClient(ctx);
+
+        BufferedReader in = new BufferedReader(new FileReader(f));
+        PrintWriter out = CommandHelper.getOutput(ctx);
+        String line = null;
+        while ((line = in.readLine()) != null) {
+            out.println(bundle.getString("word.running") + ": " + line);
+            client.runCommand(line);
+        }
+        in.close();
+        return false;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/AbstractCollect.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/AbstractCollect.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/AbstractCollect.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/AbstractCollect.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,163 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.collect;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+import org.apache.jackrabbit.util.ChildrenCollectorFilter;
+
+/**
+ * Collect the children items from the given node and store them under the given
+ * key.
+ */
+public abstract class AbstractCollect implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(AbstractCollect.class);
+
+    // ---------------------------- < keys >
+
+    /** path key. Default value is "." */
+    private String srcPathKey = "srcPath";
+
+    /** context attribute key for the depth attribute. */
+    private String depthKey = "depth";
+
+    /**
+     * context attribute key for the name pattern attribute. Default value is
+     * "*"
+     */
+    private String namePatternKey = "namePattern";
+
+    /** context attribute key for the destination attribute */
+    private String destKey = "collected";
+
+    /**
+     * {@inheritDoc}
+     */
+    public final boolean execute(Context ctx) throws Exception {
+        if (this.destKey == null || this.destKey.length() == 0) {
+            throw new IllegalStateException("target variable is not set");
+        }
+        String relPath = (String) ctx.get(this.srcPathKey);
+        if (relPath == null) {
+            relPath = ".";
+        }
+        String namePattern = (String) ctx.get(this.namePatternKey);
+        if (namePattern == null || namePattern.length() == 0) {
+            namePattern = "*";
+        }
+
+        int depth = Integer.parseInt((String) ctx.get(this.depthKey));
+
+        Node node = CommandHelper.getNode(ctx, relPath);
+        if (log.isDebugEnabled()) {
+            log.debug("collecting nodes from " + node.getPath() + " depth="
+                    + depth + " pattern=" + namePattern
+                    + " into target variable " + this.destKey);
+        }
+
+        Collection items = new ArrayList();
+        ChildrenCollectorFilter collector = new ChildrenCollectorFilter(
+            namePattern, items, isCollectNodes(), isCollectProperties(), depth);
+        collector.visit(node);
+        ctx.put(this.destKey, items.iterator());
+
+        return false;
+    }
+
+    /**
+     * @return Returns the depthKey.
+     */
+    public String getDepthKey() {
+        return depthKey;
+    }
+
+    /**
+     * @param depthKey
+     *        Set the context attribute key for the depth attribute
+     */
+    public void setDepthKey(String depthKey) {
+        this.depthKey = depthKey;
+    }
+
+    /**
+     * @return Returns the namePatternKey.
+     */
+    public String getNamePatternKey() {
+        return namePatternKey;
+    }
+
+    /**
+     * @param namePatternKey
+     *        context attribute key for the name pattern attribute
+     */
+    public void setNamePatternKey(String namePatternKey) {
+        this.namePatternKey = namePatternKey;
+    }
+
+    /**
+     * Collect nodes flag
+     * @return true if <code>Node</code> s must be collected
+     */
+    protected abstract boolean isCollectNodes();
+
+    /**
+     * Collect properties flag
+     * @return true if <code>Property</code> s must be collected
+     */
+    protected abstract boolean isCollectProperties();
+
+    /**
+     * @return the destination key
+     */
+    public String getDestKey() {
+        return destKey;
+    }
+
+    /**
+     * Sets the destination key
+     * @param destKey
+     *        the detination key
+     */
+    public void setDestKey(String destKey) {
+        this.destKey = destKey;
+    }
+
+    /**
+     * @return the source path key
+     */
+    public String getSrcPathKey() {
+        return srcPathKey;
+    }
+
+    /**
+     * Sets the source path key
+     * @param srcPathKey
+     *        the source path key
+     */
+    public void setSrcPathKey(String srcPathKey) {
+        this.srcPathKey = srcPathKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectItems.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectItems.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectItems.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectItems.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.collect;
+
+/**
+ * Collect children, either nodes or properties
+ */
+public class CollectItems extends AbstractCollect {
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectNodes() {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectProperties() {
+        return true;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectNodes.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectNodes.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectNodes.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectNodes.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.collect;
+
+/**
+ * Collect nodes only
+ */
+public class CollectNodes extends AbstractCollect {
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectNodes() {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectProperties() {
+        return false;
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectProperties.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectProperties.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/collect/CollectProperties.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.collect;
+
+/**
+ * Collect properties only
+ */
+public class CollectProperties extends AbstractCollect {
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectNodes() {
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isCollectProperties() {
+        return true;
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AbstractSetProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AbstractSetProperty.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AbstractSetProperty.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AbstractSetProperty.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import org.apache.commons.chain.Command;
+
+/**
+ * SetProperty superclass.
+ */
+public abstract class AbstractSetProperty implements Command {
+    // ---------------------------- < keys >
+
+    /** destination node path key */
+    protected String parentPathKey = "parentPath";
+
+    /** Property name key */
+    protected String nameKey = "name";
+
+    /** Propety type key */
+    protected String typeKey = "type";
+
+    /** Property value key */
+    protected String valueKey = "value";
+
+    /**
+     * @return Returns the valueKey.
+     */
+    public String getValueKey() {
+        return valueKey;
+    }
+
+    /**
+     * @param valueKey
+     *        Set the context attribute key for the value attribute.
+     */
+    public void setValueKey(String valueKey) {
+        this.valueKey = valueKey;
+    }
+
+    /**
+     * @return the parent path key
+     */
+    public String getParentPathKey() {
+        return parentPathKey;
+    }
+
+    /**
+     * Sets the parent path key
+     * @param parentPathKey
+     *        the parent path key
+     */
+    public void setParentPathKey(String parentPathKey) {
+        this.parentPathKey = parentPathKey;
+    }
+
+    /**
+     * @return the name key
+     */
+    public String getNameKey() {
+        return nameKey;
+    }
+
+    /**
+     * Sets the name key
+     * @param nameKey
+     *        the name key
+     */
+    public void setNameKey(String nameKey) {
+        this.nameKey = nameKey;
+    }
+
+    /**
+     * @return the type key
+     */
+    public String getTypeKey() {
+        return typeKey;
+    }
+
+    /**
+     * Sets the type key
+     * @param typeKey
+     *        the type key
+     */
+    public void setTypeKey(String typeKey) {
+        this.typeKey = typeKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AddNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AddNode.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AddNode.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/AddNode.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Add a node to the current working <code>Node</code>
+ */
+public class AddNode implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(AddNode.class);
+
+    // ---------------------------- < keys >
+
+    /** Node type key */
+    private String typeKey = "type";
+
+    /** Node name key */
+    private String relPathKey = "relPath";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        Node node = CommandHelper.getCurrentNode(ctx);
+        String nodeType = (String) ctx.get(this.typeKey);
+        String name = (String) ctx.get(this.relPathKey);
+
+        if (log.isDebugEnabled()) {
+            log.debug("adding node at " + node.getPath() + "/" + name);
+        }
+
+        // If the new node name starts with / add it to the root node
+        if (name.startsWith("/")) {
+            node = CommandHelper.getSession(ctx).getRootNode();
+            name = name.substring(1);
+        }
+
+        if (nodeType == null) {
+            node.addNode(name);
+        } else {
+            node.addNode(name, nodeType);
+        }
+        return false;
+    }
+
+    /**
+     * @return the nodeTypeKey.
+     */
+    public String getTypeKey() {
+        return typeKey;
+    }
+
+    /**
+     * @param nodeTypeKey
+     *            Set the context attribute key for the node type attribute.
+     */
+    public void setTypeKey(String nodeTypeKey) {
+        this.typeKey = nodeTypeKey;
+    }
+
+    /**
+     * @return the relative path.
+     */
+    public String getRelPathKey() {
+        return relPathKey;
+    }
+
+    /**
+     * @param relPathKey
+     *            the relative path key to set
+     */
+    public void setRelPathKey(String relPathKey) {
+        this.relPathKey = relPathKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ClearWorkspace.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ClearWorkspace.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ClearWorkspace.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ClearWorkspace.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Remove all the content from the current working <code>Workspace</code>
+ */
+public class ClearWorkspace implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(ClearWorkspace.class);
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        Session s = CommandHelper.getSession(ctx);
+
+        if (log.isDebugEnabled()) {
+            log.debug("removing all content from workspace "
+                    + s.getWorkspace().getName());
+        }
+
+        // Set current node to root
+        CommandHelper.setCurrentNode(ctx, s.getRootNode());
+        NodeIterator iter = s.getRootNode().getNodes();
+        while (iter.hasNext()) {
+            Node n = (Node) iter.next();
+            if (!n.getName().equals(JcrConstants.JCR_SYSTEM)) {
+                n.remove();
+            }
+        }
+        PropertyIterator pIter = s.getRootNode().getProperties();
+        while (pIter.hasNext()) {
+            Property p = pIter.nextProperty();
+            if (!p.getName().equals(JcrConstants.JCR_PRIMARYTYPE)) {
+                p.remove();
+            }
+        }
+        return false;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Clone.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Clone.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Clone.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Clone.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Workspace;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Clone the given <code>Node</code> to another <code>Workspace</code>
+ */
+public class Clone implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(Clone.class);
+
+    // ---------------------------- < keys >
+    /** Source workspace */
+    private String srcWorkspaceKey = "scrWorkspace";
+
+    /** target workspace */
+    private String srcAbsPathKey = "srcAbsPath";
+
+    /** source node */
+    private String destAbsPathKey = "destAbsPath";
+
+    /** target node */
+    private String removeExistingKey = "removeExisting";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
+        String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
+        String destAbsPath = (String) ctx.get(this.destAbsPathKey);
+        Boolean removeExisting = Boolean.valueOf((String) ctx
+            .get(this.removeExistingKey));
+
+        Workspace w = CommandHelper.getSession(ctx).getWorkspace();
+
+        if (log.isDebugEnabled()) {
+            log.debug("cloning node. from [" + srcWorkspace + ":" + srcAbsPath
+                    + "] to [" + w.getName() + ":" + destAbsPath + "]");
+        }
+
+        w.clone(srcWorkspace, srcAbsPath, destAbsPath, removeExisting
+            .booleanValue());
+
+        return false;
+    }
+
+    /**
+     * @return the destination absolute path key
+     */
+    public String getDestAbsPathKey() {
+        return destAbsPathKey;
+    }
+
+    /**
+     * Sets the destination absolute path key
+     * @param destAbsPathKey
+     *        the destination absolute path key
+     */
+    public void setDestAbsPathKey(String destAbsPathKey) {
+        this.destAbsPathKey = destAbsPathKey;
+    }
+
+    /**
+     * @return the remove existing key option
+     */
+    public String getRemoveExistingKey() {
+        return removeExistingKey;
+    }
+
+    /**
+     * Set the remove existing key option
+     * @param removeExistingKey
+     *        the remove existing key option
+     */
+    public void setRemoveExistingKey(String removeExistingKey) {
+        this.removeExistingKey = removeExistingKey;
+    }
+
+    /**
+     * @return the source absolute path key
+     */
+    public String getSrcAbsPathKey() {
+        return srcAbsPathKey;
+    }
+
+    /**
+     * Sets the source absolute path key
+     * @param srcAbsPathKey
+     *        the source absolute path key
+     */
+    public void setSrcAbsPathKey(String srcAbsPathKey) {
+        this.srcAbsPathKey = srcAbsPathKey;
+    }
+
+    /**
+     * @return the source <code>Workspace</code> key
+     */
+    public String getSrcWorkspaceKey() {
+        return srcWorkspaceKey;
+    }
+
+    /**
+     * Sets the source <code>Workspace</code> key
+     * @param srcWorkspaceKey
+     *        the source <code>Workspace</code> key
+     */
+    public void setSrcWorkspaceKey(String srcWorkspaceKey) {
+        this.srcWorkspaceKey = srcWorkspaceKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Copy.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Copy.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Copy.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Copy.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Item;
+import javax.jcr.Workspace;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Copy a Node. <br>
+ * If the source <code>Workspace</code> is unset it will create a copy of the
+ * given <code>Node</code> from the current working <code>Workspace</code>.<br>
+ * If the target path ends with '/' the source node will be copied as a child of
+ * the target node maintaining the name.
+ */
+public class Copy implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(Copy.class);
+
+    // ---------------------------- < keys >
+    /**
+     * Source workspace.
+     */
+    private String srcWorkspaceKey = "srcWorkspace";
+
+    /** source path */
+    private String srcAbsPathKey = "srcAbsPath";
+
+    /** destination path */
+    private String destAbsPathKey = "destAbsPath";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
+        String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
+        String destAbsPath = (String) ctx.get(this.destAbsPathKey);
+
+        Workspace w = CommandHelper.getSession(ctx).getWorkspace();
+
+        if (srcWorkspace == null) {
+            srcWorkspace = w.getName();
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("copying node from [" + srcWorkspace + ":" + srcAbsPath
+                    + "] to [" + w.getName() + ":" + destAbsPath + "]");
+        }
+
+        if (destAbsPath.endsWith("/")) {
+            Item source = CommandHelper.getSession(ctx).getItem(srcAbsPath);
+            destAbsPath = destAbsPath + source.getName();
+        }
+
+        w.copy(srcWorkspace, srcAbsPath, destAbsPath);
+
+        return false;
+    }
+
+    /**
+     * @return the destination absolute path key
+     */
+    public String getDestAbsPathKey() {
+        return destAbsPathKey;
+    }
+
+    /**
+     * sets the destination absolute path key
+     * 
+     * @param destAbsPathKey
+     *            the destination absolute path key
+     */
+    public void setDestAbsPathKey(String destAbsPathKey) {
+        this.destAbsPathKey = destAbsPathKey;
+    }
+
+    /**
+     * @return the source absolute path key
+     */
+    public String getSrcAbsPathKey() {
+        return srcAbsPathKey;
+    }
+
+    /**
+     * Sets the source absolute path key
+     * 
+     * @param srcAbsPathKey
+     *            the source absolute path key
+     */
+    public void setSrcAbsPathKey(String srcAbsPathKey) {
+        this.srcAbsPathKey = srcAbsPathKey;
+    }
+
+    /**
+     * @return the source <code>Workspace</code> key
+     */
+    public String getSrcWorkspaceKey() {
+        return srcWorkspaceKey;
+    }
+
+    /**
+     * Sets the source <code>Workspace</code> key
+     * 
+     * @param srcWorkspaceKey
+     *            the source <code>Workspace</code> key
+     */
+    public void setSrcWorkspaceKey(String srcWorkspaceKey) {
+        this.srcWorkspaceKey = srcWorkspaceKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/CurrentNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/CurrentNode.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/CurrentNode.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/CurrentNode.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Set the current working <code>Node</code>
+ */
+public class CurrentNode implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(CurrentNode.class);
+
+    // ---------------------------- < keys >
+
+    /** context attribute key for the path attribute */
+    private String pathKey = "path";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String dest = (String) ctx.get(this.pathKey);
+        Node n = CommandHelper.getNode(ctx, dest);
+        if (log.isDebugEnabled()) {
+            log.debug("set current working node to " + n.getPath());
+        }
+        CommandHelper.setCurrentNode(ctx, n);
+        return false;
+    }
+
+    /**
+     * @return the path key
+     */
+    public String getPathKey() {
+        return pathKey;
+    }
+
+    /**
+     * @param pathKey
+     *        the path key to set
+     */
+    public void setPathKey(String pathKey) {
+        this.pathKey = pathKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Login.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Login.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Login.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Login.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import jline.ConsoleReader;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Login to the current working <code>Repository</code>
+ */
+public class Login implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(Login.class);
+
+    // ---------------------------- < keys >
+    /** user key */
+    private String userKey = "user";
+
+    /** password key */
+    private String passwordKey = "password";
+
+    /** workspace key */
+    private String workspaceKey = "workspace";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String anon = "anonymous";
+
+        String user = (String) ctx.get(this.userKey);
+        String password = (String) ctx.get(this.passwordKey);
+        String workspace = (String) ctx.get(this.workspaceKey);
+
+        if (user == null) {
+            user = anon;
+        }
+
+        if (password == null || (password.equals(anon) && !user.equals(anon))) {
+            ConsoleReader reader = new ConsoleReader();
+            password = reader.readLine("Password: ", (char) 0);
+        }
+        
+        if (log.isDebugEnabled()) {
+            log.debug("logging in as " + user);
+        }
+
+        Session session = null;
+        Repository repo = CommandHelper.getRepository(ctx);
+
+        Credentials credentials = new SimpleCredentials(user, password
+            .toCharArray());
+
+        if (workspace == null) {
+            session = repo.login(credentials);
+        } else {
+            session = repo.login(credentials, workspace);
+        }
+        CommandHelper.setSession(ctx, session);
+        CommandHelper.setCurrentNode(ctx, session.getRootNode());
+        return false;
+    }
+
+    /**
+     * @return the password key
+     */
+    public String getPasswordKey() {
+        return passwordKey;
+    }
+
+    /**
+     * @param passwordKey
+     *        the password key to set
+     */
+    public void setPasswordKey(String passwordKey) {
+        this.passwordKey = passwordKey;
+    }
+
+    /**
+     * @return the user key.
+     */
+    public String getUserKey() {
+        return userKey;
+    }
+
+    /**
+     * @param userKey
+     *        the user key to set
+     */
+    public void setUserKey(String userKey) {
+        this.userKey = userKey;
+    }
+
+    /**
+     * @return the <code>Workspace</code>.
+     */
+    public String getWorkspaceKey() {
+        return workspaceKey;
+    }
+
+    /**
+     * @param workspaceKey
+     *        the <code>Workspace</code> key to set
+     */
+    public void setWorkspaceKey(String workspaceKey) {
+        this.workspaceKey = workspaceKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Logout.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Logout.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Logout.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Logout.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Logout from the current working <code>Repository</code>
+ */
+public class Logout implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(Logout.class);
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        Session s = CommandHelper.getSession(ctx);
+        if (log.isDebugEnabled()) {
+            log.debug("logging out user " + s.getUserID());
+        }
+        s.logout();
+        CommandHelper.setCurrentNode(ctx, null);
+        CommandHelper.setSession(ctx, null);
+        return false;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Move.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Move.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Move.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Move.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import java.util.ResourceBundle;
+
+import javax.jcr.Item;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Move a <code>Node</code>
+ */
+public class Move implements Command {
+    /** resource bundle */
+    private static ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** logger */
+    private static Log log = LogFactory.getLog(Move.class);
+
+    // ---------------------------- < keys >
+    /** source path */
+    private String srcAbsPathKey = "srcAbsPath";
+
+    /** destination path */
+    private String destAbsPathKey = "destAbsPath";
+
+    /** persistent key */
+    private String persistentKey = "persistent";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
+        String destAbsPath = (String) ctx.get(this.destAbsPathKey);
+
+        boolean persistent = Boolean.valueOf(
+                (String) ctx.get(this.persistentKey)).booleanValue();
+
+        if (!srcAbsPath.startsWith("/") || !destAbsPath.startsWith("/")) {
+            throw new IllegalArgumentException(bundle
+                    .getString("exception.illegalargument")
+                    + ". "
+                    + bundle.getString("exception.only.absolute.path")
+                    + ".");
+        }
+
+        Session s = CommandHelper.getSession(ctx);
+
+        if (log.isDebugEnabled()) {
+            log.debug("moving node from " + srcAbsPath + " to " + destAbsPath);
+        }
+
+        if (destAbsPath.endsWith("/")) {
+            Item source = s.getItem(srcAbsPath);
+            destAbsPath = destAbsPath + source.getName();
+        }
+
+        if (persistent) {
+            s.getWorkspace().move(srcAbsPath, destAbsPath);
+        } else {
+            s.move(srcAbsPath, destAbsPath);
+        }
+
+        return false;
+    }
+
+    /**
+     * @return the destintation absolute path key
+     */
+    public String getDestAbsPathKey() {
+        return destAbsPathKey;
+    }
+
+    /**
+     * @param destAbsPathKey
+     *            the destintation absolute path key to set
+     */
+    public void setDestAbsPathKey(String destAbsPathKey) {
+        this.destAbsPathKey = destAbsPathKey;
+    }
+
+    /**
+     * @return the source absolute path key
+     */
+    public String getSrcAbsPathKey() {
+        return srcAbsPathKey;
+    }
+
+    /**
+     * @param srcAbsPathKey
+     *            the source absolute path key to set
+     */
+    public void setSrcAbsPathKey(String srcAbsPathKey) {
+        this.srcAbsPathKey = srcAbsPathKey;
+    }
+
+    public String getPersistentKey() {
+        return persistentKey;
+    }
+
+    public void setPersistentKey(String persistentKey) {
+        this.persistentKey = persistentKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/OrderBefore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/OrderBefore.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/OrderBefore.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/OrderBefore.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Set the order of the given <code>Node</code>
+ */
+public class OrderBefore implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(OrderBefore.class);
+
+    // ---------------------------- < keys >
+    /** node path */
+    private String parentPathKey = "parentPath";
+
+    /** source path */
+    private String srcChildKey = "srcChild";
+
+    /** destination path */
+    private String destChildKey = "destChild";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String parentPath = (String) ctx.get(this.parentPathKey);
+        Node n = CommandHelper.getNode(ctx, parentPath);
+
+        String srcChildPath = (String) ctx.get(this.srcChildKey);
+        String destChildPath = (String) ctx.get(this.destChildKey);
+
+        if (log.isDebugEnabled()) {
+            log
+                .debug("ordering before. from " + n.getPath() + "/"
+                        + srcChildPath + " to " + n.getPath() + "/"
+                        + destChildPath);
+        }
+
+        n.orderBefore(srcChildPath, destChildPath);
+
+        return false;
+    }
+
+    /**
+     * @return the destination child key
+     */
+    public String getDestChildKey() {
+        return destChildKey;
+    }
+
+    /**
+     * @param destChildRelPathKey
+     *        the destination child key to set
+     */
+    public void setDestChildKey(String destChildRelPathKey) {
+        this.destChildKey = destChildRelPathKey;
+    }
+
+    /**
+     * @return the source child key
+     */
+    public String getSrcChildKey() {
+        return srcChildKey;
+    }
+
+    /**
+     * @param srcChildRelPathKey
+     *        the source child key to set
+     */
+    public void setSrcChildKey(String srcChildRelPathKey) {
+        this.srcChildKey = srcChildRelPathKey;
+    }
+
+    /**
+     * @return the parent path key
+     */
+    public String getParentPathKey() {
+        return parentPathKey;
+    }
+
+    /**
+     * @param parentPathKey
+     *        the parent path key to set
+     */
+    public void setParentPathKey(String parentPathKey) {
+        this.parentPathKey = parentPathKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ReadValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ReadValue.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ReadValue.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/ReadValue.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Property;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Read the <code>Value</code> of the given <code>Property</code> and store
+ * it under the given <code>Context</code> attribute.
+ */
+public class ReadValue implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(ReadValue.class);
+
+    // ---------------------------- < keys >
+
+    /** property path key */
+    private String srcPathKey = "srcPath";
+
+    /** value index key */
+    private String srcIndexKey = "srcIndex";
+
+    /** destination context attribute */
+    private String destKey = "dest";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String path = (String) ctx.get(this.srcPathKey);
+        int index = 1;
+        if (ctx.get(this.srcIndexKey) != null) {
+            index = Integer.valueOf(((String) ctx.get(this.srcIndexKey)))
+                .intValue();
+        }
+
+        String dest = (String) ctx.get(this.destKey);
+
+        if (log.isDebugEnabled()) {
+            log.debug("reading value from " + path + "[" + index + "] to "
+                    + dest);
+        }
+
+        Property p = (Property) CommandHelper.getItem(ctx, path);
+
+        if (p.getDefinition().isMultiple()) {
+            ctx.put(dest, p.getValues()[index].getString());
+        } else {
+            ctx.put(dest, p.getValue().getString());
+        }
+        return false;
+    }
+
+    /**
+     * @return the destination key
+     */
+    public String getDestKey() {
+        return destKey;
+    }
+
+    /**
+     * @param destKey
+     *        the destination key to set
+     */
+    public void setDestKey(String destKey) {
+        this.destKey = destKey;
+    }
+
+    /**
+     * @return the source index key
+     */
+    public String getSrcIndexKey() {
+        return srcIndexKey;
+    }
+
+    /**
+     * @param srcIndexKey
+     *        the source index key to set
+     */
+    public void setSrcIndexKey(String srcIndexKey) {
+        this.srcIndexKey = srcIndexKey;
+    }
+
+    /**
+     * @return the source path key
+     */
+    public String getSrcPathKey() {
+        return srcPathKey;
+    }
+
+    /**
+     * @param srcPathKey
+     *        the source path key to set
+     */
+    public void setSrcPathKey(String srcPathKey) {
+        this.srcPathKey = srcPathKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Refresh.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Refresh.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Refresh.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/core/Refresh.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.standalone.cli.core;
+
+import javax.jcr.Item;
+import javax.jcr.Session;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Refresh the <code>Item</code> if specified or the <code>Session</code> to
+ * reflect the current saved state.
+ */
+public class Refresh implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(Refresh.class);
+
+    // ---------------------------- < keys >
+    /** keep changes key */
+    private String keepChangesKey = "keepChanges";
+
+    /** path to the node to refresh key */
+    private String pathKey = "path";
+
+    /**
+     * @return the keep changes key
+     */
+    public String getKeepChangesKey() {
+        return keepChangesKey;
+    }
+
+    /**
+     * @param keepChangesKey
+     *        the keep changes key to set
+     */
+    public void setKeepChangesKey(String keepChangesKey) {
+        this.keepChangesKey = keepChangesKey;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        boolean keepChanges = Boolean.valueOf(
+            (String) ctx.get(this.keepChangesKey)).booleanValue();
+
+        String path = (String) ctx.get(this.pathKey);
+
+        if (log.isDebugEnabled()) {
+            log.debug("refreshing. from node " + path);
+        }
+
+        if (path == null) {
+            Session s = CommandHelper.getSession(ctx);
+            s.refresh(keepChanges);
+        } else {
+            Item i = CommandHelper.getItem(ctx, path);
+            i.refresh(keepChanges);
+        }
+
+        return false;
+    }
+
+    /**
+     * @return the path key
+     */
+    public String getPathKey() {
+        return pathKey;
+    }
+
+    /**
+     * @param pathKey
+     *        the path key to set
+     */
+    public void setPathKey(String pathKey) {
+        this.pathKey = pathKey;
+    }
+}



Mime
View raw message