chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1400131 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ main/resourc...
Date Fri, 19 Oct 2012 15:22:37 GMT
Author: jens
Date: Fri Oct 19 15:22:36 2012
New Revision: 1400131

URL: http://svn.apache.org/viewvc?rev=1400131&view=rev
Log:
Add basic rendition support for InMemory server (standard icons for office formats)

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-msword.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-pdf.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-excel.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-powerpoint.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/audio-x-generic.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/folder.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/image-x-generic.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-html.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-x-generic.png
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/video-x-generic.png
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ImageThumbnailGenerator.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/AtomLinkInfoProvider.java
Fri Oct 19 15:22:36 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.inmemory.server;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
@@ -26,10 +27,13 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
 import org.apache.chemistry.opencmis.commons.data.ObjectList;
 import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
+import org.apache.chemistry.opencmis.commons.impl.server.RenditionInfoImpl;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
+import org.apache.chemistry.opencmis.commons.server.RenditionInfo;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Content;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
@@ -125,7 +129,22 @@ public class AtomLinkInfoProvider {
         }
 
         // Renditions, currently not supported by in-memory provider
-        objInfo.setRenditionInfos(null);
+        List<RenditionData> renditions = so.getRenditions("*", 0, 0);
+        if (renditions == null || renditions.size() == 0)
+            objInfo.setRenditionInfos(null);
+        else {
+            List<RenditionInfo> infos = new ArrayList<RenditionInfo>();
+            for (RenditionData rendition : renditions) {
+                RenditionInfoImpl info = new RenditionInfoImpl();
+                info.setKind(rendition.getKind());
+                info.setId(rendition.getStreamId());
+                info.setContentType(rendition.getMimeType());
+                info.setLength(rendition.getBigLength());
+                info.setTitle(rendition.getTitle());
+                infos.add(info);
+            }
+            objInfo.setRenditionInfos(infos);
+        }
 
         // Relationships, currently not supported by in-memory provider
         objInfo.setSupportsRelationships(false);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Fri Oct 19 15:22:36 2012
@@ -342,7 +342,7 @@ public class InMemoryObjectServiceImpl e
             throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
         }
 
