Author: reto
Date: Sun Sep 23 17:51:04 2012
New Revision: 1389106

URL: http://svn.apache.org/viewvc?rev=1389106&view=rev
Log:
STANBOL-750: added LdViewable with supporting MessageBodyWriter for html

Added:
    stanbol/trunk/commons/web/ldviewable/   (with props)
    stanbol/trunk/commons/web/ldviewable/README.md
    stanbol/trunk/commons/web/ldviewable/pom.xml
    stanbol/trunk/commons/web/ldviewable/src/
    stanbol/trunk/commons/web/ldviewable/src/main/
    stanbol/trunk/commons/web/ldviewable/src/main/java/
    stanbol/trunk/commons/web/ldviewable/src/main/java/org/
    stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/
    stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/LdViewable.java
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/LdViewableWriter.java
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/
    
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/UserManagementWebFragment.java
Modified:
    stanbol/trunk/commons/pom.xml

Modified: stanbol/trunk/commons/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/pom.xml?rev=1389106&r1=1389105&r2=1389106&view=diff
==============================================================================
--- stanbol/trunk/commons/pom.xml (original)
+++ stanbol/trunk/commons/pom.xml Sun Sep 23 17:51:04 2012
@@ -39,7 +39,8 @@
 
     <module>web/base</module>
     <module>web/home</module>
-
+       <module>web/ldviewable</module>
+       
     <module>stanboltools/datafileprovider</module>
     <module>stanboltools/offline</module>
     <module>stanboltools/bundledatafileprovider</module>

Propchange: stanbol/trunk/commons/web/ldviewable/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 23 17:51:04 2012
@@ -0,0 +1,5 @@
+.project
+.gitignore
+.classpath
+target
+.settings

Added: stanbol/trunk/commons/web/ldviewable/README.md
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/ldviewable/README.md?rev=1389106&view=auto
==============================================================================
--- stanbol/trunk/commons/web/ldviewable/README.md (added)
+++ stanbol/trunk/commons/web/ldviewable/README.md Sun Sep 23 17:51:04 2012
@@ -0,0 +1,4 @@
+LdViewable
+===========
+
+Allows resource methods to return an instance of LdViewable encapsulating a 
template path and a GraphNode. The template path is relative to a prefix 
specific to the target media type, e.g. "html" for "text/html"

Added: stanbol/trunk/commons/web/ldviewable/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/ldviewable/pom.xml?rev=1389106&view=auto
==============================================================================
--- stanbol/trunk/commons/web/ldviewable/pom.xml (added)
+++ stanbol/trunk/commons/web/ldviewable/pom.xml Sun Sep 23 17:51:04 2012
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>stanbol-parent</artifactId>
+    <version>2-incubating-SNAPSHOT</version>
+    <relativePath>../../../parent</relativePath>
+  </parent>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>org.apache.stanbol.commons.ldviewable</artifactId>
+  <version>0.10.0-incubating-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Stanbol LDPath Template Viewable</name>
+  <description>A service providing a message body writer for ldpath template 
viewable</description>
+  <scm>
+    <connection>
+      
scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/commons/web/ldviewable
+    </connection>
+    <developerConnection>
+      
scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/commons/web/ldviewable
+    </developerConnection>
+    <url>http://incubator.apache.org/stanbol/</url>
+  </scm>
+
+  <build>
+    <!-- make it an OSGi bundle -->
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+               <groupId>org.apache.clerezza</groupId>
+               <artifactId>rdf.ontologies</artifactId>
+       </dependency>
+       <dependency>
+               <groupId>org.apache.clerezza</groupId>
+               <artifactId>rdf.utils</artifactId>
+       </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.webconsole</artifactId>
+      <version>3.1.8</version>
+    </dependency>
+    <dependency>
+               <groupId>org.apache.clerezza</groupId>
+               <artifactId>platform.config</artifactId>
+               <version>0.3-incubating</version>
+       </dependency>
+    
+    <!-- Jersey, servlet and freemarker -->
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+
+    <!-- OSGi tax -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-core-bundle</artifactId>
+    </dependency>
+
+    <!-- integrated for now
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-template</artifactId>
+         <version>0.9.13-SNAPSHOT</version>
+       </dependency>
+       -->
+       <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.web.base</artifactId>
+      <version>0.10.1-incubating-SNAPSHOT</version>
+    </dependency>
+       <dependency>
+        <groupId>org.apache.stanbol</groupId>
+               
<artifactId>org.apache.stanbol.commons.ldpathtemplate</artifactId>
+               <version>0.10.0-incubating-SNAPSHOT</version>
+    </dependency>
+
+  </dependencies>
+
+
+</project>

Added: 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/LdViewable.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/LdViewable.java?rev=1389106&view=auto
==============================================================================
--- 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/LdViewable.java
 (added)
+++ 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/LdViewable.java
 Sun Sep 23 17:51:04 2012
