[pollen] branch feature/createPreviewRessource updated (ed60d64 -> 10984f3)
This is an automated email from the git hooks/post-receive script. New change to branch feature/createPreviewRessource in repository pollen. See http://git.chorem.org/pollen.git from ed60d64 remove debug code new 10984f3 Set good header for preview, and improve getPreviewResource The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 10984f3ba7203ed4c89e747dd6e5df31bbbea928 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Aug 13 11:15:41 2014 +0200 Set good header for preview, and improve getPreviewResource Summary of changes: .../pollen/rest/api/v1/PollenResourceApi.java | 44 ++++++++++------------ .../src/main/webapp/js/controllers/pollCtrl.js | 4 +- pollen-ui-angular/src/main/webapp/js/directives.js | 3 +- .../src/main/webapp/partials/printResource.html | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/createPreviewRessource in repository pollen. See http://git.chorem.org/pollen.git commit 10984f3ba7203ed4c89e747dd6e5df31bbbea928 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Aug 13 11:15:41 2014 +0200 Set good header for preview, and improve getPreviewResource --- .../pollen/rest/api/v1/PollenResourceApi.java | 44 ++++++++++------------ .../src/main/webapp/js/controllers/pollCtrl.js | 4 +- pollen-ui-angular/src/main/webapp/js/directives.js | 3 +- .../src/main/webapp/partials/printResource.html | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java index 44cde35..db7dc0e 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenResourceApi.java @@ -1,7 +1,5 @@ package org.chorem.pollen.rest.api.v1; -import com.sun.corba.se.spi.orbutil.fsm.Input; -import org.apache.commons.io.IOUtils; import org.chorem.pollen.persistence.entity.PollenResource; import org.chorem.pollen.services.bean.*; import org.chorem.pollen.services.service.PollenResourceService; @@ -10,12 +8,12 @@ import org.debux.webmotion.server.call.UploadFile; import org.debux.webmotion.server.render.Render; import javax.imageio.ImageIO; -import javax.imageio.ImageReader; -import javax.imageio.stream.ImageInputStream; import java.awt.*; import java.awt.image.BufferedImage; -import java.io.*; -import java.util.Iterator; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; /** * Created on 10/07/14. @@ -34,24 +32,22 @@ public class PollenResourceApi extends WebMotionController { public Render getPreviewResource(PollenResourceService pollenResourceService, PollenEntityId<PollenResource> resourceId) throws IOException { ResourceStreamBean resource = pollenResourceService.getResource(resourceId.getEntityId()); + String contentType; + BufferedImage source; - ImageInputStream iis = ImageIO.createImageInputStream(resource.getResourceContent()); + switch (resource.getContentType()) { + case "image/jpeg": + case "image/png": + case "image/gif": + source = ImageIO.read(resource.getResourceContent()); + contentType = resource.getContentType(); - Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); - if (!readers.hasNext()) { - InputStream defaultFile = PollenResourceApi.class.getResourceAsStream("/default.jpg"); + break; - iis = ImageIO.createImageInputStream(new ByteArrayInputStream( - IOUtils.toByteArray(defaultFile))); - readers = ImageIO.getImageReaders(iis); - if (!readers.hasNext()) { - throw new IOException("Unreadable source. No format can be found."); - } + default: + source = ImageIO.read(PollenResourceApi.class.getResourceAsStream("/default.jpg")); + contentType = "image/jpeg"; } - ImageReader reader = readers.next(); - String format = reader.getFormatName(); - - BufferedImage source = ImageIO.read(iis); int width, height; if (source.getWidth() > source.getHeight()) { @@ -68,16 +64,14 @@ public class PollenResourceApi extends WebMotionController { g.dispose(); ByteArrayOutputStream output = new ByteArrayOutputStream(); - ImageIO.write(destination, format, output); + ImageIO.write(destination, contentType.split("/")[1], output); - return renderStream(new ByteArrayInputStream(output.toByteArray()), format); + return renderStream(new ByteArrayInputStream(output.toByteArray()), contentType); } public ResourceMetaBean getMetaResource(PollenResourceService pollenResourceService, PollenEntityId<PollenResource> resourceId) { - ResourceMetaBean resource = pollenResourceService.getMetaResource(resourceId.getEntityId()); - - return resource; + return pollenResourceService.getMetaResource(resourceId.getEntityId()); } public PollenEntityRef<PollenResource> createResource(PollenResourceService pollenResourceService, UploadFile resource) { diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index ccc01c5..a343e79 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -259,8 +259,8 @@ angular.module('pollControllers', ['ngRoute', 'pollenServices', 'pascalprecht.tr else if (choice.choiceType == 'RESOURCE') { var resourceId = choice.choiceValue; choice.choiceValue = {meta:{id:resourceId}, data:conf.restURL+'/resources/'+resourceId, id: resourceId}; - PollenResource.getMeta({resourceId : resourceId}, function (data) { - choice.choiceValue = {meta:data, data : conf.restURL+'/resources/'+data.id, id : data.id}; + PollenResource.getMeta({resourceId : resourceId}, function (meta) { + choice.choiceValue = {meta:meta, data : conf.restURL+'/resources/'+meta.id, id : meta.id}; }); } diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 34e8fdd..4adb593 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -445,6 +445,7 @@ angular.module('pollenDirective', []) scope.ngModel.promise = PollenResource.upload(formData, function (response) { scope.ngModel.meta.id = response.id; + scope.ngModel.meta.contentType = scope.ngModel.meta.type; scope.ngModel.id = response.id; scope.ngModel.data = conf.restURL+'/resources/'+response.id; }); @@ -483,7 +484,7 @@ angular.module('pollenDirective', []) scope.previewURL += "/" + scope.meta.name; } - scope.isImage = isImage(scope.meta.type); + scope.isImage = isImage(scope.meta.contentType); $(element).find('div').spin(false); } diff --git a/pollen-ui-angular/src/main/webapp/partials/printResource.html b/pollen-ui-angular/src/main/webapp/partials/printResource.html index 875f8d1..3261fd8 100644 --- a/pollen-ui-angular/src/main/webapp/partials/printResource.html +++ b/pollen-ui-angular/src/main/webapp/partials/printResource.html @@ -1,6 +1,6 @@ <div class="preview" ng-if="isImage"><img ng-attr-src="{{previewURL}}" /></div> <div class="preview" ng-if="!isImage"><a ng-attr-href="{{resourceURL}}"><img ng-attr-src="{{previewURL}}" /></a></div> -<div ng-if="showImage && isImage" class="full"> +<div ng-if="isImage && showImage" class="full"> <div class="full-content"> <span>{{meta.name}}</span> <img ng-attr-src="{{resourceURL}}" /> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm