jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r477140 - in /jackrabbit/trunk/contrib/jcr-commands: ./ src/java/org/apache/jackrabbit/command/ src/java/org/apache/jackrabbit/command/cli/ src/java/org/apache/jackrabbit/command/core/ src/java/org/apache/jackrabbit/command/fs/ src/java/org...
Date Mon, 20 Nov 2006 11:05:35 GMT
Author: edgarpoce
Date: Mon Nov 20 03:05:30 2006
New Revision: 477140

URL: http://svn.apache.org/viewvc?view=rev&rev=477140
Log:
- handle absolute paths in addnode, copy and move commands
- add setnamespaceprefix command
- lookup jcr session in httpsession in jcrcommandservlet

Added:
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetBinaryProperty.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/SetNamespacePrefix.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromInputStream.java
      - copied, changed from r473760, jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java
Removed:
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/fs/SetPropertyFromFile.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java
Modified:
    jackrabbit/trunk/contrib/jcr-commands/pom.xml
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command.xml
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties
    jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/web/JcrCommandServlet.java

Modified: jackrabbit/trunk/contrib/jcr-commands/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/pom.xml?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/pom.xml (original)
+++ jackrabbit/trunk/contrib/jcr-commands/pom.xml Mon Nov 20 03:05:30 2006
@@ -100,6 +100,13 @@
 			<version>1.0</version>
 			<scope>compile</scope>
 		</dependency>
+		
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.1</version>
+			<scope>compile</scope>
+		</dependency>			
 
 	</dependencies>
 

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command-line.xml
Mon Nov 20 03:05:30 2006
@@ -779,6 +779,20 @@
       default=","/>
   </command>
 
+  <command name="setnamespaceprefix" impl="setNamespacePrefix">
+    <alias name="setnsprefix"/>  
+    <argument
+      name="prefix"
+      position="0"
+      arg-name="word.prefix"
+      description="word.prefix"/>
+    <argument
+      name="uri"
+      position="1"
+      arg-name="word.uri"
+      description="word.uri"/>
+  </command>
+  
   <command name="setproperty" impl="setProperty">
     <alias name="setprop"/>
     <alias name="setp"/>

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command.xml?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command.xml
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/cli/command.xml
Mon Nov 20 03:05:30 2006
@@ -77,8 +77,13 @@
 		<command name="importFileSystem"
 			className="org.apache.jackrabbit.command.fs.ImportFileSystem"/>
 
-		<command name="importXmlFromFile"
-			className="org.apache.jackrabbit.command.xml.ImportXmlFromFile"/>
+		<chain name="importXmlFromFile">
+			<command name="fileToInputStream"
+				className="org.apache.jackrabbit.command.fs.FileToInputStream"
+				destKey="inputStream"/>
+			<command name="importXmlFromInputStream"
+				className="org.apache.jackrabbit.command.xml.ImportXmlFromInputStream"/>
+		</chain >
 
 		<command name="lock"
 			className="org.apache.jackrabbit.command.lock.Lock"/>
@@ -223,8 +228,15 @@
 		<command name="setProperty"
 			className="org.apache.jackrabbit.command.core.SetProperty"/>
 			
-		<command name="setPropertyFromFile"
-			className="org.apache.jackrabbit.command.fs.SetPropertyFromFile"/>
+		<chain name="setPropertyFromFile">
+			<command name="fileToInputStream"
+				className="org.apache.jackrabbit.command.fs.FileToInputStream"
+				srcFsPathKey="value"
+				destKey="inputStream"/>
+			<command name="setBinaryProperty"
+				className="org.apache.jackrabbit.command.core.SetBinaryProperty"
+				valueKey="inputStream"/>
+		</chain >
 
 		<command name="source"
 			className="org.apache.jackrabbit.command.cli.SourceCommand"/>
@@ -240,6 +252,9 @@
 				className="org.apache.commons.chain.generic.RemoveCommand"
 				fromKey="collected"/>
 		</chain>
