clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r931970 - in /incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline: pom.xml src/main/java/org/apache/clerezza/tools/offline/Generator.java
Date Thu, 08 Apr 2010 15:21:52 GMT
Author: reto
Date: Thu Apr  8 15:21:51 2010
New Revision: 931970

URL: http://svn.apache.org/viewvc?rev=931970&view=rev
Log:
CLEREZZA-96: using ReplacingOutputStream

Modified:
    incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml
    incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java

Modified: incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml?rev=931970&r1=931969&r2=931970&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml (original)
+++ incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml Thu Apr
 8 15:21:51 2010
@@ -59,6 +59,10 @@
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>org.apache.clerezza.web.fileserver</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.utils</artifactId>
+		</dependency>
 	</dependencies>
 </project>
 

Modified: incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java?rev=931970&r1=931969&r2=931970&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
(original)
+++ incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
Thu Apr  8 15:21:51 2010
@@ -21,6 +21,7 @@ package org.apache.clerezza.tools.offlin
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.nio.charset.Charset;
@@ -30,6 +31,7 @@ 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;
@@ -53,6 +55,7 @@ import org.apache.felix.scr.annotations.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.utils.ReplacingOutputStream;
 import org.apache.clerezza.web.fileserver.util.MediaTypeGuesser;
 import org.wymiwyg.commons.util.dirbrowser.PathNode;
 
@@ -120,7 +123,7 @@ public class Generator {
 		if (targetUri == null) {
 			targetUri = baseUri;
 		}
-		if (targetUri == null) {
+		if (rootLinkPrefix == null) {
 			rootLinkPrefix = "";
 		}
 		if (formatExtensions == null) {
@@ -150,7 +153,7 @@ public class Generator {
 
 	private PathNode createFileHierarchy(String baseUri, String targetUri,
 			String rootLinkPrefix, List<String> formatExtensions) throws IOException {
-		Hierarchy result = new Hierarchy("generated-site");
+		Hierarchy result = new Hierarchy("");
 		MGraph contentGraph = cgp.getContentGraph();
 		Set<UriRef> matchingUri = new HashSet<UriRef>();
 		for (Triple triple : contentGraph) {
@@ -161,6 +164,9 @@ public class Generator {
 			}
 		}
 		for (UriRef uriRef : matchingUri) {
+			if (matchingUri.contains(new UriRef(uriRef.getUnicodeString()+"index"))) {
+				continue;
+			}
 			generateFilesForResource(baseUri, targetUri,
 					rootLinkPrefix, uriRef, contentGraph, formatExtensions,
 					result);
@@ -181,19 +187,41 @@ public class Generator {
 			MediaType mediaType = mediaTypeGuesser.getTypeForExtension(formatExtension);
 			try {
 				final byte[] variant = getVariant(uriRef, mediaType);
+				if (mediaType.getSubtype().equals("png"))
+					logger.info("Got variant of length : {}",variant.length);
 				final byte[] dataPrefixApplied = applyRootLinkPrefic(variant, 
 						rootLinkPrefix, mediaType);
 				final String filePath = uriRef.getUnicodeString().endsWith("/") ? path+"index" : path;
 				final String dottedExtension = "."+formatExtension;
 				final String extendedPath = filePath.endsWith(dottedExtension) ?
 					filePath : filePath + dottedExtension;
-				hierarchy.addChild(extendedPath, dataPrefixApplied);
+				if (mediaType.getSubtype().equals("png"))
+					logger.info("Processed length : {}",dataPrefixApplied.length);
+				hierarchy.addChild(extendedPath, 
+						changeBaseUri(dataPrefixApplied, baseUri, targetBaseUri));
 			} catch (VariantUnavailableException ex) {
-				logger.info("{} not available as {}", uriRef, mediaType);
+				logger.debug("{} not available as {}", uriRef, mediaType);
 			}
 		}	
 	}
 
+	private byte[] changeBaseUri(byte[] variant, String baseUri,
+			String targetBaseUri) {
+		try {
+			//here we should locate some mediaType specific handlers
+			//a quick hack
+			final ByteArrayOutputStream resultWriter = new ByteArrayOutputStream(variant.length +
1000);
+			final OutputStream out = new ReplacingOutputStream(resultWriter,
+						baseUri.getBytes(UTF8),
+						targetBaseUri.getBytes(UTF8));
+			out.write(variant);
+			out.close();
+			return resultWriter.toByteArray();
+		} catch (IOException ex) {
+			throw new RuntimeException(ex);
+		}
+	}
+
 	private byte[] getVariant(UriRef uriRef, MediaType mediaType) throws 
 			IOException, VariantUnavailableException {
 		final URL url = new URL(uriRef.getUnicodeString());
@@ -236,16 +264,26 @@ public class Generator {
 
 	private byte[] applyRootLinkPrefic(byte[] variant, String rootLinkPrefix,
 			MediaType mediaType) {
-		//here we should locate some mediaType specific handlers
-		//a quick hack
-		String stringVersion = new String(variant, UTF8);
-		for (String rootLinkIndicator : rootLinkIndicators) {
-			stringVersion = stringVersion.replaceAll(rootLinkIndicator+"/",
-					rootLinkIndicator+rootLinkPrefix+"/");
+		try {
+			//here we should locate some mediaType specific handlers
+			//a quick hack
+			final ByteArrayOutputStream resultWriter = new ByteArrayOutputStream(variant.length +
1000);
+			OutputStream out = resultWriter;
+			for (String rootLinkIndicator : rootLinkIndicators) {
+				out = new ReplacingOutputStream(out, 
+						(rootLinkIndicator + "/").getBytes(UTF8),
+						(rootLinkIndicator + rootLinkPrefix + "/").getBytes(UTF8));
+			}
+			out.write(variant);
+			out.close();
+			return resultWriter.toByteArray();
+		} catch (IOException ex) {
+			throw new RuntimeException(ex);
 		}
-		return stringVersion.getBytes(UTF8);
 	}
 
+
+
 	private static class VariantUnavailableException extends Exception {
 
 		VariantUnavailableException(String message) {



Mime
View raw message