Author: reto
Date: Wed Feb 13 21:35:43 2013
New Revision: 1445939

URL: http://svn.apache.org/r1445939
Log:
STANBOL-910: extracted pojo viewable MBW from the bundle providing the Viewable 
classes. This prevents all Viewable and RDfVieable  clients to have a 
transitive dependency on freemarker. It also allows exchanging the MBW without 
needing a refresh of all Viewable clients.

Added:
    
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/
      - copied from r1442582, 
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/
    stanbol/trunk/commons/web/viewable-writer/
      - copied from r1445905, stanbol/trunk/commons/web/viewable/
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
      - copied, changed from r1445905, 
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/writer/ViewableWriter.java
Removed:
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/ldviewable/
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/RdfViewable.java
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/Viewable.java
    
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/web/
    
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/ldviewable/
    
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/impl/
    
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/webfragment/
    
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/writer/
Modified:
    stanbol/trunk/commons/ldpathtemplate/pom.xml
    
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
    stanbol/trunk/commons/pom.xml
    stanbol/trunk/commons/web/viewable-ldpath/pom.xml
    
stanbol/trunk/commons/web/viewable-ldpath/src/main/java/org/apache/stanbol/commons/web/viewable/ldpath/webfragment/LdViewableWebFragment.java
    stanbol/trunk/commons/web/viewable-writer/pom.xml
    stanbol/trunk/commons/web/viewable/pom.xml

Modified: stanbol/trunk/commons/ldpathtemplate/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/ldpathtemplate/pom.xml?rev=1445939&r1=1445938&r2=1445939&view=diff
==============================================================================
--- stanbol/trunk/commons/ldpathtemplate/pom.xml (original)
+++ stanbol/trunk/commons/ldpathtemplate/pom.xml Wed Feb 13 21:35:43 2013
@@ -80,8 +80,21 @@
       <groupId>org.freemarker</groupId>
       <artifactId>freemarker</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.scr.annotations</artifactId>
+    </dependency>
+    
+    <dependency>
       <groupId>at.newmedialab.ldpath</groupId>
       <artifactId>ldpath-core-bundle</artifactId>
     </dependency>
@@ -92,6 +105,11 @@
            <version>0.9.3-SNAPSHOT</version>
          </dependency>
          -->
+         <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.ldpath.clerezza</artifactId>
+      <version>0.11.0</version>
+    </dependency>
 
   </dependencies>
 </project>

Modified: 
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java?rev=1445939&r1=1442582&r2=1445939&view=diff
==============================================================================
--- 
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
 (original)
+++ 
stanbol/trunk/commons/ldpathtemplate/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
 Wed Feb 13 21:35:43 2013
@@ -16,35 +16,21 @@
 */
 package org.apache.stanbol.commons.ldpathtemplate;
 
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.template.engine.TemplateEngine;
+import freemarker.cache.TemplateLoader;
+import freemarker.template.TemplateException;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
 import java.io.Writer;
-import java.net.URL;
-import java.util.Collection;
-import java.util.HashSet;
-
 import org.apache.clerezza.rdf.core.Resource;
 import org.apache.clerezza.rdf.utils.GraphNode;