-        if (!(so instanceof Content)) {
+        if (!(so instanceof Content) && objectId.endsWith("-rendition")) {
             throw new CmisConstraintException("Id" + objectId
                     + " does not refer to a document or version, but only those can have
content");
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.java
Fri Oct 19 15:22:36 2012
@@ -18,7 +18,10 @@
  */
 package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
@@ -29,6 +32,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
 import org.apache.chemistry.opencmis.commons.data.RenditionData;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 import org.apache.chemistry.opencmis.inmemory.ConfigConstants;
@@ -49,14 +53,10 @@ import org.slf4j.LoggerFactory;
 public class DocumentImpl extends AbstractMultiFilingImpl implements Document {
     private ContentStreamDataImpl fContent;
 
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractSingleFilingImpl.class.getName());
+    private static final Logger LOG = LoggerFactory.getLogger(DocumentImpl.class.getName());
     private final Long MAX_CONTENT_SIZE_KB = ConfigurationSettings.getConfigurationValueAsLong(ConfigConstants.MAX_CONTENT_SIZE_KB);
 
-    public static final int IMG_HEIGHT = 100;
-    public static final int IMG_WIDTH = 100;
-    public static final String RENDITION_MIME_TYPE = "image/jpeg";
-    public static final String RENDITION_SUFFIX = "-rendition"
-            ;
+    public static final int THUMBNAIL_SIZE = 100;
 
     DocumentImpl(ObjectStoreImpl objStore) { // visibility should be package
         super(objStore);
@@ -184,16 +184,25 @@ public class DocumentImpl extends Abstra
             renditionFilter = "*";
         String[] formats = renditionFilter.split(tokenizer);
         boolean isImageRendition = testRenditionFilterForImage(formats);
+
         if (isImageRendition && fContent != null && hasRendition(null)) {
             List<RenditionData> renditions = new ArrayList<RenditionData>(1);
+            String mimeType = fContent.getMimeType();
             RenditionDataImpl rendition = new RenditionDataImpl();
-            rendition.setBigHeight(BigInteger.valueOf(IMG_HEIGHT));
-            rendition.setBigWidth(BigInteger.valueOf(IMG_WIDTH));
+            if (mimeType.equals("image/jpeg")) {
+                rendition.setBigHeight(BigInteger.valueOf(THUMBNAIL_SIZE));
+                rendition.setBigWidth(BigInteger.valueOf(THUMBNAIL_SIZE));
+                rendition.setMimeType(RENDITION_MIME_TYPE_JPEG);
+            } else {
+                rendition.setBigHeight(BigInteger.valueOf(ICON_SIZE));
+                rendition.setBigWidth(BigInteger.valueOf(ICON_SIZE));
+                rendition.setMimeType(RENDITION_MIME_TYPE_PNG);
+            }
             rendition.setKind("cmis:thumbnail");
-            rendition.setMimeType(RENDITION_MIME_TYPE);
             rendition.setRenditionDocumentId(getId());
             rendition.setStreamId(getId() + RENDITION_SUFFIX);
             rendition.setBigLength(BigInteger.valueOf(-1L));
+            rendition.setTitle(getName());
             renditions.add(rendition);
             return renditions;
         } else {
@@ -202,32 +211,105 @@ public class DocumentImpl extends Abstra
     }
 
     @Override
-    public ContentStream getRenditionContent(String streamId, long offset, long length) {
       
-        ImageThumbnailGenerator generator = new ImageThumbnailGenerator(getContent(0L, -1L).getStream());
-        return generator.getRendition(IMG_WIDTH, IMG_HEIGHT);
+    public ContentStream getRenditionContent(String streamId, long offset, long length) {
    
+        if (null == fContent)
+            return null;
+        
+        String mimeType = fContent.getMimeType();
+        
+        try {
+            if (isImage(mimeType)) {
+                ImageThumbnailGenerator generator = new ImageThumbnailGenerator(getContent(0L,
-1L).getStream());
+                return generator.getRendition(THUMBNAIL_SIZE, 0);
+            } else if (isAudio(mimeType)) {
+                return getIconFromResourceDir("/audio-x-generic.png");
+            } else if (isVideo(mimeType)) {
+                return getIconFromResourceDir("/video-x-generic.png");
+            } else if (isPDF(mimeType)) {
+                return getIconFromResourceDir("/application-pdf.png");
+            } else if (isWord(mimeType)) {
+                return getIconFromResourceDir("/application-msword.png");
+            } else if (isPowerpoint(mimeType)) {
+                return getIconFromResourceDir("/application-vnd.ms-powerpoint.png");
+            } else if (isExcel(mimeType)) {
+                return getIconFromResourceDir("/application-vnd.ms-excel.png");
+            } else if (isHtml(mimeType)) {
+                return getIconFromResourceDir("/text-html.png");
+            } else if (isPlainText(mimeType)) {
+                return getIconFromResourceDir("/text-x-generic.png");
+            } else
+                return null;
+        } catch (IOException e) {
+            LOG.error("Failed to generate rendition: ", e);
+            throw new CmisRuntimeException("Failed to generate rendition: " + e);
+        }
     }
     
     @Override
     public boolean hasRendition(String user) {
-        return null != fContent && fContent.getMimeType().startsWith("image/");
+        if (null == fContent)
+            return false;
+        
+        String mimeType = fContent.getMimeType();
+        
+        if (isImage(mimeType))
+            return true;
+        else if (isAudio(mimeType))
+            return true;
+        else if (isVideo(mimeType))
+            return true;
+        else if (isPDF(mimeType))
+            return true;
+        else if (isPowerpoint(mimeType))
+            return true;
+        else if (isExcel(mimeType))
+            return true;
+        else if (isWord(mimeType))
+            return true;
+        else if (isHtml(mimeType))
+            return true;
+        else if (isPlainText(mimeType))
+            return true;
+        else
+            return false;
     }
 
 
-    protected boolean testRenditionFilterForImage(String[] formats) {
-        if (formats.length == 1 && null != formats[0] && formats[0].equals("cmis:none"))
-            return false;
-        else
-            return arrayContainsString(formats, "*")  || arrayContainsString(formats, "image/*")

-                || arrayContainsString(formats, "image/jpeg") ;
+    private boolean isImage(String mimeType) {
+        return mimeType.startsWith("image/");
     }
 
-    private boolean arrayContainsString(String[] formats, String val) {
-        for (String s : formats) {
-            if (val.equals(s))
-                return true;            
-        }
-        return false;
+    private boolean isWord(String mimeType) {
+        return mimeType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
     }
 
+    private boolean isExcel(String mimeType) {
+        return mimeType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+    }
+    
+    private boolean isPowerpoint(String mimeType) {
+        return mimeType.equals("application/vnd.openxmlformats-officedocument.presentationml.slideshow")
||
+        mimeType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation");
+    }
+    
+    private boolean isPDF(String mimeType) {
+        return mimeType.equals("application/pdf");
+    }
+    
+    private boolean isHtml(String mimeType) {
+       return mimeType.equals("text/html");
+    }
+    
+    private boolean isAudio(String mimeType) {
+        return mimeType.startsWith("audio/");
+    }
 
-}
+    private boolean isVideo(String mimeType) {
+        return mimeType.startsWith("video/");
+    }
+    
+    private boolean isPlainText(String mimeType) {
+        return mimeType.equals("text/plain");
+    }
+    
+ }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.java
Fri Oct 19 15:22:36 2012
@@ -21,6 +21,8 @@ package org.apache.chemistry.opencmis.in
  */
 
 
+import java.io.IOException;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -28,9 +30,13 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 import org.apache.chemistry.opencmis.inmemory.FilterParser;
 import org.apache.chemistry.opencmis.inmemory.NameValidator;
@@ -256,4 +262,42 @@ public class FolderImpl extends Abstract
         return null;
     }
 
+    public List<RenditionData> getRenditions(String renditionFilter, long maxItems,
long skipCount) {
+        if (null==renditionFilter)
+            renditionFilter = "*";
+        String tokenizer = "[\\s;]";
+        String[] formats = renditionFilter.split(tokenizer);
+        boolean isImageRendition = testRenditionFilterForImage(formats);
+ 
+        if (isImageRendition) {
+            List<RenditionData> renditions = new ArrayList<RenditionData>(1);
+            RenditionDataImpl rendition = new RenditionDataImpl();
+            rendition.setBigHeight(BigInteger.valueOf(ICON_SIZE));
+            rendition.setBigWidth(BigInteger.valueOf(ICON_SIZE));
+            rendition.setKind("cmis:thumbnail");
+            rendition.setMimeType(RENDITION_MIME_TYPE_PNG);
+            rendition.setRenditionDocumentId(getId());
+            rendition.setStreamId(getId() + RENDITION_SUFFIX);
+            rendition.setBigLength(BigInteger.valueOf(-1L));
+            rendition.setTitle(getName());
+            rendition.setRenditionDocumentId(getId());
+            renditions.add(rendition);
+            return renditions;
+        } else {
+            return null;
+        }
+    }
+
+    public ContentStream getRenditionContent(String streamId, long offset, long length) {
+        try {
+            return getIconFromResourceDir("/folder.png");
+        } catch (IOException e) {
+            LOG.error("Failed to generate rendition: ", e);
+            throw new CmisRuntimeException("Failed to generate rendition: " + e);
+        }
+    }
+
+    public boolean hasRendition(String user) {
+        return true;
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ImageThumbnailGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ImageThumbnailGenerator.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ImageThumbnailGenerator.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ImageThumbnailGenerator.java
Fri Oct 19 15:22:36 2012
@@ -38,10 +38,20 @@ public class ImageThumbnailGenerator {
 
     private static final String RENDITION_MIME_TYPE = "image/jpeg";;
     private InputStream image;
-
+    private int thumbWidth;
+    private int thumbHeight;
+    
     public ImageThumbnailGenerator(InputStream imageContent) {
         this.image = imageContent;
     }
+    
+    public int getWidth() {
+        return thumbWidth;
+    }
+    
+    public int getHeight() {
+        return thumbHeight;
+    }
 
     public ContentStream getRendition(int width, int height) {
         byte[] thumbnail;
@@ -58,10 +68,45 @@ public class ImageThumbnailGenerator {
         }
     }
 
+    
     private byte[] scaleImage(InputStream stream, int width, int height) throws IOException
{
         
+        BufferedImage resizedImage;
         BufferedImage originalImage = ImageIO.read(stream);
 
+        if (width <= 0)
+            resizedImage = scaleLongerSideTo(originalImage, height);
+        else if (height <= 0)
+            resizedImage = scaleLongerSideTo(originalImage, width);
+        else
+            resizedImage = scaleImage(originalImage, width, height);
+        
+        thumbWidth = resizedImage.getWidth();
+        thumbHeight = resizedImage.getHeight();
+        
+        return storeImageinByteArray(resizedImage);
+    }
+    
+    private BufferedImage scaleLongerSideTo(BufferedImage bi, int longerSideLength) throws
IOException {
+        int width, height;
+        
+        if (longerSideLength <= 0)
+            longerSideLength = 100;
+        
+        if (bi.getWidth() > bi.getHeight()) {
+            width = longerSideLength;
+            height = bi.getHeight() * longerSideLength / bi.getWidth();
+        } else {
+            height = longerSideLength;
+            width = bi.getWidth() * longerSideLength / bi.getHeight();
+        }
+                
+        BufferedImage resizedImage = scaleImage(bi, width, height);
+        return resizedImage;
+    }
+    
+    private BufferedImage scaleImage(BufferedImage originalImage, int width, int height)
{
+        
         BufferedImage resizedImage = new BufferedImage(width, height, originalImage.getType());

         //        ColorSpace.TYPE_RGB);
         Graphics2D g = resizedImage.createGraphics();
@@ -74,8 +119,13 @@ public class ImageThumbnailGenerator {
         g.dispose();    
         g.setComposite(AlphaComposite.Src);
      
+        return resizedImage;
+    }
+    
+    private byte[] storeImageinByteArray(BufferedImage bi) throws IOException {
+        
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        boolean ok = ImageIO.write(resizedImage, "JPG", os);
+        boolean ok = ImageIO.write(bi, "JPG", os);
         if (ok)
             return os.toByteArray();
         else

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
Fri Oct 19 15:22:36 2012
@@ -18,6 +18,10 @@
  */
 package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigInteger;
 import java.util.Date;
 import java.util.GregorianCalendar;
@@ -49,6 +53,11 @@ import org.apache.chemistry.opencmis.inm
  */
 public class StoredObjectImpl implements StoredObject {
 
+    public static final String RENDITION_MIME_TYPE_JPEG = "image/jpeg";
+    public static final String RENDITION_MIME_TYPE_PNG = "image/png";
+    public static final String RENDITION_SUFFIX = "-rendition";
+    public static final int ICON_SIZE = 32;
+
     protected String fId;
     protected String fName;
     protected String fTypeId;
@@ -417,4 +426,43 @@ public class StoredObjectImpl implements
     public boolean hasRendition(String user) {
         return false;
     }
+    
+    protected  ContentStream getIconFromResourceDir(String name) throws IOException {
+        
+        InputStream imageStream = this.getClass().getResourceAsStream(name);
+        ContentStreamDataImpl content = new ContentStreamDataImpl(0);
+        content.setFileName(name);
+        content.setMimeType("image/png");
+
+        ByteArrayOutputStream ba = new ByteArrayOutputStream();
+        byte[] buffer = new byte [65536];
+        int noBytesRead = 0;
+
+        while ((noBytesRead = imageStream.read(buffer)) >=0 ) {
+            ba.write(buffer, 0, noBytesRead);
+        }
+        
+        content.setContent(new ByteArrayInputStream(ba.toByteArray()));
+        return content;
+    }
+    
+    protected boolean testRenditionFilterForImage(String[] formats) {
+        if (formats.length == 1 && null != formats[0] && formats[0].equals("cmis:none"))
+            return false;
+        else
+            return arrayContainsString(formats, "*")  || arrayContainsString(formats, "image/*")

+                || arrayContainsString(formats, "image/jpeg") ;
+    }
+    
+    private boolean arrayContainsString(String[] formats, String val) {
+        for (String s : formats) {
+            if (val.equals(s))
+                return true;            
+        }
+        return false;
+    }
+
+
+
+
 }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-msword.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-msword.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-msword.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-pdf.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-pdf.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-pdf.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-excel.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-excel.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-excel.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-powerpoint.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-powerpoint.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/application-vnd.ms-powerpoint.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/audio-x-generic.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/audio-x-generic.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/audio-x-generic.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/folder.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/folder.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/folder.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/image-x-generic.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/image-x-generic.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/image-x-generic.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-html.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-html.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-html.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-x-generic.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-x-generic.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/text-x-generic.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/video-x-generic.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/video-x-generic.png?rev=1400131&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/resources/video-x-generic.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
Fri Oct 19 15:22:36 2012
@@ -236,13 +236,17 @@ public class AbstractServiceTest {
     }
 
     protected ContentStream createContent(int sizeInKB) {
-        return createContent(sizeInKB, 0);
+        return createContent(sizeInKB, 0, null);
     }
 
-    protected ContentStream createContent(int sizeInKB, long maxSizeInKB) {
+    protected ContentStream createContent(int sizeInKB, long maxSizeInKB, String mimeType)
{
         ContentStreamDataImpl content = new ContentStreamDataImpl(maxSizeInKB);
         content.setFileName("data.txt");
-        content.setMimeType("text/plain");
+        
+        if (null == mimeType)
+            content.setMimeType("text/plain");
+        else
+            content.setMimeType(mimeType);
         int len = sizeInKB * 1024;
         byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
0x6d, 0x6e, 0x0c, 0x0a,
                 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d,
0x6e, 0x0c, 0x0a }; // 32

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=1400131&r1=1400130&r2=1400131&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Fri Oct 19 15:22:36 2012
@@ -111,7 +111,9 @@ public class ObjectServiceTest extends A
     private static final String FOLDER_ID = "Folder_1";
     private static final String MY_CUSTOM_NAME = "My Custom Document";
     private static final int MAX_SIZE = 100;
-
+    private static final String PNG = "image/png";
+    private static final String JPEG = "image/jpeg";
+    
     ObjectCreator fCreator;
 
     @Override
@@ -956,7 +958,7 @@ public class ObjectServiceTest extends A
     public void testMaxContentSize() {
         log.info("starting testMaxContentSize() ...");
         try {
-            createContent(MAX_SIZE + 1, MAX_SIZE);
+            createContent(MAX_SIZE + 1, MAX_SIZE, null);
             fail("createContent with exceeded content size should fail.");
         } catch (CmisInvalidArgumentException e) {
             log.debug("createDocument with exceeded failed as excpected.");
@@ -980,10 +982,9 @@ public class ObjectServiceTest extends A
     }
 
     @Test
-    public void testRendition() {
+    public void testRenditionImage() {
         // upload an image as JPEG picture
         log.info("starting testRendition() ...");
-        final String JPEG = "image/jpeg";
         
         try {
             InputStream imageStream = this.getClass().getResourceAsStream("/image.jpg");
@@ -1002,8 +1003,8 @@ public class ObjectServiceTest extends A
             assertEquals(id, rd.getRenditionDocumentId());
             assertNotNull(rd.getBigHeight());
             assertNotNull(rd.getBigWidth());
-            assertEquals(DocumentImpl.IMG_HEIGHT, rd.getBigHeight().longValue());
-            assertEquals(DocumentImpl.IMG_WIDTH, rd.getBigWidth().longValue());
+            assertEquals(DocumentImpl.THUMBNAIL_SIZE, rd.getBigHeight().longValue());
+            assertEquals(DocumentImpl.THUMBNAIL_SIZE, rd.getBigWidth().longValue());
             assertNotNull(rd.getStreamId());
             ContentStream renditionContent = fObjSvc.getContentStream(fRepositoryId, id,
rd.getStreamId(), null, null, null);
             assertEquals(rd.getMimeType(), renditionContent.getMimeType());
@@ -1012,10 +1013,77 @@ public class ObjectServiceTest extends A
             log.error("testRendition failed with exception ", e);
             fail("testRendition failed with exceetion " + e);
         }
-        log.info("... testRendition finished.");
-   
+        log.info("... testRendition finished.");   
+    }
+    
+    @Test
+    public void testRenditionIcon() {
+        // fake an office document
+        log.info("starting testRendition() ...");
+        
+        try {
+            ContentStream content = createContent(4, 0, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

+            Properties props = createDocumentProperties("TestJOffice", DOCUMENT_TYPE_ID);
+            String id = fObjSvc.createDocument(fRepositoryId, props, fRootFolderId, content,
VersioningState.NONE,
+                    null, null, null, null);
+
+            assertNotNull (id);
+            String renditionFilter = "*";
+            List<RenditionData> renditions = fObjSvc.getRenditions(fRepositoryId, id,
renditionFilter, null, null, null);
+            assertNotNull(renditions);
+            assertEquals(1, renditions.size());
+            RenditionData rd = renditions.get(0);
+            assertEquals(PNG, rd.getMimeType());
+            assertEquals("cmis:thumbnail", rd.getKind());
+            assertEquals(id, rd.getRenditionDocumentId());
+            assertNotNull(rd.getBigHeight());
+            assertNotNull(rd.getBigWidth());
+            assertEquals(DocumentImpl.ICON_SIZE, rd.getBigHeight().longValue());
+            assertEquals(DocumentImpl.ICON_SIZE, rd.getBigWidth().longValue());
+            assertNotNull(rd.getStreamId());
+            ContentStream renditionContent = fObjSvc.getContentStream(fRepositoryId, id,
rd.getStreamId(), null, null, null);
+            assertEquals(rd.getMimeType(), renditionContent.getMimeType());
+            readThumbnailStream(renditionContent.getStream());
+        } catch (Exception e) {
+            log.error("testRendition failed with exception ", e);
+            fail("testRendition failed with exceetion " + e);
+        }
+        log.info("... testRendition finished.");   
     }
+    @Test
+    public void testFolderRendition() {
+        // upload an image as JPEG picture
+        log.info("starting testFolderRendition() ...");
+        
+        try {
+            InputStream imageStream = this.getClass().getResourceAsStream("/image.jpg");
+            assertNotNull("Test setup failure no 'image.jpg' in test resources, getResourceAsStream
failed", imageStream);
+            String id = createFolder();           
 
+            assertNotNull (id);
+            String renditionFilter = "*";
+            List<RenditionData> renditions = fObjSvc.getRenditions(fRepositoryId, id,
renditionFilter, null, null, null);
+            assertNotNull(renditions);
+            assertEquals(1, renditions.size());
+            RenditionData rd = renditions.get(0);
+            assertEquals(PNG, rd.getMimeType());
+            assertEquals("cmis:thumbnail", rd.getKind());
+            assertEquals(id, rd.getRenditionDocumentId());
+            assertNotNull(rd.getBigHeight());
+            assertNotNull(rd.getBigWidth());
+            assertEquals(DocumentImpl.ICON_SIZE, rd.getBigHeight().longValue());
+            assertEquals(DocumentImpl.ICON_SIZE, rd.getBigWidth().longValue());
+            assertNotNull(rd.getStreamId());
+            ContentStream renditionContent = fObjSvc.getContentStream(fRepositoryId, id,
rd.getStreamId(), null, null, null);
+            assertEquals(rd.getMimeType(), renditionContent.getMimeType());
+            readThumbnailStream(renditionContent.getStream());
+        } catch (Exception e) {
+            log.error("testFolderRendition failed with exception ", e);
+            fail("testFolderRendition failed with exceetion " + e);
+        }
+        log.info("... testFolderRendition finished.");
+   
+    }
     protected String createDocumentFromStream(String name, String folderId, String typeId,
InputStream is,
             String contentType) throws IOException {
 



Mime
View raw message