Author: ogrisel
Date: Mon Mar 28 21:25:02 2011
New Revision: 1086409
URL: http://svn.apache.org/viewvc?rev=1086409&view=rev
Log:
STANBOL-120: more updates of the enhancer related resources to make them work
using the WebFragment system
Added:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ContextHelper.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/processor/FreemarkerViewProcessor.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/resource/StanbolRootResource.java
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnginesRootResource.java
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/SparqlQueryResource.java
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java
Added:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ContextHelper.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ContextHelper.java?rev=1086409&view=auto
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ContextHelper.java
(added)
+++
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/ContextHelper.java
Mon Mar 28 21:25:02 2011
@@ -0,0 +1,29 @@
+package org.apache.stanbol.commons.web;
+
+import javax.servlet.ServletContext;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class ContextHelper {
+
+ // TODO: turn the following into a annotation that derives from the JAX-RS
@Context annotation
+ /**
+ * Fetch an OSGi service instance broadcasted into the OSGi context.
+ *
+ * @param <T>
+ * the type of the service
+ * @param clazz
+ * the class of the service
+ * @param context
+ * the servlet context
+ * @return the registered instance of the service (assuming cardinality 1)
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T getServiceFromContext(Class<T> clazz, ServletContext
context) {
+ BundleContext bundleContext = (BundleContext)
context.getAttribute(BundleContext.class.getName());
+ ServiceReference reference =
bundleContext.getServiceReference(clazz.getName());
+ return (T) bundleContext.getService(reference);
+ }
+
+}
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=1086409&r1=1086408&r2=1086409&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
Mon Mar 28 21:25:02 2011
@@ -83,7 +83,7 @@ public class JerseyEndpoint {
String templateClasspath = (String)
ctx.getProperties().get(FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY);
// register the base template loader
- templateClasspath.replaceAll("/$", "");
+ templateClasspath = templateClasspath.replaceAll("/$", "");
app.contributeTemplateLoader(new ClassTemplateLoader(getClass(),
templateClasspath));
// register the root of static resources
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/processor/FreemarkerViewProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/processor/FreemarkerViewProcessor.java?rev=1086409&r1=1086408&r2=1086409&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/processor/FreemarkerViewProcessor.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/processor/FreemarkerViewProcessor.java
Mon Mar 28 21:25:02 2011
@@ -62,8 +62,6 @@ public class FreemarkerViewProcessor imp
protected Configuration freemarkerConfig;
- protected String rootPath;
-
protected TemplateLoader templateLoader;
@Context
@@ -178,8 +176,7 @@ public class FreemarkerViewProcessor imp
try {
return getConfig().getTemplate(filePath);
} catch (IOException e) {
- log.error("Failed to load freemaker template: " + rootPath
- + filePath);
+ log.error("Failed to load freemaker template: " + filePath);
return null;
}
}
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=1086409&r1=1086408&r2=1086409&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
Mon Mar 28 21:25:02 2011
@@ -1,17 +1,25 @@
package org.apache.stanbol.commons.web.resource;
-import javax.ws.rs.Path;
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
-import com.sun.jersey.api.view.ImplicitProduces;
+import com.sun.jersey.api.view.Viewable;
/**
- * Root JAX-RS resource. The HTML view is implicitly rendered by a freemarker
- * template to be found in the META-INF/templates folder.
+ * Root JAX-RS resource. The HTML view is implicitly rendered by a freemarker
template to be found in the
+ * META-INF/templates folder.
*/
@Path("/")
-@ImplicitProduces("text/html")
public class StanbolRootResource extends NavigationMixin {
+ @GET
+ @Produces(TEXT_HTML)
+ public Response get() {
+ return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+ }
}
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=1086409&r1=1086408&r2=1086409&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
Mon Mar 28 21:25:02 2011
@@ -24,9 +24,9 @@ public class EnhancerWebFragment impleme
private static final String NAME = "enhancer";
- private static final String STATIC_RESOURCE_PATH =
"org/apache/stanbol/enhancer/jersey/static";
+ private static final String STATIC_RESOURCE_PATH =
"/org/apache/stanbol/enhancer/jersey/static";
- private static final String TEMPLATE_PATH =
"org/apache/stanbol/enhancer/jersey/templates";
+ private static final String TEMPLATE_PATH =
"/org/apache/stanbol/enhancer/jersey/templates";
@Override
public String getName() {
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java?rev=1086409&r1=1086408&r2=1086409&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentItemResource.java
Mon Mar 28 21:25:02 2011
@@ -20,6 +20,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
@@ -52,9 +55,8 @@ import org.apache.stanbol.enhancer.servi
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.jersey.api.view.ImplicitProduces;
+import com.sun.jersey.api.view.Viewable;
-@ImplicitProduces(TEXT_HTML + ";qs=2")
public class ContentItemResource extends NavigationMixin {
@SuppressWarnings("unused")
@@ -473,5 +475,11 @@ public class ContentItemResource extends
serializer.serialize(out, g, SupportedFormat.RDF_JSON);
return out.toString("utf-8");
}
+
+ @GET
+ @Produces(TEXT_HTML)
+ public Response get() {
+ return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+ }
}
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnginesRootResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnginesRootResource.java?rev=1086409&r1=1086408&r2=1086409&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnginesRootResource.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/EnginesRootResource.java
Mon Mar 28 21:25:02 2011
@@ -1,7 +1,6 @@
package org.apache.stanbol.enhancer.jersey.resource;
import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
@@ -10,8 +9,6 @@ import static org.apache.clerezza.rdf.co
import static
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_XML;
import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -26,12 +23,12 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.access.TcManager;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.stanbol.commons.web.ContextHelper;
import org.apache.stanbol.commons.web.resource.NavigationMixin;
import org.apache.stanbol.enhancer.jersey.cache.EntityCacheProvider;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
@@ -39,22 +36,19 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
-import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.jersey.api.view.ImplicitProduces;
import com.sun.jersey.api.view.Viewable;
/**
- * RESTful interface to browse the list of available engines and allow to call
- * them in a stateless, synchronous way.
+ * RESTful interface to browse the list of available engines and allow to call
them in a stateless,
+ * synchronous way.
* <p>
- * If you need the content of the extractions to be stored on the server, use
- * the StoreRootResource API instead.
+ * If you need the content of the extractions to be stored on the server, use
the StoreRootResource API
+ * instead.
*/
@Path("/engines")
-@ImplicitProduces(TEXT_HTML + ";qs=2")
public class EnginesRootResource extends NavigationMixin {
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -69,15 +63,22 @@ public class EnginesRootResource extends
// bind the job manager by looking it up from the servlet request context
public EnginesRootResource(@Context ServletContext context) {
- jobManager = (EnhancementJobManager)
context.getAttribute(EnhancementJobManager.class.getName());
- tcManager = (TcManager)
context.getAttribute(TcManager.class.getName());
- serializer = (Serializer)
context.getAttribute(Serializer.class.getName());
- EntityCacheProvider entityCacheProvider = (EntityCacheProvider)
context.getAttribute(EntityCacheProvider.class.getName());
+ jobManager =
ContextHelper.getServiceFromContext(EnhancementJobManager.class, context);
+ tcManager = ContextHelper.getServiceFromContext(TcManager.class,
context);
+ serializer = ContextHelper.getServiceFromContext(Serializer.class,
context);
+ EntityCacheProvider entityCacheProvider =
ContextHelper.getServiceFromContext(
+ EntityCacheProvider.class, context);
if (entityCacheProvider != null) {
entityCache = entityCacheProvider.getEntityCache();
}
}
+ @GET
+ @Produces(TEXT_HTML)
+ public Response get() {
+ return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+ }
+
public List<EnhancementEngine> getActiveEngines() {
if (jobManager != null) {
return jobManager.getActiveEngines();
@@ -86,84 +87,56 @@ public class EnginesRootResource extends
}
}
- private List<EnhancementEngine> getEngines() {
- if (jobManager != null) {
- return jobManager.getActiveEngines();
- }
- return new ArrayList<EnhancementEngine>();
- }
-
- @GET
- @Produces(APPLICATION_JSON)
- public JSONArray getEnginesAsJsonArray() {
- JSONArray uriArray = new JSONArray();
- for (EnhancementEngine engine : getEngines()) {
- UriBuilder ub = uriInfo.getAbsolutePathBuilder();
- URI userUri = ub.path(makeEngineId(engine)).build();
- uriArray.put(userUri.toASCIIString());
- }
- return uriArray;
- }
-
- @GET
- @Produces(TEXT_PLAIN)
- public String getEnginesAsString() {
- final StringBuilder sb = new StringBuilder();
- for (EnhancementEngine engine : getEngines()) {
- sb.append(engine.getClass().getName());
- sb.append("\n");
- }
- return sb.toString();
- }
-
public static String makeEngineId(EnhancementEngine engine) {
// TODO: add a property on engines to provided custom local ids and
make
// this static method a method of the interface EnhancementEngine
String engineClassName = engine.getClass().getSimpleName();
String suffixToRemove = "EnhancementEngine";
if (engineClassName.endsWith(suffixToRemove)) {
- engineClassName = engineClassName.substring(0,
- engineClassName.length() - suffixToRemove.length());
+ engineClassName = engineClassName
+ .substring(0, engineClassName.length() -
suffixToRemove.length());
}
return engineClassName.toLowerCase();
}
/**
* Form-based OpenCalais-compatible interface
- *
- * TODO: should we parse the OpenCalais paramsXML and find the closest
- * Stanbol Enhancer semantics too?
- *
+ *
+ * TODO: should we parse the OpenCalais paramsXML and find the closest
Stanbol Enhancer semantics too?
+ *
* Note: the format parameter is not part of the official API
- *
- * @throws EngineException if the content is somehow corrupted
+ *
+ * @throws EngineException
+ * if the content is somehow corrupted
* @throws IOException
*/
@POST
@Consumes(APPLICATION_FORM_URLENCODED)
public Response enhanceFromForm(@FormParam("content") String content,
- @FormParam("format") String format,
- @FormParam("ajax") boolean buildAjaxview,
- @Context HttpHeaders headers) throws EngineException, IOException {
- log.info("enhance from From: "+content); ContentItem ci = new
InMemoryContentItem(content.getBytes("UTF-8"),
- TEXT_PLAIN);
+ @FormParam("format") String format,
+ @FormParam("ajax") boolean buildAjaxview,
+ @Context HttpHeaders headers) throws
EngineException, IOException {
+ log.info("enhance from From: " + content);
+ ContentItem ci = new InMemoryContentItem(content.getBytes("UTF-8"),
TEXT_PLAIN);
return enhanceAndBuildResponse(format, headers, ci, buildAjaxview);
}
/**
* Media-Type based handling of the raw POST data.
- *
- * @param data binary payload to analyze
- * @param uri optional URI for the content items (to be used as an
- * identifier in the enhancement graph)
- * @throws EngineException if the content is somehow corrupted
+ *
+ * @param data
+ * binary payload to analyze
+ * @param uri
+ * optional URI for the content items (to be used as an
identifier in the enhancement graph)
+ * @throws EngineException
+ * if the content is somehow corrupted
* @throws IOException
*/
@POST
@Consumes(WILDCARD)
public Response enhanceFromData(byte[] data,
- @QueryParam(value = "uri") String uri, @Context HttpHeaders
headers)
- throws EngineException, IOException {
+ @QueryParam(value = "uri") String uri,
+ @Context HttpHeaders headers) throws
EngineException, IOException {
String format = TEXT_PLAIN;
if (headers.getMediaType() != null) {
format = headers.getMediaType().toString();
@@ -177,27 +150,26 @@ public class EnginesRootResource extends
}
protected Response enhanceAndBuildResponse(String format,
- HttpHeaders headers, ContentItem ci, boolean buildAjaxview)
- throws EngineException, IOException {
+ HttpHeaders headers,
+ ContentItem ci,
+ boolean buildAjaxview) throws
EngineException, IOException {
if (jobManager != null) {
jobManager.enhanceContent(ci);
}
MGraph graph = ci.getMetadata();
if (buildAjaxview) {
- ContentItemResource contentItemResource = new ContentItemResource(
- null, ci, entityCache, uriInfo, tcManager, serializer);
+ ContentItemResource contentItemResource = new
ContentItemResource(null, ci, entityCache, uriInfo,
+ tcManager, serializer);
contentItemResource.setRdfSerializationFormat(format);
- Viewable ajaxView = new Viewable("/ajax/contentitem",
- contentItemResource);
+ Viewable ajaxView = new Viewable("/ajax/contentitem",
contentItemResource);
return Response.ok(ajaxView).type(TEXT_HTML).build();
}
if (format != null) {
// force mimetype from form params
return Response.ok(graph, format).build();
}
- if (headers.getAcceptableMediaTypes().contains(
- APPLICATION_JSON_TYPE)) {
+ if (headers.getAcceptableMediaTypes().contains(APPLICATION_JSON_TYPE))
{
// force RDF JSON media type (TODO: move this logic
return Response.ok(graph, RDF_JSON).build();
} else if (headers.getAcceptableMediaTypes().isEmpty()) {
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/SparqlQueryResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/SparqlQueryResource.java?rev=1086409&r1=1086408&r2=1086409&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/SparqlQueryResource.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/SparqlQueryResource.java
Mon Mar 28 21:25:02 2011
@@ -17,6 +17,7 @@ import org.apache.clerezza.rdf.core.spar
import org.apache.clerezza.rdf.core.sparql.query.ConstructQuery;
import org.apache.clerezza.rdf.core.sparql.query.DescribeQuery;
import org.apache.clerezza.rdf.core.sparql.query.Query;
+import org.apache.stanbol.commons.web.ContextHelper;
import org.apache.stanbol.commons.web.resource.NavigationMixin;
import org.apache.stanbol.enhancer.servicesapi.Store;
import
org.apache.stanbol.enhancer.servicesapi.SparqlQueryEngine.SparqlQueryEngineException;
@@ -46,9 +47,9 @@ public class SparqlQueryResource extends
protected TcManager tcManager;
- public SparqlQueryResource(@Context ServletContext servletContext) {
- tcManager = (TcManager)
servletContext.getAttribute(TcManager.class.getName());
- store = (Store) servletContext.getAttribute(Store.class.getName());
+ public SparqlQueryResource(@Context ServletContext ctx) {
+ tcManager = ContextHelper.getServiceFromContext(TcManager.class, ctx);
+ store = ContextHelper.getServiceFromContext(Store.class, ctx);
}
@GET
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java?rev=1086409&r1=1086408&r2=1086409&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java
Mon Mar 28 21:25:02 2011
@@ -59,6 +59,7 @@ import org.apache.clerezza.rdf.core.spar
import org.apache.clerezza.rdf.core.sparql.query.SelectQuery;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.commons.web.ContextHelper;
import org.apache.stanbol.commons.web.resource.NavigationMixin;
import org.apache.stanbol.enhancer.jersey.cache.EntityCacheProvider;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
@@ -150,21 +151,21 @@ public class StoreRootResource extends N
}
public StoreRootResource(@Context ServletContext context,
- @Context UriInfo uriInfo, @QueryParam(value = "offset") int offset,
- @QueryParam(value = "pageSize") @DefaultValue("5") int pageSize)
- throws ParseException {
- tcManager = (TcManager)
context.getAttribute(TcManager.class.getName());
- store = (Store) context.getAttribute(Store.class.getName());
- jobManager = (EnhancementJobManager)
context.getAttribute(EnhancementJobManager.class.getName());
- serializer = (Serializer)
context.getAttribute(Serializer.class.getName());
- EntityCacheProvider entityCacheProvider = (EntityCacheProvider)
context.getAttribute(EntityCacheProvider.class.getName());
+ @Context UriInfo uriInfo,
+ @QueryParam(value = "offset") int offset,
+ @QueryParam(value = "pageSize")
@DefaultValue("5") int pageSize) throws ParseException {
+ store = ContextHelper.getServiceFromContext(Store.class, context);
+ jobManager =
ContextHelper.getServiceFromContext(EnhancementJobManager.class, context);
+ tcManager = ContextHelper.getServiceFromContext(TcManager.class,
context);
+ serializer = ContextHelper.getServiceFromContext(Serializer.class,
context);
+ EntityCacheProvider entityCacheProvider =
ContextHelper.getServiceFromContext(
+ EntityCacheProvider.class, context);
if (entityCacheProvider != null) {
entityCache = entityCacheProvider.getEntityCache();
}
if (store == null || tcManager == null) {
- log.error("Missing either store={} or tcManager={}", store,
- tcManager);
+ log.error("Missing either store={} or tcManager={}", store,
tcManager);
throw new WebApplicationException(404);
}
this.uriInfo = uriInfo;