clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r990834 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline: pom.xml src/main/java/org/apache/clerezza/tools/offline/Generator.java src/main/java/org/apache/clerezza/tools/offline/utils/
Date Mon, 30 Aug 2010 15:58:49 GMT
Author: mir
Date: Mon Aug 30 15:58:49 2010
New Revision: 990834

URL: http://svn.apache.org/viewvc?rev=990834&view=rev
Log:
CLEREZZA-292: hrefs and scrs which use the thumbnail-service are replaced with the thumbnail
uri.

Added:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/utils/
Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/pom.xml
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/pom.xml?rev=990834&r1=990833&r2=990834&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/pom.xml
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/pom.xml
Mon Aug 30 15:58:49 2010
@@ -63,6 +63,10 @@
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.utils</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.content.representations.core</artifactId>
+		</dependency>
 	</dependencies>
 </project>
 

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java?rev=990834&r1=990833&r2=990834&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
Mon Aug 30 15:58:49 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.clerezza.tools.offline;
 
+import org.apache.clerezza.tools.offline.utils.ConditionalOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -31,7 +32,6 @@ import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.logging.Level;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -41,6 +41,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Response.Status;
+import org.apache.clerezza.platform.content.representations.core.ThumbnailService;
 import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
 import org.apache.clerezza.platform.typerendering.RendererFactory;
 import org.apache.clerezza.rdf.core.MGraph;
@@ -80,6 +81,9 @@ public class Generator {
 	@Reference
 	private RendererFactory rendererFactory;
 
+	@Reference
+	private ThumbnailService thumbnailService;
+
 	private MediaTypeGuesser mediaTypeGuesser = MediaTypeGuesser.getInstance();
 
 	final Logger logger = LoggerFactory.getLogger(Generator.class);
@@ -189,7 +193,8 @@ public class Generator {
 				final byte[] variant = getVariant(uriRef, mediaType);
 				if (mediaType.getSubtype().equals("png"))
 					logger.info("Got variant of length : {}",variant.length);
-				final byte[] dataPrefixApplied = applyRootLinkPrefic(variant, 
+				final byte[] addedThumbnailUris = applyThumbnailService(variant);
+				final byte[] dataPrefixApplied = applyRootLinkPrefix(addedThumbnailUris,
 						rootLinkPrefix, mediaType);
 				final String filePath = uriRef.getUnicodeString().endsWith("/") ? path+"index" : path;
 				final String dottedExtension = "."+formatExtension;
@@ -266,7 +271,7 @@ public class Generator {
 		rootLinkIndicators.add("url\\(");
 	}
 
-	private byte[] applyRootLinkPrefic(byte[] variant, String rootLinkPrefix,
+	private byte[] applyRootLinkPrefix(byte[] variant, String rootLinkPrefix,
 			MediaType mediaType) {
 		try {
 			//here we should locate some mediaType specific handlers
@@ -286,6 +291,19 @@ public class Generator {
 		}
 	}
 
+	private byte[] applyThumbnailService(byte[] variant) {
+		try {			
+			final ByteArrayOutputStream resultWriter = new ByteArrayOutputStream(variant.length);
+			OutputStream thumbnailCorrectingStream = new ConditionalOutputStream(resultWriter,
+					new ThumbnailCondition(thumbnailService));
+			thumbnailCorrectingStream.write(variant);
+			thumbnailCorrectingStream.close();
+			return resultWriter.toByteArray();
+		} catch (IOException ex) {
+			throw new RuntimeException(ex);
+		}
+	}
+
 
 
 	private static class VariantUnavailableException extends Exception {



Mime
View raw message