-import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.stanbol.commons.ldpath.clerezza.ClerezzaBackend;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-import at.newmedialab.ldpath.template.engine.TemplateEngine;
-import freemarker.cache.TemplateLoader;
-import freemarker.template.Configuration;
-import freemarker.template.DefaultObjectWrapper;
-import freemarker.template.TemplateException;
-
 /**
  * This service renders a GraphNode to a Writer given the 
  * path of an ldpath template
@@ -58,78 +44,8 @@ public class LdRenderer {
 
        private static final Logger log = 
LoggerFactory.getLogger(LdRenderer.class);
        
-       private final Collection<Bundle> bundles = new HashSet<Bundle>();
-       
-       private BundleListener bundleListener = new BundleListener() {
-               
-               @Override
-               public void bundleChanged(BundleEvent event) {
-                       if ((event.getType() == BundleEvent.STARTED) && 
containsTemplates(event.getBundle())) {
-                               bundles.add(event.getBundle());
-                       } else {
-                               bundles.remove(event.getBundle());
-                       }
-               }
-       };
-       
-       private TemplateLoader templateLoader = new TemplateLoader() {
-               
-               @Override
-               public Reader getReader(Object templateSource, String encoding)
-                               throws IOException {
-                       URL templateUrl = (URL) templateSource;
-                       return new InputStreamReader(templateUrl.openStream(), 
encoding);
-               }
-               
-               @Override
-               public long getLastModified(Object templateSource) {
-                       // not known
-                       return -1;
-               }
-               
-               @Override
-               public Object findTemplateSource(String name) throws 
IOException {
-                       if (!name.endsWith(".ftl")) {
-                               name = name +".ftl";
-                       }
-                       final String path = TEMPLATES_PATH_IN_BUNDLES+name;
-                       for (Bundle bundle : bundles) {
-                               URL res = bundle.getResource(path);
-                               if (res != null) {
-                                       return res;
-                               }
-                       }
-                       log.warn("Template "+name+" not known");
-                       return null;
-               }
-               
-               @Override
-               public void closeTemplateSource(Object templateSource) throws 
IOException {
-
-                       
-               }
-       };
-       
-       @Activate
-       protected void activate(final ComponentContext context) {
-               final Bundle[] registeredBundles = 
context.getBundleContext().getBundles();
-               for (int i = 0; i < registeredBundles.length; i++) {
-                       if ((registeredBundles[i].getState() == Bundle.ACTIVE) 
-                                       && 
containsTemplates(registeredBundles[i])) {
-                               bundles.add(registeredBundles[i]);
-                       }
-               }       
-               context.getBundleContext().addBundleListener(bundleListener);
-       }
-
-       @Deactivate
-       protected void deactivate(final ComponentContext context) {
-               context.getBundleContext().removeBundleListener(bundleListener);
-       }
-       
-       private boolean containsTemplates(Bundle bundle) {
-               return bundle.getResource(TEMPLATES_PATH_IN_BUNDLES) != null;
-       }
+       @Reference
+       private TemplateLoader templateLoader;
 
        /**
         * Renders a GraphNode with a template located in the templates
@@ -156,24 +72,4 @@ public class LdRenderer {
                }
        }
        
-       /**
-        * Old school classical freemarker rendering, no LD here
-        */
-       public void renderPojo(Object pojo, final String templatePath, Writer 
out) {    
-               Configuration freemarker= new Configuration();
-               freemarker.setDefaultEncoding("utf-8");
-               freemarker.setOutputEncoding("utf-8");
-               freemarker.setLocalizedLookup(false);
-           freemarker.setObjectWrapper(new DefaultObjectWrapper());
-               freemarker.setTemplateLoader(templateLoader);
-               try {
-                       //should root be a map instead?
-                       freemarker.getTemplate(templatePath).process(pojo, out);
-                       out.flush();
-               } catch (IOException e) {
-                       throw new RuntimeException(e);
-               } catch (TemplateException e) {
-                       throw new RuntimeException(e);
-               }
-       }
 }

Modified: stanbol/trunk/commons/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/pom.xml?rev=1445939&r1=1445938&r2=1445939&view=diff
==============================================================================
--- stanbol/trunk/commons/pom.xml (original)
+++ stanbol/trunk/commons/pom.xml Wed Feb 13 21:35:43 2013
@@ -65,6 +65,7 @@
     <module>web/home</module>
     <module>web/viewable</module>
     <module>web/viewable-ldpath</module>
+    <module>web/viewable-writer</module>
     <module>web/resources</module>
     <module>web/sparql</module>
     <module>freemarker</module>

Modified: stanbol/trunk/commons/web/viewable-ldpath/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/viewable-ldpath/pom.xml?rev=1445939&r1=1445938&r2=1445939&view=diff
==============================================================================
--- stanbol/trunk/commons/web/viewable-ldpath/pom.xml (original)
+++ stanbol/trunk/commons/web/viewable-ldpath/pom.xml Wed Feb 13 21:35:43 2013
@@ -91,12 +91,21 @@
       <artifactId>org.apache.stanbol.commons.ldpathtemplate</artifactId>
       <version>0.12.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.web.base</artifactId>
+      <version>0.12.0-SNAPSHOT</version>
+    </dependency>
 
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
+      <groupId>javax.ws.rs</groupId>
+      <artifactId>jsr311-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.clerezza</groupId>
       <artifactId>rdf.ontologies</artifactId>
     </dependency>

Modified: 
stanbol/trunk/commons/web/viewable-ldpath/src/main/java/org/apache/stanbol/commons/web/viewable/ldpath/webfragment/LdViewableWebFragment.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/viewable-ldpath/src/main/java/org/apache/stanbol/commons/web/viewable/ldpath/webfragment/LdViewableWebFragment.java?rev=1445939&r1=1445938&r2=1445939&view=diff
==============================================================================
--- 
stanbol/trunk/commons/web/viewable-ldpath/src/main/java/org/apache/stanbol/commons/web/viewable/ldpath/webfragment/LdViewableWebFragment.java
 (original)
+++ 
stanbol/trunk/commons/web/viewable-ldpath/src/main/java/org/apache/stanbol/commons/web/viewable/ldpath/webfragment/LdViewableWebFragment.java
 Wed Feb 13 21:35:43 2013
@@ -33,7 +33,6 @@ import org.apache.stanbol.commons.web.ba
 import org.apache.stanbol.commons.web.base.ScriptResource;
 import org.apache.stanbol.commons.web.base.WebFragment;
 import org.apache.stanbol.commons.web.viewable.ldpath.writer.LdViewableWriter;
-import org.apache.stanbol.commons.web.viewable.writer.ViewableWriter;
 import org.osgi.service.component.ComponentContext;
 
 import freemarker.cache.TemplateLoader;

