jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1855719 [4/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/info/AbstractLsNodes.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsNodes.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsNodes.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsNodes.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,783 @@
+/*
+ * 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.info;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * List nodes. <br>
+ * The following attributes will be used in order to customize the output:
+ * <ul>
+ * <li>pathKey</li>
+ * <li>uuidKey</li>
+ * <li>mixinKey</li>
+ * <li>nodesSizeKey</li>
+ * <li>propertiesSizeKey</li>
+ * <li>referencesSizeKey</li>
+ * <li>versionableKey</li>
+ * <li>lockableKey</li>
+ * <li>referenceableKey</li>
+ * <li>lockedKey</li>
+ * <li>hasLockKey</li>
+ * <li>newKey</li>
+ * <li>modifiedKey</li>
+ * </ul>
+ */
+public abstract class AbstractLsNodes extends AbstractLs {
+    /** bundle */
+    private static final ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** show path */
+    private String pathKey = "path";
+
+    /** show uuid */
+    private String uuidKey = "uuid";
+
+    /** show mixin */
+    private String mixinKey = "mixin";
+
+    /** show node size */
+    private String nodesSizeKey = "nodeSize";
+
+    /** show properties size */
+    private String propertiesSizeKey = "propertiesSize";
+
+    /** show references size */
+    private String referencesSizeKey = "referencesSize";
+
+    /** show is versionable */
+    private String versionableKey = "versionable";
+
+    /** show is lockable */
+    private String lockableKey = "lockable";
+
+    /** show is referenceable */
+    private String referenceableKey = "referenceable";
+
+    /** show is locked */
+    private String lockedKey = "locked";
+
+    /** show has lock */
+    private String hasLockKey = "hasLock";
+
+    /** show is new */
+    private String newKey = "new";
+
+    /** show is modified */
+    private String modifiedKey = "modified";
+
+    /** show lock tocken */
+    private String lockTokenKey = "lockToken";
+
+    /** uuid width */
+    private int uuidWidth = 36;
+
+    /** path width */
+    private int nameWidth = 30;
+
+    /** node type width */
+    private int nodeTypeWidth = 20;
+
+    /** node type width */
+    private int pathWidth = 40;
+
+    /** referenceable width */
+    private int mixinWidth = 30;
+
+    /**
+     * {@inheritDoc}
+     */
+    public final boolean execute(Context ctx) throws Exception {
+        OptionHolder oh = new OptionHolder(ctx);
+
+        // Get children
+        Iterator iter = getNodes(ctx);
+
+        // write header
+        writeHeader(ctx, oh);
+
+        int index = 0;
+
+        int maxItems = getMaxItems(ctx);
+
+        // Write item
+        while (iter.hasNext() && index < maxItems) {
+            Node n = (Node) iter.next();
+            writeItem(ctx, n, oh);
+            index++;
+        }
+
+        // Write footer
+        printFooter(ctx, iter);
+
+        return false;
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @return the <code>Node</code>s to show
+     * @throws RepositoryException if the current working <code>Repository</code> throws a <code>RepositoryException</code>
+     * @throws CommandException
+     */
+    protected abstract Iterator getNodes(Context ctx) throws CommandException,
+            RepositoryException;
+
+    /**
+     * Write a node to the current output
+     * @param ctx
+     *        the <code>Context</code>
+     * @param n
+     *        the <code>Node</code>
+     * @throws RepositoryException
+     * @throws CommandException
+     */
+    void writeItem(Context ctx, Node n, OptionHolder oh)
+            throws RepositoryException, CommandException {
+        // TODO do something with this long piece of code
+        Collection widths = new ArrayList();
+        Collection texts = new ArrayList();
+
+        widths.add(new Integer(this.nameWidth));
+
+        String name = n.getName();
+        if (n.getIndex() > 1) {
+            name += "[" + n.getIndex() + "]";
+        }
+        texts.add(name);
+
+        widths.add(new Integer(this.nodeTypeWidth));
+        texts.add(n.getPrimaryNodeType().getName());
+
+        // uuid
+        if (oh.isUuid()) {
+            widths.add(new Integer(this.uuidWidth));
+            if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
+                texts.add(n.getUUID());
+            } else {
+                texts.add("");
+            }
+        }
+
+        // is new
+        if (oh.isNew()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n.isNew()));
+        }
+
+        // is new
+        if (oh.isModified()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n.isModified()));
+        }
+
+        // mixin
+        if (oh.isMixin()) {
+            widths.add(new Integer(this.mixinWidth));
+            Collection mixins = new ArrayList();
+            // Assigned mixin types
+            NodeType[] assigned = n.getMixinNodeTypes();
+            for (int i = 0; i < assigned.length; i++) {
+                mixins.add(assigned[i].getName());
+            }
+
+            // Inherited mixin types
+            NodeType[] nt = n.getPrimaryNodeType().getSupertypes();
+            for (int i = 0; i < nt.length; i++) {
+                if (nt[i].isMixin()) {
+                    mixins.add(nt[i].getName());
+                }
+            }
+            texts.add(mixins);
+        }
+
+        // node size
+        if (oh.isNodesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Long.toString(n.getNodes().getSize()));
+        }
+
+        // prop size
+        if (oh.isPropertiesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Long.toString(n.getProperties().getSize()));
+        }
+
+        // ref size
+        if (oh.isReferencesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Long.toString(n.getReferences().getSize()));
+        }
+
+        // is versionable
+        if (oh.isVersionable()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n
+                .isNodeType(JcrConstants.MIX_VERSIONABLE)));
+        }
+
+        // is lockable
+        if (oh.isLockable()) {
+            widths.add(new Integer(this.longWidth));
+            texts
+                .add(Boolean.toString(n.isNodeType(JcrConstants.MIX_LOCKABLE)));
+        }
+
+        // is referenceable
+        if (oh.isReferenceable()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n
+                .isNodeType(JcrConstants.MIX_REFERENCEABLE)));
+        }
+
+        // is locked
+        if (oh.isLocked()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n.isLocked()));
+        }
+
+        // has lock
+        if (oh.isHasLock()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(Boolean.toString(n.holdsLock()));
+        }
+
+        // path
+        if (oh.isPath()) {
+            widths.add(new Integer(this.pathWidth));
+            texts.add(n.getPath());
+        }
+
+        // lock token
+        if (oh.isLockToken()) {
+            widths.add(new Integer(this.nameWidth));
+            if (n.isLocked()) {
+                texts.add(n.getLock().getLockToken());
+            } else {
+                texts.add("");
+            }
+        }
+
+        PrintHelper.printRow(ctx, widths, texts);
+    }
+
+    /**
+     * Prints the header
+     * @param ctx
+     *        the <code>Context</code>
+     * @throws CommandException
+     */
+    void writeHeader(Context ctx, OptionHolder oh) throws CommandException {
+        // TODO do something with this long piece of code
+        Collection widths = new ArrayList();
+        Collection texts = new ArrayList();
+        widths.add(new Integer(this.nameWidth));
+        texts.add(bundle.getString("word.name"));
+        widths.add(new Integer(this.nodeTypeWidth));
+        texts.add(bundle.getString("word.nodetype"));
+
+        // uuid
+        if (oh.isUuid()) {
+            widths.add(new Integer(this.uuidWidth));
+            texts.add("uuid");
+        }
+
+        // is new
+        if (oh.isNew()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.new"));
+        }
+
+        // is new
+        if (oh.isModified()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.modified"));
+        }
+
+        // mixin
+        if (oh.isMixin()) {
+            widths.add(new Integer(this.mixinWidth));
+            texts.add("mixin");
+        }
+
+        // node size
+        if (oh.isNodesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.nodes"));
+        }
+
+        // prop size
+        if (oh.isPropertiesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.properties"));
+        }
+
+        // ref size
+        if (oh.isReferencesSize()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.references"));
+        }
+
+        // is versionable
+        if (oh.isVersionable()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.versionable"));
+        }
+
+        // is lockable
+        if (oh.isLockable()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.lockable"));
+        }
+
+        // is referenceable
+        if (oh.isReferenceable()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.referenceable"));
+        }
+
+        // is locked
+        if (oh.isLocked()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("word.locked"));
+        }
+
+        // has lock
+        if (oh.isHasLock()) {
+            widths.add(new Integer(this.longWidth));
+            texts.add(bundle.getString("phrase.haslock"));
+        }
+
+        // path
+        if (oh.isPath()) {
+            widths.add(new Integer(this.pathWidth));
+            texts.add(bundle.getString("word.path"));
+        }
+
+        if (oh.isLockToken()) {
+            widths.add(new Integer(this.nameWidth));
+            texts.add(bundle.getString("word.locktoken"));
+        }
+
+        PrintHelper.printRow(ctx, widths, texts);
+        PrintHelper.printSeparatorRow(ctx, widths, '-');
+    }
+
+    /**
+     * option holder
+     */
+    private class OptionHolder {
+        /** show path */
+        private boolean path = false;
+
+        /** show uuid */
+        private boolean uuid = false;
+
+        /** show mixin */
+        private boolean mixin = false;
+
+        /** show node size */
+        private boolean nodesSize = false;
+
+        /** show properties size */
+        private boolean propertiesSize = false;
+
+        /** show references size */
+        private boolean referencesSize = false;
+
+        /** show is versionable */
+        private boolean versionable = false;
+
+        /** show is lockable */
+        private boolean lockable = false;
+
+        /** show is referenceable */
+        private boolean referenceable = false;
+
+        /** show is locked */
+        private boolean locked = false;
+
+        /** show has lock */
+        private boolean hasLock = false;
+
+        /** show is new */
+        private boolean new_ = false;
+
+        /** show is modified */
+        private boolean modified = false;
+
+        /** lock tokeb */
+        private boolean lockToken = false;
+
+        /** context */
+        private Context ctx;
+
+        /**
+         * @param key
+         *        the key the flag key
+         * @return the boolean value for the given key
+         */
+        private boolean getFlag(String key) {
+            boolean flag = false;
+            if (ctx.containsKey(key)) {
+                flag = Boolean.valueOf((String) ctx.get(key)).booleanValue();
+            }
+            return flag;
+        }
+
+        /**
+         * Constructor
+         * @param ctx
+         *        the <code>Context</code>
+         */
+        public OptionHolder(Context ctx) {
+            super();
+            this.ctx = ctx;
+            path = getFlag(pathKey);
+            uuid = getFlag(uuidKey);
+            mixin = getFlag(mixinKey);
+            nodesSize = getFlag(nodesSizeKey);
+            propertiesSize = getFlag(propertiesSizeKey);
+            referencesSize = getFlag(referencesSizeKey);
+            versionable = getFlag(versionableKey);
+            lockable = getFlag(lockableKey);
+            referenceable = getFlag(referenceableKey);
+            locked = getFlag(lockedKey);
+            hasLock = getFlag(hasLockKey);
+            new_ = getFlag(newKey);
+            modified = getFlag(modifiedKey);
+            lockToken = getFlag(lockTokenKey);
+        }
+
+        /**
+         * @return the has lock
+         */
+        public boolean isHasLock() {
+            return hasLock;
+        }
+
+        /**
+         * @return Returns the lockable.
+         */
+        public boolean isLockable() {
+            return lockable;
+        }
+
+        /**
+         * @return Returns the locked.
+         */
+        public boolean isLocked() {
+            return locked;
+        }
+
+        /**
+         * @return Returns the mixin.
+         */
+        public boolean isMixin() {
+            return mixin;
+        }
+
+        /**
+         * @return Returns the modified.
+         */
+        public boolean isModified() {
+            return modified;
+        }
+
+        /**
+         * @return Returns the new_.
+         */
+        public boolean isNew() {
+            return new_;
+        }
+
+        /**
+         * @return Returns the nodesSize.
+         */
+        public boolean isNodesSize() {
+            return nodesSize;
+        }
+
+        /**
+         * @return Returns the propertiesSize.
+         */
+        public boolean isPropertiesSize() {
+            return propertiesSize;
+        }
+
+        /**
+         * @return Returns the referenceable.
+         */
+        public boolean isReferenceable() {
+            return referenceable;
+        }
+
+        /**
+         * @return Returns the referencesSize.
+         */
+        public boolean isReferencesSize() {
+            return referencesSize;
+        }
+
+        /**
+         * @return Returns the uuid.
+         */
+        public boolean isUuid() {
+            return uuid;
+        }
+
+        /**
+         * @return Returns the versionable.
+         */
+        public boolean isVersionable() {
+            return versionable;
+        }
+
+        /**
+         * @return Returns the path.
+         */
+        public boolean isPath() {
+            return path;
+        }
+
+        public boolean isLockToken() {
+            return lockToken;
+        }
+    }
+
+    /**
+     * @return Returns the hasLockKey.
+     */
+    public String getHasLockKey() {
+        return hasLockKey;
+    }
+
+    /**
+     * @param hasLockKey
+     *        The hasLockKey to set.
+     */
+    public void setHasLockKey(String hasLockKey) {
+        this.hasLockKey = hasLockKey;
+    }
+
+    /**
+     * @return Returns the lockableKey.
+     */
+    public String getLockableKey() {
+        return lockableKey;
+    }
+
+    /**
+     * @param lockableKey
+     *        The lockableKey to set.
+     */
+    public void setLockableKey(String lockableKey) {
+        this.lockableKey = lockableKey;
+    }
+
+    /**
+     * @return Returns the lockedKey.
+     */
+    public String getLockedKey() {
+        return lockedKey;
+    }
+
+    /**
+     * @param lockedKey
+     *        The lockedKey to set.
+     */
+    public void setLockedKey(String lockedKey) {
+        this.lockedKey = lockedKey;
+    }
+
+    /**
+     * @return Returns the mixinKey.
+     */
+    public String getMixinKey() {
+        return mixinKey;
+    }
+
+    /**
+     * @param mixinKey
+     *        The mixinKey to set.
+     */
+    public void setMixinKey(String mixinKey) {
+        this.mixinKey = mixinKey;
+    }
+
+    /**
+     * @return Returns the modifiedKey.
+     */
+    public String getModifiedKey() {
+        return modifiedKey;
+    }
+
+    /**
+     * @param modifiedKey
+     *        The modifiedKey to set.
+     */
+    public void setModifiedKey(String modifiedKey) {
+        this.modifiedKey = modifiedKey;
+    }
+
+    /**
+     * @return Returns the newKey.
+     */
+    public String getNewKey() {
+        return newKey;
+    }
+
+    /**
+     * @param newKey
+     *        The new_Key to set.
+     */
+    public void setNewKey(String newKey) {
+        this.newKey = newKey;
+    }
+
+    /**
+     * @return Returns the nodesSizeKey.
+     */
+    public String getNodesSizeKey() {
+        return nodesSizeKey;
+    }
+
+    /**
+     * @param nodesSizeKey
+     *        The nodesSizeKey to set.
+     */
+    public void setNodesSizeKey(String nodesSizeKey) {
+        this.nodesSizeKey = nodesSizeKey;
+    }
+
+    /**
+     * @return Returns the pathKey.
+     */
+    public String getPathKey() {
+        return pathKey;
+    }
+
+    /**
+     * @param pathKey
+     *        The pathKey to set.
+     */
+    public void setPathKey(String pathKey) {
+        this.pathKey = pathKey;
+    }
+
+    /**
+     * @return Returns the propertiesSizeKey.
+     */
+    public String getPropertiesSizeKey() {
+        return propertiesSizeKey;
+    }
+
+    /**
+     * @param propertiesSizeKey
+     *        The propertiesSizeKey to set.
+     */
+    public void setPropertiesSizeKey(String propertiesSizeKey) {
+        this.propertiesSizeKey = propertiesSizeKey;
+    }
+
+    /**
+     * @return Returns the referenceableKey.
+     */
+    public String getReferenceableKey() {
+        return referenceableKey;
+    }
+
+    /**
+     * @param referenceableKey
+     *        The referenceableKey to set.
+     */
+    public void setReferenceableKey(String referenceableKey) {
+        this.referenceableKey = referenceableKey;
+    }
+
+    /**
+     * @return Returns the referencesSizeKey.
+     */
+    public String getReferencesSizeKey() {
+        return referencesSizeKey;
+    }
+
+    /**
+     * @param referencesSizeKey
+     *        The referencesSizeKey to set.
+     */
+    public void setReferencesSizeKey(String referencesSizeKey) {
+        this.referencesSizeKey = referencesSizeKey;
+    }
+
+    /**
+     * @return Returns the uuidKey.
+     */
+    public String getUuidKey() {
+        return uuidKey;
+    }
+
+    /**
+     * @param uuidKey
+     *        The uuidKey to set.
+     */
+    public void setUuidKey(String uuidKey) {
+        this.uuidKey = uuidKey;
+    }
+
+    /**
+     * @return Returns the versionableKey.
+     */
+    public String getVersionableKey() {
+        return versionableKey;
+    }
+
+    /**
+     * @param versionableKey
+     *        The versionableKey to set.
+     */
+    public void setVersionableKey(String versionableKey) {
+        this.versionableKey = versionableKey;
+    }
+
+    /**
+     * @return the lock token key
+     */
+    public String getLockTokenKey() {
+        return lockTokenKey;
+    }
+
+    /**
+     * @param lockTokenKey
+     *        the lock token to set
+     */
+    public void setLockTokenKey(String lockTokenKey) {
+        this.lockTokenKey = lockTokenKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsProperties.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsProperties.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/AbstractLsProperties.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,151 @@
+/*
+ * 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.info;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * List properties superclass
+ */
+public abstract class AbstractLsProperties extends AbstractLs {
+
+    /** bundle */
+    private static ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** length of length field */
+    private static final int LENGTH_LENGTH = 8;
+
+    /**
+     * {@inheritDoc}
+     */
+    public final boolean execute(Context ctx) throws Exception {
+        int[] width = new int[] {
+                30, longWidth, longWidth, LENGTH_LENGTH, 18
+        };
+
+        String header[] = new String[] {
+                bundle.getString("word.name"),
+                bundle.getString("word.multiple"),
+                bundle.getString("word.type"), bundle.getString("word.length"),
+                bundle.getString("word.preview")
+        };
+
+        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 + "]";
+            }
+
+            Collection row = new ArrayList();
+            row.add(p.getName());
+            row.add(multiple);
+            row.add(PropertyType.nameFromValue(p.getType()));
+            row.add(Long.toString(length));
+            // preview
+            if (p.getDefinition().isMultiple()) {
+                row.add(this.getMultiplePreview(p));
+            } else {
+                row.add(this.getPreview(p));
+            }
+
+            PrintHelper.printRow(ctx, width, row);
+            index++;
+        }
+
+        CommandHelper.getOutput(ctx).println();
+
+        // Write footer
+        printFooter(ctx, iter);
+
+        return false;
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @return collected <code>Property</code> s to display
+     * @throws Exception
+     *         if the <code>Property</code> s can't be retrieved
+     */
+    protected abstract Iterator getProperties(Context ctx) throws Exception;
+
+    /**
+     * @param property
+     * @return the first 50 characters of single value properties
+     * @throws RepositoryException
+     */
+    private String getPreview(Property p) throws RepositoryException {
+        String value = p.getValue().getString();
+        return value.substring(0, Math.min(value.length(), 50));
+    }
+
+    /**
+     * @param property
+     * @return a <code>Collection</code> in which element contains the first
+     *         50 characters of the <code>Value</code>'s string
+     *         representation
+     * @throws RepositoryException
+     * @throws ValueFormatException
+     */
+    private Collection getMultiplePreview(Property p)
+            throws ValueFormatException, RepositoryException {
+        Collection c = new ArrayList();
+        Value[] values = p.getValues();
+        for (int i = 0; i < values.length; i++) {
+            try {
+                String value = values[i].getString();
+                c.add(value.substring(0, Math.min(value.length(), 50)));
+            } catch (ValueFormatException e) {
+                c.add(bundle.getString("phrase.notavailable"));
+            }
+        }
+        return c;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Cat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Cat.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Cat.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Cat.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,168 @@
+/*
+ * 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.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.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Display the content of a <code>Property</code> or a <code>Node</code> of
+ * type nt:file or nt:resource.
+ */
+public class Cat implements Command {
+    /** property name */
+    private String pathKey = "path";
+
+    /** index. [optional] argument to display multivalue properties */
+    private String indexKey = "index";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String path = (String) ctx.get(this.pathKey);
+        Item item = CommandHelper.getItem(ctx, path);
+        if (item.isNode()) {
+            printNode(ctx, (Node) item);
+        } else {
+            printProperty(ctx, (Property) item);
+        }
+        return false;
+    }
+
+    /**
+     * @return the path key
+     */
+    public String getPathKey() {
+        return pathKey;
+    }
+
+    /**
+     * @param path
+     *        the path key to set
+     */
+    public void setPathKey(String path) {
+        this.pathKey = path;
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @param n
+     *        the <code>Node</code>
+     * @throws PathNotFoundException
+     * @throws CommandException
+     * @throws RepositoryException
+     * @throws IllegalStateException
+     * @throws IOException
+     */
+    private void printNode(Context ctx, Node n) throws PathNotFoundException,
+            CommandException, 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 CommandException("exception.cat.unsupported.type",
+                new String[] {
+                    n.getPrimaryNodeType().getName()
+                });
+        }
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @param p
+     *        the <code>Property</code>
+     * @throws CommandException
+     * @throws ValueFormatException
+     * @throws IllegalStateException
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    private void printProperty(Context ctx, Property p)
+            throws CommandException, ValueFormatException,
+            IllegalStateException, RepositoryException, IOException {
+        String indexStr = (String) ctx.get(this.indexKey);
+        int index = 0;
+        if (indexStr != null) {
+            index = Integer.parseInt(indexStr);
+        }
+        if (p.getDefinition().isMultiple()) {
+            printValue(ctx, p.getValues()[index]);
+        } else {
+            printValue(ctx, p.getValue());
+        }
+    }
+
+    /**
+     * Read the value
+     * @param ctx
+     *        the <code>Context</code>
+     * @param value
+     *        the <code>Value</code>
+     * @throws ValueFormatException
+     * @throws IllegalStateException
+     * @throws RepositoryException
+     * @throws IOException
+     */
+    private void printValue(Context ctx, Value value)
+            throws ValueFormatException, IllegalStateException,
+            RepositoryException, IOException {
+        PrintWriter out = CommandHelper.getOutput(ctx);
+        out.println();
+        BufferedReader in = new BufferedReader(new StringReader(value
+            .getString()));
+        String str = null;
+        while ((str = in.readLine()) != null) {
+            out.println(str);
+        }
+    }
+
+    /**
+     * @return the index key
+     */
+    public String getIndexKey() {
+        return indexKey;
+    }
+
+    /**
+     * @param indexKey
+     *        the index key to set
+     */
+    public void setIndexKey(String indexKey) {
+        this.indexKey = indexKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Describe.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Describe.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Describe.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Describe.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,34 @@
+/*
+ * 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.info;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+
+/**
+ * Describes the given <code>Node</code>.
+ */
+public class Describe implements Command {
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context arg0) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Dump.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Dump.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Dump.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Dump.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.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.standalone.cli.CommandHelper;
+
+/**
+ * Dump stored data from the current working <code>Node</code>
+ */
+public class Dump implements Command {
+    /** root node to dump */
+    private String pathKey = "path";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String path = (String) ctx.get(this.pathKey);
+        PrintWriter out = CommandHelper.getOutput(ctx);
+        dump(out, CommandHelper.getNode(ctx, path));
+        return false;
+    }
+
+    /**
+     * Dumps the given <code>Node</code> to the given <code>PrintWriter</code>
+     * @param out
+     *        the <code>PrintWriter</code>
+     * @param n
+     *        the <code>Node</code>
+     * @throws RepositoryException
+     */
+    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);
+        }
+    }
+
+    /**
+     * @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/info/Help.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Help.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Help.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Help.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,237 @@
+/*
+ * 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.info;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.jackrabbit.standalone.cli.AbstractParameter;
+import org.apache.jackrabbit.standalone.cli.Argument;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+import org.apache.jackrabbit.standalone.cli.CommandLine;
+import org.apache.jackrabbit.standalone.cli.CommandLineFactory;
+import org.apache.jackrabbit.standalone.cli.Flag;
+import org.apache.jackrabbit.standalone.cli.Option;
+
+/**
+ * Show available <code>Command</code>s. If a <code>Command</code> is
+ * specified it will show its description, usage and parameters.
+ */
+public class Help implements Command {
+    /** bundle */
+    private static ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** Command factory */
+    private CommandLineFactory factory = CommandLineFactory.getInstance();
+
+    /** Help formatter */
+    private HelpFormatter hf = new HelpFormatter();
+
+    /** command key */
+    private String commandKey = "command";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String command = (String) ctx.get(this.commandKey);
+        PrintWriter out = CommandHelper.getOutput(ctx);
+        out.println();
+        if (command == null) {
+            helpAll(ctx);
+        } else {
+            helpCommand(ctx);
+        }
+        return false;
+    }
+
+    /**
+     * Writes help for all the commands
+     * @param ctx
+     *        the current working <code>Context</code>
+     * @throws CommandException
+     */
+    private void helpAll(Context ctx) throws CommandException {
+        PrintWriter out = CommandHelper.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, 70, tabPos, buf.toString());
+        }
+    }
+
+    /**
+     * Writes detailed help for the given command
+     * @param ctx
+     *        the current working <code>Context</code>
+     * @throws CommandException
+     */
+    private void helpCommand(Context ctx) throws CommandException {
+        PrintWriter out = CommandHelper.getOutput(ctx);
+
+        String cmdName = (String) ctx.get(this.commandKey);
+
+        CommandLine desc = factory.getCommandLine(cmdName);
+
+        out.println(getString(bundle, "word.description") + ": ");
+        out.println(desc.getLocalizedDescription());
+        out.println();
+
+        // Usage
+        out.print(getString(bundle, "word.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(getString(bundle, "word.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("<" + getString(bundle, "word.arguments") + ">");
+            printParam(ctx, desc.getArguments().values());
+        }
+
+        // Options details
+        if (desc.getOptions().values().size() > 0) {
+            out.println();
+            out.println("<" + getString(bundle, "word.options") + ">");
+            printParam(ctx, desc.getOptions().values());
+        }
+
+        // flag details
+        if (desc.getFlags().values().size() > 0) {
+            out.println();
+            out.println("<" + getString(bundle, "word.flags") + ">");
+            printParam(ctx, desc.getFlags().values());
+        }
+
+    }
+
+    /**
+     * @param ctx
+     *        the current working <code>Context</code>
+     * @param params
+     *        the parameters
+     */
+    private void printParam(Context ctx, Collection params) {
+        int[] width = new int[] {
+                10, 10, 10, 40
+        };
+
+        String[] header = new String[] {
+                getString(bundle, "word.name"),
+                getString(bundle, "word.argument"),
+                getString(bundle, "word.required"),
+                getString(bundle, "word.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);
+        }
+
+    }
+
+    /**
+     * @return the command key
+     */
+    public String getCommandKey() {
+        return commandKey;
+    }
+
+    /**
+     * @param commandKey
+     *        the command key to set
+     */
+    public void setCommandKey(String commandKey) {
+        this.commandKey = commandKey;
+    }
+    
+    private String getString(ResourceBundle bundle, String key) {
+        try {
+            return bundle.getString(key) ;
+        } catch (MissingResourceException e) {
+            return "not available";
+        }
+          
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Info.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Info.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Info.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/Info.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,75 @@
+/*
+ * 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.info;
+
+import java.io.PrintWriter;
+
+import javax.jcr.Session;
+
+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;
+
+public class Info implements Command {
+
+    public boolean execute(Context ctx) throws Exception {
+        PrintWriter out = CommandHelper.getOutput(ctx);
+
+        out.println();
+
+        try {
+            CommandHelper.getRepository(ctx);
+        } catch (CommandException e) {
+            out.println("No connection to a repository.");
+            return false;
+        }
+
+        out.println("Repository: " + CommandHelper.getRepositoryAddress(ctx));
+
+        Session session;
+        String currentPath;
+        try {
+            session = CommandHelper.getSession(ctx);
+            currentPath = CommandHelper.getCurrentNode(ctx).getPath();
+        } catch (CommandException e) {
+            out.println("Not logged in / no session.");
+            return false;
+        }
+
+        out.println("User      : " + session.getUserID());
+        out.println("Workspace : " + session.getWorkspace().getName());
+        out.println("Node      : " + currentPath);
+
+        out.println();
+
+        if (session.isLive()) {
+            out.println("Session is live.");
+        } else {
+            out.println("Session is not live.");
+        }
+
+        if (session.hasPendingChanges()) {
+            out.println("Session has pending changes.");
+        } else {
+            out.println("Session has no changes.");
+        }
+
+        return false;
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/JcrInfoCommandException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/JcrInfoCommandException.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/JcrInfoCommandException.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/JcrInfoCommandException.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,70 @@
+/*
+ * 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.info;
+
+import org.apache.jackrabbit.standalone.cli.CommandException;
+
+/**
+ * Exception thrown by Info Commands
+ */
+public class JcrInfoCommandException extends CommandException {
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3257854259679866933L;
+
+    /**
+     * @param message
+     *        the message
+     */
+    public JcrInfoCommandException(String message) {
+        super(message);
+    }
+
+    /**
+     * @param message
+     *        the message
+     * @param arguments
+     *        the arguments
+     */
+    public JcrInfoCommandException(String message, Object[] arguments) {
+        super(message, arguments);
+    }
+
+    /**
+     * @param message
+     *        the message
+     * @param cause
+     *        the cause
+     */
+    public JcrInfoCommandException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * @param message
+     *        the message
+     * @param cause
+     *        the cause
+     * @param arguments
+     *        the arguments
+     */
+    public JcrInfoCommandException(String message, Throwable cause,
+        Object[] arguments) {
+        super(message, cause, arguments);
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedItems.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedItems.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedItems.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedItems.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,67 @@
+/*
+ * 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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+
+/**
+ * Lists collected <code>Item</code>s.<br>
+ * This <code>Command</code> looks for an <code>Iterator</code> under the
+ * given <code>Context</code> variable and lists its <code>Item</code>s.
+ */
+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 from
+     *        from key to set
+     */
+    public void setFromKey(String from) {
+        this.fromKey = from;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getItems(Context ctx) throws CommandException,
+            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;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedNodes.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedNodes.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedNodes.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedNodes.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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+
+/**
+ * Lists collected <code>Node</code>s.<br>
+ * This <code>Command</code> looks for an <code>Iterator</code> under the
+ * given <code>Context</code> variable and lists its <code>Node</code>s.
+ */
+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 <code>Context</code> variable
+     * @param contextVariable
+     *        the context variable
+     */
+    public void setFromKey(String contextVariable) {
+        this.fromKey = contextVariable;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getNodes(Context ctx) throws CommandException,
+            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;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedProperties.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedProperties.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsCollectedProperties.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,67 @@
+/*
+ * 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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+
+/**
+ * Lists collected <code>Property</code>s.<br>
+ * This <code>Command</code> looks for an <code>Iterator</code> under the
+ * given <code>Context</code> variable and lists its <code>Property</code>s.
+ */
+public class LsCollectedProperties extends AbstractLsProperties {
+    /** Context variable that holds the Iterator */
+    private String fromKey = "collected";
+
+    /**
+     * @return the from key
+     */
+    public String getFromKey() {
+        return fromKey;
+    }
+
+    /**
+     * @param fromKey
+     *        from key to set
+     */
+    public void setFromKey(String fromKey) {
+        this.fromKey = fromKey;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getProperties(Context ctx) throws CommandException,
+            RepositoryException {
+        // show the path
+        this.setPath(true);
+        Object o = ctx.get(fromKey);
+        if (o == null || !(o instanceof Iterator)) {
+            throw new JcrInfoCommandException(
+                "illegalargument.no.iterator.under", new String[] {
+                    fromKey
+                });
+        }
+        return (Iterator) o;
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsItems.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsItems.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsItems.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsItems.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,67 @@
+/*
+ * 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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * List items
+ * <ul>
+ * <li>name</li>
+ * <li>type</li>
+ * <li>isNode</li>
+ * <li>isNew</li>
+ * <li>isModified</li>
+ * </ul>
+ */
+public class LsItems extends AbstractLsItems {
+
+    /** name pattern key */
+    private String patternKey = "pattern";
+
+    /**
+     * @return the name pattern
+     */
+    public String getPatternKey() {
+        return patternKey;
+    }
+
+    /**
+     * @param pattern
+     *        the pattern
+     */
+    public void setPatternKey(String pattern) {
+        this.patternKey = pattern;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getItems(Context ctx) throws CommandException,
+            RepositoryException {
+        String pattern = (String) ctx.get(this.patternKey);
+        Node n = CommandHelper.getCurrentNode(ctx);
+        return CommandHelper.getItems(ctx, n, pattern);
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNamespaces.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNamespaces.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNamespaces.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNamespaces.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,33 @@
+/*
+ * 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.info;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+
+/**
+ * Lists the registered namespaces.
+ */
+public class LsNamespaces implements Command {
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        throw new UnsupportedOperationException();
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNodes.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNodes.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNodes.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsNodes.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,61 @@
+/*
+ * 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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * List the <code>Node</code>s under the current working <code>Node</code>
+ * that match the given pattern.
+ */
+public class LsNodes extends AbstractLsNodes {
+
+    /** name pattern key */
+    private String patternKey = "pattern";
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getNodes(Context ctx) throws CommandException,
+            RepositoryException {
+        String pattern = (String) ctx.get(this.patternKey);
+        Node n = CommandHelper.getCurrentNode(ctx);
+        return CommandHelper.getNodes(ctx, n, pattern);
+    }
+
+    /**
+     * @return the pattern key
+     */
+    public String getPatternKey() {
+        return patternKey;
+    }
+
+    /**
+     * @param patternKey
+     *        the pattern key to set
+     */
+    public void setPatternKey(String patternKey) {
+        this.patternKey = patternKey;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsProperties.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsProperties.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsProperties.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.info;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Property fields:
+ * <ul>
+ * <li>name</li>
+ * <li>multiple</li>
+ * <li>type</li>
+ * <li>length</li>
+ * </ul>
+ */
+public class LsProperties extends AbstractLsProperties {
+
+    /** property name pattern key */
+    private String patternKey = "pattern";
+
+    /**
+     * @return name pattern
+     */
+    public String getPatternKey() {
+        return patternKey;
+    }
+
+    /**
+     * Sets the name pattern
+     * @param pattern the pattern key
+     */
+    public void setPatternKey(String pattern) {
+        this.patternKey = pattern;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Iterator getProperties(Context ctx) throws CommandException,
+            RepositoryException {
+        String pattern = (String) ctx.get(this.patternKey);
+        Node n = CommandHelper.getCurrentNode(ctx);
+        return CommandHelper.getProperties(ctx, n, pattern);
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsReferences.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsReferences.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsReferences.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsReferences.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,90 @@
+/*
+ * 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.info;
+
+import java.util.ResourceBundle;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Displays references to the given <code>Node</code>
+ */
+public class LsReferences implements Command {
+    /** bundle */
+    private static ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** path to the <code>Node</code> key */
+    private String pathKey = "path";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String path = (String) ctx.get(this.pathKey);
+        Node n = CommandHelper.getNode(ctx, path);
+
+        // header
+        int[] width = new int[] {
+            60
+        };
+        String[] header = new String[] {
+            bundle.getString("word.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()
+            });
+        }
+
+        CommandHelper.getOutput(ctx).println();
+        CommandHelper.getOutput(ctx).println(
+            iter.getSize() + " " + bundle.getString("word.references"));
+
+        return false;
+    }
+
+    /**
+     * @return the path key
+     */
+    public String getPathKey() {
+        return pathKey;
+    }
+
+    /**
+     * @param path
+     *        the path key to set
+     */
+    public void setPathKey(String path) {
+        this.pathKey = path;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsVersions.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsVersions.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsVersions.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/LsVersions.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,88 @@
+/*
+ * 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.info;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.ResourceBundle;
+
+import javax.jcr.Node;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionIterator;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * List the <code>Version</code> s in the <code>VersionHistory</code>.
+ */
+public class LsVersions implements Command {
+    /** bundle */
+    private static ResourceBundle bundle = CommandHelper.getBundle();
+
+    /** path to the node */
+    private String pathKey = "path";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String path = (String) ctx.get(this.pathKey);
+        Node n = CommandHelper.getNode(ctx, path);
+
+        // header
+        int[] width = new int[] {
+                20, 50
+        };
+        String[] header = new String[] {
+                bundle.getString("word.version"),
+                bundle.getString("word.labels")
+        };
+        // print header
+        PrintHelper.printRow(ctx, width, header);
+        // print separator
+        PrintHelper.printSeparatorRow(ctx, width, '-');
+        VersionIterator iter = n.getVersionHistory().getAllVersions();
+        while (iter.hasNext()) {
+            Version v = iter.nextVersion();
+            Collection row = new ArrayList();
+            row.add(v.getName());
+            row.add(Arrays.asList(n.getVersionHistory().getVersionLabels(v)));
+            PrintHelper.printRow(ctx, width, row);
+        }
+
+        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/info/PrintHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/PrintHelper.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/PrintHelper.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/info/PrintHelper.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,206 @@
+/*
+ * 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.info;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.chain.Context;
+import org.apache.jackrabbit.standalone.cli.CommandException;
+import org.apache.jackrabbit.standalone.cli.CommandHelper;
+
+/**
+ * Utility class for printing
+ */
+final class PrintHelper {
+
+    /**
+     * private constructor
+     */
+    private PrintHelper() {
+        super();
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @param width
+     *        the columns width
+     * @param text
+     *        the 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 = CommandHelper.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
+     *        the <code>Context</code>
+     * @param width
+     *        the column width
+     * @param separator
+     *        the separator chr
+     */
+    public static void printSeparatorRow(
+        Context ctx,
+        int[] width,
+        char separator) {
+        PrintWriter out = CommandHelper.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
+     *        the <code>Context</code>
+     * @param width
+     *        the column width
+     * @param texts
+     *        the texts
+     * @throws CommandException
+     */
+    public static void printRow(Context ctx, int[] width, Collection texts)
+            throws CommandException {
+        String[] text = new String[width.length];
+        Iterator iter = texts.iterator();
+        int column = 0;
+        while (iter.hasNext()) {
+            Object o = iter.next();
+            if (o == null) {
+                text[column] = "";
+            } else 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 CommandException("exception.illegalargument");
+            }
+            column++;
+        }
+        printRow(ctx, width, text);
+    }
+
+    /**
+     * @param ctx
+     *        the <code>Context</code>
+     * @param widths
+     *        the column width
+     * @param texts
+     *        the texts
+     * @throws CommandException
+     */
+    public static void printRow(Context ctx, Collection widths, Collection texts)
+            throws CommandException {
+        printRow(ctx, convertWidth(widths), texts);
+    }
+
+    /**
+     * @param widths
+     *        the column width
+     * @return the column width
+     * @throws CommandException
+     */
+    private static int[] convertWidth(Collection widths)
+            throws CommandException {
+        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
+     *        the <code>Context</code>
+     * @param widths
+     *        the columns widths
+     * @param separator
+     *        the separator char
+     * @throws CommandException
+     */
+    public static void printSeparatorRow(
+        Context ctx,
+        Collection widths,
+        char separator) throws CommandException {
+        printSeparatorRow(ctx, convertWidth(widths), separator);
+    }
+
+}

Added: jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/lock/AddLockToken.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/lock/AddLockToken.java?rev=1855719&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/lock/AddLockToken.java (added)
+++ jackrabbit/trunk/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/cli/lock/AddLockToken.java Sun Mar 17 21:44:46 2019
@@ -0,0 +1,69 @@
+/*
+ * 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.lock;
+
+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;
+
+/**
+ * Add the given <code>Lock</code> token to the current <code>Session</code>
+ */
+public class AddLockToken implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(AddLockToken.class);
+
+    // ---------------------------- < keys >
+    /**
+     * token
+     */
+    private String tokenKey = "token";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String token = (String) ctx.get(this.tokenKey);
+        if (log.isDebugEnabled()) {
+            log
+                .debug("Adding lock token " + token
+                        + " to the current session.");
+        }
+        Session s = CommandHelper.getSession(ctx);
+        s.addLockToken(token);
+        return false;
+    }
+
+    /**
+     * @return the token key
+     */
+    public String getTokenKey() {
+        return tokenKey;
+    }
+
+    /**
+     * @param tokenKey
+     *        the token key to set
+     */
+    public void setTokenKey(String tokenKey) {
+        this.tokenKey = tokenKey;
+    }
+}



Mime
View raw message