Author: ogrisel
Date: Fri Apr  8 11:07:07 2011
New Revision: 1090200

URL: http://svn.apache.org/viewvc?rev=1090200&view=rev
Log:
Disable RelatedTopicEnhancementEngine by default as it need additional data

Added:
    
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource.java
    
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/contenthubDescription.ftl
    
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/
    
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/index.ftl
Removed:
    
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/StoreRootResource.java
    
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/storeDescription.ftl
Modified:
    
incubator/stanbol/trunk/enhancer/engines/autotagging/src/main/java/org/apache/stanbol/enhancer/engines/autotagging/impl/RelatedTopicEnhancementEngine.java
    
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java

Modified: 
incubator/stanbol/trunk/enhancer/engines/autotagging/src/main/java/org/apache/stanbol/enhancer/engines/autotagging/impl/RelatedTopicEnhancementEngine.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/autotagging/src/main/java/org/apache/stanbol/enhancer/engines/autotagging/impl/RelatedTopicEnhancementEngine.java?rev=1090200&r1=1090199&r2=1090200&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/engines/autotagging/src/main/java/org/apache/stanbol/enhancer/engines/autotagging/impl/RelatedTopicEnhancementEngine.java
 (original)
+++ 
incubator/stanbol/trunk/enhancer/engines/autotagging/src/main/java/org/apache/stanbol/enhancer/engines/autotagging/impl/RelatedTopicEnhancementEngine.java
 Fri Apr  8 11:07:07 2011
@@ -39,15 +39,16 @@ import org.apache.stanbol.enhancer.servi
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
- * OSGi wrapper for the iks-autotagging library. Uses a lucene index of DBpedia
- * to suggest related related topics out of the text content of the
- * content item.
+ * OSGi wrapper for the iks-autotagging library. Uses a lucene index of 
DBpedia to suggest related related
+ * topics out of the text content of the content item.
+ *
+ * Note: this engine does not works as it requires a dedicated lucene index 
that does not work yet. It will be
+ * replaced by a matching engine that uses the EntityHub instead of the 
iks-autotaggin lib.
  *
  * @author ogrisel
  */
-@Component(immediate = true, metatype = true)
+@Component(immediate = false, metatype = true)
 @Service
 public class RelatedTopicEnhancementEngine implements EnhancementEngine {
 

Modified: 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java?rev=1090200&r1=1090199&r2=1090200&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
 (original)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/fragment/EnhancerWebFragment.java
 Fri Apr  8 11:07:07 2011
@@ -14,7 +14,7 @@ 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.enhancer.jersey.resource.EnginesRootResource;
-import org.apache.stanbol.enhancer.jersey.resource.StoreRootResource;
+import org.apache.stanbol.enhancer.jersey.resource.ContentHubRootResource;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 
@@ -52,7 +52,7 @@ public class EnhancerWebFragment impleme
         Set<Class<?>> classes = new HashSet<Class<?>>();
         // resources
         classes.add(EnginesRootResource.class);
-        classes.add(StoreRootResource.class);
+        classes.add(ContentHubRootResource.class);
         return classes;
     }
 
@@ -92,7 +92,7 @@ public class EnhancerWebFragment impleme
     public List<NavigationLink> getNavigationLinks() {
         List<NavigationLink> links = new ArrayList<NavigationLink>();
         links.add(new NavigationLink("engines", "/engines", 
"/imports/enginesDescription.ftl", 10));
-        links.add(new NavigationLink("store", "/store", 
"/imports/storeDescription.ftl", 20));
+        links.add(new NavigationLink("contenthub", "/contenthub", 
"/imports/contenthubDescription.ftl", 20));
         return links;
     }
 

Added: 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource.java?rev=1090200&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource.java
 (added)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource.java
 Fri Apr  8 11:07:07 2011
