jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r588236 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ jackrabbit-webapp/src/main/webapp/WEB-INF/
Date Thu, 25 Oct 2007 13:44:02 GMT
Author: angela
Date: Thu Oct 25 06:43:59 2007
New Revision: 588236

URL: http://svn.apache.org/viewvc?rev=588236&view=rev
Log:
JCR-1188 WebDAV: Allow for Extensions of MimeResolver in the Configuration.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContext.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContextImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContext.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/MimeResolver.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ZipHandler.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/AbstractExportContext.java
Thu Oct 25 06:43:59 2007
@@ -32,13 +32,21 @@
     private final IOListener ioListener;
     private final Item exportRoot;
     private final boolean hasStream;
+    private final MimeResolver mimeResolver;
 
     protected boolean completed;
 
-    public AbstractExportContext(Item exportRoot, boolean hasStream, IOListener ioListener)
{
+    public AbstractExportContext(Item exportRoot, boolean hasStream,
+                                 IOListener ioListener) {
+        this(exportRoot, hasStream, ioListener, null);
+    }
+
+    public AbstractExportContext(Item exportRoot, boolean hasStream,
+                                 IOListener ioListener, MimeResolver mimeResolver) {
         this.exportRoot = exportRoot;
         this.hasStream = hasStream;
         this.ioListener = (ioListener != null) ? ioListener : new DefaultIOListener(log);
+        this.mimeResolver = (mimeResolver != null) ? mimeResolver : IOUtil.MIME_RESOLVER;
     }
 
     public IOListener getIOListener() {
@@ -47,6 +55,10 @@
 
     public Item getExportRoot() {
         return exportRoot;
+    }
+
+    public MimeResolver getMimeResolver() {
+        return mimeResolver;
     }
 
     public boolean hasStream() {

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContext.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContext.java
Thu Oct 25 06:43:59 2007
@@ -39,6 +39,13 @@
     public OutputStream getOutputStream();
 
     /**
+     * Return the <code>MimeResolver</code> defined for this export context.
+     *
+     * @return mimetype resolver defined for this export context.
+     */
+    public MimeResolver getMimeResolver();
+
+    /**
      * Set the content type for the resource content
      *
      * @param mimeType

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContextImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContextImpl.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContextImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ExportContextImpl.java
Thu Oct 25 06:43:59 2007
@@ -54,7 +54,12 @@
     private OutputStream outStream;
 
     public ExportContextImpl(Item exportRoot, OutputContext outputCtx) throws IOException
{
-        super(exportRoot, (outputCtx != null) ? outputCtx.hasStream() : false, null);
+        this(exportRoot, outputCtx, null);
+    }
+
+    public ExportContextImpl(Item exportRoot, OutputContext outputCtx,
+                             MimeResolver mimeResolver) throws IOException {
+        super(exportRoot, (outputCtx != null) ? outputCtx.hasStream() : false, null, mimeResolver);
         this.outputCtx = outputCtx;
         if (hasStream()) {
             // we need a tmp file, since the export could fail

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContext.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContext.java
Thu Oct 25 06:43:59 2007
@@ -33,6 +33,13 @@
     public Item getImportRoot();
 
     /**
+     * Return the <code>MimeResolver</code> defined for this import context.
+     *
+     * @return mimetype resolver defined for this import context.
+     */
+    public MimeResolver getMimeResolver();
+
+    /**
      * Returns the system id of the resource to be imported. This id depends on
      * the system the resource is comming from. it can be a filename, a
      * display name of a webdav resource, an URI, etc.

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ImportContextImpl.java
Thu Oct 25 06:43:59 2007
@@ -38,6 +38,7 @@
     private final Item importRoot;
     private final String systemId;
     private final File inputFile;
+    private final MimeResolver mimeResolver;
 
     private InputContext inputCtx;
     private boolean completed;
@@ -51,10 +52,29 @@
      * the import has been completed and it will not be used any more.
      *
      * @param importRoot the import root node
+     * @param systemId
      * @param inputCtx wrapped by this <code>ImportContext</code>
      */
     public ImportContextImpl(Item importRoot, String systemId, InputContext inputCtx) throws
IOException {
-        this(importRoot, systemId, (inputCtx != null) ? inputCtx.getInputStream() : null,
null);
+        this(importRoot, systemId, inputCtx, null);
+    }
+
+    /**
+     * Creates a new item import context with the given root item and the
+     * specified <code>InputContext</code>. If the input context provides an
+     * input stream, the stream is written to a temporary file in order to avoid
+     * problems with multiple IOHandlers that try to run the import but fail.
+     * The temporary file is deleted as soon as this context is informed that
+     * the import has been completed and it will not be used any more.
+     *
+     * @param importRoot the import root node
+     * @param systemId
+     * @param inputCtx wrapped by this <code>ImportContext</code>
+     * @param mimeResolver
+     */
+    public ImportContextImpl(Item importRoot, String systemId, InputContext inputCtx,
+                             MimeResolver mimeResolver) throws IOException {
+        this(importRoot, systemId, (inputCtx != null) ? inputCtx.getInputStream() : null,
null, mimeResolver);
         this.inputCtx = inputCtx;
     }
 
@@ -72,11 +92,34 @@
      * @throws IOException
      * @see ImportContext#informCompleted(boolean)
      */
-    public ImportContextImpl(Item importRoot, String systemId, InputStream in, IOListener
ioListener) throws IOException {
+    public ImportContextImpl(Item importRoot, String systemId, InputStream in,
+                             IOListener ioListener) throws IOException {
+        this(importRoot, systemId, in, ioListener, null);
+    }
+
+    /**
+     * Creates a new item import context. The specified InputStream is written
+     * to a temporary file in order to avoid problems with multiple IOHandlers
+     * that try to run the import but fail. The temporary file is deleted as soon
+     * as this context is informed that the import has been completed and it
+     * will not be used any more.
+     *
+     * @param importRoot
+     * @param systemId
+     * @param in
+     * @param ioListener
+     * @param mimeResolver
+     * @throws IOException
+     * @see ImportContext#informCompleted(boolean)
+     */
+    public ImportContextImpl(Item importRoot, String systemId, InputStream in,
+                             IOListener ioListener, MimeResolver mimeResolver)
+            throws IOException {
         this.importRoot = importRoot;
         this.systemId = systemId;
         this.inputFile = IOUtil.getTempFile(in);
         this.ioListener = (ioListener != null) ? ioListener : new DefaultIOListener(log);
+        this.mimeResolver = (mimeResolver == null) ? IOUtil.MIME_RESOLVER : mimeResolver;
     }
 
     /**
@@ -94,6 +137,13 @@
     }
 
     /**
+     * @see ImportContext#getImportRoot()
+     */
+    public MimeResolver getMimeResolver() {
+        return mimeResolver;
+    }
+
+    /**
      * @see ImportContext#hasStream()
      */
     public boolean hasStream() {
@@ -174,7 +224,7 @@
         if (contentType != null) {
             mimeType = IOUtil.getMimeType(contentType);
         } else if (getSystemId() != null) {
-            mimeType = IOUtil.MIME_RESOLVER.getMimeType(getSystemId());
+            mimeType = mimeResolver.getMimeType(getSystemId());
         }
         return mimeType;
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/MimeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/MimeResolver.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/MimeResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/MimeResolver.java
Thu Oct 25 06:43:59 2007
@@ -27,17 +27,18 @@
 public class MimeResolver {
 
     /**
-     * the loaded mime types
+     * the loaded mimetypes
      */
     private Properties mimeTypes = new Properties();
 
     /**
-     * the default mime type
+     * the default mimetype
      */
     private String defaultMimeType = "application/octet-stream";
 
     /**
-     * Creates a new mime resolver.
+     * Creates a new mimetype resolver containing the default mappings and having
+     * "application/octet-stream" set as default mimetype.
      */
     public MimeResolver() {
         try {
@@ -49,11 +50,34 @@
     }
 
     /**
+     * Creates a new mime type resolver extending the default mapping by the
+     * entries of the given Properties. The default mimetype is set to the
+     * given <code>defaultMimeType</code>.
+     *
+     * @param additionalProperties MimeType mappings to be added to the default
+     * properties.
+     * @param defaultMimeType The default mimetype. A non-null String with a
+     * length greater than 0.
+     */
+    public MimeResolver(Properties additionalProperties, String defaultMimeType) {
+        // init default mimetypes.
+        this();
+        // extend or adjust mapping.
+        if (additionalProperties != null && !additionalProperties.isEmpty()) {
+            mimeTypes.putAll(additionalProperties);
+        }
+        // set the default type.
+        if (defaultMimeType != null && defaultMimeType.length() > 0) {
+            this.defaultMimeType = defaultMimeType;
+        }
+    }
+
+    /**
      * Returns the default mime type
      * @return
      */
     public String getDefaultMimeType() {
-	return defaultMimeType;
+        return defaultMimeType;
     }
 
     /**
@@ -61,7 +85,7 @@
      * @param defaultMimeType
      */
     public void setDefaultMimeType(String defaultMimeType) {
-	this.defaultMimeType = defaultMimeType;
+        this.defaultMimeType = defaultMimeType;
     }
 
     /**
@@ -70,11 +94,10 @@
      * @return
      */
     public String getMimeType(String filename) {
-	String ext = Text.getName(filename, '.');
+        String ext = Text.getName(filename, '.');
         if (ext.equals("")) {
             ext = filename;
         }
-	return mimeTypes.getProperty(ext.toLowerCase(), defaultMimeType);
+        return mimeTypes.getProperty(ext.toLowerCase(), defaultMimeType);
     }
-
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/XmlHandler.java
Thu Oct 25 06:43:59 2007
@@ -140,7 +140,7 @@
                 if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                     mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                 } else {
-                    mimeType = IOUtil.MIME_RESOLVER.getMimeType(context.getExportRoot().getName());
+                    mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                 }
             } catch (RepositoryException e) {
                 // ignore and return false

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ZipHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ZipHandler.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ZipHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ZipHandler.java
Thu Oct 25 06:43:59 2007
@@ -153,7 +153,7 @@
                 if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                     mimeType  = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                 } else {
-                    mimeType = IOUtil.MIME_RESOLVER.getMimeType(context.getExportRoot().getName());
+                    mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                 }
             } catch (RepositoryException e) {
                 // ignore and return false
@@ -283,7 +283,7 @@
         private final ZipEntry entry;
 
         private ZipEntryImportContext(ImportContext context, ZipEntry entry, BoundedInputStream
bin, Node contentNode) throws IOException, RepositoryException {
-            super(contentNode, Text.getName(makeValidJCRPath(entry.getName(), true)), bin,
context.getIOListener());
+            super(contentNode, Text.getName(makeValidJCRPath(entry.getName(), true)), bin,
context.getIOListener(), context.getMimeResolver());
             this.entry = entry;
             String path = makeValidJCRPath(entry.getName(), true);
             importRoot = IOUtil.mkDirs(contentNode, Text.getRelativeParent(path, 1), getCollectionNodeType());
@@ -312,7 +312,7 @@
         private OutputStream out;
 
         private ZipEntryExportContext(Item exportRoot, OutputStream out, ExportContext context,
int pos) {
-            super(exportRoot, out != null, context.getIOListener());
+            super(exportRoot, out != null, context.getIOListener(), context.getMimeResolver());
             this.out = out;
             try {
                 String entryPath = (exportRoot.getPath().length() > pos) ? exportRoot.getPath().substring(pos)
: "";

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
Thu Oct 25 06:43:59 2007
@@ -28,7 +28,6 @@
 import org.apache.jackrabbit.server.io.ImportContextImpl;
 import org.apache.jackrabbit.server.io.PropertyExportContext;
 import org.apache.jackrabbit.server.io.PropertyImportContext;
-import org.apache.jackrabbit.server.io.PropertyManager;
 import org.apache.jackrabbit.util.Text;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavResource;
@@ -69,7 +68,6 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.lock.Lock;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -99,10 +97,7 @@
     protected boolean propsInitialized = false;
     private boolean isCollection = true;
 
-    private ItemFilter filter;
-    private IOManager ioManager;
-    private PropertyManager propManager;
-
+    private ResourceConfig config;
     private long modificationTime = IOUtil.UNDEFINED_TIME;
 
     /**
@@ -119,9 +114,7 @@
         this.session = (JcrDavSession)session;
         this.factory = factory;
         this.locator = locator;
-        this.filter = config.getItemFilter();
-        this.ioManager = config.getIOManager();
-        this.propManager = config.getPropertyManager();
+        this.config = config;
 
         if (locator != null && locator.getRepositoryPath() != null) {
             try {
@@ -178,9 +171,7 @@
         this.session = (JcrDavSession)session;
         this.factory = factory;
         this.locator = locator;
-        this.filter = config.getItemFilter();
-        this.ioManager = config.getIOManager();
-        this.propManager = config.getPropertyManager();
+        this.config = config;
 
         if (locator.getResourcePath() != null) {
             if (node != null) {
@@ -294,7 +285,7 @@
     public void spool(OutputContext outputContext) throws IOException {
         if (exists() && outputContext != null) {
             ExportContext exportCtx = getExportContext(outputContext);
-            if (!ioManager.exportContent(exportCtx, this)) {
+            if (!config.getIOManager().exportContent(exportCtx, this)) {
                 throw new IOException("Unexpected Error while spooling resource.");
             }
         }
@@ -332,7 +323,7 @@
         }
 
         try {
-            propManager.exportProperties(getPropertyExportContext(), isCollection());
+            config.getPropertyManager().exportProperties(getPropertyExportContext(), isCollection());
         } catch (RepositoryException e) {
             log.warn("Error while accessing resource properties", e);
         }
@@ -392,7 +383,7 @@
             List l = new ArrayList(1);
             l.add(prop);
             alterProperties(l);
-            Map failure = propManager.alterProperties(getPropertyImportContext(l), isCollection());
+            Map failure = config.getPropertyManager().alterProperties(getPropertyImportContext(l),
isCollection());
             if (failure.isEmpty()) {
                 node.save();
             } else {
@@ -443,7 +434,7 @@
         }
         MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
         try {
-            Map failures = propManager.alterProperties(getPropertyImportContext(changeList),
isCollection());
+            Map failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList),
isCollection());
             if (failures.isEmpty()) {
                 // save all changes together (reverted in case this fails)
                 node.save();
@@ -555,7 +546,7 @@
 
             String memberName = Text.getName(member.getLocator().getRepositoryPath());
             ImportContext ctx = getImportContext(inputContext, memberName);
-            if (!ioManager.importContent(ctx, member)) {
+            if (!config.getIOManager().importContent(ctx, member)) {
                 // any changes should have been reverted in the importer
                 throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
             }
@@ -833,7 +824,7 @@
      * @throws IOException
      */
     protected ImportContext getImportContext(InputContext inputCtx, String systemId) throws
IOException {
-        return new ImportContextImpl(node, systemId, inputCtx);
+        return new ImportContextImpl(node, systemId, inputCtx, config.getMimeResolver());
     }
 
     /**
@@ -844,7 +835,7 @@
      * @throws IOException
      */
     protected ExportContext getExportContext(OutputContext outputCtx) throws IOException
{
-        return new ExportContextImpl(node, outputCtx);
+        return new ExportContextImpl(node, outputCtx, config.getMimeResolver());
     }
 
     /**
@@ -918,10 +909,12 @@
 
     private boolean isFilteredResource(DavResource resource) {
         // TODO: filtered nodetypes should be checked as well in order to prevent problems.
+        ItemFilter filter = config.getItemFilter();
         return filter != null && filter.isFilteredItem(resource.getDisplayName(),
getJcrSession());
     }
 
     private boolean isFilteredItem(Item item) {
+        ItemFilter filter = config.getItemFilter();
         return filter != null && filter.isFilteredItem(item);
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
Thu Oct 25 06:43:59 2007
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.server.io.PropertyManager;
 import org.apache.jackrabbit.server.io.PropertyHandler;
 import org.apache.jackrabbit.server.io.PropertyManagerImpl;
+import org.apache.jackrabbit.server.io.MimeResolver;
 import org.apache.jackrabbit.webdav.xml.ElementIterator;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
 import org.slf4j.Logger;
@@ -38,6 +39,7 @@
 import java.net.URL;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Properties;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -53,12 +55,13 @@
     private PropertyManager propManager;
     private String[] nodetypeNames = new String[0];
     private boolean collectionNames = false;
+    private MimeResolver mimeResolver;
 
     /**
      * Tries to parse the given xml configuration file.
      * The xml must match the following structure:<br>
      * <pre>
-     * &lt;!ELEMENT config (iomanager, propertymanager, (collection | noncollection)?,
filter?) &gt;
+     * &lt;!ELEMENT config (iomanager, propertymanager, (collection | noncollection)?,
filter?, mimetypeproperties?) &gt;
      * &lt;!ELEMENT iomanager (class, iohandler*) &gt;
      * &lt;!ELEMENT iohandler (class) &gt;
      * &lt;!ELEMENT propertymanager (class, propertyhandler*) &gt;
@@ -75,6 +78,13 @@
      * &lt;!ELEMENT uri (CDATA) &gt;
      * &lt;!ELEMENT nodetypes (nodetype)* &gt;
      * &lt;!ELEMENT nodetype (CDATA) &gt;
+     * &lt;!ELEMENT mimetypeproperties (mimemapping*, defaultmimetype) &gt;
+     * &lt;!ELEMENT mimemapping &gt;
+     *    &lt;!ATTLIST mimemapping
+     *      extension  CDATA #REQUIRED
+     *      mimetype  CDATA #REQUIRED
+     *    &gt;
+     * &lt;!ELEMENT defaultmimetype (CDATA) &gt;
      * </pre>
      *
      * @param configURL
@@ -91,6 +101,7 @@
                 return;
             }
 
+            // iomanager config entry
             Element el = DomUtil.getChildElement(config, "iomanager", null);
             if (el != null) {
                 Object inst = buildClassFromConfig(el);
@@ -115,6 +126,7 @@
                 log.warn("Resource configuration: 'iomanager' element is missing.");
             }
 
+            // propertymanager config entry
             el = DomUtil.getChildElement(config, "propertymanager", null);
             if (el != null) {
                 Object inst = buildClassFromConfig(el);
@@ -139,6 +151,7 @@
                 log.debug("Resource configuration: 'propertymanager' element is missing.");
             }
 
+            // collection/non-collection config entry
             el = DomUtil.getChildElement(config, "collection", null);
             if (el != null) {
                 nodetypeNames = parseNodeTypesEntry(el);
@@ -149,6 +162,7 @@
             }
             // todo: should check if both 'noncollection' and 'collection' are present and
write a warning
 
+            // filter config entry
             el = DomUtil.getChildElement(config, "filter", null);
             if (el != null) {
                 Object inst = buildClassFromConfig(el);
@@ -162,6 +176,22 @@
             } else {
                 log.debug("Resource configuration: no 'filter' element specified.");
             }
+
+            // optional mimetype properties
+            Properties properties = new Properties();
+            String defaultMimetype = null;
+            el = DomUtil.getChildElement(config, "mimetypeproperties", null);
+            if (el != null) {
+                defaultMimetype = DomUtil.getChildText(el, "defaultmimetype", null);
+                ElementIterator it = DomUtil.getChildren(el, "mimemapping", null);
+                while (it.hasNext()) {
+                    Element mimeMapping = it.nextElement();
+                    String extension = DomUtil.getAttribute(mimeMapping, "extension", null);
+                    String mimetype = DomUtil.getAttribute(mimeMapping, "mimetype", null);
+                    properties.put(extension, mimetype);
+                }
+            }
+            mimeResolver = new MimeResolver(properties, defaultMimetype);
         } catch (IOException e) {
             log.debug("Invalid resource configuration: " + e.getMessage());
         } catch (ParserConfigurationException e) {
@@ -298,5 +328,13 @@
             itemFilter = new DefaultItemFilter();
         }
         return itemFilter;
+    }
+
+    /**
+     *
+     * @return
+     */
+    public MimeResolver getMimeResolver() {
+        return mimeResolver;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml?rev=588236&r1=588235&r2=588236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml (original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml Thu Oct 25 06:43:59
2007
@@ -17,7 +17,7 @@
   -->
 <!--
 <!DOCTYPE config [
-        <!ELEMENT config (iomanager , propertymanager, (collection | noncollection)? ,
filter?) >
+        <!ELEMENT config (iomanager , propertymanager, (collection | noncollection)? ,
filter?, mimetypeproperties?) >
 
         <!ELEMENT iomanager (class, iohandler*) >
         <!ELEMENT iohandler (class) >
@@ -40,13 +40,23 @@
 
         <!ELEMENT nodetypes (nodetype)* >
         <!ELEMENT nodetype (CDATA) >
+
+        <!ELEMENT mimetypeproperties (mimemapping*, defaultmimetype) >
+
+        <!ELEMENT mimemapping >
+        <!ATTLIST mimemapping
+            extension  CDATA #REQUIRED
+            mimetype  CDATA #REQUIRED
+        >
+
+        <!ELEMENT defaultmimetype (CDATA) >
 ]>
 -->
 
 <config>
     <!--
-    Defines the IOManager implementation that is responsible for passing import/export
-    request to the individual IO-handlers.
+     Defines the IOManager implementation that is responsible for passing
+     import/export request to the individual IO-handlers.
     -->
     <iomanager>
         <!-- class element defines the manager to be used. The specified class
@@ -75,8 +85,8 @@
         </iohandler>
     </iomanager>
     <!--
-    Example config for iomanager that populates its list of handlers with
-    default values. Therefore the 'iohandler' elements are omited.
+     Example config for iomanager that populates its list of handlers with
+     default values. Therefore the 'iohandler' elements are omited.
     -->
     <!--
     <iomanager>
@@ -84,8 +94,8 @@
     </iomanager>
     -->
     <!--
-    Defines the PropertyManager implementation that is responsible for export
-    and import of resource properties.
+     Defines the PropertyManager implementation that is responsible for export
+     and import of resource properties.
     -->
     <propertymanager>
         <!-- class element defines the manager to be used. The specified class
@@ -114,7 +124,7 @@
         </propertyhandler>
     </propertymanager>
     <!--
-    Define nodetypes, that should never by displayed as 'collection'
+     Define nodetypes, that should never by displayed as 'collection'
     -->
     <noncollection>
         <nodetypes>
@@ -123,7 +133,7 @@
         </nodetypes>
     </noncollection>
     <!--
-    Example: Defines nodetypes, that should always be displayed as 'collection'.
+     Example: Defines nodetypes, that should always be displayed as 'collection'.
     -->
     <!--
     <collection>
@@ -146,20 +156,22 @@
         <!-- class element defines the resource filter to be used. The specified class
              must implement the ItemFilter interface -->
         <class name="org.apache.jackrabbit.webdav.simple.DefaultItemFilter" />
-        <!-- Nodetype names to be used to filter child nodes.
-             A child node can be filtered if the declaring nodetype of its definition
-             is one of the nodetype names specified in the nodetypes Element.
-             E.g. defining 'rep:root' as filtered nodetype whould result in jcr:system
-             being hidden but no other child node of the root node, since those
-             are defined by the nodetype nt:unstructered.
+        <!--
+         Nodetype names to be used to filter child nodes.
+         A child node can be filtered if the declaring nodetype of its definition
+         is one of the nodetype names specified in the nodetypes Element.
+         E.g. defining 'rep:root' as filtered nodetype whould result in jcr:system
+         being hidden but no other child node of the root node, since those
+         are defined by the nodetype nt:unstructered.
         -->
         <!--
         <nodetypes>
             <nodetype>rep:root</nodetype>
         </nodetypes>
         -->
-        <!-- Namespace prefixes or uris. Items having a name that matches any of the
-             entries will be filtered.
+        <!--
+         Namespace prefixes or uris. Items having a name that matches any of the
+         entries will be filtered.
         -->
         <namespaces>
             <prefix>rep</prefix>
@@ -170,5 +182,20 @@
             -->
         </namespaces>
     </filter>
+    
+    <!--
+     Optional 'mimetypeproperties' element.
+     It defines additional or replaces existing mappings for the MimeResolver
+     instance created by the ResourceConfig.
+     The default mappings are defined in org.apache.jackrabbit.server.io.mimetypes.properties.
+     If the default mime type defined by MimeResolver is 'application/octet-stream'.
+    -->
+    <!--
+    <mimetypeproperties>
+        <mimemapping extension="rtf" mimetype="application/rtf" />
+        <mimemapping extension="ott" mimetype="application/vnd.oasis.opendocument.text-template"
/>
+        <defaultmimetype>text/html</defaultmimetype>
+    </mimetypeproperties>
+    -->
 </config>
 



Mime
View raw message