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 eefa9e6a97ce948e992f99c3681b09b6f633a867 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Aug 12 18:32:21 2014 +0200 add default preview if no image resource --- pollen-rest-api/pom.xml | 1 + .../org/chorem/pollen/rest/api/v1/PollenResourceApi.java | 13 ++++++++++--- pollen-rest-api/src/main/resources/default.jpg | Bin 0 -> 8374 bytes 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pollen-rest-api/pom.xml b/pollen-rest-api/pom.xml index af88551..8ec1831 100644 --- a/pollen-rest-api/pom.xml +++ b/pollen-rest-api/pom.xml @@ -204,6 +204,7 @@ <includes> <include>**/mapping</include> <include>**/*.properties</include> + <include>**/*.jpg</include> </includes> <filtering>true</filtering> </resource> 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 0b5f931..44cde35 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,5 +1,6 @@ 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.*; @@ -38,9 +39,15 @@ public class PollenResourceApi extends WebMotionController { Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); if (!readers.hasNext()) { - throw new IOException("Unreadable source. No format can be found."); + InputStream defaultFile = PollenResourceApi.class.getResourceAsStream("/default.jpg"); + + 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."); + } } - ImageReader reader = readers.next(); String format = reader.getFormatName(); @@ -63,7 +70,7 @@ public class PollenResourceApi extends WebMotionController { ByteArrayOutputStream output = new ByteArrayOutputStream(); ImageIO.write(destination, format, output); - return renderStream(new ByteArrayInputStream(output.toByteArray()), resource.getContentType()); + return renderStream(new ByteArrayInputStream(output.toByteArray()), format); } public ResourceMetaBean getMetaResource(PollenResourceService pollenResourceService, PollenEntityId<PollenResource> resourceId) { diff --git a/pollen-rest-api/src/main/resources/default.jpg b/pollen-rest-api/src/main/resources/default.jpg new file mode 100644 index 0000000..60aaa5d Binary files /dev/null and b/pollen-rest-api/src/main/resources/default.jpg differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.