@@ -0,0 +1,412 @@
+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_OCTET_STREAM_TYPE;
+import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
+import static javax.ws.rs.core.MediaType.WILDCARD;
+import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N3;
+import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N_TRIPLE;
+import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_JSON;
+import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.RDF_XML;
+import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.TURTLE;
+import static 
org.apache.clerezza.rdf.core.serializedform.SupportedFormat.X_TURTLE;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.sparql.ParseException;
+import org.apache.clerezza.rdf.core.sparql.QueryParser;
+import org.apache.clerezza.rdf.core.sparql.ResultSet;
+import org.apache.clerezza.rdf.core.sparql.SolutionMapping;
+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.base.ContextHelper;
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.enhancer.jersey.cache.EntityCacheProvider;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.enhancer.servicesapi.EngineException;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
+import org.apache.stanbol.enhancer.servicesapi.Store;
+import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
+import org.apache.stanbol.enhancer.servicesapi.rdf.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.view.Viewable;
+import com.sun.jersey.core.header.FormDataContentDisposition;
+
+/**
+ * Resource to provide a CRU[D] REST API for content items and there related
+ * enhancements.
+ * <p>
+ * Creation is achieved using either POST requests on the root of the store or
+ * as PUT requests on the expected content item URI.
+ * <p>
+ * Retrieval is achieved using simple GET requests on the content item or
+ * enhancement public URIs.
+ * <p>
+ * Update is achieved by issue a PUT request on an existing content item public
+ * URI.
+ * <p>
+ * The Delete operation is not implemented yet.
+ */
+@Path("/contenthub")
+public class ContentHubRootResource extends BaseStanbolResource {
+
+    public static final Set<String> RDF_MEDIA_TYPES = new TreeSet<String>(
+            Arrays.asList(N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON));
+
+    private static final Logger log = 
LoggerFactory.getLogger(ContentHubRootResource.class);
+
+    protected TcManager tcManager;
+
+    protected Store store;
+
+    protected EnhancementJobManager jobManager;
+
+    protected Serializer serializer;
+
+    protected UriInfo uriInfo;
+
+    protected int offset = 0;
+
+    protected int pageSize = 5;
+
+    protected List<RecentlyEnhanced> recentlyEnhanced;
+
+    protected TripleCollection entityCache;
+
+    public static class RecentlyEnhanced {
+
+        public final String localId;
+
+        public final String uri;
+
+        public final String mimetype;
+
+        public final long enhancements;
+
+        public RecentlyEnhanced(String uri, String mimetype, long 
enhancements) {
+            this.localId = uri.substring(uri.lastIndexOf("/") + 1);
+            this.uri = uri;
+            this.mimetype = mimetype;
+            this.enhancements = enhancements;
+        }
+
+        public String getLocalId() {
+            return localId;
+        }
+
+        public String getUri() {
+            return uri;
+        }
+
+        public String getMimetype() {
+            return mimetype;
+        }
+
+        public long getEnhancements() {
+            return enhancements;
+        }
+
+    }
+
+    public ContentHubRootResource(@Context ServletContext context,
+                             @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);
+            throw new WebApplicationException(404);
+        }
+        this.uriInfo = uriInfo;
+        this.offset = offset;
+        this.pageSize = pageSize;
+
+        // compute the latest: todo move some of this as OSGi parameters
+        // somewhere
+        String q = "PREFIX enhancer: <http://fise.iks-project.eu/ontology/> "
+                + "PREFIX dc:   <http://purl.org/dc/terms/> "
+                + "SELECT DISTINCT ?content WHERE { "
+                + "  ?enhancement enhancer:extracted-from ?content ."
+                + "  ?enhancement dc:created ?extraction_time . } "
+                + "ORDER BY DESC(?extraction_time) LIMIT %d OFFSET %d";
+        q = String.format(q, pageSize, offset);
+
+        SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(q);
+        ResultSet result = tcManager.executeSparqlQuery(query,
+                store.getEnhancementGraph());
+
+        recentlyEnhanced = new ArrayList<RecentlyEnhanced>();
+        while (result.hasNext()) {
+            SolutionMapping mapping = result.next();
+            UriRef content = (UriRef) mapping.get("content");
+            ContentItem ci = store.get(content.getUnicodeString());
+            String mimetype = null;
+            long enhancements = 0;
+            if (ci != null) {
+                mimetype = ci.getMimeType();
+                Iterator<Triple> it = ci.getMetadata().filter(null,
+                        Properties.ENHANCER_EXTRACTED_FROM, content);
+                while (it.hasNext()) {
+                    it.next();
+                    enhancements++;
+                }
+                recentlyEnhanced.add(new RecentlyEnhanced(
+                        content.getUnicodeString(), mimetype, enhancements));
+            }
+        }
+    }
+
+    public List<RecentlyEnhanced> getRecentlyEnhancedItems()
+            throws ParseException {
+        return recentlyEnhanced;
+    }
+
+    public URI getMoreRecentItemsUri() {
+        if (offset >= pageSize) {
+            return uriInfo.getBaseUriBuilder().path(getClass()).queryParam(
+                    "offset", offset - pageSize).build();
+        } else {
+            return null;
+        }
+    }
+
+    public URI getOlderItemsUri() {
+        if (recentlyEnhanced.size() < pageSize) {
+            return null;
+        } else {
+            return uriInfo.getBaseUriBuilder().path(getClass()).queryParam(
+                    "offset", offset + pageSize).build();
+        }
+    }
+
+    public UriRef makeContentItemUri(byte[] data) {
+        // TODO: factorize this logic out in a dedicated OSGi service
+        return ContentItemHelper.makeDefaultUri(uriInfo.getBaseUri()
+                + "contenthub/content/", data);
+    }
+
+    public UriRef makeContentItemUri(String localId) {
+        // TODO: factorize this logic out in a dedicated OSGi service
+        return new UriRef(uriInfo.getBaseUri() + "contenthub/content/" + 
localId);
+    }
+
+    @GET
+    @Produces(TEXT_HTML + ";qs=2")
+    public Viewable getView() {
+        return new Viewable("index", this);
+    }
+
+    /**
+     * Cool URI handler for the uploaded resource.
+     *
+     * @param localId the local id of the resource in the Stanbol Enhancer 
store
+     * @param headers
+     * @return a redirection to either a browser view, the RDF metadata or the
+     *         raw binary content
+     */
+    @GET
+    @Path("/content/{localId}")
+    public Response getContent(@PathParam(value = "localId") String localId,
+            @Context HttpHeaders headers) {
+
+        UriRef uri = makeContentItemUri(localId);
+        ContentItem ci = store.get(uri.getUnicodeString());
+        if (ci == null) {
+            throw new WebApplicationException(404);
+        }
+
+        // handle smart redirection to browser view
+        for (MediaType mt : headers.getAcceptableMediaTypes()) {
+            if (mt.toString().startsWith(TEXT_HTML)) {
+                URI pageUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/page").path(localId).build();
+                return Response.temporaryRedirect(pageUri).build();
+            }
+        }
+
+        // handle smart redirection to RDF metadata view
+        for (MediaType mt : headers.getAcceptableMediaTypes()) {
+            if (RDF_MEDIA_TYPES.contains(mt.toString())) {
+                URI metadataUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/metadata").path(localId).build();
+                return Response.temporaryRedirect(metadataUri).build();
+            }
+        }
+        URI rawUri = 
uriInfo.getBaseUriBuilder().path("/contenthub/raw").path(localId).build();
+        return Response.temporaryRedirect(rawUri).build();
+    }
+
+    @GET
+    @Path("/raw/{localId}")
+    public Response getRawContent(@PathParam(value = "localId") String localId)
+            throws IOException {
+        UriRef uri = makeContentItemUri(localId);
+        ContentItem ci = store.get(uri.getUnicodeString());
+        if (ci == null) {
+            throw new WebApplicationException(404);
+        }
+        return Response.ok(ci.getStream(), ci.getMimeType()).build();
+    }
+
+    @Path("/page/{localId}")
+    @Produces(TEXT_HTML)
+    public ContentItemResource getContentItemView(
+            @PathParam(value = "localId") String localId) throws IOException {
+        UriRef uri = makeContentItemUri(localId);
+        ContentItem ci = store.get(uri.getUnicodeString());
+        if (ci == null) {
+            throw new WebApplicationException(404);
+        }
+        return new ContentItemResource(localId, ci, entityCache, uriInfo,
+                tcManager, serializer, servletContext);
+    }
+
+    @GET
+    @Path("/metadata/{localId}")
+    public MGraph getContentItemMetaData(
+            @PathParam(value = "localId") String localId) {
+        UriRef uri = makeContentItemUri(localId);
+        // TODO: rewrite me to perform a CONSTRUCT query on the TcManager
+        // instead
+        ContentItem ci = store.get(uri.getUnicodeString());
+        if (ci == null) {
+            throw new WebApplicationException(404);
+        }
+        return ci.getMetadata();
+    }
+
+    @POST
+    @Consumes(WILDCARD + ";qs=0.5")
+    public Response createContentItem(byte[] data, @Context HttpHeaders 
headers)
+            throws URISyntaxException, EngineException {
+        String uri = makeContentItemUri(data).getUnicodeString();
+        return createEnhanceAndRedirect(data, headers.getMediaType(), uri);
+    }
+
+    @POST
+    @Consumes( { APPLICATION_FORM_URLENCODED + ";qs=1.0",
+            MULTIPART_FORM_DATA + ";qs=0.9" })
+    public Response createContentItemFromForm(
+            @FormParam("content") String content, @FormParam("url") String url,
+            @FormParam("file") File file,
+            @FormParam("file") FormDataContentDisposition disposition,
+            @Context HttpHeaders headers) throws URISyntaxException,
+            EngineException, MalformedURLException, IOException {
+        byte[] data = null; // TODO: rewrite me in a streamable way to avoid
+        // buffering all the content in memory
+        MediaType mt = null;
+        if (content != null && !content.trim().isEmpty()) {
+            data = content.getBytes();
+            mt = TEXT_PLAIN_TYPE;
+        } else if (url != null && !url.trim().isEmpty()) {
+            try {
+                URLConnection uc = (new URL(url)).openConnection();
+                data = IOUtils.toByteArray(uc.getInputStream());
+                mt = MediaType.valueOf(uc.getContentType());
+            } catch (IOException e) {
+                // TODO: collect remote resource error message for user 
friendly
+                // feedback
+            }
+        } else if (file != null) {
+            data = FileUtils.readFileToByteArray(file);
+            String lowerFilename = disposition.getFileName().toLowerCase();
+            // TODO: use a mimetype sniffer lib instead
+            if (lowerFilename.matches(".*\\.jpe?g")) {
+                mt = MediaType.valueOf("image/jpeg");
+            } else {
+                mt = APPLICATION_OCTET_STREAM_TYPE;
+            }
+        }
+        if (data != null && mt != null) {
+            String uri = makeContentItemUri(data).getUnicodeString();
+            return createEnhanceAndRedirect(data, mt, uri, true);
+        } else {
+            // TODO: add user-friendly feedback on empty requests from a form
+            return Response.seeOther(new URI("/store")).build();
+        }
+    }
+
+    @PUT
+    @Path("/content/{localId}")
+    @Consumes(WILDCARD)
+    public Response createContentItemWithId(
+            @PathParam(value = "localId") String localId, byte[] data,
+            @Context HttpHeaders headers) throws URISyntaxException,
+            EngineException {
+        String uri = makeContentItemUri(localId).getUnicodeString();
+        return createEnhanceAndRedirect(data, headers.getMediaType(), uri);
+    }
+
+    protected Response createEnhanceAndRedirect(byte[] data,
+            MediaType mediaType, String uri) throws EngineException,
+            URISyntaxException {
+        return createEnhanceAndRedirect(data, mediaType, uri, false);
+    }
+
+    protected Response createEnhanceAndRedirect(byte[] data,
+            MediaType mediaType, String uri, boolean useExplicitRedirect)
+            throws EngineException, URISyntaxException {
+        ContentItem ci = store.create(uri, data, mediaType.toString());
+        jobManager.enhanceContent(ci);
+        store.put(ci);
+        if (useExplicitRedirect) {
+            // use an redirect to point browsers to newly created content
+            return Response.seeOther(new URI(uri)).build();
+        } else {
+            // use the correct way of notifying the RESTful client that the
+            // resource has been successfully created
+            return Response.created(new URI(uri)).build();
+        }
+    }
+
+    // TODO: implement GET handler for dereferencable Enhancement URIs using
+    // SPARQL DESCRIBE query
+}

