]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3245: Additional functionality to the blob service for the v1.2 sprint.
authorRichard Millet <richard.millet@berkeley.edu>
Thu, 9 Dec 2010 08:52:24 +0000 (08:52 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Thu, 9 Dec 2010 08:52:24 +0000 (08:52 +0000)
services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java
services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java

index 8c2001d83d6f60f22f0e5f9337b8ad05290d0eda..56fd5187dd751a4c750125889243cebcbba78ce4 100644 (file)
@@ -30,6 +30,7 @@ import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.blob.BlobInput;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.blob.BlobsCommon;
 import org.collectionspace.services.blob.BlobsCommonList;
 
@@ -38,6 +39,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 //FIXME: REM - We should not have Nuxeo dependencies in our resource classes.
 import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils;
+import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 
 import javax.servlet.http.HttpServletRequest;
@@ -79,7 +81,9 @@ public class BlobResource extends ResourceBase {
        return BlobsCommon.class;
     }
 
-    public BlobsCommonList getBlobList(MultivaluedMap<String, String> queryParams) {
+    //FIXME: Is this method used/needed?
+    @Deprecated
+    private BlobsCommonList getBlobList(MultivaluedMap<String, String> queryParams) {
         return (BlobsCommonList)getList(queryParams);
     }
 
@@ -88,21 +92,37 @@ public class BlobResource extends ResourceBase {
         return (BlobsCommonList) getList(csidList);
     }
 
+    @Deprecated
     protected BlobsCommonList search(MultivaluedMap<String,String> queryParams,String keywords) {
          return (BlobsCommonList) super.search(queryParams, keywords);
     }
     
+    private BlobsCommonList getDerivativeList(String csid) throws Exception {
+       BlobsCommonList result = null;
+       
+       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+       ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, Boolean.TRUE);
+       MultipartOutput response = this.get(csid, ctx);
+       if (logger.isDebugEnabled() == true) {
+               logger.debug(response.toString());
+       }
+       result = (BlobsCommonList)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY);
+       
+       return result;
+    }
+    
     private InputStream getBlobContent(String csid, String derivativeTerm) throws WebApplicationException {
        InputStream result = null;
        
        try {
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               ctx.setProperty(BlobInput.DERIVATIVE_TERM_KEY, derivativeTerm);
+               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivativeTerm);
+               ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, Boolean.TRUE);
                MultipartOutput response = this.get(csid, ctx);
                if (logger.isDebugEnabled() == true) {
                        logger.debug(response.toString());
                }
-               result = (InputStream)ctx.getProperty(BlobInput.DERIVATIVE_CONTENT_KEY);
+               result = (InputStream)ctx.getProperty(BlobInput.BLOB_CONTENT_KEY);
        } catch (Exception e) {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
        }
@@ -146,10 +166,10 @@ public class BlobResource extends ResourceBase {
     @GET
     @Path("{csid}/content")
     @Produces({"image/jpeg", "image/png", "image/tiff"})
-    public InputStream getPicture(
+    public InputStream getBlobContent(
                @PathParam("csid") String csid) {
        InputStream result = null;
-           result = getBlobContent(csid, BlobInput.DERIVATIVE_ORIGINAL_VALUE);         
+           result = getBlobContent(csid, null /*derivative term*/);            
        return result;
     }
 
@@ -160,7 +180,55 @@ public class BlobResource extends ResourceBase {
                @PathParam("csid") String csid,
                @PathParam("derivative_term") String derivative_term) {
        InputStream result = null;
-           result = getBlobContent(csid, derivative_term);     
+           result = getBlobContent(csid, derivative_term);
+           
+       return result;
+    }
+    
+    @GET
+    @Path("{csid}/derivatives/{derivative_term}")
+    public MultipartOutput getDerivative(@PathParam("csid") String csid,
+               @PathParam("derivative_term") String derivative_term) {
+       MultipartOutput result = null;
+       
+       ensureCSID(csid, READ);
+        try {
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY, derivative_term);
+            result = get(csid, ctx);
+            if (result == null) {
+                Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
+                throw new WebApplicationException(response);
+            }
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+        }
+        
+        return result;
+    }
+        
+    @GET
+    @Path("{csid}/derivatives")
+    @Produces("application/xml")
+    public BlobsCommonList getDerivatives(
+               @PathParam("csid") String csid) {
+       BlobsCommonList result = null;
+
+       ensureCSID(csid, READ);
+        try {
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+               ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, true);
+            result = this.getDerivativeList(csid);
+            if (result == null) {
+                Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
+                throw new WebApplicationException(response);
+            }
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);
+        }
+           
        return result;
     }
     
