You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2010/11/06 19:29:01 UTC

svn commit: r1032128 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench: ClientHelper.java details/RenditionTable.java

Author: fmui
Date: Sat Nov  6 18:29:01 2010
New Revision: 1032128

URL: http://svn.apache.org/viewvc?rev=1032128&view=rev
Log:
- fixed CMIS-265: Workbench fails to display renditions on folders

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/RenditionTable.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1032128&r1=1032127&r2=1032128&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java Sat Nov  6 18:29:01 2010
@@ -41,7 +41,9 @@ import javax.swing.ImageIcon;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 
+import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.Rendition;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
@@ -93,11 +95,19 @@ public class ClientHelper {
         return sdf.format(cal.getTime());
     }
 
-    public static void download(Component component, Document doc, String streamId) {
-        String filename = doc.getContentStreamFileName();
+    public static void download(Component component, CmisObject object, String streamId) {
+        ContentStream content = getContentStream(object, streamId);
+        if (content == null) {
+            return;
+        }
 
+        String filename = content.getFileName();
         if (filename == null) {
-            return;
+            if (object instanceof Document) {
+                filename = ((Document) object).getContentStreamFileName();
+            } else {
+                filename = object.getName();
+            }
         }
 
         JFileChooser fileChooser = new JFileChooser();
@@ -106,11 +116,6 @@ public class ClientHelper {
         int chooseResult = fileChooser.showDialog(component, "Download");
         if (chooseResult == JFileChooser.APPROVE_OPTION) {
             try {
-                ContentStream content = doc.getContentStream(streamId);
-                if (content == null) {
-                    throw new Exception("No content!");
-                }
-
                 storeStream(content.getStream(), fileChooser.getSelectedFile());
             } catch (Exception e) {
                 showError(component, e);
@@ -132,23 +137,23 @@ public class ClientHelper {
         }
     }
 
-    public static void open(Component component, Document doc, String streamId) {
+    public static void open(Component component, CmisObject object, String streamId) {
         if (!Desktop.isDesktopSupported()) {
-            download(component, doc, streamId);
+            download(component, object, streamId);
             return;
         }
 
         Desktop desktop = Desktop.getDesktop();
 
         if (!desktop.isSupported(Desktop.Action.OPEN)) {
-            download(component, doc, streamId);
+            download(component, object, streamId);
             return;
         }
 
         File file = null;
 
         try {
-            file = createTempFileFromDocument(doc, streamId);
+            file = createTempFileFromDocument(object, streamId);
         } catch (Exception e) {
             showError(component, e);
         }
@@ -178,21 +183,23 @@ public class ClientHelper {
         return tempFile;
     }
 
-    public static File createTempFileFromDocument(Document doc, String streamId) throws Exception {
-        ContentStream content = doc.getContentStream(streamId);
+    public static File createTempFileFromDocument(CmisObject object, String streamId) throws Exception {
+        ContentStream content = getContentStream(object, streamId);
         if (content == null) {
             throw new Exception("No content!");
         }
 
         String filename = content.getFileName();
         if ((filename == null) || (filename.length() == 0)) {
-            filename = doc.getContentStreamFileName();
+            if (object instanceof Document) {
+                filename = ((Document) object).getContentStreamFileName();
+            }
         }
         if ((filename == null) || (filename.length() == 0)) {
-            filename = doc.getName();
+            filename = object.getName();
         }
         if ((filename == null) || (filename.length() == 0)) {
-            filename = "document";
+            filename = "content";
         }
 
         if (filename.indexOf('.') == -1) {
@@ -236,6 +243,33 @@ public class ClientHelper {
         }
     }
 
+    private static ContentStream getContentStream(CmisObject object, String streamId) {
+        if (object == null) {
+            return null;
+        }
+
+        if (object instanceof Document) {
+            return ((Document) object).getContentStream(streamId);
+        } else {
+            if (streamId == null) {
+                return null;
+            }
+
+            List<Rendition> renditions = object.getRenditions();
+            if (renditions == null) {
+                return null;
+            }
+
+            for (Rendition rendition : renditions) {
+                if (streamId.equals(rendition.getStreamId())) {
+                    return rendition.getContentStream();
+                }
+            }
+        }
+
+        return null;
+    }
+
     public static String readFileAndRemoveHeader(String file) {
         if (file == null) {
             return "";

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/RenditionTable.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/RenditionTable.java?rev=1032128&r1=1032127&r2=1032128&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/RenditionTable.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/RenditionTable.java Sat Nov  6 18:29:01 2010
@@ -20,7 +20,6 @@ package org.apache.chemistry.opencmis.wo
 
 import java.awt.event.MouseEvent;
 
-import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Rendition;
 import org.apache.chemistry.opencmis.workbench.ClientHelper;
 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
@@ -40,11 +39,11 @@ public class RenditionTable extends Abst
     @Override
     public void doubleClickAction(MouseEvent e, int rowIndex) {
         String streamId = getObject().getRenditions().get(rowIndex).getStreamId();
-        
+
         if (e.isShiftDown()) {
-            ClientHelper.download(this.getParent(), (Document) getObject(), streamId);
+            ClientHelper.download(this.getParent(), getObject(), streamId);
         } else {
-            ClientHelper.open(this.getParent(), (Document) getObject(), streamId);
+            ClientHelper.open(this.getParent(), getObject(), streamId);
         }
     }