Modified: stanbol/trunk/commons/web/viewable-writer/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/viewable-writer/pom.xml?rev=1445939&r1=1445905&r2=1445939&view=diff
==============================================================================
--- stanbol/trunk/commons/web/viewable-writer/pom.xml (original)
+++ stanbol/trunk/commons/web/viewable-writer/pom.xml Wed Feb 13 21:35:43 2013
@@ -26,18 +26,18 @@
   </parent>
 
   <groupId>org.apache.stanbol</groupId>
-  <artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
+  <artifactId>org.apache.stanbol.commons.web.viewable.writer</artifactId>
   <version>0.12.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
-  <name>Apache Stanbol Commons Web Template Viewable</name>
-  <description>A service providing classes and message body writer for 
response rendering with the viewable pattern.</description>
+  <name>Apache Stanbol Commons Web Template Viewable Writer</name>
+  <description>A bundle providing MessageBodyWriters for Viewable</description>
   <scm>
     <connection>
-      
scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/commons/web/viewable
+      
scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/commons/web/viewable-writer
     </connection>
     <developerConnection>
-      
scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/commons/web/viewable
+      
scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/commons/web/viewable-writer
     </developerConnection>
     <url>http://stanbol.apache.org/</url>
   </scm>
@@ -55,16 +55,6 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
-            <Export-Package>
-              org.apache.stanbol.commons.viewable;version=${project.version},
-              
org.apache.stanbol.commons.web.viewable;version=${project.version},
-              
org.apache.stanbol.commons.web.viewable.writer;version=${project.version}
-            </Export-Package>
-            <Private-Package>
-              
org.apache.stanbol.commons.web.viewable.impl;version=${project.version},
-              
org.apache.stanbol.commons.web.viewable.webfragment;version=${project.version},
-            </Private-Package>
-            <Embed-Transitive>true</Embed-Transitive>
             <Import-Package>
               javax.servlet.*; version="[2.5.0,4.0.0)",
               javax.ws.rs.*; version="[0,2)",
@@ -82,25 +72,22 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
-       <dependency>
-                 <groupId>org.apache.clerezza</groupId>
-               <artifactId>rdf.utils</artifactId>
-       </dependency>
-   
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency> 
+    <dependency>
+      <groupId>javax.ws.rs</groupId>
+      <artifactId>jsr311-api</artifactId>
     </dependency>
-    
     <dependency>
-      <groupId>org.apache.stanbol</groupId>
-      <artifactId>org.apache.stanbol.commons.web.base</artifactId>
-      <version>0.12.0-SNAPSHOT</version>
+      <groupId>org.freemarker</groupId>
+      <artifactId>freemarker</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
-         <artifactId>org.apache.stanbol.commons.ldpathtemplate</artifactId>
-         <version>0.11.0</version>
+         <artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
+         <version>0.12.0-SNAPSHOT</version>
     </dependency>
   </dependencies>
 

Copied: 
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
 (from r1445905, 
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/writer/ViewableWriter.java)
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java?p2=stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java&p1=stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/writer/ViewableWriter.java&r1=1445905&r2=1445939&rev=1445939&view=diff
==============================================================================
--- 
stanbol/trunk/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/writer/ViewableWriter.java
 (original)
+++ 
stanbol/trunk/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
 Wed Feb 13 21:35:43 2013
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.stanbol.commons.web.viewable.writer;
+package org.apache.stanbol.commons.viewable.writer.impl;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -35,21 +35,22 @@ import freemarker.cache.TemplateLoader;
 import freemarker.template.Configuration;
 import freemarker.template.DefaultObjectWrapper;
 import freemarker.template.TemplateException;
-
+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;
+
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
 @Produces("text/html")
 @Provider
 public class ViewableWriter implements MessageBodyWriter<Viewable> {
 
     
-    
+    @Reference
        private TemplateLoader templateLoader;
 
-       public ViewableWriter(TemplateLoader templateLoader) {
-           if(templateLoader == null){
-               throw new IllegalArgumentException("The parsed templateLoader 
MUST NOT be NULL");
-           }
-        this.templateLoader = templateLoader;
-    }
        
        @Override
        public boolean isWriteable(Class<?> type, Type genericType,

Modified: stanbol/trunk/commons/web/viewable/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/web/viewable/pom.xml?rev=1445939&r1=1445938&r2=1445939&view=diff
==============================================================================
--- stanbol/trunk/commons/web/viewable/pom.xml (original)
+++ stanbol/trunk/commons/web/viewable/pom.xml Wed Feb 13 21:35:43 2013
@@ -83,25 +83,13 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
        <dependency>
-                 <groupId>org.apache.clerezza</groupId>
+               <groupId>org.apache.clerezza</groupId>
                <artifactId>rdf.utils</artifactId>
        </dependency>
-   
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.scr.annotations</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.apache.stanbol</groupId>
-      <artifactId>org.apache.stanbol.commons.web.base</artifactId>
-      <version>0.12.0-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.stanbol</groupId>
-         <artifactId>org.apache.stanbol.commons.ldpathtemplate</artifactId>
-         <version>0.11.0</version>
-    </dependency>
+    </dependency>  
   </dependencies>
 
 </project>


Reply via email to