index f3b250a66fa66537a5c98f6d88c8bc421044a2da..13f1498a50a9ca5a23c8af7c09fe463b967857be 100644 (file)
@@ -31,6 +31,7 @@ import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.jaxb.BlobJAXBSchema;
 
 import org.collectionspace.services.common.blob.BlobInput;
+import org.collectionspace.services.common.blob.BlobOutput;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.DocumentHandler.Action;
@@ -78,6 +79,11 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
                List list = ((BlobsCommonList)commonList).getBlobListItem();
                return list;
        }
+       
+       private String getDerivativePathBase(DocumentModel docModel) {
+               return getServiceContextPath() + docModel.getName() + "/" +
+                       BlobInput.URI_DERIVATIVES_PATH + "/";
+       }
 
        public Object createItemForCommonList(DocumentModel docModel, String label, String id) throws Exception {
                BlobListItem item = new BlobListItem();
@@ -114,7 +120,8 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
                                docModel.getProperty(label, BlobJAXBSchema.name));
                result.setRepositoryId((String)
                                docModel.getProperty(label, BlobJAXBSchema.repositoryId));
-               result.setUri(getServiceContextPath() + docModel.getName() + "/content");
+               result.setUri(getServiceContextPath() + docModel.getName() + "/" +
+                               BlobInput.URI_CONTENT_PATH);
                
                return result;
        }
@@ -139,28 +146,37 @@ extends DocHandlerBase<BlobsCommon, AbstractCommonList> {
        public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
                        throws Exception {
                ServiceContext ctx = this.getServiceContext();
+               RepositoryInstance repoSession = this.getRepositorySession();
                DocumentModel docModel = wrapDoc.getWrappedObject();
-               //
-               // Setup of the content URL's
-               //
-               BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);
-               String derivativeTerm = (String)ctx.getProperty(BlobInput.DERIVATIVE_TERM_KEY);
-               if (derivativeTerm != null  && !derivativeTerm.equalsIgnoreCase(BlobInput.DERIVATIVE_ORIGINAL_VALUE)) {
-                       blobsCommon.setUri(getServiceContextPath() + docModel.getName() + "/derivatives/" +
-                                       derivativeTerm + "/content");
-               }
-               blobsCommon.setRepositoryId(null); //hide the repository id from the GET results since it is private
-               this.setCommonPartProperties(docModel, blobsCommon);
+               BlobsCommon blobsCommon = this.getCommonPartProperties(docModel);               
+               String blobRepositoryId = blobsCommon.getRepositoryId(); //cache the value to pass to the blob retriever
                
-               super.extractAllParts(wrapDoc);
-               //
-               // If the derivativeTerm is set then we need to get the blob stream
-               //
+               if (ctx.getProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY) != null) {
+                       BlobsCommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives(
+                                       repoSession, blobRepositoryId, getDerivativePathBase(docModel));
+                       ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList);
+                       return;  //FIXME: Don't like this exit point.  Perhaps derivatives should be a sub-resource?
+               }               
+
+               String derivativeTerm = (String)ctx.getProperty(BlobInput.BLOB_DERIVATIVE_TERM_KEY);
+               Boolean getContentFlag = ctx.getProperty(BlobInput.BLOB_CONTENT_KEY) != null ? true : false;
+               BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession,
+                               blobRepositoryId, derivativeTerm, getContentFlag);
+               if (getContentFlag == true) {
+                       ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, blobOutput.getBlobInputStream());
+               }
+
                if (derivativeTerm != null) {
-                       RepositoryInstance repoSession = this.getRepositorySession();
-                       InputStream blobStream = NuxeoImageUtils.getPicture(ctx, repoSession, blobsCommon.getRepositoryId(), derivativeTerm);
-                       ctx.setProperty(BlobInput.DERIVATIVE_CONTENT_KEY, blobStream);
+                       // reset 'blobsCommon' if we have a derivative request
+                       blobsCommon = blobOutput.getBlobsCommon();
+                       blobsCommon.setUri(getDerivativePathBase(docModel) +
+                                       derivativeTerm + "/" + BlobInput.URI_CONTENT_PATH);
                }
+               
+               blobsCommon.setRepositoryId(null); //hide the repository id from the GET results payload since it is private
+               this.setCommonPartProperties(docModel, blobsCommon);
+               // finish extracting the other parts by calling the parent
+               super.extractAllParts(wrapDoc);
        }
 
        @Override