Added: 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/contenthubDescription.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/contenthubDescription.ftl?rev=1090200&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/contenthubDescription.ftl
 (added)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/imports/contenthubDescription.ftl
 Fri Apr  8 11:07:07 2011
@@ -0,0 +1,4 @@
+This is a <strong>stateful interface</strong> to submit content to <strong>
+analyze and store the results</strong> on the server. It is then possible
+to browse the resulting enhanced content items. The longer-term goal of this
+endpoint is to implement faceted semantic search of the enhanced content items.
\ No newline at end of file

Added: 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/index.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/index.ftl?rev=1090200&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/index.ftl
 (added)
+++ 
incubator/stanbol/trunk/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/ContentHubRootResource/index.ftl
 Fri Apr  8 11:07:07 2011
@@ -0,0 +1,155 @@
+<#import "/imports/common.ftl" as common>
+<#escape x as x?html>
+<@common.page title="Content Hub" hasrestapi=true> 
+
+<div class="panel" id="webview">
+
+<em><strong>Disclaimer</strong>: this endpoint is a proof of concept /
+<strong>experimental</strong> feature. It does not actually store the content
+on the disk, just in memory.</em>
+
+<h3>Recently uploaded Content Items</h3>
+
+<div class="storeContents">
+<table>
+  <tr>
+    <th>Local ID</th>
+    <th>Media type</th>
+    <th>Enhancements <img src="${it.staticRootUrl}/images/rdf.png"
+       alt="Format: RDF"/></th>
+  </tr>
+  <#list it.recentlyEnhancedItems as item>
+  <tr>
+    <td><a href="${item.uri}" title="${item.uri}">${item.localId}</a></td>
+    <td>${item.mimetype}</td>
+    <td><a 
href="${it.rootUrl}/contenthub/metadata/${item.localId}">${item.enhancements}</a></td>
+  </tr>
+  </#list>
+</ul>
+</table>
+<ul class="previousNext">
+  <#if it.moreRecentItemsUri?exists>
+    <li class="moreRecent"><a href="${it.moreRecentItemsUri}">More recent 
items</a></li>
+  </#if>
+  <#if it.olderItemsUri?exists>
+    <li class="older"><a href="${it.olderItemsUri}">Older items</a></li>
+  </#if>
+</ul>
+</div>
+
+
+<h3>Submit a new Content Item for analysis</h3>
+
+<form method="POST" accept-charset="utf-8">
+  <fieldset>
+  <legend>Submit raw text content</legend>
+  <p><textarea rows="15" name="content"></textarea></p>
+  <p><input type="submit" value="Submit text"></p>
+  </fieldset>
+</form>
+
+<form method="POST" accept-charset="utf-8">
+  <fieldset>
+  <legend>Submit a remote public resource by URL</legend>
+  <p><input name="url" type="text" class="url" />
+     <input type="submit" value="Submit URL"></p>
+  </fieldset>
+</form>
+
+<form method="POST" accept-charset="utf-8"  enctype="multipart/form-data">
+  <fieldset>
+  <legend>Upload a local file</legend>
+  <p><input name="file" type="file"/>
+     <input type="submit" value="Submit file"></p>
+  </fieldset>
+</form>
+
+
+</div>
+
+<div class="panel" id="restapi" style="display: none;">
+<h3>Uploading new content to the Content Hub</h3>
+
+  <p>You can upload content to the Content Hub for analysis with or without 
providing the content
+   id at your option:<p>
+  <ol>
+    <li><code>PUT</code> content to 
<code>${it.publicBaseUri}contenthub/content/<strong>content-id</strong></code>
+     with <code>Content-Type: text/plain</code>.</li>
+    <li><code>GET</code> enhancements from the same URL with
+     header <code>Accept: application/rdf+xml</code>.</li>
+  </ol>
+  
+  <p><code><strong>content-id</strong></code> can be any valid path and
+   will be used to fetch your item back later.</p>
+
+  <p>On a unix-ish box you can use run the following command from
+   the top-level source directory to populate the Stanbol enhancer service with
+    sample content items:</p>
+
+<pre>
+for file in data/text-examples/*.txt;
+do
+  curl -i -X PUT -H "Content-Type:text/plain" -T $file 
${it.publicBaseUri}contenthub/content/$(basename $file) ;
+done
+</pre> 
+
+  Alternatively you can let the Stanbol enhancer automatically build an id 
base on the SHA1
+  hash of the content by posting it at the root of the Content Hub.
+  <ol>
+    <li><code>POST</code> content to 
<code>${it.publicBaseUri}contenthub/</code>
+     with <code>Content-Type: text/plain</code>.</li>
+    <li><code>GET</code> enhancements from the URL in the response along with
+       header <code>Accept: application/rdf+xml</code>.</li>
+  </ol>
+  
+  <p>For instance:</p>
+<pre>
+curl -i -X POST -H "Content-Type:text/plain" \
+     --data "The Stanbol enhancer can detect famous cities such as Paris." \
+     ${it.publicBaseUri}contenthub
+    
+HTTP/1.1 201 Created
+Location: 
${it.publicBaseUri}contenthub/content/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+Content-Length: 0
+Server: Jetty(6.1.x)
+</pre>
+
+
+<h3>Fetching back the original content item and the related enhancements from 
the Content Hub</h3>
+
+<p>Once the content is created in the Content Hub, you can fetch back either 
the original content, a HTML summary view or
+the extracted RDF metadata by dereferencing the URL using the 
<code>Accept</code> header
+as selection switch:<p>
+
+<pre>
+curl -i <strong>-H "Accept: text/plain"</strong> 
${it.publicBaseUri}contenthub/content/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+
+HTTP/1.1 307 TEMPORARY_REDIRECT
+Location: 
${it.publicBaseUri}contenthub/<strong>raw</strong>/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+Content-Length: 0
+Server: Jetty(6.1.x)
+</pre>
+
+<pre>
+curl -i <strong>-H "Accept: text/html"</strong> 
${it.publicBaseUri}contenthub/content/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+
+HTTP/1.1 307 TEMPORARY_REDIRECT
+Location: 
${it.publicBaseUri}contenthub/<strong>page</strong>/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+Content-Length: 0
+Server: Jetty(6.1.x)
+</pre>
+
+<pre>
+curl -i <strong>-H "Accept: application/rdf+xml"</strong> 
${it.publicBaseUri}contenthub/content/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+
+HTTP/1.1 307 TEMPORARY_REDIRECT
+Location: 
${it.publicBaseUri}contenthub/<strong>metadata</strong>/sha1-84854eb6802a601ca2349ba28cc55f0b930ac96d
+Content-Length: 0
+Server: Jetty(6.1.x)
+</pre>
+
+</div>
+
+
+</@common.page>
+</#escape>


Reply via email to