jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r180346 [4/9] - in /incubator/jackrabbit/trunk/contrib/jcr-server: ./ client/ client/src/java/org/apache/jackrabbit/client/ client/src/java/org/apache/jackrabbit/webdav/client/methods/ commons/ commons/src/ commons/src/java/ commons/src/java/org/ commons/src/java/org/apache/ commons/src/java/org/apache/jackrabbit/ commons/src/java/org/apache/jackrabbit/nodetype/ commons/src/java/org/apache/jackrabbit/nodetype/xml/ commons/src/java/org/apache/jackrabbit/util/ commons/src/java/org/apache/jackrabbit/util/uuid/ commons/src/java/org/apache/jackrabbit/value/ server/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ server/src/java/org/apache/jackrabbit/server/jcr/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/webdav/jcr/ server/src/java/org/apache/jackrabbit/webdav/jcr/lock/ server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ server/src/java/org/apache/jackrabbit/webdav/jcr/observation/ server/src/java/org/apache/jackrabbit/webdav/jcr/property/ server/src/java/org/apache/jackrabbit/webdav/jcr/search/ server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/ server/src/java/org/apache/jackrabbit/webdav/jcr/version/ server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ server/src/java/org/apache/jackrabbit/webdav/simple/ webapp/ webapp/src/java/ webapp/src/java/org/ webapp/src/java/org/apache/ webapp/src/java/org/apache/jackrabbit/ webapp/src/java/org/apache/jackrabbit/j2ee/ webapp/src/webapp/ webapp/src/webapp/WEB-INF/ webdav/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/ webdav/src/java/org/apache/jackrabbit/webdav/lock/ webdav/src/java/org/apache/jackrabbit/webdav/property/ webdav/src/java/org/apache/jackrabbit/webdav/util/ webdav/src/java/org/apache/jackrabbit/webdav/version/report/
Date Mon, 06 Jun 2005 17:36:13 GMT
Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractContext.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractExportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractExportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractExportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractExportCommand.java Mon Jun  6 10:36:09 2005
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.JcrConstants;
-
 import javax.jcr.Node;
 
 /**
@@ -35,7 +31,7 @@
  * <li>jcr:mimeType
  * <ul>
  */
