Author: reto
Date: Fri Jun 7 21:47:41 2013
New Revision: 1490847
URL: http://svn.apache.org/r1490847
Log:
STANBOL-1097: better support for porting migrating Viewable(this)-style apps to
whiteboard pattern. Ported job service
Added:
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/TemplateLayoutConfiguration.java
Modified:
stanbol/branches/commons-ng/commons/jobs/web/pom.xml
stanbol/branches/commons-ng/commons/jobs/web/src/main/java/org/apache/stanbol/commons/jobs/web/resources/JobsResource.java
stanbol/branches/commons-ng/commons/jobs/web/src/main/resources/templates/html/org/apache/stanbol/commons/jobs/web/resources/JobsResource/info.ftl
stanbol/branches/commons-ng/commons/web/base.jersey/src/main/java/org/apache/stanbol/commons/web/base/jersey/EditableLayoutConfiguration.java
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/LayoutConfiguration.java
stanbol/branches/commons-ng/commons/web/home/pom.xml
stanbol/branches/commons-ng/commons/web/home/src/main/java/org/apache/stanbol/commons/web/home/HomeWebFragment.java
stanbol/branches/commons-ng/commons/web/rdfviewable-writer/pom.xml
stanbol/branches/commons-ng/commons/web/viewable-writer/pom.xml
stanbol/branches/commons-ng/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
stanbol/branches/commons-ng/commons/web/viewable/pom.xml
stanbol/branches/commons-ng/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/Viewable.java
stanbol/branches/commons-ng/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml
Modified: stanbol/branches/commons-ng/commons/jobs/web/pom.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/jobs/web/pom.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/jobs/web/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/jobs/web/pom.xml Fri Jun 7 21:47:41
2013
@@ -73,7 +73,7 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.11.0</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- For logging -->
Modified:
stanbol/branches/commons-ng/commons/jobs/web/src/main/java/org/apache/stanbol/commons/jobs/web/resources/JobsResource.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/jobs/web/src/main/java/org/apache/stanbol/commons/jobs/web/resources/JobsResource.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/jobs/web/src/main/java/org/apache/stanbol/commons/jobs/web/resources/JobsResource.java
(original)
+++
stanbol/branches/commons-ng/commons/jobs/web/src/main/java/org/apache/stanbol/commons/jobs/web/resources/JobsResource.java
Fri Jun 7 21:47:41 2013
@@ -73,13 +73,9 @@ public class JobsResource extends BaseSt
private JobManager jobManager;
- /*public JobInfo getJobInfo(){
- return info;
- }*/
-
@GET
public Response get(){
- return Response.ok(new Viewable("index",this)).build();
+ return Response.ok(new Viewable("index",new ResultData() {})).build();
}
/**
@@ -105,7 +101,7 @@ public class JobsResource extends BaseSt
log.info("Found job with id {}", id);
Future<?> f = m.ping(id);
//this.info = new JobInfoImpl();
- JobInfo info = new JobInfoImpl();
+ final JobInfo info = new JobInfoImpl();
if(f.isDone()){
// The job is finished
if(f.isCancelled()){
@@ -130,7 +126,11 @@ public class JobsResource extends BaseSt
if(isHTML()){
// Result as HTML
- return Response.ok(new Viewable("info", info)).build();
+ return Response.ok(new Viewable("info", new ResultData() {
+ public JobInfo getJobInfo(){
+ return info;
+ }
+ })).build();
}else{
// Result as application/json, text/plain
return Response.ok(info).build();
Modified:
stanbol/branches/commons-ng/commons/jobs/web/src/main/resources/templates/html/org/apache/stanbol/commons/jobs/web/resources/JobsResource/info.ftl
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/jobs/web/src/main/resources/templates/html/org/apache/stanbol/commons/jobs/web/resources/JobsResource/info.ftl?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/jobs/web/src/main/resources/templates/html/org/apache/stanbol/commons/jobs/web/resources/JobsResource/info.ftl
(original)
+++
stanbol/branches/commons-ng/commons/jobs/web/src/main/resources/templates/html/org/apache/stanbol/commons/jobs/web/resources/JobsResource/info.ftl
Fri Jun 7 21:47:41 2013
@@ -20,7 +20,7 @@
<div class="panel">
<p><b>Status: </b> ${it.jobInfo.status}</p>
-<p><b>Output location: </b> <a
href="${it.outputLocation}">${it.outputLocation}</a></p>
+<p><b>Output location: </b> <a
href="${it.jobInfo.outputLocation}">${it.jobInfo.outputLocation}</a></p>
<p><b>Messages:</b> </p>
<ul>
<#list it.jobInfo.messages as message>
Modified:
stanbol/branches/commons-ng/commons/web/base.jersey/src/main/java/org/apache/stanbol/commons/web/base/jersey/EditableLayoutConfiguration.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base.jersey/src/main/java/org/apache/stanbol/commons/web/base/jersey/EditableLayoutConfiguration.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/base.jersey/src/main/java/org/apache/stanbol/commons/web/base/jersey/EditableLayoutConfiguration.java
(original)
+++
stanbol/branches/commons-ng/commons/web/base.jersey/src/main/java/org/apache/stanbol/commons/web/base/jersey/EditableLayoutConfiguration.java
Fri Jun 7 21:47:41 2013
@@ -77,12 +77,12 @@ public class EditableLayoutConfiguration
}
@Override
- public List<LinkResource> getLinkResources() {
+ public List<LinkResource> getRegisteredLinkResources() {
return linkResources;
}
@Override
- public List<ScriptResource> getScriptResources() {
+ public List<ScriptResource> getRegisteredScriptResources() {
return scriptResources;
}
Modified:
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
(original)
+++
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
Fri Jun 7 21:47:41 2013
@@ -42,20 +42,8 @@ import org.apache.stanbol.commons.web.ba
//according to
http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html
//"With the annotations the super class is required to have the Component
annotation."
@Component(componentAbstract = true)
-public abstract class BaseStanbolResource {
-
- /*public static final String LINK_RESOURCES =
"org.apache.stanbol.commons.web.base.resource.links";
-
- public static final String SCRIPT_RESOURCES =
"org.apache.stanbol.commons.web.base.resource.scripts";
-
- public static final String STATIC_RESOURCES_ROOT_URL =
"org.apache.stanbol.commons.web.base.resource.static.root";
-
- public static final String NAVIGATION_LINKS =
"org.apache.stanbol.commons.web.base.navigation.link";
-
- public static final String ROOT_URL =
"org.apache.stanbol.commons.web.base.root";*/
-
- public static final String SYSTEM_CONSOLE = "system/console";
-
+public class BaseStanbolResource extends TemplateLayoutConfiguration {
+
@Reference
private LayoutConfiguration layoutConfiguration;
@@ -63,120 +51,32 @@ public abstract class BaseStanbolResourc
@Context
protected UriInfo uriInfo;
-
- public URI getRequestUri(){
- if (uriInfo == null) throw new RuntimeException("UriInfo has not been
injected");
- return uriInfo.getAbsolutePath();
+ protected LayoutConfiguration getLayoutConfiguration() {
+ return layoutConfiguration;
}
- public URI getPublicBaseUri() {
- if (uriInfo == null) throw new RuntimeException("UriInfo has not been
injected");
- return uriInfo.getBaseUri();
+ protected UriInfo getUriInfo() {
+ return uriInfo;
}
/**
- * The Apache Felix Webconsole base URL does not depend on alias configured
- * for the Stanbol JerseyEndpoint. However they is affected by the base
- * path of the Servlet when Stanbol is running as WAR within a web
container.<p>
- * <i>LIMITATION</i> this does not take into account the path configured
- * for the Apache Felix Webconsole (property: <code>manager.root</code>
- * class:
<code>org.apache.felix.webconsole.internal.servlet.OsgiManager</code>)
- * Because of this it will only work with the default {@link
#SYSTEM_CONSOLE}.
- * @return The URI for the Apache Felix Webconsole
- */
- public URI getConsoleBaseUri() {
- String root = getRootUrl();
- UriBuilder consolePathBuilder;
- if(StringUtils.isNotBlank(root) && !"/".equals(root)){
- String request = uriInfo.getRequestUri().toString();
- int aliasIndex = request.lastIndexOf(root);
- if(aliasIndex > 0) {
- request = request.substring(0, request.lastIndexOf(root));
- }
- consolePathBuilder = UriBuilder.fromUri(request);
- } else {
- consolePathBuilder = uriInfo.getRequestUriBuilder();
- }
-
- if (this.getClass().isAnnotationPresent(Path.class)) {
- String path = this.getClass().getAnnotation(Path.class).value();
- int levels = (path.endsWith("/") ?
StringUtils.countMatches(path, "/")-1 : StringUtils.countMatches(path, "/"));
- for (int i=levels; i>0; i--) {
- consolePathBuilder = consolePathBuilder.path("../");
- }
- }
-
- return consolePathBuilder.path(SYSTEM_CONSOLE).build();
- }
-
- /**
- * @return the sorted list of navigation links data transfer objects
- */
-
- public List<NavigationLink> getNavigationLinks() {
- return layoutConfiguration.getNavigationLinks();
- }
-
- /**
- * @return menu items with "selected" CSS class for the active link
precomputed where applicable
+ * Subclassed extend this object typically as inline object to provide
+ * a data model for rendering with a Viewable Object
*/
- public List<MenuItem> getMainMenuItems() {
- List<MenuItem> items = new ArrayList<MenuItem>();
- for (NavigationLink link : getNavigationLinks()) {
- items.add(new MenuItem(link.getLabel(), link.getPath(), uriInfo));
- }
- return items;
- }
-
- public static class MenuItem {
+ public abstract class ResultData extends TemplateLayoutConfiguration {
- public MenuItem(String label, String link, UriInfo uriInfo) {
- this.label = label;
- if (link.startsWith("/")) {
- link = link.substring(1);
- }
- this.link = link;
- cssClass = uriInfo.getPath().startsWith(link) ? "selected" :
"unselected";
+ @Override
+ protected LayoutConfiguration getLayoutConfiguration() {
+ return BaseStanbolResource.this.getLayoutConfiguration();
}
- protected final String label;
-
- protected final String link;
-
- protected final String cssClass;
-
- public String getLabel() {
- return label;
+ @Override
+ protected UriInfo getUriInfo() {
+ return BaseStanbolResource.this.getUriInfo();
}
- public String getLink() {
- return link;
- }
- public String getCssClass() {
- return cssClass;
- }
-
- }
-
- public String getRootUrl() {
- return layoutConfiguration.getRootUrl();
}
- public String getStaticRootUrl() {
- String baseURI = getPublicBaseUri().toString();
- if (layoutConfiguration == null) throw new
RuntimeException("layoutConfiguration has not been injected!");
- return baseURI.substring(0, baseURI.length() - 1)
- + layoutConfiguration.getStaticResourcesRootUrl();
- }
-
- @SuppressWarnings("unchecked")
- public List<LinkResource> getRegisteredLinkResources() {
- return layoutConfiguration.getLinkResources();
- }
- @SuppressWarnings("unchecked")
- public List<ScriptResource> getRegisteredScriptResources() {
- return layoutConfiguration.getScriptResources();
- }
}
Modified:
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/LayoutConfiguration.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/LayoutConfiguration.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/LayoutConfiguration.java
(original)
+++
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/LayoutConfiguration.java
Fri Jun 7 21:47:41 2013
@@ -21,8 +21,7 @@ import org.apache.stanbol.commons.web.ba
import org.apache.stanbol.commons.web.base.ScriptResource;
/**
- *
- * @author Reto
+ * That's the data the Web Binding Provider need to provide
*/
public interface LayoutConfiguration {
@@ -32,8 +31,8 @@ public interface LayoutConfiguration {
public String getStaticResourcesRootUrl();
- public List<LinkResource> getLinkResources();
+ public List<LinkResource> getRegisteredLinkResources();
- public List<ScriptResource> getScriptResources();
+ public List<ScriptResource> getRegisteredScriptResources();
}
Added:
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/TemplateLayoutConfiguration.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/TemplateLayoutConfiguration.java?rev=1490847&view=auto
==============================================================================
---
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/TemplateLayoutConfiguration.java
(added)
+++
stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/TemplateLayoutConfiguration.java
Fri Jun 7 21:47:41 2013
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.web.base.resource;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.StringUtils;
+import org.apache.stanbol.commons.web.base.LinkResource;
+import org.apache.stanbol.commons.web.base.NavigationLink;
+import org.apache.stanbol.commons.web.base.ScriptResource;
+
+/**
+ * Provides the method the common templates expect in the data object
+ */
+public abstract class TemplateLayoutConfiguration implements
LayoutConfiguration{
+
+ public static final String SYSTEM_CONSOLE = "system/console";
+
+ /**
+ * The Apache Felix Webconsole base URL does not depend on alias configured
+ * for the Stanbol JerseyEndpoint. However they is affected by the base
+ * path of the Servlet when Stanbol is running as WAR within a web
container.<p>
+ * <i>LIMITATION</i> this does not take into account the path configured
+ * for the Apache Felix Webconsole (property: <code>manager.root</code>
+ * class:
<code>org.apache.felix.webconsole.internal.servlet.OsgiManager</code>)
+ * Because of this it will only work with the default {@link
#SYSTEM_CONSOLE}.
+ * @return The URI for the Apache Felix Webconsole
+ */
+ public URI getConsoleBaseUri() {
+ String root = getRootUrl();
+ UriBuilder consolePathBuilder;
+ if (StringUtils.isNotBlank(root) && !"/".equals(root)) {
+ String request = getUriInfo().getRequestUri().toString();
+ int aliasIndex = request.lastIndexOf(root);
+ if (aliasIndex > 0) {
+ request = request.substring(0, request.lastIndexOf(root));
+ }
+ consolePathBuilder = UriBuilder.fromUri(request);
+ } else {
+ consolePathBuilder = getUriInfo().getRequestUriBuilder();
+ }
+ if (this.getClass().isAnnotationPresent(Path.class)) {
+ String path = this.getClass().getAnnotation(Path.class).value();
+ int levels = path.endsWith("/") ? StringUtils.countMatches(path,
"/") - 1 : StringUtils.countMatches(path, "/");
+ for (int i = levels; i > 0; i--) {
+ consolePathBuilder = consolePathBuilder.path("../");
+ }
+ }
+ return consolePathBuilder.path(SYSTEM_CONSOLE).build();
+ }
+
+ protected abstract LayoutConfiguration getLayoutConfiguration();
+
+ /**
+ * @return menu items with "selected" CSS class for the active link
precomputed where applicable
+ */
+ public List<MenuItem> getMainMenuItems() {
+ List<MenuItem> items = new ArrayList<MenuItem>();
+ for (NavigationLink link : getNavigationLinks()) {
+ items.add(new MenuItem(link.getLabel(), link.getPath(),
getUriInfo()));
+ }
+ return items;
+ }
+
+ /**
+ * @return the sorted list of navigation links data transfer objects
+ */
+ public List<NavigationLink> getNavigationLinks() {
+ return getLayoutConfiguration().getNavigationLinks();
+ }
+
+ public URI getPublicBaseUri() {
+ if (getUriInfo() == null) {
+ throw new RuntimeException("UriInfo has not been injected");
+ }
+ return getUriInfo().getBaseUri();
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ public List<LinkResource> getRegisteredLinkResources() {
+ return getLayoutConfiguration().getRegisteredLinkResources();
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ public List<ScriptResource> getRegisteredScriptResources() {
+ return getLayoutConfiguration().getRegisteredScriptResources();
+ }
+
+ public URI getRequestUri() {
+ if (getUriInfo() == null) {
+ throw new RuntimeException("UriInfo has not been injected");
+ }
+ return getUriInfo().getAbsolutePath();
+ }
+
+ public String getRootUrl() {
+ return getLayoutConfiguration().getRootUrl();
+ }
+
+
+ public String getStaticResourcesRootUrl() {
+ return getLayoutConfiguration().getStaticResourcesRootUrl();
+ }
+
+ public String getStaticRootUrl() {
+ String baseURI = getPublicBaseUri().toString();
+ return baseURI.substring(0, baseURI.length() - 1) +
getStaticResourcesRootUrl();
+ }
+
+ protected abstract UriInfo getUriInfo();
+
+
+ public static class MenuItem {
+
+ public MenuItem(String label, String link, UriInfo uriInfo) {
+ this.label = label;
+ if (link.startsWith("/")) {
+ link = link.substring(1);
+ }
+ this.link = link;
+ cssClass = uriInfo.getPath().startsWith(link) ? "selected" :
"unselected";
+ }
+
+ protected final String label;
+
+ protected final String link;
+
+ protected final String cssClass;
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public String getCssClass() {
+ return cssClass;
+ }
+
+ }
+
+}
Modified: stanbol/branches/commons-ng/commons/web/home/pom.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/home/pom.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/home/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/web/home/pom.xml Fri Jun 7 21:47:41
2013
@@ -106,7 +106,7 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.11.0</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>
<groupId>com.sun.jersey</groupId>
Modified:
stanbol/branches/commons-ng/commons/web/home/src/main/java/org/apache/stanbol/commons/web/home/HomeWebFragment.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/home/src/main/java/org/apache/stanbol/commons/web/home/HomeWebFragment.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/home/src/main/java/org/apache/stanbol/commons/web/home/HomeWebFragment.java
(original)
+++
stanbol/branches/commons-ng/commons/web/home/src/main/java/org/apache/stanbol/commons/web/home/HomeWebFragment.java
Fri Jun 7 21:47:41 2013
@@ -29,12 +29,9 @@ import org.apache.stanbol.commons.web.ba
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.apache.stanbol.commons.web.home.resource.StanbolRootResource;
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
Modified: stanbol/branches/commons-ng/commons/web/rdfviewable-writer/pom.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/rdfviewable-writer/pom.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/rdfviewable-writer/pom.xml
(original)
+++ stanbol/branches/commons-ng/commons/web/rdfviewable-writer/pom.xml Fri Jun
7 21:47:41 2013
@@ -67,7 +67,7 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.12.0-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
Modified: stanbol/branches/commons-ng/commons/web/viewable-writer/pom.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/viewable-writer/pom.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/viewable-writer/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/web/viewable-writer/pom.xml Fri Jun 7
21:47:41 2013
@@ -89,7 +89,7 @@
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.12.0-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
Modified:
stanbol/branches/commons-ng/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
(original)
+++
stanbol/branches/commons-ng/commons/web/viewable-writer/src/main/java/org/apache/stanbol/commons/viewable/writer/impl/ViewableWriter.java
Fri Jun 7 21:47:41 2013
@@ -35,6 +35,8 @@ import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.TemplateException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
@@ -42,44 +44,55 @@ import org.apache.felix.scr.annotations.
@Component
@Service(Object.class)
-@Property(name="javax.ws.rs", boolValue=true)
+@Property(name = "javax.ws.rs", boolValue = true)
@Produces(MediaType.TEXT_HTML)
@Provider
public class ViewableWriter implements MessageBodyWriter<Viewable> {
+ @Context
+ private UriInfo uriInfo;
+
@Reference
- private TemplateLoader templateLoader;
+ private TemplateLoader templateLoader;
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return Viewable.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(Viewable t, Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final Viewable 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");
+ renderPojo(new Wrapper(t.getPojo()), "html/" +
getResolvedTemplatePath(t), out);
+ out.flush();
+ }
+
+ private String getResolvedTemplatePath(Viewable t) {
+ final String slahSeparatedPacakgeName =
getEffectiveClass(t).getName().replace('.', '/');
+ if (t.getTemplatePath().startsWith("/")) {
+ return slahSeparatedPacakgeName + t.getTemplatePath();
+ } else {
+ return slahSeparatedPacakgeName + '/' + t.getTemplatePath();
+ }
+ }
-
- @Override
- public boolean isWriteable(Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
- return Viewable.class.isAssignableFrom(type);
- }
-
- @Override
- public long getSize(Viewable t, Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mediaType) {
- return -1;
- }
-
- @Override
- public void writeTo(final Viewable 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");
- renderPojo(new Wrapper(t.getPojo()),
"html/"+t.getTemplatePath(), out);
- out.flush();
- }
-
- /**
+ /**
* Old school classical freemarker rendering, no LD here
*/
- public void renderPojo(Object pojo, final String templatePath, Writer out)
{
- Configuration freemarker= new Configuration();
+ 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);
@@ -95,18 +108,24 @@ public class ViewableWriter implements M
throw new RuntimeException(e);
}
}
-
- static public class Wrapper {
- private Object wrapped;
- public Wrapper(Object wrapped) {
- this.wrapped = wrapped;
- }
- public Object getIt() {
- return wrapped;
- }
-
-
- }
+ private Class getEffectiveClass(Viewable t) {
+ if (t.getContextClass() != null) {
+ return t.getContextClass();
+ }
+ return uriInfo.getMatchedResources().get(0).getClass();
+ }
+
+ static public class Wrapper {
+
+ private Object wrapped;
+ public Wrapper(Object wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ public Object getIt() {
+ return wrapped;
+ }
+ }
}
Modified: stanbol/branches/commons-ng/commons/web/viewable/pom.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/viewable/pom.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/viewable/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/web/viewable/pom.xml Fri Jun 7
21:47:41 2013
@@ -27,7 +27,7 @@
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.12.0-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Stanbol Commons Web Viewable</name>
Modified:
stanbol/branches/commons-ng/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/Viewable.java
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/Viewable.java?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/Viewable.java
(original)
+++
stanbol/branches/commons-ng/commons/web/viewable/src/main/java/org/apache/stanbol/commons/web/viewable/Viewable.java
Fri Jun 7 21:47:41 2013
@@ -31,6 +31,7 @@ package org.apache.stanbol.commons.web.v
*
*/
public class Viewable {
+
/**
* This uses the class name of Pojo to prefix the template
@@ -39,7 +40,7 @@ public class Viewable {
* @param graphNode the graphNode with the actual content
*/
public Viewable(final String templatePath, final Object pojo) {
- this(templatePath, pojo, pojo.getClass());
+ this(templatePath, pojo, null);
}
/**
@@ -48,17 +49,14 @@ public class Viewable {
*
*/
public Viewable(final String templatePath, final Object pojo, final
Class<?> clazz) {
- final String slahSeparatedPacakgeName = clazz.getName().replace('.',
'/');
- if (templatePath.startsWith("/")) {
- this.templatePath = slahSeparatedPacakgeName+templatePath;
- } else {
- this.templatePath = slahSeparatedPacakgeName+'/'+templatePath;
- }
+ this.templatePath = templatePath;
this.pojo = pojo;
+ this.contextClass = clazz;
}
private String templatePath;
private Object pojo;
+ private Class contextClass;
public String getTemplatePath() {
return templatePath;
@@ -67,4 +65,9 @@ public class Viewable {
public Object getPojo() {
return pojo;
}
+
+ public Class getContextClass() {
+ return contextClass;
+ }
+
}
Modified:
stanbol/branches/commons-ng/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml
URL:
http://svn.apache.org/viewvc/stanbol/branches/commons-ng/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml?rev=1490847&r1=1490846&r2=1490847&view=diff
==============================================================================
---
stanbol/branches/commons-ng/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml
(original)
+++
stanbol/branches/commons-ng/launchers/bundlelists/stanbolcommons/src/main/bundles/list.xml
Fri Jun 7 21:47:41 2013
@@ -610,7 +610,7 @@
<bundle>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
- <version>0.12.0-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.stanbol</groupId>