You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by og...@apache.org on 2011/03/29 18:11:05 UTC
svn commit: r1086636 - in
/incubator/stanbol/branches/http-endpoint-refactoring:
commons/web/src/main/java/org/apache/stanbol/commons/web/
commons/web/src/main/java/org/apache/stanbol/commons/web/resource/
commons/web/src/main/resources/META-INF/static...
Author: ogrisel
Date: Tue Mar 29 16:11:04 2011
New Revision: 1086636
URL: http://svn.apache.org/viewvc?rev=1086636&view=rev
Log:
STANBOL-120: progress on pluggable static resources registration
Added:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/LinkResource.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ScriptResource.java
Removed:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/static/openlayers-2.9/
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/static/scripts/
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/resources/META-INF/
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/static/scripts/jit.js
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/static/style/
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/common.ftl
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpointApplication.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/WebFragment.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/imports/common.ftl
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java Tue Mar 29 16:11:04 2011
@@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.stanbol.commons.web.resource.NavigationMixin;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
@@ -91,8 +92,13 @@ public class JerseyEndpoint {
registeredAlias.add(staticUrlRoot);
// incrementally contribute fragment resources
+ List<LinkResource> linkResources = new ArrayList<LinkResource>();
+ List<ScriptResource> scriptResources = new ArrayList<ScriptResource>();
+
for (WebFragment fragment : webFragments) {
log.info("Registering web fragment '{}' into jaxrs application", fragment.getName());
+ linkResources.addAll(fragment.getLinkResources());
+ scriptResources.addAll(fragment.getScriptResources());
app.contributeClasses(fragment.getJaxrsResourceClasses());
app.contributeSingletons(fragment.getJaxrsResourceSingletons());
app.contributeTemplateLoader(fragment.getTemplateLoader());
@@ -118,7 +124,9 @@ public class JerseyEndpoint {
// services
servletContext = container.getServletContext();
servletContext.setAttribute(BundleContext.class.getName(), ctx.getBundleContext());
- servletContext.setAttribute(STATIC_RESOURCES_URL_ROOT_PROPERTY, staticUrlRoot);
+ servletContext.setAttribute(NavigationMixin.STATIC_RESOURCES_ROOT_URL, staticUrlRoot);
+ servletContext.setAttribute(NavigationMixin.LINK_RESOURCES, linkResources);
+ servletContext.setAttribute(NavigationMixin.SCRIPT_RESOURCES, scriptResources);
log.info("JerseyEndpoint servlet registered at {}", alias);
}
Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpointApplication.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpointApplication.java?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpointApplication.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpointApplication.java Tue Mar 29 16:11:04 2011
@@ -34,7 +34,7 @@ public class JerseyEndpointApplication e
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
- // hardcoded root resource class for now (to be externalize into a stanbol.commons.web.home package
+ // hardcoded root resource class for now (to be externalized into a stanbol.commons.web.home package
// for instance)
classes.add(StanbolRootResource.class);
Added: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/LinkResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/LinkResource.java?rev=1086636&view=auto
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/LinkResource.java (added)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/LinkResource.java Tue Mar 29 16:11:04 2011
@@ -0,0 +1,30 @@
+package org.apache.stanbol.commons.web;
+
+/**
+ * Simple data transfer object for stylesheet (CSS) and fiveicon list to be contributed by WebFragment for
+ * inclusion to the HTML head of the pages by the NavigationMixin abstract JAX-RS resource.
+ */
+public class LinkResource {
+
+ private final String rel;
+ private final String relativePath;
+ private final WebFragment fragment;
+
+ public LinkResource(String rel, String relativePath, WebFragment fragment) {
+ this.rel = rel;
+ this.relativePath = relativePath;
+ this.fragment = fragment;
+ }
+
+ public String getRel() {
+ return rel;
+ }
+
+ public String getRelativePath() {
+ return relativePath;
+ }
+
+ public String getFragmentName() {
+ return fragment.getName();
+ }
+}
Added: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ScriptResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ScriptResource.java?rev=1086636&view=auto
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ScriptResource.java (added)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ScriptResource.java Tue Mar 29 16:11:04 2011
@@ -0,0 +1,31 @@
+package org.apache.stanbol.commons.web;
+
+/**
+ * Simple data transfer object for scripts (typically javascript) to be contributed by WebFragment for
+ * inclusion to the HTML head of the pages by the NavigationMixin abstract JAX-RS resource.
+ */
+public class ScriptResource {
+
+ private final String type;
+ private final String relativePath;
+ private final WebFragment fragment;
+
+ public ScriptResource(String type, String relativePath, WebFragment fragment) {
+ this.type = type;
+ this.relativePath = relativePath;
+ this.fragment = fragment;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getRelativePath() {
+ return relativePath;
+ }
+
+ public String getFragmentName() {
+ return fragment.getName();
+ }
+
+}
Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/WebFragment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/WebFragment.java?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/WebFragment.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/WebFragment.java Tue Mar 29 16:11:04 2011
@@ -1,5 +1,6 @@
package org.apache.stanbol.commons.web;
+import java.util.List;
import java.util.Set;
import freemarker.cache.TemplateLoader;
@@ -7,6 +8,8 @@ import freemarker.cache.TemplateLoader;
/**
* Interface to be implemented by bundles that want to customize the stanbol web interface and REST API by
* contributing static resources, JAX-RS resources and Freemarker views.
+ *
+ * TODO: add some kind of ordering information
*/
public interface WebFragment {
@@ -47,4 +50,20 @@ public interface WebFragment {
*/
public TemplateLoader getTemplateLoader();
+ /**
+ * CSS and favicon resources to be linked in the head of all HTML pages controlled by the NavigationMixin
+ * abstract resource. The resources will be published under:
+ *
+ * ${it.staticRootUrl}/${link.fragmentName}/${link.relativePath}
+ */
+ public List<LinkResource> getLinkResources();
+
+ /**
+ * Javascript resources to be linked in the head of all HTML pages controlled by the NavigationMixin
+ * abstract resource. The resources will be published under:
+ *
+ * ${it.staticRootUrl}/${script.fragmentName}/${script.relativePath}
+ */
+ public List<ScriptResource> getScriptResources();
+
}
Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java Tue Mar 29 16:11:04 2011
@@ -4,9 +4,13 @@ import java.net.URI;
import java.util.Arrays;
import java.util.List;
+import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
+import org.apache.stanbol.commons.web.LinkResource;
+import org.apache.stanbol.commons.web.ScriptResource;
+
/**
* Mixin class to provide the controller method for the navigation template.
*
@@ -14,9 +18,18 @@ import javax.ws.rs.core.UriInfo;
*/
public class NavigationMixin {
+ public static final String LINK_RESOURCES = "org.apache.stanbol.commons.web.resource.links";
+
+ public static final String SCRIPT_RESOURCES = "org.apache.stanbol.commons.web.resource.scripts";
+
+ public static final String STATIC_RESOURCES_ROOT_URL = "org.apache.stanbol.commons.web.resource.static.url.root";
+
@Context
protected UriInfo uriInfo;
+ @Context
+ protected ServletContext servletContext;
+
public URI getPublicBaseUri() {
return uriInfo.getBaseUri();
}
@@ -54,4 +67,17 @@ public class NavigationMixin {
}
+ public String getStaticRootUrl() {
+ return (String) servletContext.getAttribute(STATIC_RESOURCES_ROOT_URL);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<LinkResource> getRegisteredLinkResources() {
+ return (List<LinkResource>) servletContext.getAttribute(LINK_RESOURCES);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<ScriptResource> getRegisteredScriptResources() {
+ return (List<ScriptResource>) servletContext.getAttribute(SCRIPT_RESOURCES);
+ }
}
Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/imports/common.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/imports/common.ftl?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/imports/common.ftl (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/imports/common.ftl Tue Mar 29 16:11:04 2011
@@ -2,18 +2,20 @@
<html>
<head>
- <title>Apache Stanbol - ${title?html}</title>
+ <title>${title?html} - Apache Stanbol</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <!-- to be moved in the dedicated fragment -->
<link rel="stylesheet" href="/static/style/stanbol.css" />
- <link rel="stylesheet" href="/static/openlayers-2.9/theme/default/style.css" type="text/css" />
- <link rel="stylesheet" href="/static/scripts/prettify/prettify.css" />
<link rel="icon" type="image/png" href="/static/images/favicon.png" />
- <script type="text/javascript" src="/static/openlayers-2.9/OpenLayers.js"></script>
- <script type="text/javascript" src="/static/scripts/prettify/prettify.js"></script>
- <script type="text/javascript" src="/static/scripts/jquery-1.4.2.js"></script>
- <script type="text/javascript" src="/static/scripts/jit.js"></script>
+ <#list it.registeredLinkResources as link>
+ <link rel="${link.rel}" href="${it.staticRootUrl}/${link.fragmentName}/${link.relativePath}" />
+ </#list>
+
+ <#list it.registeredScriptResources as script>
+ <script type="${script.type}" src="${it.staticRootUrl}/${script.fragmentName}/${script.relativePath}"></script>
+ </#list>
</head>
Modified: incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java?rev=1086636&r1=1086635&r2=1086636&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java Tue Mar 29 16:11:04 2011
@@ -1,11 +1,15 @@
package org.apache.stanbol.enhancer.jersey.fragment;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.web.LinkResource;
+import org.apache.stanbol.commons.web.ScriptResource;
import org.apache.stanbol.commons.web.WebFragment;
import org.apache.stanbol.enhancer.jersey.resource.EnginesRootResource;
import org.apache.stanbol.enhancer.jersey.resource.SparqlQueryResource;
@@ -58,4 +62,21 @@ public class EnhancerWebFragment impleme
return new ClassTemplateLoader(getClass(), TEMPLATE_PATH);
}
+ @Override
+ public List<LinkResource> getLinkResources() {
+ List<LinkResource> resources = new ArrayList<LinkResource>();
+ resources.add(new LinkResource("stylesheet", "openlayers-2.9/theme/default/style.css", this));
+ resources.add(new LinkResource("stylesheet", "scripts/prettify/prettify.css", this));
+ return resources;
+ }
+
+ @Override
+ public List<ScriptResource> getScriptResources() {
+ List<ScriptResource> resources = new ArrayList<ScriptResource>();
+ resources.add(new ScriptResource("text/javascript", "openlayers-2.9/OpenLayers.js", this));
+ resources.add(new ScriptResource("text/javascript", "scripts/prettify/prettify.js", this));
+ resources.add(new ScriptResource("text/javascript", "scripts/jquery-1.4.2.js", this));
+ return resources;
+ }
+
}