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/30 16:05:59 UTC

svn commit: r1086959 - in /incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web: JerseyEndpoint.java resource/BaseStanbolResource.java resource/NavigationMixin.java resource/StanbolRootResource.java

Author: ogrisel
Date: Wed Mar 30 14:05:58 2011
New Revision: 1086959

URL: http://svn.apache.org/viewvc?rev=1086959&view=rev
Log:
STANBOL-120: better name for the base stanbol JAX-RS resource

Added:
    incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/BaseStanbolResource.java
Removed:
    incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/NavigationMixin.java
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/resource/StanbolRootResource.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=1086959&r1=1086958&r2=1086959&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 Wed Mar 30 14:05:58 2011
@@ -16,7 +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.apache.stanbol.commons.web.resource.BaseStanbolResource;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
@@ -121,9 +121,9 @@ public class JerseyEndpoint {
         // services
         servletContext = container.getServletContext();
         servletContext.setAttribute(BundleContext.class.getName(), ctx.getBundleContext());
-        servletContext.setAttribute(NavigationMixin.STATIC_RESOURCES_ROOT_URL, staticUrlRoot);
-        servletContext.setAttribute(NavigationMixin.LINK_RESOURCES, linkResources);
-        servletContext.setAttribute(NavigationMixin.SCRIPT_RESOURCES, scriptResources);
+        servletContext.setAttribute(BaseStanbolResource.STATIC_RESOURCES_ROOT_URL, staticUrlRoot);
+        servletContext.setAttribute(BaseStanbolResource.LINK_RESOURCES, linkResources);
+        servletContext.setAttribute(BaseStanbolResource.SCRIPT_RESOURCES, scriptResources);
         log.info("JerseyEndpoint servlet registered at {}", applicationAlias);
     }
 

Added: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/BaseStanbolResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/BaseStanbolResource.java?rev=1086959&view=auto
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/BaseStanbolResource.java (added)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/BaseStanbolResource.java Wed Mar 30 14:05:58 2011
@@ -0,0 +1,92 @@
+package org.apache.stanbol.commons.web.resource;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+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.
+ * 
+ * TODO: make the list of menu items dynamically contributed by WebFragments from the OSGi runtime.
+ */
+public class BaseStanbolResource {
+
+    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();
+    }
+
+    public List<MenuItem> getMainMenuItems() {
+        return Arrays.asList(new MenuItem("/engines", "/engines", uriInfo), new MenuItem("/store", "/store",
+                uriInfo), new MenuItem("/sparql", "/sparql", uriInfo));
+    }
+
+    public static class MenuItem {
+
+        public MenuItem(String label, String link, UriInfo uriInfo) {
+            this.label = label;
+            this.link = link;
+            cssClass = uriInfo.getPath().startsWith(link.substring(1)) ? "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;
+        }
+
+    }
+
+    public String getStaticRootUrl() {
+        return (String) servletContext.getAttribute(STATIC_RESOURCES_ROOT_URL);
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<LinkResource> getRegisteredLinkResources() {
+        if (servletContext != null) {
+            return (List<LinkResource>) servletContext.getAttribute(LINK_RESOURCES);
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<ScriptResource> getRegisteredScriptResources() {
+        if (servletContext != null) {
+            return (List<ScriptResource>) servletContext.getAttribute(SCRIPT_RESOURCES);
+        } else {
+            return Collections.emptyList();
+        }
+    }
+}

Modified: incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/StanbolRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/StanbolRootResource.java?rev=1086959&r1=1086958&r2=1086959&view=diff
==============================================================================
--- incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/StanbolRootResource.java (original)
+++ incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/StanbolRootResource.java Wed Mar 30 14:05:58 2011
@@ -14,7 +14,7 @@ import com.sun.jersey.api.view.Viewable;
  * META-INF/templates folder.
  */
 @Path("/")
-public class StanbolRootResource extends NavigationMixin {
+public class StanbolRootResource extends BaseStanbolResource {
 
     @GET
     @Produces(TEXT_HTML)