@@ -0,0 +1,48 @@
+package org.apache.stanbol.commons.ldviewable;
+
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+/**
+ * An LdViewable is a GraphNode associated with a template path. The template 
+ * path will be attempted to be resolved based on the accepted target formats
+ * to create a representation of the GraphNode. 
+ *
+ */
+public class LdViewable {
+
+       /**
+        * 
+        * @param templatePath the templatePath
+        * @param graphNode the graphNode with the actual content
+        */
+       public LdViewable(final String templatePath, final GraphNode graphNode) 
{
+               this.templatePath = templatePath;
+               this.graphNode = graphNode;
+       }
+       
+       /**
+        * With this version of the constructor the templatePath is prefixed 
with
+        * the slash-separated package name of the given Class.
+        * 
+        */
+       public LdViewable(final String templatePath, final GraphNode graphNode, 
final Class<?> clazz) {
+               final String slahSeparatedPacakgeName = 
clazz.getPackage().getName().replace('.', '/');
+               if (templatePath.startsWith("/")) {
+                       this.templatePath = 
slahSeparatedPacakgeName+templatePath;
+               } else {
+                       this.templatePath = 
slahSeparatedPacakgeName+'/'+templatePath;
+               }
+               this.graphNode = graphNode;
+       }
+       
+       private String templatePath;
+       private GraphNode graphNode;
+       
+       public String getTemplatePath() {
+               return templatePath;
+       }
+       
+       public GraphNode getGraphNode() {
+               return graphNode;
+       }
+}

Added: 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/LdViewableWriter.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/LdViewableWriter.java?rev=1389106&view=auto
==============================================================================
--- 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/LdViewableWriter.java
 (added)
+++ 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/mbw/LdViewableWriter.java
 Sun Sep 23 17:51:04 2012
@@ -0,0 +1,53 @@
+package org.apache.stanbol.commons.ldviewable.mbw;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.ldpathtemplate.LdRenderer;
+import org.apache.stanbol.commons.ldviewable.LdViewable;
+
+@Component
+@Service(LdViewableWriter.class)
+@Produces("text/html")
+public class LdViewableWriter implements MessageBodyWriter<LdViewable> {
+
+       @Reference
+       private LdRenderer ldRenderer;
+       
+       @Override
+       public boolean isWriteable(Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType) {
+               return LdViewable.class.isAssignableFrom(type);
+       }
+
+       @Override
+       public long getSize(LdViewable t, Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType) {
+               return -1;
+       }
+
+       @Override
+       public void writeTo(LdViewable t, Class<?> type, Type genericType,
+                       Annotation[] annotations, MediaType mediaType,
+                       MultivaluedMap<String, Object> httpHeaders,
+                       OutputStream entityStream) throws IOException,
+                       WebApplicationException {
+               Writer out = new OutputStreamWriter(entityStream, "utf-8"); 
+               ldRenderer.render(t.getGraphNode(), 
"html/"+t.getTemplatePath(), out);
+               out.flush();
+       }
+
+}

Added: 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/UserManagementWebFragment.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/UserManagementWebFragment.java?rev=1389106&view=auto
==============================================================================
--- 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/UserManagementWebFragment.java
 (added)
+++ 
stanbol/trunk/commons/web/ldviewable/src/main/java/org/apache/stanbol/commons/ldviewable/webfragment/UserManagementWebFragment.java
 Sun Sep 23 17:51:04 2012
@@ -0,0 +1,111 @@
+/*
+ * 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.stanbol.commons.ldviewable.webfragment;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.ldviewable.mbw.LdViewableWriter;
+import org.apache.stanbol.commons.web.base.LinkResource;
+import org.apache.stanbol.commons.web.base.NavigationLink;
+import org.apache.stanbol.commons.web.base.ScriptResource;
+import org.apache.stanbol.commons.web.base.WebFragment;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+
+import freemarker.cache.ClassTemplateLoader;
+import freemarker.cache.TemplateLoader;
+
+/**
+ * Statically define the list of available resources and providers to be
+ * contributed to the the Stanbol JAX-RS Endpoint.
+ */
+@Component(immediate = true, metatype = true)
+@Service
+public class UserManagementWebFragment implements WebFragment {
+
+       @Reference
+       private LdViewableWriter ldViewableWriter;
+       
+       private static final String NAME = "ld-viewable";
+
+       private BundleContext bundleContext;
+
+       @Override
+       public String getName() {
+               return NAME;
+       }
+
+       @Activate
+       protected void activate(ComponentContext ctx) {
+               this.bundleContext = ctx.getBundleContext();
+       }
+
+       @Override
+       public Set<Class<?>> getJaxrsResourceClasses() {
+               Set<Class<?>> classes = new HashSet<Class<?>>();
+               return classes;
+       }
+
+       @Override
+       public Set<Object> getJaxrsResourceSingletons() {
+               Set<Object> instances = new HashSet<Object>();
+               instances.add(ldViewableWriter);
+               return instances;
+       }
+
+       @Override
+       public String getStaticResourceClassPath() {
+               return "foobar";
+       }
+
+       @Override
+       public TemplateLoader getTemplateLoader() {
+               return new ClassTemplateLoader(getClass(), "foobar");
+       }
+
+       @Override
+       public List<LinkResource> getLinkResources() {
+               List<LinkResource> resources = new ArrayList<LinkResource>();
+               return resources;
+       }
+
+       @Override
+       public List<ScriptResource> getScriptResources() {
+               List<ScriptResource> resources = new 
ArrayList<ScriptResource>();
+               return resources;
+       }
+
+       @Override
+       public List<NavigationLink> getNavigationLinks() {
+               List<NavigationLink> links = new ArrayList<NavigationLink>();
+               return links;
+       }
+
+       @Override
+       public BundleContext getBundleContext() {
+               return bundleContext;
+       }
+
+}


Reply via email to