Author: ozeigermann
Date: Thu Apr 12 15:26:09 2007
New Revision: 528261

URL: http://svn.apache.org/viewvc?view=rev&rev=528261
Log:
Simple extension to let the store infer the content type of 
resources without properties

Modified:
    
jakarta/slide/trunk/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java

Modified: 
jakarta/slide/trunk/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java
URL: 
http://svn.apache.org/viewvc/jakarta/slide/trunk/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java?view=diff&rev=528261&r1=528260&r2=528261
==============================================================================
--- 
jakarta/slide/trunk/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java
 (original)
+++ 
jakarta/slide/trunk/wck/src/org/apache/slide/simple/store/WebdavStoreAdapter.java
 Thu Apr 12 15:26:09 2007
@@ -61,6 +61,59 @@
 public class WebdavStoreAdapter extends AbstractXAServiceBase implements 
Service, ContentStore, NodeStore, LockStore,
         RevisionDescriptorStore, RevisionDescriptorsStore, SecurityStore {
 
+    private static final String[][] QND_EXTENSION_TO_DOCTYPE_MAPPING_STRINGS = 
new String[][] {
+            { "txt", "text/plain" }, { "html", "text/html" }, { "csv", 
"text/csv" },
+            { "pdf", "application/pdf" }, { "doc", "application/msword" },
+            { "ppt", "application/mspowerpoint" }, { "xls", 
"application/msexcel" },
+            { "xml", "text/xml" }, };
+
+    protected static final Map QND_EXTENSION_TO_DOCTYPE_MAPPING = new 
HashMap();
+
+    static {
+        for (int i = 0; i < QND_EXTENSION_TO_DOCTYPE_MAPPING_STRINGS.length; 
i++) {
+            String[] entry = QND_EXTENSION_TO_DOCTYPE_MAPPING_STRINGS[i];
+            String ext = entry[0];
+            String type = entry[1];
+            QND_EXTENSION_TO_DOCTYPE_MAPPING.put(ext, type);
+        }
+    }
+
+    public static String getContentTypeForExtension(String extension) {
+        String type = (String)QND_EXTENSION_TO_DOCTYPE_MAPPING.get(extension);
+        return type;
+    }
+    
+    public static String getFileName(String uri) {
+        String name;
+        int lastSlash = uri.lastIndexOf('/');
+        if (lastSlash != -1) {
+            name = uri.substring(lastSlash + 1);
+        } else {
+            name = uri;
+        }
+        return name;
+    }
+    
+    public static String getFileNameNoExtension(String uri) {
+        String name = getFileName(uri);
+        int lastDot = name.lastIndexOf('.');
+        if (lastDot != -1) {
+            name = name.substring(0, lastDot + 1);
+        }
+        return name;
+    }
+    
+    public static String getExtension(String filename) {
+        String ext = "";
+        int lastDot = filename.lastIndexOf('.');
+        if (lastDot != -1) {
+            ext = filename.substring(lastDot + 1);
+        }
+        return ext;
+    }
+    
+
+    
     protected static final String LOG_CHANNEL = 
WebdavStoreAdapter.class.getName();
 
     protected static final String CALLBACK_PARAMETER = "callback-store";
@@ -769,6 +822,11 @@
                             
descriptor.setResourceType(NodeRevisionDescriptor.COLLECTION_TYPE);
                             descriptor.setContentLength(0);
                         } else {
+                            String extension = 
getExtension(getFileName(uri.toString()));
+                            String type = 
getContentTypeForExtension(extension);
+                            if (type != null) {
+                                descriptor.setContentType(type);
+                            }
                             
descriptor.removeProperty(NodeRevisionDescriptor.RESOURCE_TYPE);
                             long length = 
store.getResourceLength(uri.toString());
                             if (length != -1) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to