index 2847aa9f134d4b443f3aefbe2264d11cfeeee862..3377d479aab8d5bbd33084a86260bb5c6688f565 100644 (file)
@@ -514,107 +514,6 @@ public class CollectionObjectResource
                
                return result;
     }
-        
-    @GET
-    @Path("{csid}/getpicture/{blobId}")
-    @Produces({"image/jpeg", "image/png", "image/tiff"})
-    public InputStream getPicture(
-               @PathParam("csid") String csid,
-               @PathParam("blobId") String blobId) {
-       InputStream result = null;
-       RepositoryInstance repoSession = null;
-       try {
-                       repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
-                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-                       result = NuxeoImageUtils.getPicture(ctx, repoSession, blobId, null);
-       } catch (Exception e) {
-               logger.error("Could not get image blob: " + blobId, e);
-       } finally {
-               try {
-                               ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
-                       } catch (Exception e) {
-                               logger.error("Could not release Nuxeo repository session", e);
-                       }
-       }
-       
-       if (result == null) {
-               Response response = Response.status(
-                       Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
-               throw new WebApplicationException(response);
-       }
-       
-       return result;
-    }
-    
-    @GET
-    @Path("{csid}/getpicture/{blobId}/{derivativeTerm}")
-    @Produces({"image/jpeg", "image/png", "image/tiff"})
-    public InputStream getPicture(
-               @PathParam("csid") String csid,
-               @PathParam("blobId") String blobId,
-               @PathParam("derivativeTerm") String derivativeTerm) {
-       InputStream result = null;
-       RepositoryInstance repoSession = null;
-       try {
-                       repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
-                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-                       result = NuxeoImageUtils.getPicture(ctx, repoSession, blobId, derivativeTerm);
-       } catch (Exception e) {
-               logger.error("Could not get image blob: " + blobId, e);
-       } finally {
-               try {
-                               ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
-                       } catch (Exception e) {
-                               logger.error("Could not release Nuxeo repository session", e);
-                       }
-       }
-       
-       if (result == null) {
-               Response response = Response.status(
-                       Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
-               throw new WebApplicationException(response);
-       }
-        
-       return result;
-    }    
-    
-    @POST
-    @Path("{csid}/postpicture")
-    @Consumes("multipart/form-data")
-    @Produces("application/xml")
-    public String createPictureDocument(@Context HttpServletRequest req,
-               @PathParam("csid") String csid,
-               @QueryParam("blobUri") String blobUri) {
-       String result = null;
-       
-       RepositoryInstance repoSession = null;
-       try {
-                       repoSession = ServiceMain.getInstance().getNuxeoConnector().getRepositorySession();
-               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
-               File tmpFile = FileUtils.createTmpFile(req);
-               BlobInput blobInput = new BlobInput(tmpFile, blobUri);
-                       BlobsCommon blobCommon = NuxeoImageUtils.createPicture(ctx, repoSession, blobInput);
-                       if (blobCommon != null) {
-                               result = blobCommon.getRepositoryId();
-                       }
-       } catch (Exception e) {
-               logger.error("Could not create the new image file", e);
-       } finally {
-               try {
-                               ServiceMain.getInstance().getNuxeoConnector().releaseRepositorySession(repoSession);
-                       } catch (Exception e) {
-                               logger.error("Could not release Nuxeo repository session", e);
-                       }
-       }
-       
-       if (result == null) {
-               Response response = Response.status(
-                       Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed.").type("text/plain").build();
-               throw new WebApplicationException(response);
-       }       
-               
-               return result;
-    }    
 
     /**
      * This method is deprecated.  Use kwSearchCollectionObjects() method instead.
index 35e569b903d856df1e239034eb54bbc4ccedb218..b3222b2bb21b6560fad83ec999074beb980ad091 100644 (file)
@@ -218,17 +218,17 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
 \r
     //======================= GET without csid. List, search, etc. =====================================\r
 \r
-    @GET\r
-    @Produces("application/xml")\r
-    public AbstractCommonList getList   (@Context UriInfo ui,\r
-                                         @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {\r
-        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();\r
-       if (keywords != null) {\r
-               return search(queryParams, keywords);\r
-       } else {\r
-               return getList(queryParams);\r
-       }\r
-    }\r
+       @GET\r
+       @Produces("application/xml")\r
+       public AbstractCommonList getList(@Context UriInfo ui,\r
+                       @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {\r
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();\r
+               if (keywords != null) {\r
+                       return search(queryParams, keywords);\r
+               } else {\r
+                       return getList(queryParams);\r
+               }\r
+       }\r
 \r
     protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {\r
         try {\r
@@ -241,7 +241,6 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
         }\r
     }\r
 \r
-\r
     protected AbstractCommonList search(MultivaluedMap<String, String> queryParams, String keywords) {\r
         try {\r
                ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);\r
@@ -262,6 +261,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
         }\r
     }\r
 \r
+    //FIXME: REM - This should not be @Deprecated since we may want to implement this -it has been on the wish list.\r
     @Deprecated\r
     public AbstractCommonList getList(List<String> csidList) {\r
         try {\r
index b103eeda98233264d640abf992599fa7649dc7eb..c76c06b84a9fadb73fb19362d6ca6feafb80cbb3 100644 (file)
@@ -7,9 +7,12 @@ public class BlobInput {
        private File blobFile;\r
        private String blobUri;\r
        \r
-       public static final String DERIVATIVE_TERM_KEY = "Derivative";\r
-       public static final String DERIVATIVE_ORIGINAL_VALUE = "Original";\r
-       public static final String DERIVATIVE_CONTENT_KEY = "Derivative_Content_Stream";\r
+       public static final String URI_CONTENT_PATH = "content";\r
+       public static final String URI_DERIVATIVES_PATH = "derivatives";\r
+       \r
+       public static final String BLOB_DERIVATIVE_TERM_KEY = "derivative";\r
+       public static final String BLOB_DERIVATIVE_LIST_KEY = "derivative.list";\r
+       public static final String BLOB_CONTENT_KEY = "derivative.content.stream";\r
        \r
        public BlobInput(File blobFile, String blobUri) {\r
                this.blobFile = blobFile;\r
index ddb776e3b42d0b288d0ada70331a6c81afc09665..91c56e4772f2e59f5f197cd6fc5dcd3b076c6dc9 100644 (file)
@@ -105,6 +105,9 @@ import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentUtils;\r
 import org.collectionspace.services.common.FileUtils;\r
 import org.collectionspace.services.blob.BlobsCommon;\r
+import org.collectionspace.services.blob.BlobsCommonList;\r
+import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;\r
+import org.collectionspace.services.common.blob.BlobOutput;\r
 \r
 // TODO: Auto-generated Javadoc\r
 /**\r
@@ -113,6 +116,23 @@ import org.collectionspace.services.blob.BlobsCommon;
 public class NuxeoImageUtils {\r
        /** The Constant logger. */\r
        private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class);\r
+       \r
+       /*\r
+        * FIXME: REM - These constants should be coming from configuration and NOT hard coded.\r
+        */\r
+       public static final String DERIVATIVE_ORIGINAL = "Original";\r
+       public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + "_";\r
+       \r
+       public static final String DERIVATIVE_ORIGINAL_JPEG = "OriginalJpeg";\r
+       public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + "_";\r
+       \r
+       public static final String DERIVATIVE_MEDIUM = "Medium";\r
+       public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_";\r
+       \r
+       public static final String DERIVATIVE_THUMBNAIL = "Thumbnail";\r
+       public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + "_";\r
+       \r
+       public static final String DERIVATIVE_UNKNOWN = "_UNKNOWN_DERIVATIVE_NAME_";\r
        \r
 //     static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class)\r
 \r
@@ -139,7 +159,55 @@ public class NuxeoImageUtils {
                //empty method\r
        }       \r
        \r
-       static private BlobsCommon createBlobCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
+       //FIXME: This needs to be configuration-bases and NOT hard coded!\r
+       static private String getDerivativeUri(String uri, String derivativeName) {\r
+               String result = DERIVATIVE_UNKNOWN;\r
+               \r
+               if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_TAG) == true) {\r
+                       result = DERIVATIVE_ORIGINAL;\r
+               } else if (derivativeName.startsWith(DERIVATIVE_ORIGINAL_JPEG_TAG) == true) {\r
+                       result = DERIVATIVE_ORIGINAL_JPEG;\r
+               } else if (derivativeName.startsWith(DERIVATIVE_MEDIUM_TAG) == true) {\r
+                       result = DERIVATIVE_MEDIUM;\r
+               } else if (derivativeName.startsWith(DERIVATIVE_THUMBNAIL_TAG) == true) {\r
+                       result = DERIVATIVE_THUMBNAIL;\r
+               }\r
+               \r
+               return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
+       }\r
+       \r
+       static private BlobListItem createBlobListItem(Blob blob, String uri) {\r
+               BlobListItem result = new BlobListItem();\r
+\r
+               result.setEncoding(blob.getEncoding());\r
+               result.setLength(Long.toString(blob.getLength()));\r
+               result.setMimeType(blob.getMimeType());\r
+               result.setName(blob.getFilename());\r
+               result.setUri(getDerivativeUri(uri, blob.getFilename()));\r
+               \r
+               return result;\r
+       }\r
+       \r
+       static public BlobsCommonList getBlobDerivatives(RepositoryInstance repoSession,\r
+                       String repositoryId,\r
+                       String uri) throws Exception {\r
+               BlobsCommonList result = new BlobsCommonList();\r
+               \r
+               IdRef documentRef = new IdRef(repositoryId);\r
+               DocumentModel documentModel = repoSession.getDocument(documentRef);             \r
+               DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
+               List<Blob> docBlobs = docBlobHolder.getBlobs();         \r
+               List<BlobListItem> blobListItems = result.getBlobListItem();\r
+               BlobListItem blobListItem = null;\r
+               for (Blob blob : docBlobs) {\r
+                       blobListItem = createBlobListItem(blob, uri);\r
+                       blobListItems.add(blobListItem);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
                BlobsCommon result = new BlobsCommon();\r
                if (documentModel != null) {\r
                        result.setMimeType(nuxeoBlob.getMimeType());\r
@@ -153,8 +221,7 @@ public class NuxeoImageUtils {
        static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) {\r
                DefaultBinaryManager binaryManager = null;\r
                RepositoryDescriptor descriptor = null;\r
-               \r
-               \r
+                               \r
                try {\r
                        ServiceManager sm = (ServiceManager) Framework.getService(ServiceManager.class);\r
                        ServiceDescriptor[] sd = sm.getServiceDescriptors();\r
@@ -485,7 +552,7 @@ public class NuxeoImageUtils {
                        String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call.\r
                        DocumentModel documentModel = getFileManagerService().createDocumentFromBlob(nuxeoSession,\r
                                        fileBlob, blobLocation.getPathAsString(), true, fileName);\r
-                       result = createBlobCommon(documentModel, fileBlob);\r
+                       result = createBlobsCommon(documentModel, fileBlob);\r
                } catch (Exception e) {\r
                        result = null;\r
                        logger.error("Could not create new image blob", e);\r
@@ -493,22 +560,7 @@ public class NuxeoImageUtils {
                \r
                return result;\r
        }\r
-       \r
-       \r
-    /**\r
-     * Gets the picture.\r
-     *\r
-     * @param ctx the ctx\r
-     * @param repoSession the repo session\r
-     * @param blobId the blob id\r
-     * @param derivativeTerm the derivative term\r
-     * @return the picture\r
-     */\r
-    public static InputStream getPicture(ServiceContext ctx, RepositoryInstance repoSession,\r
-               String blobId, String derivativeTerm) {\r
-       return getImage(repoSession, blobId, derivativeTerm);\r
-    }\r
-       \r
+               \r
        /**\r
         * Gets the image.\r
         *\r
@@ -517,9 +569,12 @@ public class NuxeoImageUtils {
         * @param derivativeTerm the derivative term\r
         * @return the image\r
         */\r
-       static public InputStream getImage(RepositoryInstance repoSession,\r
-                       String repositoryId, String derivativeTerm) {\r
-               InputStream result = null;\r
+       static public BlobOutput getBlobOutput(ServiceContext ctx,\r
+                       RepositoryInstance repoSession,\r
+                       String repositoryId, \r
+                       String derivativeTerm,\r
+                       Boolean getContentFlag) {\r
+               BlobOutput result = new BlobOutput();\r
 \r
                try {\r
                        IdRef documentRef = new IdRef(repositoryId);\r
@@ -540,12 +595,17 @@ public class NuxeoImageUtils {
                        } else {\r
                                pictureBlob = pictureBlobHolder.getBlob();\r
                        }\r
+                       //\r
+                       // Create the result instance\r
+                       //\r
+                       BlobsCommon blobsCommon = createBlobsCommon(documentModel, pictureBlob);\r
+                       result.setBlobsCommon(blobsCommon); // the blob metadata\r
+                       if (getContentFlag == true) {\r
+                               InputStream remoteStream = pictureBlob.getStream();\r
+                               BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream);\r
+                               result.setBlobInputStream(bufferedInputStream); // the blob stream\r
+                       }\r
                        \r
-                       InputStream remoteStream = pictureBlob.getStream();\r
-                       BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream);\r
-                       result = bufferedInputStream;\r
-//                     File tmpFile = FileUtils.createTmpFile(remoteStream);\r
-//                     result = new FileInputStream(tmpFile);\r
                } catch (Exception e) {\r
                        logger.error(e.getMessage(), e);\r
                }\r