+
+		<command name="setNamespacePrefix"
+			className="org.apache.jackrabbit.command.namespace.SetNamespacePrefix"/>
 
 		<command name="startJackrabbit"
 			className="org.apache.jackrabbit.command.ext.StartJackrabbit"/>

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/AddNode.java
Mon Nov 20 03:05:30 2006
@@ -51,6 +51,12 @@
             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 {
@@ -68,7 +74,7 @@
 
     /**
      * @param nodeTypeKey
-     *        Set the context attribute key for the node type attribute.
+     *            Set the context attribute key for the node type attribute.
      */
     public void setTypeKey(String nodeTypeKey) {
         this.typeKey = nodeTypeKey;
@@ -83,7 +89,7 @@
 
     /**
      * @param relPathKey
-     *        the relative path key to set
+     *            the relative path key to set
      */
     public void setRelPathKey(String relPathKey) {
         this.relPathKey = relPathKey;

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Copy.java
Mon Nov 20 03:05:30 2006
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.command.core;
 
+import javax.jcr.Item;
 import javax.jcr.Workspace;
 
 import org.apache.commons.chain.Command;
@@ -27,7 +28,9 @@
 /**
  * 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>.
+ * 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 */
@@ -64,6 +67,11 @@
                     + "] 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;
@@ -78,8 +86,9 @@
 
     /**
      * sets the destination absolute path key
+     * 
      * @param destAbsPathKey
-     *        the destination absolute path key
+     *            the destination absolute path key
      */
     public void setDestAbsPathKey(String destAbsPathKey) {
         this.destAbsPathKey = destAbsPathKey;
@@ -94,8 +103,9 @@
 
     /**
      * Sets the source absolute path key
+     * 
      * @param srcAbsPathKey
-     *        the source absolute path key
+     *            the source absolute path key
      */
     public void setSrcAbsPathKey(String srcAbsPathKey) {
         this.srcAbsPathKey = srcAbsPathKey;
@@ -110,8 +120,9 @@
 
     /**
      * Sets the source <code>Workspace</code> key
+     * 
      * @param srcWorkspaceKey
-     *        the source <code>Workspace</code> key
+     *            the source <code>Workspace</code> key
      */
     public void setSrcWorkspaceKey(String srcWorkspaceKey) {
         this.srcWorkspaceKey = srcWorkspaceKey;

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Move.java
Mon Nov 20 03:05:30 2006
@@ -18,7 +18,8 @@
 
 import java.util.ResourceBundle;
 
-import javax.jcr.Workspace;
+import javax.jcr.Item;
+import javax.jcr.Session;
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
@@ -43,6 +44,9 @@
     /** destination path */
     private String destAbsPathKey = "destAbsPath";
 
+    /** persistent key */
+    private String persistentKey = "persistent";
+
     /**
      * {@inheritDoc}
      */
@@ -50,21 +54,33 @@
         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")
+                    .getString("exception.illegalargument")
                     + ". "
                     + bundle.getString("exception.only.absolute.path")
                     + ".");
         }
 
-        Workspace w = CommandHelper.getSession(ctx).getWorkspace();
+        Session s = CommandHelper.getSession(ctx);
 
         if (log.isDebugEnabled()) {
             log.debug("moving node from " + srcAbsPath + " to " + destAbsPath);
         }
 
-        w.move(srcAbsPath, 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;
     }
@@ -78,7 +94,7 @@
 
     /**
      * @param destAbsPathKey
-     *        the destintation absolute path key to set
+     *            the destintation absolute path key to set
      */
     public void setDestAbsPathKey(String destAbsPathKey) {
         this.destAbsPathKey = destAbsPathKey;
@@ -93,9 +109,17 @@
 
     /**
      * @param srcAbsPathKey
-     *        the source absolute path key to set
+     *            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;
     }
 }

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Rename.java
Mon Nov 20 03:05:30 2006
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.command.core;
 
-import javax.jcr.Node;
+import javax.jcr.Item;
 import javax.jcr.Session;
 
 import org.apache.commons.chain.Command;
@@ -26,7 +26,9 @@
 import org.apache.jackrabbit.command.CommandHelper;
 
 /**
- * Rename a <code>Node<code>
+ * Rename a <code>Node<code><br>
+ * The persistent flag indicates whether to use the session or the workspace 
+ * to perform the move command
  */
 public class Rename implements Command {
     /** logger */
@@ -39,6 +41,9 @@
     /** destination path */
     private String destPathKey = "destPath";
 
+    /** persistent key */
+    private String persistentKey = "persistent";
+
     /**
      * {@inheritDoc}
      */
@@ -46,17 +51,29 @@
         String from = (String) ctx.get(this.srcPathKey);
         String to = (String) ctx.get(this.destPathKey);
 
+        boolean persistent = Boolean.valueOf(
+                (String) ctx.get(this.persistentKey)).booleanValue();
+
         if (log.isDebugEnabled()) {
             log.debug("renaming node from " + from + " to " + to);
         }
 
         Session s = CommandHelper.getSession(ctx);
-        Node nodeFrom = CommandHelper.getNode(ctx, from);
-        if (nodeFrom.getDepth() == 1) {
-            s.move(nodeFrom.getPath(), "/" + to);
+        Item itemFrom = CommandHelper.getItem(ctx, from);
+        if (itemFrom.getDepth() == 1) {
+            if (persistent) {
+                s.getWorkspace().move(itemFrom.getPath(), "/" + to);
+            } else {
+                s.move(itemFrom.getPath(), "/" + to);
+            }
         } else {
-            s.move(nodeFrom.getPath(), nodeFrom.getParent().getPath() + "/"
-                    + to);
+            if (persistent) {
+                s.getWorkspace().move(itemFrom.getPath(),
+                        itemFrom.getParent().getPath() + "/" + to);
+            } else {
+                s.move(itemFrom.getPath(), itemFrom.getParent().getPath() + "/"
+                        + to);
+            }
         }
 
         return false;
@@ -71,7 +88,7 @@
 
     /**
      * @param destPathKey
-     *        the destination path key to set
+     *            the destination path key to set
      */
     public void setDestPathKey(String destPathKey) {
         this.destPathKey = destPathKey;
@@ -86,9 +103,17 @@
 
     /**
      * @param srcPathKey
-     *        the source path key to set
+     *            the source path key to set
      */
     public void setSrcPathKey(String srcPathKey) {
         this.srcPathKey = srcPathKey;
+    }
+
+    public String getPersistentKey() {
+        return persistentKey;
+    }
+
+    public void setPersistentKey(String persistentKey) {
+        this.persistentKey = persistentKey;
     }
 }

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/Save.java
Mon Nov 20 03:05:30 2006
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.command.core;
 
-import javax.jcr.Node;
+import javax.jcr.Item;
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
@@ -25,7 +25,7 @@
 import org.apache.jackrabbit.command.CommandHelper;
 
 /**
- * Save the current working <code>Node</code> if specified, or the current
+ * Save the current working <code>Item</code> if specified, or the current
  * working <code>Session</code>
  */
 public class Save implements Command {
@@ -47,8 +47,8 @@
             CommandHelper.getSession(ctx).save();
         } else {
             log.debug("saving node at " + path);
-            Node n = CommandHelper.getNode(ctx, path);
-            n.save();
+            Item i = CommandHelper.getItem(ctx, path);
+            i.save();
         }
 
         return false;

Added: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetBinaryProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetBinaryProperty.java?view=auto&rev=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetBinaryProperty.java
(added)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/core/SetBinaryProperty.java
Mon Nov 20 03:05:30 2006
@@ -0,0 +1,54 @@
+/*
+ * 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.command.core;
+
+import java.io.InputStream;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.command.CommandHelper;
+
+/**
+ * Set a binary <code>Property</code>
+ */
+public class SetBinaryProperty extends AbstractSetProperty {
+    /** logger */
+    private static Log log = LogFactory.getLog(SetBinaryProperty.class);
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        InputStream value = (InputStream) ctx.get(this.valueKey);
+        String name = (String) ctx.get(this.nameKey);
+        String parent = (String) ctx.get(this.parentPathKey);
+
+        Node node = CommandHelper.getNode(ctx, parent);
+        if (log.isDebugEnabled()) {
+            log.debug("setting property to node at " + node.getPath()
+                    + ". property=" + name + " value=" + value);
+        }
+
+        node.setProperty(name, value);
+
+        return false;
+    }
+
+}

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/info/Help.java
Mon Nov 20 03:05:30 2006
@@ -19,6 +19,7 @@
 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;
@@ -111,12 +112,12 @@
 
         CommandLine desc = factory.getCommandLine(cmdName);
 
-        out.println(bundle.getString("word.description") + ": ");
+        out.println(getString(bundle, "word.description") + ": ");
         out.println(desc.getLocalizedDescription());
         out.println();
 
         // Usage
-        out.print(bundle.getString("word.usage") + ":");
+        out.print(getString(bundle, "word.usage") + ":");
         out.print(desc.getName() + " ");
 
         // Arguments
@@ -144,7 +145,7 @@
 
         // Alias
         if (desc.getAlias().size() > 0) {
-            out.print(bundle.getString("word.alias") + ":");
+            out.print(getString(bundle, "word.alias") + ":");
             iter = desc.getAlias().iterator();
             while (iter.hasNext()) {
                 out.print((String) iter.next() + " ");
@@ -156,21 +157,21 @@
 
         // Arguments details
         if (desc.getArguments().size() > 0) {
-            out.println("<" + bundle.getString("word.arguments") + ">");
+            out.println("<" + getString(bundle, "word.arguments") + ">");
             printParam(ctx, desc.getArguments().values());
         }
 
         // Options details
         if (desc.getOptions().values().size() > 0) {
             out.println();
-            out.println("<" + bundle.getString("word.options") + ">");
+            out.println("<" + getString(bundle, "word.options") + ">");
             printParam(ctx, desc.getOptions().values());
         }
 
         // flag details
         if (desc.getFlags().values().size() > 0) {
             out.println();
-            out.println("<" + bundle.getString("word.flags") + ">");
+            out.println("<" + getString(bundle, "word.flags") + ">");
             printParam(ctx, desc.getFlags().values());
         }
 
@@ -188,10 +189,10 @@
         };
 
         String[] header = new String[] {
-                bundle.getString("word.name"),
-                bundle.getString("word.argument"),
-                bundle.getString("word.required"),
-                bundle.getString("word.description")
+                getString(bundle, "word.name"),
+                getString(bundle, "word.argument"),
+                getString(bundle, "word.required"),
+                getString(bundle, "word.description")
         };
 
         PrintHelper.printRow(ctx, width, header);
@@ -223,5 +224,14 @@
      */
     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/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/SetNamespacePrefix.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/SetNamespacePrefix.java?view=auto&rev=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/SetNamespacePrefix.java
(added)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/namespace/SetNamespacePrefix.java
Mon Nov 20 03:05:30 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.command.namespace;
+
+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.command.CommandHelper;
+
+/**
+ * Sets a namespace prefix
+ */
+public class SetNamespacePrefix implements Command {
+    /** logger */
+    private static Log log = LogFactory.getLog(SetNamespacePrefix.class);
+
+    // ---------------------------- < keys >
+    /** prefix key */
+    private String prefixKey = "prefix";
+
+    /** uri key */
+    private String uriKey = "uri";
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean execute(Context ctx) throws Exception {
+        String prefix = (String) ctx.get(this.prefixKey);
+        String uri = (String) ctx.get(this.uriKey);
+        if (log.isDebugEnabled()) {
+            log.debug("setting namespace prefix uri=" + uri + " new prefix=" + prefix);
+        }
+        CommandHelper.getSession(ctx).setNamespacePrefix(prefix, uri);
+        return false;
+    }
+
+    /**
+     * @return the prefix key.
+     */
+    public String getPrefixKey() {
+        return prefixKey;
+    }
+
+    /**
+     * @param prefixKey
+     *        the prefix key to set
+     */
+    public void setPrefixKey(String prefixKey) {
+        this.prefixKey = prefixKey;
+    }
+
+    /**
+     * @return the uri key
+     */
+    public String getUriKey() {
+        return uriKey;
+    }
+
+    /**
+     * @param uriKey
+     *        the uri key to set
+     */
+    public void setUriKey(String uriKey) {
+        this.uriKey = uriKey;
+    }
+}

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/resources.properties
Mon Nov 20 03:05:30 2006
@@ -108,6 +108,7 @@
 cmd.save                           = Save the current working Node if specified, or the current
working Session
 cmd.setmultivalueproperty          = Set a multivalue Property to the current working Node.
The default regular expression is ",".
 cmd.setmultivalueproperty.regExp   = Regular expression used to split the value into tokens.
+cmd.setnamespaceprefix             = Sets a namespace prefix
 cmd.setproperty                    = Set a Property Value to the current working Node
 cmd.setproperty.name               = property name
 cmd.setproperty.type               = property type. Default is String.

Modified: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/web/JcrCommandServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/web/JcrCommandServlet.java?view=diff&rev=477140&r1=477139&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/web/JcrCommandServlet.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/web/JcrCommandServlet.java
Mon Nov 20 03:05:30 2006
@@ -36,157 +36,216 @@
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.config.ConfigParser;
 import org.apache.commons.chain.impl.CatalogFactoryBase;
+import org.apache.commons.lang.ClassUtils;
 import org.apache.jackrabbit.command.CommandHelper;
 import org.apache.log4j.Logger;
 
 /**
  * <p>
  * Servlet that handler jcr requests with commons-chain.<br>
- * Usage scenarion example: JCR Ajax server.
+ * Usage scenario example: JCR Ajax server.
  * </p>
  */
 public class JcrCommandServlet extends HttpServlet {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private static Logger log = Logger.getLogger(JcrCommandServlet.class);
+    private static Logger log = Logger.getLogger(JcrCommandServlet.class);
 
-	private static String CATALOG_KEY = "catalog";
+    private static String CATALOG_KEY = "catalog";
 
-	private static String JNDI_PROPERTIES_KEY = "jndi.properties";
+    private static String JNDI_PROPERTIES_KEY = "jndi.properties";
 
-	private static String JNDI_ADDRESS_KEY = "jndi.address";
+    private static String JNDI_ADDRESS_KEY = "jndi.address";
+
+    private static String USER_KEY = "user";
+
+    private static String PASSWORD_KEY = "password";
+
+    public static String COMMAND_KEY = "command";
+
+    public static String OUTPUT_FLAVOR_KEY = "flavor";
+
+    private static String DEFAULT_OUTPUT_FLAVOR = "text/plain";
+
+    private static String PRINT_SUCCESS_KEY = "print.success";
+
+    private static String SUCCESS_MESSAGE_KEY = "success.message.key";
+
+    private static String AUTO_SAVE_KEY = "auto.save";
+
+    private static String SESSION_KEY = "session.key";
+
+    /**
+     * key under which the jcr is stored in the http session
+     */
+    private String sessionKey = CommandHelper.SESSION_KEY;
+
+    /**
+     * flag that indicates whether a "success" string should be printed in the
+     * response
+     */
+    private boolean printSuccess;
+
+    /**
+     * Sucess message context key
+     */
+    private String successMessageKey = "success.message";
+
+    /**
+     * flag that indicates whether the changes should be saved automatically
+     */
+    private boolean autoSave;
+
+    /**
+     * jcr repository
+     */
+    private Repository repository;
+
+    /**
+     * user name to login
+     */
+    private String user;
+
+    /**
+     * password to login
+     */
+    private String password;
+
+    /**
+     * commons chain catalog
+     */
+    private Catalog catalog;
+
+    public void service(HttpServletRequest req, HttpServletResponse res)
+            throws ServletException, IOException {
+
+        // read parameters
+        String cmdName = req.getRequestURI().substring(
+                req.getContextPath().length() + req.getServletPath().length());
+        String flavor = req.getParameter(OUTPUT_FLAVOR_KEY);
+        if (flavor == null) {
+            flavor = DEFAULT_OUTPUT_FLAVOR;
+        }
+
+        // set content type
+        res.setContentType(flavor);
+        // try to get the jcr session from the httpsession
+        boolean closeSession = false;
+        Session session = (Session) req.getSession().getAttribute(
+                this.sessionKey);
+        try {
+            if (session == null) {
+                if (this.user == null) {
+                    session = this.repository.login(req.getRemoteUser());
+                } else {
+                    session = this.repository.login(new SimpleCredentials(
+                            this.user, this.password.toCharArray()));
+                }
+                // If a new session was created then close it after running the
+                // command
+                closeSession = true;
+            }
+
+            PrintWriter pw = null;
+            try {
+                // create context
+                JcrServletWebContext ctx = new JcrServletWebContext(session,
+                        getServletContext(), req, res);
+
+                // get writer
+                pw = CommandHelper.getOutput(ctx);
+
+                // lookup command
+                Command cmd = catalog.getCommand(cmdName);
+                if (cmd == null) {
+                    throw new IllegalArgumentException("command " + cmdName
+                            + " not found");
+                }
+
+                // execute command
+                cmd.execute(ctx);
+
+                if (this.autoSave) {
+                    // save changes
+                    session.save();
+                }
+
+                if (this.printSuccess) {
+                    // write success message
+                    String msg = (String) ctx.get(successMessageKey);
+                    if (msg == null) {
+                        pw.write("success");
+                    } else {
+                        pw.write(msg);
+                    }
+                }
+
+            } catch (Exception e) {
+                pw.write(ClassUtils.getShortClassName(e.getClass()) + "\n"
+                        + e.getMessage());
+            } finally {
+                pw.close();
+
+            }
+
+        } catch (Exception e) {
+            throw new ServletException(e);
+
+        } finally {
+            if (closeSession && session != null) {
+                session.logout();
+            }
+
+        }
+    }
+
+    public void init(ServletConfig cfg) throws ServletException {
+        super.init(cfg);
+
+        String jndiProperties = cfg.getInitParameter(JNDI_PROPERTIES_KEY);
+        String jndiAddress = cfg.getInitParameter(JNDI_ADDRESS_KEY);
+        this.user = cfg.getInitParameter(USER_KEY);
+        this.password = cfg.getInitParameter(PASSWORD_KEY);
+        
+        this.successMessageKey = cfg.getInitParameter(SUCCESS_MESSAGE_KEY);
+
+        if (cfg.getInitParameter(PRINT_SUCCESS_KEY) != null) {
+            this.printSuccess = Boolean.valueOf(cfg
+                    .getInitParameter(PRINT_SUCCESS_KEY));
+        }
+
+        if (cfg.getInitParameter(AUTO_SAVE_KEY) != null) {
+            this.autoSave = Boolean
+                    .valueOf(cfg.getInitParameter(AUTO_SAVE_KEY));
+        }
+
+        if (cfg.getInitParameter(SESSION_KEY) != null) {
+            this.sessionKey = cfg.getInitParameter(SESSION_KEY);
+        }
+
+        try {
+
+            // parse catalog
+            ConfigParser parser = new ConfigParser();
+            parser.parse(JcrCommandServlet.class.getClassLoader().getResource(
+                    cfg.getInitParameter(CATALOG_KEY)));
+            catalog = CatalogFactoryBase.getInstance().getCatalog();
+
+            // get repository
+            InputStream is = new ByteArrayInputStream(jndiProperties
+                    .getBytes("UTF-8"));
+            Properties props = new Properties();
+            props.load(is);
+            InitialContext ctx = new InitialContext(props);
+            this.repository = (Repository) ctx.lookup(jndiAddress);
+
+        } catch (Exception e) {
+            String msg = "unable to get repository through jndi";
+            log.error(msg, e);
+            throw new ServletException(msg, e);
 
-	private static String USER_KEY = "user";
-
-	private static String PASSWORD_KEY = "password";
-
-	public static String COMMAND_KEY = "command";
-
-	public static String OUTPUT_FLAVOR_KEY = "flavor";
-
-	private static String DEFAULT_OUTPUT_FLAVOR = "text/plain";
-
-	/**
-	 * jcr repository
-	 */
-	private Repository repository;
-
-	/**
-	 * user name to login
-	 */
-	private String user;
-
-	/**
-	 * password to login
-	 */
-	private String password;
-
-	/**
-	 * commons chain catalog
-	 */
-	private Catalog catalog;
-
-	public void service(HttpServletRequest req, HttpServletResponse res)
-			throws ServletException, IOException {
-
-		// read parameters
-		String cmdName = req.getParameter(COMMAND_KEY);
-		String flavor = req.getParameter(OUTPUT_FLAVOR_KEY);
-		if (flavor == null) {
-			flavor = DEFAULT_OUTPUT_FLAVOR;
-		}
-
-		// set content type
-		res.setContentType(flavor);
-
-		// process command
-		Session session = null;
-		try {
-
-			if (this.user == null) {
-				session = this.repository.login(req.getRemoteUser());
-			} else {
-				session = this.repository.login(new SimpleCredentials(
-						this.user, this.password.toCharArray()));
-			}
-
-			PrintWriter pw = null;
-			try {
-				// create context
-				JcrServletWebContext ctx = new JcrServletWebContext(session,
-						getServletContext(), req, res);
-
-				// get writer
-				pw = CommandHelper.getOutput(ctx);
-
-				// lookup command
-				Command cmd = catalog.getCommand(cmdName);
-				if (cmd == null) {
-					throw new IllegalArgumentException("command " + cmdName
-							+ " not found");
-				}
-
-				// execute command
-				cmd.execute(ctx);
-
-				// save changes
-				session.save();
-
-				// write success message
-				pw.write("success");
-
-			} catch (Exception e) {
-				// write error message
-				pw.write("an error occured\n");
-				pw.write(e.getMessage());
-
-			} finally {
-				pw.close();
-
-			}
-
-		} catch (Exception e) {
-			throw new ServletException(e);
-
-		} finally {
-			if (session != null) {
-				session.logout();
-			}
-
-		}
-	}
-
-	public void init(ServletConfig cfg) throws ServletException {
-		super.init(cfg);
-
-		String jndiProperties = cfg.getInitParameter(JNDI_PROPERTIES_KEY);
-		String jndiAddress = cfg.getInitParameter(JNDI_ADDRESS_KEY);
-		this.user = cfg.getInitParameter(USER_KEY);
-		this.password = cfg.getInitParameter(PASSWORD_KEY);
-
-		try {
-
-			// parse catalog
-			ConfigParser parser = new ConfigParser();
-			parser.parse(JcrCommandServlet.class.getClassLoader().getResource(
-					cfg.getInitParameter(CATALOG_KEY)));
-			catalog = CatalogFactoryBase.getInstance().getCatalog();
-
-			// get repository
-			InputStream is = new ByteArrayInputStream(jndiProperties
-					.getBytes("UTF-8"));
-			Properties props = new Properties();
-			props.load(is);
-			InitialContext ctx = new InitialContext(props);
-			this.repository = (Repository) ctx.lookup(jndiAddress);
-
-		} catch (Exception e) {
-			String msg = "unable to get repository through jndi";
-			log.error(msg, e);
-			throw new ServletException(msg, e);
-
-		}
-	}
+        }
+    }
 
 }

Copied: jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromInputStream.java
(from r473760, jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromInputStream.java?view=diff&rev=477140&p1=jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java&r1=473760&p2=jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromInputStream.java&r2=477140
==============================================================================
--- jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromFile.java
(original)
+++ jackrabbit/trunk/contrib/jcr-commands/src/java/org/apache/jackrabbit/command/xml/ImportXmlFromInputStream.java
Mon Nov 20 03:05:30 2006
@@ -17,26 +17,27 @@
 package org.apache.jackrabbit.command.xml;
 
 import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 
 import javax.jcr.Node;
 import javax.jcr.Session;
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.command.CommandException;
 import org.apache.jackrabbit.command.CommandHelper;
 
 /**
- * Import the xml view from the given file to the current working <code>Node</code>
+ * Import the xml view to the target <code>Node</code>
  */
-public class ImportXmlFromFile implements Command {
+public class ImportXmlFromInputStream implements Command {
 
     // ---------------------------- < keys >
 
     /** doc view file key */
-    private String srcFsPathKey = "srcFsPath";
+    private String inputStreamKey = "inputStream";
+
+    /** flag that indicates whether to use the transient space or not */
+    private String persistentKey = "persistent";
 
     /** target node */
     private String destJcrPathKey = "destJcrPath";
@@ -48,37 +49,25 @@
      * {@inheritDoc}
      */
     public boolean execute(Context ctx) throws Exception {
-        String file = (String) ctx.get(this.srcFsPathKey);
+        InputStream is = (InputStream) ctx.get(this.inputStreamKey);
         String dest = (String) ctx.get(this.destJcrPathKey);
+        String persistent = (String) ctx.get(this.persistentKey);
+
         int uuidBehaviour = Integer.valueOf(
-            (String) ctx.get(this.uuidBehaviourKey)).intValue();
-        File f = new File(file);
-        if (!f.exists()) {
-            throw new CommandException("exception.file.not.found",
-                new String[] {
-                    file
-                });
-        }
-        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+                (String) ctx.get(this.uuidBehaviourKey)).intValue();
+
+        BufferedInputStream bis = new BufferedInputStream(is);
         Session s = CommandHelper.getSession(ctx);
         Node n = CommandHelper.getNode(ctx, dest);
-        s.importXML(n.getPath(), in, uuidBehaviour);
-        return false;
-    }
 
-    /**
-     * @return the from key
-     */
-    public String getSrcFsPathKey() {
-        return srcFsPathKey;
-    }
+        if (persistent != null
+                && Boolean.valueOf(persistent).equals(Boolean.TRUE)) {
+            s.getWorkspace().importXML(n.getPath(), bis, uuidBehaviour);
+        } else {
+            s.importXML(n.getPath(), bis, uuidBehaviour);
+        }
 
-    /**
-     * @param fromKey
-     *        the from key to set
-     */
-    public void setSrcFsPathKey(String fromKey) {
-        this.srcFsPathKey = fromKey;
+        return false;
     }
 
     /**
@@ -90,7 +79,7 @@
 
     /**
      * @param uuidBehaviourKey
-     *        the uuidBehaviourKey to set
+     *            the uuidBehaviourKey to set
      */
     public void setUuidBehaviourKey(String uuidBehaviourKey) {
         this.uuidBehaviourKey = uuidBehaviourKey;
@@ -105,9 +94,39 @@
 
     /**
      * @param destJcrPathKey
-     *        the destination jcr path key to set
+     *            the destination jcr path key to set
      */
     public void setDestJcrPathKey(String destJcrPathKey) {
         this.destJcrPathKey = destJcrPathKey;
+    }
+
+    /**
+     * @return the inputStreamKey
+     */
+    public String getInputStreamKey() {
+        return inputStreamKey;
+    }
+
+    /**
+     * @param inputStreamKey
+     *            the inputStreamKey to set
+     */
+    public void setInputStreamKey(String inputStreamKey) {
+        this.inputStreamKey = inputStreamKey;
+    }
+
+    /**
+     * @return the persistentKey
+     */
+    public String getPersistentKey() {
+        return persistentKey;
+    }
+
+    /**
+     * @param persistentKey
+     *            the persistentKey to set
+     */
+    public void setPersistentKey(String persistentKey) {
+        this.persistentKey = persistentKey;
     }
 }



Mime
View raw message