Author: reto
Date: Wed Mar  3 14:27:35 2010
New Revision: 918485

URL: http://svn.apache.org/viewvc?rev=918485&view=rev
Log:
CLERREZZA-96: skeleton

Added:
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml
    incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Hierarchy.java
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/ZipCreationUtil.java
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/documentation.nt
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/sparql-endpoint.ssp
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/
    
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/ZipCreationUtilTest.java

Added: 
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=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml 
(added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/pom.xml 
Wed Mar  3 14:27:35 2010
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project 
xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.apache.clerezza</groupId>
+               <artifactId>org.apache.clerezza.rdf.web</artifactId>
+               <version>0.8-incubating-SNAPSHOT</version>
+       </parent>
+       <groupId>org.apache.clerezza</groupId>
+       <artifactId>org.apache.clerezza.tools.offline</artifactId>
+       <packaging>bundle</packaging>
+       <version>0.1-incubating-SNAPSHOT</version>
+       <name>Clerezza - Tools Offline Site Generator</name>
+       <description>The core part of SCB Web Access</description>
+       <dependencies>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.platform.typerendering.core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.platform.typerendering.scalaserverpages</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>org.apache.clerezza.rdf.core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.rdf.jena.parser</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>javax.ws.rs</groupId>
+                       <artifactId>jsr311-api</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>org.apache.clerezza.jaxrs.utils</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.rdf.ontologies</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       
<artifactId>org.apache.clerezza.rdf.web.ontologies</artifactId>
+               </dependency>
+       </dependencies>
+</project>

Added: 
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=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Generator.java
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.tools.offline;
+
+import org.apache.clerezza.rdf.utils.UriMutatingTripleCollection;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+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.graphprovider.content.ContentGraphProvider;
+import org.apache.clerezza.platform.typerendering.Renderer;
+import org.apache.clerezza.platform.typerendering.RendererFactory;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+/**
+ * This JAX-RS resource provides a method to retrieve a zip file containing
+ * all triple collections that the use may access. The triple collection are
+ * serialized in N-Triples format. The URI path of this resource is
+ * "/admin/backup".
+ *
+ * @author hasan
+ */
+...@component
+...@service(Object.class)
+...@property(name = "javax.ws.rs", boolValue = true)
+...@path("/admin/offline")
+public class Generator {
+
+       @Reference
+       private ContentGraphProvider cgp;
+
+       @Reference
+       private Serializer serializer;
+
+       @Reference
+       private RendererFactory rendererFactory;
+
+       final Logger logger = LoggerFactory.getLogger(Generator.class);
+
+       /**
+        *
+        * The service takes the following argumens:
+        * - 1 base-uri: for all resources with a URI starting with this Uri
+        * creation of the specified target fomats is attempted
+        * - 1 target-uri: where base-uri appears in the representations it is
+        * replaces with target-uri
+        * - 0 or 1 root link prefix: prefix to be prepended to links with Uri
+        * reference starting with a slash
+        * - 1 - n target formats: the file- extensions represing the different
+        * formats to be produced, the extensions are added to the generated 
files
+        * where the file would not otherwise end with the extension.
+        *
+        * The service generates a zip containing a directory structure 
matching the
+        * subpaths from base-uri, the directories contains files for the 
individual
+        * representations, URIs ending with / are matched to a file called
+        * "index"+format extension within the respective directory.
+        *
+        * @return
+        *              a zipped file
+        */
+       @GET
+       @Path("download")
+       @Produces("application/zip")
+       public Response download(@QueryParam("baseUri") String baseUri,
+                       @QueryParam("targetUri") String targetUri,
+                       @QueryParam("rootLinkPrefix") String rootLinkPrefix,
+                       @QueryParam("formatExtensions") List<String> 
formatExtensions) throws IOException {
+
+               byte[] byteArray = createOfflineSite(baseUri, targetUri, 
rootLinkPrefix,
+                               formatExtensions);
+               ResponseBuilder responseBuilder = Response.status(Status.OK).
+                               entity(byteArray);
+               responseBuilder.header("Content-Disposition",
+                               "attachment; filename=site" + getCurrentDate() 
+ ".zip");
+               return responseBuilder.build();
+       }
+
+       private byte[] createOfflineSite(String baseUri, String targetUri,
+                       String rootLinkPrefix, List<String> formatExtensions) 
throws IOException {
+               PathNode rootNode = createFileHierarchy(baseUri, targetUri, 
rootLinkPrefix,
+                               formatExtensions);
+               try {
+                       return ZipCreationUtil.createZip(rootNode);
+               } catch (IOException ex) {
+                       throw new WebApplicationException(ex);
+               }
+       }
+
+       private PathNode createFileHierarchy(String baseUri, String targetUri,
+                       String rootLinkPrefix, List<String> formatExtensions) 
throws IOException {
+               Hierarchy result = new Hierarchy("generated-site");
+               MGraph contentGraph = cgp.getContentGraph();
+               Set<UriRef> matchingUri = new HashSet<UriRef>();
+               for (Triple triple : contentGraph) {
+                       final NonLiteral subject = triple.getSubject();
+                       if ((subject instanceof UriRef) &&
+                                       
((UriRef)subject).getUnicodeString().startsWith(baseUri)) {
+                               matchingUri.add((UriRef)subject);
+                       }
+               }
+               for (UriRef uriRef : matchingUri) {
+                       generateFileForResource(baseUri, targetUri,
+                                       rootLinkPrefix, uriRef, contentGraph, 
result);
+               }
+               return result;
+       }
+
+       private void generateFileForResource(String baseUri, String 
targetBaseUri,
+                       String rootLinkPrefix, UriRef uriRef, TripleCollection 
graph,
+                       Hierarchy hierarchy) throws IOException {
+               final String path = getPathForUriRef(uriRef, baseUri);
+               final UriRef targetUri = new UriRef(baseUri+path);
+               final byte[] data = getGeneratedContent(targetUri,
+                               new UriMutatingTripleCollection(graph, baseUri, 
targetBaseUri));
+               final byte[] dataPrefixApplied = applyRootLinkPrefic(data, 
rootLinkPrefix);
+               hierarchy.addChild(path+".xhtml", dataPrefixApplied);
+       }
+
+       private String getPathForUriRef(UriRef uriRef, String baseUri) {
+               return uriRef.getUnicodeString().substring(baseUri.length());
+       }
+
+       private String getCurrentDate() {
+               DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+               Date date = new Date();
+               return dateFormat.format(date);
+       }
+
+       private byte[] getGeneratedContent(UriRef resource, TripleCollection 
graph) throws IOException {
+               GraphNode docRootNode = new GraphNode(resource, graph);
+               Renderer renderer = rendererFactory.createRenderer(docRootNode, 
null,
+                               
Collections.singletonList(MediaType.APPLICATION_XHTML_XML_TYPE));
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               renderer.render(docRootNode, docRootNode, baos);
+               return baos.toByteArray();
+       }
+
+       private byte[] applyRootLinkPrefic(byte[] data, String rootLinkPrefix) {
+               //TODO impl
+               return data;
+       }
+
+
+
+}

Added: 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Hierarchy.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/Hierarchy.java?rev=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Hierarchy.java
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/Hierarchy.java
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,160 @@
+package org.apache.clerezza.tools.offline;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.wymiwyg.commons.util.dirbrowser.PathNameFilter;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+class Hierarchy implements PathNode {
+
+       static class ValueNode implements PathNode {
+               private byte[] data;
+               private String path;
+
+               public ValueNode(String path, byte[] data) {
+                       this.data = data;
+                       this.path = path;
+               }
+
+               @Override
+               public PathNode getSubPath(String requestPath) {
+                       throw new UnsupportedOperationException("Not supported 
yet.");
+               }
+
+               @Override
+               public boolean isDirectory() {
+                       return false;
+               }
+
+               @Override
+               public String[] list(PathNameFilter filter) {
+                       throw new UnsupportedOperationException("Not supported 
yet.");
+               }
+
+               @Override
+               public String[] list() {
+                       throw new UnsupportedOperationException("Not supported 
yet.");
+               }
+
+               @Override
+               public InputStream getInputStream() throws IOException {
+                       return new ByteArrayInputStream(data);
+               }
+
+               @Override
+               public long getLength() {
+                       return data.length;
+               }
+
+               @Override
+               public String getPath() {
+                       return path;
+               }
+
+               @Override
+               public Date getLastModified() {
+                       throw new UnsupportedOperationException("Not supported 
yet.");
+               }
+
+               @Override
+               public boolean exists() {
+                       return true;
+               }
+
+       }
+
+       private Map<String, PathNode> childMap = new HashMap<String, 
PathNode>();
+       private String path;
+
+       Hierarchy() {
+               this.path = "";
+       }
+
+       Hierarchy(String path) {
+               this.path = path;
+       }
+
+       /**
+        * creates a direct or indirect child
+        */
+       void addChild(String subPath, byte[] data) {
+               final int slashPos = subPath.indexOf('/');
+               if (slashPos == -1) {
+                       childMap.put(subPath, new ValueNode(path+"/"+subPath, 
data));
+               } else {
+                       String subPath1 = subPath.substring(0, slashPos);
+                       String subPath2 = subPath.substring(slashPos+1);
+                       PathNode directChild = childMap.get(subPath1);
+                       if (directChild == null) {
+                               directChild = new Hierarchy(path+"/"+subPath1);
+                               childMap.put(subPath1, directChild);
+                       } else {
+                               if (!(directChild instanceof Hierarchy)) {
+                                       throw new RuntimeException("Attempt to 
add subPath "+
+                                                       subPath+" but 
"+directChild+" has a value");
+                               }
+                       }
+                       ((Hierarchy)directChild).addChild(subPath2, data);
+               }
+       }
+
+       @Override
+       public PathNode getSubPath(String subPath) {
+               return childMap.get(subPath);
+       }
+
+       @Override
+       public boolean isDirectory() {
+               return true;
+       }
+
+       @Override
+       public String[] list(PathNameFilter filter) {
+               String[] fullList = list();
+               ArrayList resultList = new ArrayList();
+               for (int i = 0; i < fullList.length; i++) {
+                       if (filter.accept(this, fullList[i])) {
+                               resultList.add(fullList[i]);
+                       }
+               }
+
+               return (String[]) resultList.toArray(new 
String[resultList.size()]);
+       }
+
+       @Override
+       public String[] list() {
+               final Set<String> keySet = childMap.keySet();
+               return keySet.toArray(new String[keySet.size()]);
+       }
+
+       @Override
+       public InputStream getInputStream() throws IOException {
+               return null;
+       }
+
+       @Override
+       public long getLength() {
+               return -1;
+       }
+
+       @Override
+       public String getPath() {
+               return path;
+       }
+
+       @Override
+       public Date getLastModified() {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+
+       @Override
+       public boolean exists() {
+               throw new UnsupportedOperationException("Not supported yet.");
+       }
+}

Added: 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/ZipCreationUtil.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/ZipCreationUtil.java?rev=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/ZipCreationUtil.java
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/java/org/apache/clerezza/tools/offline/ZipCreationUtil.java
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.tools.offline;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+/**
+ *
+ * @author reto
+ */
+class ZipCreationUtil {
+       static byte[] createZip(PathNode rootNode) throws IOException {
+               ByteArrayOutputStream result = new ByteArrayOutputStream();
+                       ZipOutputStream compressedTcs = new 
ZipOutputStream(result);
+                       archive(compressedTcs, rootNode);
+                       compressedTcs.close();
+               return result.toByteArray();
+       }
+
+       private static void archive(ZipOutputStream compressedTcs,
+                       PathNode pathNode) throws IOException {
+               if (pathNode.isDirectory()) {
+                       String[] childNames = pathNode.list();
+                       for (String childName : childNames) {
+                               archive(compressedTcs, 
pathNode.getSubPath(childName));
+                       }
+               } else {
+                       compressedTcs.putNextEntry(new 
ZipEntry(removeLeadingSlash(pathNode.getPath())));
+                       final int BUF_SIZE = 2048;
+                       byte buffer[] = new byte[BUF_SIZE];
+                       InputStream in = pathNode.getInputStream();
+                       int count;
+                       while ((count = in.read(buffer, 0, BUF_SIZE)) != -1) {
+                               compressedTcs.write(buffer, 0, count);
+                       }
+               }
+       }
+
+       private static String removeLeadingSlash(String string) {
+               if (string.length() > 0 && string.charAt(0) == '/') {
+                       return string.substring(1);
+               } else {
+                       return string;
+               }
+       }
+}

Added: 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/documentation.nt
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/documentation.nt?rev=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/documentation.nt
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/META-INF/documentation.nt
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,52 @@
+_:A68e2cd06X3aX12545840449X3aXX2dX7a91 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a91 <http://discobits.org/ontology#pos> "1" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a91 <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content> .
+<bundle:///scb-web-title> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///scb-web-title> <http://discobits.org/ontology#infoBit> "SCB 
Web"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a90 <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/0-title> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a90 <http://discobits.org/ontology#pos> "0" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a90 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+<bundle:///scb-web-content> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8f .
+<bundle:///scb-web-content> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8e .
+<bundle:///scb-web-content> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8d .
+<bundle:///scb-web-content> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#OrderedContent> .
+<bundle:///scb-web-content-el/0-title> <http://discobits.org/ontology#infoBit> 
"Upload Triples with a POST 
Request"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///scb-web-content-el/0-title> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///scb-web-content-el/2> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8c .
+<bundle:///scb-web-content-el/2> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#TitledContent> .
+<bundle:///scb-web-content-el/2> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8b .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8b <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/2-title> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8b <http://discobits.org/ontology#pos> "0" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8b 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+<bundle:///scb-web-content-el/1> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///scb-web-content-el/1> <http://discobits.org/ontology#infoBit> "The 
bundle SCB Web allows access to SCB graphs over HTTP with 
JAX-RS."^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///scb-web-content-el/0> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a8a .
+<bundle:///scb-web-content-el/0> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a90 .
+<bundle:///scb-web-content-el/0> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#TitledContent> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8e 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8e <http://discobits.org/ontology#pos> "1" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8e <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/0> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8a 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8a <http://discobits.org/ontology#pos> "1" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8a <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/0-content> .
+<bundle:///scb-web-content-el/2-title> <http://discobits.org/ontology#infoBit> 
"Backup of Triple 
Collections"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+<bundle:///scb-web-content-el/0-content> 
<http://discobits.org/ontology#infoBit> "To upload triples with a POST request, 
a client can use the URI path \"/graph\" and place the triples and other 
required information into the body as multipart/form-data which consists 
of\n<ul xmlns=\"http://www.w3.org/1999/xhtml\";>\n<li>a file labeled \"graph\" 
containing the triples and specifying the mime-type.</li>\n<li>a text field 
labeled \"name\" specifying the name of the MGraph. If an MGraph with this name 
does not already exist, a new one will be created.</li>\n<li>an optional text 
field labeled \"mode\" specifying the mode. If the mode is \"replace\", 
existing triples of the MGraph will be deleted before new triples are added. If 
the mode is not specified or is \"append\", posted triples will be added to the 
MGraph.</li>\n<li>an optional text field labeled \"redirection\" specifying an 
URI which the client should be redirected to in case of success.</li>\n</ul>\nA 
response with the s
 tatus code BAD REQUEST (400) is returned if the required data are missing. If 
the request can be satisfied, one of the following responses is returned:\n<ul 
xmlns=\"http://www.w3.org/1999/xhtml\";>\n<li>SEE OTHER (303), if redirection is 
specified.</li>\n<li>CREATED (201), if redirection is not specified and a new 
MGraph is created.</li>\n<li>NO CONTENT (204), if redirection is not specified 
and no new MGraph is 
created.</li>\n</ul>\n"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>
 .
+<bundle:///scb-web-content-el/0-content> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///scb-web-content-el/2-title> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8d 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8d <http://discobits.org/ontology#pos> "0" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8d <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/1> .
+<bundle:///scb-web-content-el/2-content> 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#XHTMLInfoDiscoBit> .
+<bundle:///scb-web-content-el/2-content> 
<http://discobits.org/ontology#infoBit> "The platform allows the current user 
to download all triple collections that he has access to through the URI path 
\"/admin/backup/download\". The resulted file is a compressed archive in zip 
format. All triple collections in this file are serialized in N-Triples format. 
Furthermore, a file called \"triplecollections.nt\" is contained in backup.zip, 
which describes the mapping of file names to triple collection 
names.\n"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8f 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8f <http://discobits.org/ontology#pos> "2" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8f <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/2> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a89 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a89 <http://discobits.org/ontology#pos> "0" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a89 <http://discobits.org/ontology#holds> 
<bundle:///scb-web-title> .
+<bundle:///scb-web> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a91 .
+<bundle:///scb-web> <http://discobits.org/ontology#contains> 
_:A68e2cd06X3aX12545840449X3aXX2dX7a89 .
+<bundle:///scb-web> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#TitledContent> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8c 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://discobits.org/ontology#Entry> .
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8c <http://discobits.org/ontology#pos> "1" 
.
+_:A68e2cd06X3aX12545840449X3aXX2dX7a8c <http://discobits.org/ontology#holds> 
<bundle:///scb-web-content-el/2-content> .

Added: 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/sparql-endpoint.ssp
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/sparql-endpoint.ssp?rev=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/sparql-endpoint.ssp
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/main/resources/org/apache/clerezza/rdf/web/core/sparql-endpoint.ssp
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,54 @@
+def se(s: Any) = new UriRef("http://clerezza.org/2009/11/sparql-endpoint#"+s)
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"; lang="en">
+       <head>
+               <title>SPARQL Endpoint</title>
+               <script type="text/javascript">
+                       function toggle(checkbox){{
+                               var uri = 
document.getElementById('stylesheeturi');
+                               var urilable = 
document.getElementById('urilable');
+                               var server = document.getElementById('server');
+                               var serverlabel = 
document.getElementById('serverlabel');
+                               if (checkbox.checked){{
+                                       uri.style.visibility = 'visible';
+                                       urilable.style.visibility = 'visible';
+                                       server.style.visibility = 'visible';
+                                       serverlabel.style.visibility = 
'visible';
+                               }} else {{
+                                       uri.style.visibility = 'hidden';
+                                       urilable.style.visibility = 'hidden';
+                                       server.style.visibility = 'hidden';
+                                       serverlabel.style.visibility = 'hidden';
+                               }}
+                       }}
+               </script>
+       </head>
+       <body>
+               <h1>SPARQL Endpoint</h1>
+               <hr />
+               <h4>SPARQL Query</h4>
+               <form method="post" action="../sparql">
+                       <lable for="query">Type in your query:</lable>
+                       <br />
+                       <textarea cols="70" rows="10" name="query" />
+                       <br />
+                       <br />
+                       <label for="default-graph-uri">Select a graph 
URI:</label>
+                       <select name="default-graph-uri">
+                               {for (tc <- (res/se("tripleCollection"))) yield
+                                       <option>{tc*}</option>
+                               }
+                       </select>
+                       <br />
+                       <lable for="apply-style-sheet">Add XSLT style sheet on 
the result: </lable>
+                       <input type="checkbox" name="apply-style-sheet" 
id="checkbox" onclick="toggle(this)" />
+                       <br />
+                       <label for="style-sheet-uri" id="urilable" 
style="visibility:hidden">URI of XSLT style sheet</label>
+                       <input type="text" name="style-sheet-uri" 
id="stylesheeturi" style="width:350px;visibility:hidden" 
value="http://www.w3.org/TR/rdf-sparql-XMLres/result-to-html.xsl"; />
+                       <label id="serverlabel" style="visibility:hidden">Add 
stylesheet on server side</label>
+                       <input type="checkbox" name="server-side" id="server" 
checked="checked" style="visibility:hidden"/>
+                       <br />
+                       <br />
+                       <input type="submit" value="Submit Query" />
+               </form>
+       </body>
+</html>

Added: 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/ZipCreationUtilTest.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/ZipCreationUtilTest.java?rev=918485&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/ZipCreationUtilTest.java
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-96/org.apache.clerezza.tools.offline/src/test/java/org/apache/clerezza/tools/offline/ZipCreationUtilTest.java
 Wed Mar  3 14:27:35 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.tools.offline;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests backup functionality.
+ *
+ * @author hasan
+ */
+public class ZipCreationUtilTest {
+
+       @Test
+       public void simple() throws Exception {
+               Hierarchy root = new Hierarchy();
+               root.addChild("/foo/bar/test", "my testdata".getBytes());
+               root.addChild("/foo/bar/test1", "another testdata".getBytes());
+               root.addChild("/foo/something", "something else".getBytes());
+               byte[] zipData = ZipCreationUtil.createZip(root);
+               File tmpFile = File.createTempFile("test", "zip");
+               FileOutputStream fout = new FileOutputStream(tmpFile);
+               fout.write(zipData);
+               fout.close();
+               ZipFile zipFile = new ZipFile(tmpFile);
+               Enumeration<? extends ZipEntry> entriesEnum = zipFile.entries();
+               Set<ZipEntry> entries = new HashSet<ZipEntry>();
+               while (entriesEnum.hasMoreElements()) {
+                       final ZipEntry nextElement = entriesEnum.nextElement();
+                       System.out.println(nextElement);
+                       entries.add(nextElement);
+               }
+               Assert.assertEquals(3, entries.size());
+
+       }
+}
\ No newline at end of file


Reply via email to