-public abstract class AbstractExportCommand implements Command, JcrConstants {
+public abstract class AbstractExportCommand extends AbstractCommand {
 
     /**
      * Executes this command by calling {@link #execute(ExportContext)} if
@@ -45,7 +41,7 @@
      * @return the return value of the delegated method or false;
      * @throws Exception in an error occurrs
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ExportContext) {
             return execute((ExportContext) context);
         } else {

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractImportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractImportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractImportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AbstractImportCommand.java Mon Jun  6 10:36:09 2005
@@ -16,17 +16,21 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.util.Text;
 
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 import java.io.InputStream;
 
 /**
  * This Class implements an abstract import command for a nc-resource.
  */
-public abstract class AbstractImportCommand implements Command, JcrConstants {
+public abstract class AbstractImportCommand extends AbstractCommand {
+
+    /**
+     * the nodetype for the node
+     */
+    private String nodeType = "nt:file";
 
     /**
      * Executes this command by calling {@link #importResource} if
@@ -36,7 +40,7 @@
      * @return the return value of the delegated method or false;
      * @throws Exception in an error occurrs
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ImportContext) {
             return execute((ImportContext) context);
         } else {
@@ -64,10 +68,52 @@
             // ignore imports
             return false;
         }
-        if (importResource(context, parentNode, in)) {
+        // check 'file' node
+        Node fileNode = parentNode.hasNode(context.getSystemId())
+            ? parentNode.getNode(context.getSystemId())
+            : parentNode.addNode(context.getSystemId(), nodeType);
+
+        if (importResource(context, fileNode, in)) {
             context.setInputStream(null);
         }
+        // set current node
+        context.setNode(fileNode);
         return false;
+    }
+
+    /**
+     * Creates collection recursively.
+     *
+     * @param root
+     * @param relPath
+     * @return
+     * @throws RepositoryException
+     */
+    static public Node mkDirs(ImportContext context, Node root, String relPath)
+            throws RepositoryException {
+        String[] seg = Text.explode(relPath, '/');
+        for (int i=0; i< seg.length; i++) {
+            if (!root.hasNode(seg[i])) {
+                // not quite correct
+                ImportContext subctx = context.createSubContext(root);
+                subctx.setSystemId(seg[i]);
+                try {
+                    ImportCollectionChain.getChain().execute(subctx);
+                } catch (Exception e) {
+                    throw new RepositoryException(e);
+                }
+            }
+            root = root.getNode(seg[i]);
+        }
+        return root;
+    }
+
+    /**
+     * Sets the node type
+     * @param nodeType
+     */
+    public void setNodeType(String nodeType) {
+        this.nodeType = nodeType;
     }
 
     /**

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddMixinCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddMixinCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddMixinCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddMixinCommand.java Mon Jun  6 10:36:09 2005
@@ -16,17 +16,13 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.JcrConstants;
-
 import javax.jcr.Node;
 
 /**
  * This Class implements a import command that adds a mixin node type to the
  * current node.
  */
-public class AddMixinCommand implements Command, JcrConstants {
+public class AddMixinCommand extends AbstractCommand {
 
     /**
      * the mixin node type to add
@@ -74,7 +70,7 @@
      * @return <code>false</code>.
      * @throws Exception if an error occurrs.
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ImportContext) {
             return execute((ImportContext) context);
         } else {
@@ -94,7 +90,9 @@
         if (nodeType == null) {
             throw new IllegalArgumentException("AddMixinCommand needs 'nodeType' attribute.");
         }
-        parentNode.addMixin(nodeType);
+        if (!parentNode.isNodeType(nodeType)) {
+            parentNode.addMixin(nodeType);
+        }
         return false;
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddNodeCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddNodeCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddNodeCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/AddNodeCommand.java Mon Jun  6 10:36:09 2005
@@ -16,17 +16,13 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.JcrConstants;
-
 import javax.jcr.Node;
 
 /**
  * This Class implements a import command that adds a mixin node type to the
  * current node.
  */
-public class AddNodeCommand implements Command, JcrConstants {
+public class AddNodeCommand extends AbstractCommand {
 
     /**
      * the nodetype to be added.
@@ -74,7 +70,7 @@
      * @return <code>false</code>.
      * @throws Exception if an error occurrs.
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ImportContext) {
             return execute((ImportContext) context);
         } else {

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.server.io;
+
+import javax.jcr.Node;
+
+/**
+ * This Class implements a import command that saves the current node.
+ */
+public class CheckinCommand extends AbstractCommand {
+
+    /**
+     * Executes this command by delegating to {@link #execute(ImportContext)} if
+     * the context has the correct class.
+     *
+     * @param context the (import) context.
+     * @return <code>false</code>.
+     * @throws Exception if an error occurrs.
+     */
+    public boolean execute(AbstractContext context) throws Exception {
+        if (context instanceof ImportContext) {
+            return execute((ImportContext) context);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Adds the mixin nodetype to the current import node.
+     * 
+     * @param context the import context.
+     * @return <code>false</code>
+     * @throws Exception if an error occurrs.
+     */
+    public boolean execute(ImportContext context) throws Exception {
+        Node node = context.getNode();
+        if (node.isNodeType(MIX_VERSIONABLE)) {
+            node.checkin();
+        }
+        return false;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/CheckinCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DirListingExportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DirListingExportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DirListingExportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DirListingExportCommand.java Mon Jun  6 10:36:09 2005
@@ -16,10 +16,7 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.webdav.util.Text;
-import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.util.Text;
 
 import javax.jcr.Node;
 import javax.jcr.Repository;
@@ -28,18 +25,27 @@
 import java.io.FileOutputStream;
 import java.io.PrintWriter;
 import java.io.FileInputStream;
+import java.util.HashSet;
 
 /**
  * This Class implements a collection export command that produces a HTML
- * directory listing of all child nodes. All child nodes having the
- * {@link #getCollectionNodeType()} result in a directory link.
+ * directory listing of all child nodes. If {@link #isCollectionNodeType(String)}
+ * returns true, when passed the primary node type of a child node, the result
+ * will be a directory link.<p/>
+ * The corresponding mapping is retrieved from the catalog. By default if no
+ * behaviour is specified, nodes are displayed as directories.
  */
-public class DirListingExportCommand implements Command, JcrConstants {
+public class DirListingExportCommand extends AbstractCommand {
 
     /**
-     * the node type of a collection
+     * define which node types define collection resources
      */
-    private String collectionNodeType = NT_FOLDER;
+    private HashSet collectionNodeTypes = new HashSet();
+
+    /**
+     * define which node types don't define collection resources
+     */
+    private HashSet nonCollectionNodeTypes = new HashSet();
 
     /**
      * Creates a DirListingExportCommand
@@ -48,31 +54,45 @@
     }
 
     /**
-     * Creates a DirListingExportCommand with the given collection node type.
+     * Returns true if the given the node type name denotes a collection.
      *
-     * @param collectionNodeType
+     * @return true if the given the node type name denotes a collection node.
      */
-    public DirListingExportCommand(String collectionNodeType) {
-        this.collectionNodeType = collectionNodeType;
+    public boolean isCollectionNodeType(String nodeTypeName) {
+        if (nonCollectionNodeTypes.isEmpty()) {
+            // check collection-set
+            return collectionNodeTypes.contains(nodeTypeName);
+        } else {
+            // check non-collection-set
+            return !nonCollectionNodeTypes.contains(nodeTypeName);
+        }
     }
 
     /**
-     * Returns the node type of a collection node.
+     * Defines the given node type names to represent collection nodes.
+     * Child nodes having this node type result in a directory link.
      *
-     * @return the node type of a collection node.
+     * @param nodeTypeNames comma separated String value
      */
-    public String getCollectionNodeType() {
-        return collectionNodeType;
+    public void setCollectionNodeTypes(String nodeTypeNames) {
+        String[] names = nodeTypeNames.split(",");
+        for (int i = 0; i < names.length; i++) {
+            collectionNodeTypes.add(names[i].trim());
+        }
     }
 
     /**
-     * Sets the node type of collection nodes. child nodes having this node
-     * type result in a directory link.
+     * Defines the given node type names to represent non-collection nodes.
+     * Child nodes having this node type will never result in a directory
+     * link.
      *
-     * @param collectionNodeType
+     * @param nodeTypeNames comma separated String value
      */
-    public void setCollectionNodeType(String collectionNodeType) {
-        this.collectionNodeType = collectionNodeType;
+    public void setNonCollectionNodeTypes(String nodeTypeNames) {
+        String[] names = nodeTypeNames.split(",");
+        for (int i = 0; i < names.length; i++) {
+             nonCollectionNodeTypes.add(names[i].trim());
+        }
     }
 
     /**
@@ -83,7 +103,7 @@
      * @return <code>false</code>.
      * @throws Exception if an error occurrs.
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ExportContext) {
             return execute((ExportContext) context);
         } else {
@@ -125,7 +145,7 @@
             String label = Text.getLabel(child.getPath());
             writer.print("<li><a href=\"");
             writer.print(Text.escape(label));
-            if (child.getPrimaryNodeType().getName().equals(collectionNodeType)) {
+            if (isCollectionNodeType(child.getPrimaryNodeType().getName())) {
                 writer.print("/");
             }
             writer.print("\">");

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportCollectionChain.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportCollectionChain.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportCollectionChain.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportCollectionChain.java Mon Jun  6 10:36:09 2005
@@ -20,16 +20,17 @@
 import org.apache.commons.chain.impl.CatalogFactoryBase;
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Catalog;
-import org.apache.jackrabbit.JcrConstants;
 
 /**
  * This Class implements a default chain for exporting collection resources.
  * It adds the following commands:
  * <ul>
- * <li>{@link DirListingExportCommand}("nt:folder").
+ * <li>{@link DirListingExportCommand}()
  * </ul>
+ *
+ * @see DirListingExportCommand
  */
-public class ExportCollectionChain extends ChainBase implements JcrConstants {
+public class ExportCollectionChain extends ChainBase {
 
     /**
      * the name of this chain
@@ -41,7 +42,7 @@
      */
     public ExportCollectionChain() {
         super();
-        addCommand(new DirListingExportCommand(NT_FOLDER));
+        addCommand(new DirListingExportCommand());
     }
 
     /**

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportContext.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportContext.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportContext.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ExportContext.java Mon Jun  6 10:36:09 2005
@@ -16,10 +16,9 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.impl.ContextBase;
-
 import javax.jcr.Node;
 import java.io.InputStream;
+import java.util.Properties;
 
 /**
  * This Class implements a export context which is passed to the respective
@@ -30,7 +29,7 @@
  * information is not needed in any of the known export commands but leaves this
  * I/O framework more generic.
  */
-public class ExportContext extends ContextBase {
+public class ExportContext extends AbstractContext {
 
     /**
      * the node to be exported
@@ -65,11 +64,34 @@
     /**
      * Creates a new ExportContext for the given node
      *
+     * @param exportRoot
+     */
+    public ExportContext(Node exportRoot) {
+        this(null, exportRoot);
+    }
+
+    /**
+     * Creats a new import context with the given root node and property defaults.
+     * @param props
+     * @param exportRoot
+     */
+    public ExportContext(Properties props, Node exportRoot) {
+        super(props);
+        if (exportRoot == null) {
+            throw new IllegalArgumentException("exportRoot can not be null.");
+        }
+        this.node = exportRoot;
+    }
+
+    /**
+     * Creates a new sub context which bases on this contexts properties
      * @param node
+     * @return
      */
-    public ExportContext(Node node) {
-        this.node = node;
+    public ExportContext createSubContext(Node node) {
+        return new ExportContext(this, node);
     }
+
 
     /**
      * Returns the input stream

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileExportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileExportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileExportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/FileExportCommand.java Mon Jun  6 10:36:09 2005
@@ -74,7 +74,7 @@
      */
     public boolean canHandle(Node node) {
         try {
-            return node.hasNode(JCR_CONTENT) && node.getNode(JCR_CONTENT).isNodeType(NT_RESOURCE);
+            return node.isNodeType(NT_RESOURCE) || node.hasNode(JCR_CONTENT) && node.getNode(JCR_CONTENT).isNodeType(NT_RESOURCE);
         } catch (RepositoryException e) {
             return false;
         }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportContext.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportContext.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportContext.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportContext.java Mon Jun  6 10:36:09 2005
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.impl.ContextBase;
-
 import javax.jcr.Node;
 import java.io.InputStream;
 
@@ -33,7 +31,7 @@
  * information is not needed in any of the known import commands but leaves this
  * I/O framework more generic.
  */
-public class ImportContext extends ContextBase {
+public class ImportContext extends AbstractContext {
 
     /**
      * The import root node, i.e. the parent node of the new content.
@@ -71,6 +69,16 @@
      * @param importRoot the import root node
      */
     public ImportContext(Node importRoot) {
+        this(null, importRoot);
+    }
+
+    /**
+     * Creats a new import context with the given root node and property defaults.
+     * @param base
+     * @param importRoot
+     */
+    public ImportContext(ImportContext base, Node importRoot) {
+        super(base);
         if (importRoot == null) {
             throw new IllegalArgumentException("importRoot can not be null.");
         }
@@ -78,6 +86,15 @@
     }
 
     /**
+     * Creates a new sub context which bases on this contexts properties
+     * @param importRoot
+     * @return
+     */
+    public ImportContext createSubContext(Node importRoot) {
+        return new ImportContext(this, importRoot);
+    }
+
+    /**
      * Retruns the input stream of the resource to import.
      * @return the input stream.
      */
@@ -170,4 +187,5 @@
     public void setModificationTime(long modificationTime) {
         this.modificationTime = modificationTime;
     }
-}
+
+}
\ No newline at end of file

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportResourceChain.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportResourceChain.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportResourceChain.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ImportResourceChain.java Mon Jun  6 10:36:09 2005
@@ -45,9 +45,8 @@
     public ImportResourceChain() {
         super();
         addCommand(new SetContentTypeCommand());
-        addCommand(new AddNodeCommand(NT_FILE));
-        addCommand(new AddMixinCommand(MIX_VERSIONABLE));
         addCommand(new FileImportCommand());
+        addCommand(new AddMixinCommand(MIX_VERSIONABLE));
     }
 
     /**

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.server.io;
+
+import java.util.Properties;
+import java.io.IOException;
+
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * This Class implements a very simple mime type resolver.
+ */
+public class MimeResolver {
+
+    /**
+     * the loaded mime types
+     */
+    private Properties mimeTypes = new Properties();
+
+    /**
+     * the default mime type
+     */
+    private String defaultMimeType = "application/octet-stream";
+
+    /**
+     * Creates a new mime resolver.
+     */
+    public MimeResolver() {
+        try {
+            // init the mime types
+            mimeTypes.load(getClass().getResourceAsStream("mimetypes.properties"));
+        } catch (IOException e) {
+            throw new InternalError("Unable to load mimetypes: " + e.toString());
+        }
+    }
+
+    /**
+     * Returns the default mime type
+     * @return
+     */
+    public String getDefaultMimeType() {
+	return defaultMimeType;
+    }
+
+    /**
+     * Sets the default mime type
+     * @param defaultMimeType
+     */
+    public void setDefaultMimeType(String defaultMimeType) {
+	this.defaultMimeType = defaultMimeType;
+    }
+
+    /**
+     * Retrusn the mime type for the given name.
+     * @param filename
+     * @return
+     */
+    public String getMimeType(String filename) {
+	String ext = Text.getLabel(filename, '.');
+        if (ext.equals("")) {
+            ext = filename;
+        }
+	return mimeTypes.getProperty(ext.toLowerCase(), defaultMimeType);
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/MimeResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/PrimaryItemExportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/PrimaryItemExportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/PrimaryItemExportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/PrimaryItemExportCommand.java Mon Jun  6 10:36:09 2005
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.jackrabbit.JcrConstants;
-
 import javax.jcr.Node;
 import javax.jcr.Item;
 import javax.jcr.ItemNotFoundException;
@@ -33,7 +29,7 @@
  * exporting node.
  * </p>
  */
-public class PrimaryItemExportCommand implements Command, JcrConstants {
+public class PrimaryItemExportCommand extends AbstractCommand {
 
     /**
      * Executes this command by calling {@link #execute(ExportContext)} if
@@ -43,7 +39,7 @@
      * @return the return value of the delegated method or false;
      * @throws Exception in an error occurrs
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ExportContext) {
             return execute((ExportContext) context);
         } else {

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.server.io;
+
+import javax.jcr.Node;
+
+/**
+ * This Class implements a import command that saves the current node.
+ */
+public class SaveCommand extends AbstractCommand {
+
+    /**
+     * Executes this command by delegating to {@link #execute(ImportContext)} if
+     * the context has the correct class.
+     *
+     * @param context the (import) context.
+     * @return <code>false</code>.
+     * @throws Exception if an error occurrs.
+     */
+    public boolean execute(AbstractContext context) throws Exception {
+        if (context instanceof ImportContext) {
+            return execute((ImportContext) context);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Saves the node or its parent node if this is new.
+     * 
+     * @param context the import context.
+     * @return <code>false</code>
+     * @throws Exception if an error occurrs.
+     */
+    public boolean execute(ImportContext context) throws Exception {
+        Node node = context.getNode();
+        if (node.isNew()) {
+            node = node.getParent();
+        }
+        if (!node.isNew()) {
+            node.save();
+        }
+        return false;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SaveCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SetContentTypeCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SetContentTypeCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SetContentTypeCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/SetContentTypeCommand.java Mon Jun  6 10:36:09 2005
@@ -16,16 +16,18 @@
  */
 package org.apache.jackrabbit.server.io;
 
-import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-
 /**
  * This Class implements...
  *
  * @author tripod
  * @version $Revision:$, $Date:$
  */
-public class SetContentTypeCommand implements Command {
+public class SetContentTypeCommand extends AbstractCommand {
+
+    /**
+     * the mime resolver
+     */
+    private MimeResolver resolver = new MimeResolver();
 
     /**
      * Executes this command by calling {@link #execute(ImportContext)} if
@@ -35,7 +37,7 @@
      * @return the return value of the delegated method or false;
      * @throws Exception in an error occurrs
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ImportContext) {
             return execute((ImportContext) context);
         } else {
@@ -54,14 +56,7 @@
     public boolean execute(ImportContext context) throws Exception {
         if (context.getContentType() == null) {
             String name = context.getSystemId();
-            // todo: add extensible list
-            if (name.endsWith(".xml")) {
-                context.setContentType("text/xml");
-            } else if (name.endsWith(".zip")) {
-                context.setContentType("application/zip");
-            } else {
-                context.setContentType("application/octet-stream");
-            }
+            context.setContentType(resolver.getMimeType(name));
         }
         return false;
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLExportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLExportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLExportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLExportCommand.java Mon Jun  6 10:36:09 2005
@@ -91,6 +91,10 @@
      * @throws Exception if an error occurrs.
      */
     public boolean exportNode(ExportContext context, Node content) throws Exception {
+        // first child of content is document root
+        if (content.getNodes().hasNext()) {
+            content = content.getNodes().nextNode();
+        }
         File tmpfile = File.createTempFile("__webdav", ".xml");
         FileOutputStream out = new FileOutputStream(tmpfile);
         if (mode.equals(MODE_DOCVIEW)) {

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLImportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLImportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLImportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/XMLImportCommand.java Mon Jun  6 10:36:09 2005
@@ -18,6 +18,7 @@
 
 import javax.jcr.Node;
 import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.RepositoryException;
 import java.io.InputStream;
 import java.util.Calendar;
 
@@ -38,6 +39,11 @@
     public static final String XML_CONTENT_TYPE = "text/xml";
 
     /**
+     * the node type for the jcr:content node
+     */
+    private String contentNodeType = NT_UNSTRUCTURED;
+
+    /**
      * Imports the resource by deseriaizing the xml.
      * @param ctx
      * @param parentNode
@@ -50,13 +56,21 @@
             throws Exception {
         Node content = parentNode.hasNode(JCR_CONTENT)
                 ? parentNode.getNode(JCR_CONTENT)
-                : parentNode.addNode(JCR_CONTENT, NT_UNSTRUCTURED);
-        content.setProperty(JCR_MIMETYPE, ctx.getContentType());
+                : parentNode.addNode(JCR_CONTENT, contentNodeType);
+        try {
+            content.setProperty(JCR_MIMETYPE, ctx.getContentType());
+        } catch (RepositoryException e) {
+            // ignore, since given nodetype could not allow mimetype
+        }
         Calendar lastMod = Calendar.getInstance();
         if (ctx.getModificationTime() != 0) {
             lastMod.setTimeInMillis(ctx.getModificationTime());
         }
-        content.setProperty(JCR_LASTMODIFIED, lastMod);
+        try {
+            content.setProperty(JCR_LASTMODIFIED, lastMod);
+        } catch (RepositoryException e) {
+            // ignore
+        }
         parentNode.getSession().importXML(content.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
         return true;
     }
@@ -69,5 +83,22 @@
      */
     public boolean canHandle(String contentType) {
         return XML_CONTENT_TYPE.equals(contentType);
+    }
+
+    /**
+     * Returns the nodetype for the jcr:content node
+     * @return
+     */
+    public String getContentNodeType() {
+        return contentNodeType;
+    }
+
+    /**
+     * Sets the nodetype for the jcr:content node.
+     *
+     * @param contentNodeType
+     */
+    public void setContentNodeType(String contentNodeType) {
+        this.contentNodeType = contentNodeType;
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ZIPImportCommand.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ZIPImportCommand.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ZIPImportCommand.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/ZIPImportCommand.java Mon Jun  6 10:36:09 2005
@@ -17,13 +17,9 @@
 package org.apache.jackrabbit.server.io;
 
 import org.apache.log4j.Logger;
-import org.apache.jackrabbit.webdav.util.Text;
-import org.apache.jackrabbit.JcrConstants;
-import org.apache.commons.chain.Context;
-import org.apache.commons.chain.Command;
+import org.apache.jackrabbit.util.Text;
 
 import javax.jcr.Node;
-import javax.jcr.RepositoryException;
 import java.io.InputStream;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipEntry;
@@ -32,7 +28,7 @@
  * This Class implements an import command that reads entries from a zip input
  * stream and delegates the extracted file back to the import chain.
  */
-public class ZIPImportCommand implements Command, JcrConstants {
+public class ZIPImportCommand extends AbstractCommand {
 
     /** the default logger */
     private static final Logger log = Logger.getLogger(ZIPImportCommand.class);
@@ -43,6 +39,11 @@
     public static final String ZIP_CONTENT_TYPE = "application/zip";
 
     /**
+     * flag, indicating if zip should be extracted recusively
+     */
+    private boolean recursive = false;
+            
+    /**
      * Executes this command by calling {@link #importResource} if
      * the given context is of the correct class.
      *
@@ -50,7 +51,7 @@
      * @return the return value of the delegated method or false;
      * @throws Exception in an error occurrs
      */
-    public boolean execute(Context context) throws Exception {
+    public boolean execute(AbstractContext context) throws Exception {
         if (context instanceof ImportContext) {
             return execute((ImportContext) context);
         } else {
@@ -59,28 +60,30 @@
     }
 
     /**
-     * Executes this command. It checks if this command can handle the content
-     * type and delegates it to {@link #importResource}. If the import is
-     * successfull, the input stream of the importcontext is cleared.
-     *
-     * @param context the import context
-     * @return false
-     * @throws Exception if an error occurrs
+     * Override default behaviour and abort chain if input is processed.
+     * @param context
+     * @return
+     * @throws Exception
      */
     public boolean execute(ImportContext context) throws Exception {
+        if (!canHandle(context.getContentType())) {
+            // ignore imports
+            return false;
+        }
+        // disable this command for further subcommands if recursive is false
+        context.enableCommand(getId(), recursive);
+
         Node parentNode = context.getNode();
         InputStream in = context.getInputStream();
         if (in == null) {
             // assume already consumed
             return false;
         }
-        if (!canHandle(context.getContentType())) {
-            // ignore imports
-            return false;
+        if (importResource(context, parentNode, in)) {
+            context.setInputStream(null);
+            return true;
         }
-        importResource(parentNode, in);
-        context.setInputStream(null);
-        return true;
+        return false;
     }
 
     /**
@@ -91,7 +94,8 @@
      * @param in the input stream
      * @throws Exception in an error occurrs
      */
-    private void importResource(Node parentNode, InputStream in)
+
+    public boolean importResource(ImportContext context, Node parentNode, InputStream in)
             throws Exception {
 
         // assuming zip content
@@ -100,19 +104,19 @@
         while ((entry=zin.getNextEntry())!=null) {
             log.info("entry: " + entry.getName() + " size: " + entry.getSize());
             if (entry.isDirectory()) {
-                mkDirs(parentNode, Text.makeValidJCRPath(entry.getName()));
+                AbstractImportCommand.mkDirs(context, parentNode, Text.makeValidJCRPath(entry.getName()));
                 zin.closeEntry();
             } else {
                 String path = Text.makeValidJCRPath(entry.getName());
                 if (path.charAt(0)!='/') {
                     path  = "/" + path;
                 }
-                Node parent = mkDirs(parentNode, Text.getRelativeParent(path, 1));
+                Node parent = AbstractImportCommand.mkDirs(context, parentNode, Text.getRelativeParent(path, 1));
 
                 BoundedInputStream bin = new BoundedInputStream(zin);
                 bin.setPropagateClose(false);
 
-                ImportContext subctx = new ImportContext(parent);
+                ImportContext subctx = context.createSubContext(parent);
                 subctx.setInputStream(bin);
                 subctx.setSystemId(Text.getLabel(path));
                 subctx.setModificationTime(entry.getTime());
@@ -121,32 +125,7 @@
             }
         }
         zin.close();
-    }
-
-    /**
-     * Creates collection recursively.
-     *
-     * @param root
-     * @param relPath
-     * @return
-     * @throws RepositoryException
-     */
-    private Node mkDirs(Node root, String relPath) throws RepositoryException {
-        String[] seg = Text.explode(relPath, '/');
-        for (int i=0; i< seg.length; i++) {
-            if (!root.hasNode(seg[i])) {
-                // not quite correct
-                ImportContext subctx = new ImportContext(root);
-                subctx.setSystemId(seg[i]);
-                try {
-                    ImportCollectionChain.getChain().execute(subctx);
-                } catch (Exception e) {
-                    throw new RepositoryException(e);
-                }
-            }
-            root = root.getNode(seg[i]);
-        }
-        return root;
+        return true;
     }
 
     /**
@@ -157,5 +136,13 @@
      */
     public boolean canHandle(String contentType) {
         return ZIP_CONTENT_TYPE.equals(contentType);
+    }
+
+    /**
+     * Sets if the zips should be extracted again
+     * @param recursive
+     */
+    public void setRecursive(boolean recursive) {
+        this.recursive = recursive;
     }
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties Mon Jun  6 10:36:09 2005
@@ -0,0 +1,130 @@
+ai=application/postscript	
+aif=audio/x-aiff
+aifc=audio/x-aiff
+aiff=audio/x-aiff
+any=text/any
+asc=text/plain
+au=audio/basic
+avi=video/x-msvideo
+bcpio=application/x-bcpio
+bin=application/octet-stream
+bz2=application/x-bzip2
+cdf=application/x-netcdf
+class=application/octet-stream
+cpio=application/x-cpio
+cpt=application/mac-compactpro
+cq=application/cq-durboser
+csh=application/x-csh
+css=text/css
+dcr=application/x-director
+dir=application/x-director
+dms=application/octet-stream
+doc=application/msword
+dvi=application/x-dvi
+dxr=application/x-director
+ecma=text/qhtml
+eps=application/postscript
+esp=text/qhtml
+etx=text/x-setext
+exe=application/octet-stream
+ez=application/andrew-inset
+gif=image/gif
+gtar=application/x-gtar
+gz=application/x-gzip
+hdf=application/x-hdf
+hqx=application/mac-binhex40
+htm=text/html
+html=text/html
+ice=x-conference/x-cooltalk
+ief=image/ief
+iges=model/iges
+igs=model/iges
+jpe=image/jpeg
+jpeg=image/jpeg
+jpg=image/jpeg
+js=application/x-javascript
+kar=audio/midi
+latex=application/x-latex
+lha=application/octet-stream
+lzh=application/octet-stream
+man=application/x-troff-man
+me=application/x-troff-me
+mesh=model/mesh
+mid=audio/midi
+midi=audio/midi
+mif=application/vnd=mif
+mov=video/quicktime
+movie=video/x-sgi-movie
+mp2=audio/mpeg
+mp3=audio/mpeg
+mpe=video/mpeg
+mpeg=video/mpeg
+mpg=video/mpeg
+mpga=audio/mpeg
+ms=application/x-troff-ms
+msh=model/mesh
+nc=application/x-netcdf
+oda=application/oda
+pbm=image/x-portable-bitmap
+pdb=chemical/x-pdb
+pdf=application/pdf
+pgm=image/x-portable-graymap
+pgn=application/x-chess-pgn
+png=image/png
+pnm=image/x-portable-anymap
+ppm=image/x-portable-pixmap
+ppt=application/vnd=ms-powerpoint
+ps=application/postscript
+qhtml=text/qhtml
+qt=video/quicktime
+ra=audio/x-realaudio
+ram=audio/x-pn-realaudio
+ras=image/x-cmu-raster
+rgb=image/x-rgb
+rm=audio/x-pn-realaudio
+roff=application/x-troff
+rpm=application/x-rpm
+rtf=application/rtf
+rtf=text/rtf
+rtx=text/richtext
+sgm=text/sgml
+sgml=text/sgml
+sh=application/x-sh
+shar=application/x-shar
+silo=model/mesh
+sit=application/x-stuffit
+skd=application/x-koan
+skm=application/x-koan
+skp=application/x-koan
+skt=application/x-koan
+smi=application/smil
+smil=application/smil
+snd=audio/basic
+spl=application/x-futuresplash
+src=application/x-wais-source
+sv4cpio=application/x-sv4cpio
+sv4crc=application/x-sv4crc
+swf=application/x-shockwave-flash
+t=application/x-troff
+tar=application/x-tar
+tcl=application/x-tcl
+tex=application/x-tex
+texi=application/x-texinfo
+texinfo=application/x-texinfo
+tgz=application/x-gzip
+tif=image/tiff
+tiff=image/tiff
+tr=application/x-troff
+tsv=text/tab-separated-values
+txt=text/plain
+ustar=application/x-ustar
+vcd=application/x-cdlink
+vrml=model/vrml
+wav=audio/x-wav
+wrl=model/vrml
+xbm=image/x-xbitmap
+xml=text/xml
+xpm=image/x-xpixmap
+xwd=image/x-xwindowdump
+xyz=chemical/x-pdb
+zip=application/zip
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/mimetypes.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/jcr/JCRWebdavServer.java Mon Jun  6 10:36:09 2005
@@ -1,27 +1,28 @@
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 package org.apache.jackrabbit.server.jcr;
 
 import org.apache.log4j.Logger;
 import org.apache.jackrabbit.webdav.*;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
-import org.apache.jackrabbit.client.RepositoryAccessServlet;
+import org.apache.jackrabbit.server.SessionProvider;
 
 import javax.jcr.*;
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
 import java.util.HashMap;
 import java.util.HashSet;
 /**
@@ -38,13 +39,17 @@
     /** the jcr repository */
     private final Repository repository;
 
+    /** the provider for the credentials */
+    private final SessionProvider sessionProvider;
+
     /**
      * Creates a new JCRWebdavServer that operates on the given repository.
      *
      * @param repository
      */
-    public JCRWebdavServer(Repository repository) {
-	this.repository = repository;
+    public JCRWebdavServer(Repository repository, SessionProvider sessionProvider) {
+        this.repository = repository;
+        this.sessionProvider = sessionProvider;
     }
 
     //---------------------------------------< DavSessionProvider interface >---
@@ -55,12 +60,13 @@
      *
      * @param request
      * @throws DavException if no session could be obtained.
-     * @see DavSessionProvider#acquireSession(org.apache.jackrabbit.webdav.WebdavRequest)
+     * @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
      */
-    public void acquireSession(WebdavRequest request)
-            throws DavException {
+    public boolean attachSession(WebdavRequest request)
+        throws DavException {
         DavSession session = cache.get(request);
-	request.setDavSession(session);
+        request.setDavSession(session);
+        return true;
     }
 
     /**
@@ -72,12 +78,12 @@
      * @see DavSessionProvider#releaseSession(org.apache.jackrabbit.webdav.WebdavRequest)
      */
     public void releaseSession(WebdavRequest request) {
-	DavSession session = request.getDavSession();
-	if (session != null) {
-	    session.removeReference(request);
-	}
-	// remove the session from the request
-	request.setDavSession(null);
+        DavSession session = request.getDavSession();
+        if (session != null) {
+            session.removeReference(request);
+        }
+        // remove the session from the request
+        request.setDavSession(null);
     }
 
     //--------------------------------------------------------------------------
@@ -86,7 +92,7 @@
      */
     private class DavSessionImpl implements DavSession {
 
-	/** the underlaying jcr session */
+        /** the underlaying jcr session */
         private final Session session;
 
         /**
@@ -98,8 +104,7 @@
         private DavSessionImpl(DavServletRequest request) throws DavException {
             try {
                 String workspaceName = request.getRequestLocator().getWorkspaceName();
-		Credentials creds = RepositoryAccessServlet.getCredentialsFromHeader(request.getHeader(DavConstants.HEADER_AUTHORIZATION));
-                session = repository.login(creds, workspaceName);
+                session = sessionProvider.getSession(request, repository, workspaceName);
             } catch (LoginException e) {
                 // LoginException results in UNAUTHORIZED,
                 throw new JcrDavException(e);
@@ -107,8 +112,8 @@
                 // RepositoryException results in FORBIDDEN
                 throw new JcrDavException(e);
             } catch (ServletException e) {
-		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
-	    }
+                throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            }
         }
 
         /**
@@ -139,26 +144,26 @@
             return session;
         }
 
-	/**
-	 * @see DavSession#addLockToken(String)
-	 */
-	public void addLockToken(String token) {
-	    session.addLockToken(token);
-	}
-
-	/**
-	 * @see DavSession#getLockTokens()
-	 */
-	public String[] getLockTokens() {
-	    return session.getLockTokens();
-	}
-
-	/**
-	 * @see DavSession#removeLockToken(String)
-	 */
-	public void removeLockToken(String token) {
-	    session.removeLockToken(token);
-	}
+        /**
+         * @see DavSession#addLockToken(String)
+         */
+        public void addLockToken(String token) {
+            session.addLockToken(token);
+        }
+
+        /**
+         * @see DavSession#getLockTokens()
+         */
+        public String[] getLockTokens() {
+            return session.getLockTokens();
+        }
+
+        /**
+         * @see DavSession#removeLockToken(String)
+         */
+        public void removeLockToken(String token) {
+            session.removeLockToken(token);
+        }
     }
 
     /**
@@ -179,7 +184,7 @@
          * @throws DavException
          */
         private DavSession get(WebdavRequest request)
-                throws DavException {
+            throws DavException {
             String txId = request.getTransactionId();
             String subscriptionId = request.getSubscriptionId();
             String lockToken = request.getLockToken();

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.jcr;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.property.*;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.jcr.version.report.*;
+import org.apache.jackrabbit.webdav.transaction.TxLockEntry;
+import org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.apache.jackrabbit.util.Text;
+
+import javax.jcr.*;
+
+/**
+ * <code>AbstractItemResource</code> covers common functionality for the various
+ * resources, that represent a repository item.
+ */
+abstract class AbstractItemResource extends AbstractResource implements
+    ItemResourceConstants {
+
+    private static Logger log = Logger.getLogger(AbstractItemResource.class);
+
+    protected final Item item;
+
+    /**
+     * Create a new <code>AbstractItemResource</code>.
+     *
+     * @param locator
+     * @param session
+     */
+    AbstractItemResource(DavResourceLocator locator, DavSession session, DavResourceFactory factory, Item item) {
+        super(locator, session, factory);
+        this.item = item;
+
+	// initialize the supported locks and reports
+        initLockSupport();
+        initSupportedReports();
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass()
+     */
+    public String getComplianceClass() {
+        return ItemResourceConstants.COMPLIANCE_CLASS;
+    }
+
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        return ItemResourceConstants.METHODS;
+    }
+
+    /**
+     * Returns true if there exists a {@link Item repository item} with the given
+     * resource path, false otherwise.
+     *
+     * @see DavResource#exists()
+     */
+    public boolean exists() {
+        return item != null;
+    }
+
+    /**
+     * @see DavResource#getDisplayName() )
+     */
+    public String getDisplayName() {
+        String name = null;
+        if (exists()) {
+            try {
+                name = item.getName();
+            } catch (RepositoryException e) {
+                // ignore: should not occure
+                log.warn(e.getMessage());
+            }
+        }
+        String resPath = getResourcePath();
+        if (name == null && resPath != null) {
+            int pos = resPath.lastIndexOf('/');
+            if (pos>=0) {
+                name = resPath.substring(pos+1);
+            } else {
+                name = resPath;
+            }
+            // note: since index info is present only with existing resources
+            // there is no need to check for any '[index]' suffix.
+        }
+        return name;
+    }
+
+    /**
+     * Returns the resource representing the parent item of the repository item
+     * represented by this resource. If this resoure represents the root item
+     * a {@link RootCollection} is returned.
+     *
+     * @return the collection this resource is internal member of. Except for the
+     * repository root, the returned collection always represent the parent
+     * repository node.
+     * @see DavResource#getCollection()
+     */
+    public DavResource getCollection() {
+        DavResource collection = null;
+
+        String resourcePath = getResourcePath();
+        // No special treatment for the root-item needed, because this is
+        // covered by the RootItemCollection itself.
+        String parentResourcePath = Text.getRelativeParent(resourcePath, 1);
+        String parentWorkspacePath = getLocator().getWorkspacePath();
+
+        DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), parentWorkspacePath, parentResourcePath);
+        try {
+            collection = createResourceFromLocator(parentLoc);
+        } catch (DavException e) {
+            log.error("Unexpected error while retrieving collection: " + e.getMessage());
+        }
+
+        return collection;
+    }
+
+    /**
+     * Moves the underlaying repository item to the indicated destination.
+     *
+     * @param destination
+     * @throws DavException
+     * @see DavResource#move(DavResource)
+     * @see Session#move(String, String)
+     */
+    public void move(DavResource destination) throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        DavResourceLocator destPath = destination.getLocator();
+        if (!getLocator().isSameWorkspace(destPath)) {
+            throw new DavException(DavServletResponse.SC_FORBIDDEN);
+        }
+
+        try {
+            if (getTransactionId() == null) {
+                // if not part of a transaction directely import on workspace
+                getRepositorySession().getWorkspace().move(getResourcePath(), destination.getResourcePath());
+            } else {
+                // changes will not be persisted unless the tx is completed.
+                getRepositorySession().move(getResourcePath(), destination.getResourcePath());
+            }
+            // no use in calling 'complete' that would fail for a moved item anyway.
+        } catch (PathNotFoundException e) {
+            // according to rfc 2518
+            throw new DavException(DavServletResponse.SC_CONFLICT, e.getMessage());
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Copies the underlaying repository item to the indicated destination. If
+     * the locator of the specified destination resource indicates a different
+     * workspace, {@link Workspace#copy(String, String, String)} is used to perform
+     * the copy operation, {@link Workspace#copy(String, String)} otherwise.
+     * <p/>
+     * Note, that this implementation does not support shallow copy.
+     *
+     * @param destination
+     * @param shallow
+     * @throws DavException
+     * @see DavResource#copy(DavResource, boolean)
+     * @see Workspace#copy(String, String)
+     * @see Workspace#copy(String, String, String)
+     */
+    public void copy(DavResource destination, boolean shallow) throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        // TODO: support shallow and deep copy is required by RFC 2518
+        if (shallow) {
+            throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");
+        }
+
+        if (!(destination instanceof AbstractItemResource)) {
+            throw new DavException(DavServletResponse.SC_FORBIDDEN, "Cannot copy a resource that does not represent a repository item.");
+        }
+
+        try {
+            AbstractItemResource destResource = (AbstractItemResource) destination;
+            String destResourcePath = destResource.getResourcePath();
+            Workspace workspace = getRepositorySession().getWorkspace();
+            if (getLocator().isSameWorkspace(destination.getLocator())) {
+                workspace.copy(getResourcePath(), destResourcePath);
+            } else {
+                Workspace destWorkspace = destResource.getRepositorySession().getWorkspace();
+                destWorkspace.copy(workspace.getName(), getResourcePath(), destResourcePath);
+            }
+        } catch (PathNotFoundException e) {
+            // according to RFC 2518, should not occur
+            throw new DavException(DavServletResponse.SC_NOT_FOUND, e.getMessage());
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Initialize the {@link org.apache.jackrabbit.webdav.lock.SupportedLock} property
+     * with entries that are valid for any type item resources.
+     *
+     * @see org.apache.jackrabbit.webdav.lock.SupportedLock
+     * @see org.apache.jackrabbit.webdav.transaction.TxLockEntry
+     * @see AbstractResource#initLockSupport()
+     */
+    protected void initLockSupport() {
+        if (exists()) {
+            // add supportedlock entries for local and eventually for global transaction locks
+            supportedLock.addEntry(new TxLockEntry(true));
+            supportedLock.addEntry(new TxLockEntry(false));
+        }
+    }
+
+    /**
+     * Define the set of reports supported by this resource.
+     *
+     * @see org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty
+     * @see AbstractResource#initSupportedReports()
+     */
+    protected void initSupportedReports() {
+        if (exists()) {
+            supportedReports = new SupportedReportSetProperty(new ReportType[] {
+                ReportType.EXPAND_PROPERTY,
+                NodeTypesReport.NODETYPES_REPORT,
+                ExportViewReport.EXPORTVIEW_REPORT,
+                LocateByUuidReport.LOCATE_BY_UUID_REPORT,
+                RegisteredNamespacesReport.REGISTERED_NAMESPACES_REPORT,
+                RepositoryDescriptorsReport.REPOSITORY_DESCRIPTORS_REPORT
+            });
+        }
+    }
+
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        super.initProperties();
+        if (exists()) {
+            try {
+                properties.add(new DefaultDavProperty(JCR_NAME, item.getName()));
+                properties.add(new DefaultDavProperty(JCR_PATH, item.getPath()));
+                properties.add(new DefaultDavProperty(JCR_DEPTH, String.valueOf(item.getDepth())));
+            } catch (RepositoryException e) {
+                log.error("Error while accessing jcr properties: " + e.getMessage());
+            }
+
+            // transaction resource additional protected properties
+            if (item.isNew()) {
+                properties.add(new DefaultDavProperty(JCR_ISNEW, null, true));
+            } else if (item.isModified()) {
+                properties.add(new DefaultDavProperty(JCR_ISMODIFIED, null, true));
+            }
+        }
+    }
+
+    /**
+     * @return href of the workspace or <code>null</code> if this resource
+     * does not represent a repository item.
+     *
+     * @see AbstractResource#getWorkspaceHref()
+     */
+    protected String getWorkspaceHref() {
+        String workspaceHref = null;
+	DavResourceLocator locator = getLocator();
+        if (locator != null && locator.getWorkspaceName() != null) {
+            workspaceHref = locator.getHref(isCollection());
+            if (locator.getResourcePath() != null) {
+                workspaceHref = workspaceHref.substring(workspaceHref.indexOf(locator.getResourcePath()));
+            }
+        }
+	log.info(workspaceHref);
+        return workspaceHref;
+    }
+
+    /**
+     * If this resource exists but does not contain a transaction id, complete
+     * will try to persist any modifications prsent on the underlaying repository
+     * item.
+     *
+     * @throws DavException if calling {@link Item#save()} fails
+     */
+    void complete() throws DavException {
+        if (exists() && getTransactionId() == null) {
+            try {
+                if (item.isModified()) {
+                    item.save();
+                }
+            } catch (RepositoryException e) {
+                // this includes LockException, ConstraintViolationException etc. not detected before
+                log.error("Error while completing request: " + e.getMessage() +" -> reverting changes.");
+                try {
+                    item.refresh(false);
+                } catch (RepositoryException re) {
+                    log.error("Error while reverting changes: " + re.getMessage());
+                }
+                throw new JcrDavException(e);
+            }
+        }
+    }
+
+    /**
+     * Build a new {@link DavResourceLocator} from the given repository item.
+     *
+     * @param repositoryItem
+     * @return a new locator for the specified item.
+     * @see #getLocatorFromResourcePath(String)
+     */
+    protected DavResourceLocator getLocatorFromItem(Item repositoryItem) {
+        String itemPath = null;
+        try {
+            if (repositoryItem != null) {
+                itemPath = repositoryItem.getPath();
+            }
+        } catch (RepositoryException e) {
+            // ignore: should not occur
+            log.warn(e.getMessage());
+        }
+        return getLocatorFromResourcePath(itemPath);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractItemResource.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message