You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by re...@apache.org on 2013/02/21 18:37:39 UTC
svn commit: r1448739 - in /stanbol/trunk: ./ development/
development/archetypes/ development/archetypes/statefull-webmodule/
development/archetypes/statefull-webmodule/src/
development/archetypes/statefull-webmodule/src/main/
development/archetypes/st...
Author: reto
Date: Thu Feb 21 17:37:38 2013
New Revision: 1448739
URL: http://svn.apache.org/r1448739
Log:
STANBOL-919: created archetype for module that accesses SiteManager and stores some data (log) persistently.
Added:
stanbol/trunk/development/
stanbol/trunk/development/archetypes/
stanbol/trunk/development/archetypes/statefull-webmodule/ (with props)
stanbol/trunk/development/archetypes/statefull-webmodule/pom.xml
stanbol/trunk/development/archetypes/statefull-webmodule/src/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/archetype-metadata.xml
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/.gitignore
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/README.md
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/pom.xml
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ExampleMenuItem.java
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/Ontology.java
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ResourceResolver.java
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/ResourceResolver.ttl
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/resource-resolver.css
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/ResourceResolver.ftl
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/
stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/footer.ftl
Modified:
stanbol/trunk/pom.xml
Propchange: stanbol/trunk/development/archetypes/statefull-webmodule/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Feb 21 17:37:38 2013
@@ -0,0 +1 @@
+target
Added: stanbol/trunk/development/archetypes/statefull-webmodule/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/pom.xml?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/pom.xml (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/pom.xml Thu Feb 21 17:37:38 2013
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>4-SNAPSHOT</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>statefull-webmodule-archetype</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ <packaging>maven-archetype</packaging>
+
+ <name>Apache Stanbol Statefull Webmodule Archetype</name>
+ <!-- don't add line breaks to the description as archetype:generate only shows one line -->
+ <description>Archetype for a project that accesses the entityhub, and logs queries to a persisten graph</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <excludes>
+ <!--
+ The artifact files do not contain copyright notices
+ as the generated skeleton shall not contain any such
+ notice
+ -->
+ <exclude>src/main/resources/archetype-resources/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.2</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
+
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/archetype-metadata.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/archetype-metadata.xml?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/archetype-metadata.xml (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/META-INF/maven/archetype-metadata.xml Thu Feb 21 17:37:38 2013
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="example-project"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.ttl</include>
+ <include>**/*.css</include>
+ </includes>
+ </fileSet>
+ <fileSet packaged="true" encoding="UTF-8">
+ <directory>src/main/resources/templates/html</directory>
+ <includes>
+ <include>**/*.ftl</include>
+ </includes>
+ <excludes>
+ <exclude>includes/**</exclude>
+ </excludes>
+ </fileSet>
+ <fileSet encoding="UTF-8">
+ <directory>src/main/resources/templates/html/includes</directory>
+ <includes>
+ <include>**/*.ftl</include>
+ </includes>
+ </fileSet>
+ <fileSet encoding="UTF-8">
+ <directory></directory>
+ <includes>
+ <include>.gitignore</include>
+ <include>README.md</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/.gitignore
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/.gitignore?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/.gitignore (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/.gitignore Thu Feb 21 17:37:38 2013
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+*~
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/README.md
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/README.md?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/README.md (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/README.md Thu Feb 21 17:37:38 2013
@@ -0,0 +1,9 @@
+Example Apache Stanbol Component
+===========
+
+This is an example Apache Stanbol component.
+
+After installing a new menu item pointing you to /example-service will appear.
+
+The example service allows to look up resources using the site-manager. The
+service can be accessed via browser as HTML or as RDF for machine clients.
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/pom.xml?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/pom.xml (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/pom.xml Thu Feb 21 17:37:38 2013
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+
+ <packaging>bundle</packaging>
+
+ <name>Skeleton for ${artifactId}</name>
+ <description>Looks up entities on the Entityhub-Sites and Logs the queries</description>
+
+
+ <build>
+ <!-- make it an OSGi bundle -->
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ <version>1.9.0</version>
+ <executions>
+ <execution>
+ <id>generate-scr-scrdescriptor</id>
+ <goals>
+ <goal>scr</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <version>2.3.7</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.web.base</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.model.clerezza</artifactId>
+ <version>0.10.0-incubating</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.web.viewable</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.core</artifactId>
+ <version>0.11.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+ <version>0.11.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.ontologies</artifactId>
+ <version>0.11-incubating</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.utils</artifactId>
+ <version>0.13-incubating</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ExampleMenuItem.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ExampleMenuItem.java?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ExampleMenuItem.java (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ExampleMenuItem.java Thu Feb 21 17:37:38 2013
@@ -0,0 +1,18 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.web.base.NavigationLink;
+
+@Component
+@Service(NavigationLink.class)
+public class ExampleMenuItem extends NavigationLink {
+
+ public ExampleMenuItem() {
+ super("${artifactId}", "Example:${artifactId}", "An Example Service", 300);
+ }
+
+}
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/Ontology.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/Ontology.java?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/Ontology.java (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/Ontology.java Thu Feb 21 17:37:38 2013
@@ -0,0 +1,42 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+
+/**
+ * Ideally this should be a dereferenceable ontology on the web. Given such
+ * an ontology a class of constant (similar to this) can be generated with
+ * the org.apache.clerezza:maven-ontologies-plugin
+ */
+public class Ontology {
+ /**
+ * Resources of this type can be dereferenced and will return a description
+ * of the resource of which the IRI is specified in the "iri" query parameter.
+ *
+ */
+ public static final UriRef ResourceResolver = new UriRef("http://example.org/service-description${symbol_pound}ResourceResolver");
+
+ /**
+ * Point to the resource resolved by the subject.
+ */
+ public static final UriRef describes = new UriRef("http://example.org/service-description${symbol_pound}describes");
+
+ /**
+ * The description of a Request in the log.
+ */
+ public static final UriRef LoggedRequest = new UriRef("http://example.org/service-description${symbol_pound}LoggedRequest");
+
+ /**
+ * The User Agent performing the requested described by the subject.
+ */
+ public static final UriRef userAgent = new UriRef("http://example.org/service-description${symbol_pound}userAgent");
+
+ /**
+ * The Entity of which a description was requested in the request
+ * described by the subject.
+ */
+ public static final UriRef requestedEntity = new UriRef("http://example.org/service-description${symbol_pound}requestedEntity");
+}
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ResourceResolver.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ResourceResolver.java?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ResourceResolver.java (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/java/ResourceResolver.java Thu Feb 21 17:37:38 2013
@@ -0,0 +1,185 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+import java.util.Date;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.access.security.TcAccessController;
+import org.apache.clerezza.rdf.core.access.security.TcPermission;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.ontologies.DC;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.rdf.utils.UnionMGraph;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.commons.web.viewable.RdfViewable;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteManager;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses the SiteManager to resolve entities. Every requested is recorded to
+ * a graph. The client gets information and meta-information about the resource
+ * and sees all previous requests for that resource.
+ */
+@Component
+@Service(Object.class)
+@Property(name="javax.ws.rs", boolValue=true)
+@Path("${artifactId}")
+public class ResourceResolver {
+
+ /**
+ * Using slf4j for normal logging
+ */
+ private static final Logger log = LoggerFactory.getLogger(ResourceResolver.class);
+
+ /**
+ * This service allows to get entities from configures sites
+ */
+ @Reference
+ private SiteManager siteManager;
+
+ /**
+ * This service allows accessing and creating persistent triple collections
+ */
+ @Reference
+ private TcManager tcManager;
+
+ /**
+ * This is the name of the graph in which we "log" the requests
+ */
+ private UriRef REQUEST_LOG_GRAPH_NAME = new UriRef("http://example.org/resource-resolver-log.graph");
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ log.info("The example service is being activated");
+ try {
+ tcManager.createMGraph(REQUEST_LOG_GRAPH_NAME);
+ //now make sure everybody can read from the graph
+ //or more precisly, anybody who can read the content-graph
+ TcAccessController tca = new TcAccessController(tcManager);
+ tca.setRequiredReadPermissions(REQUEST_LOG_GRAPH_NAME,
+ Collections.singleton((Permission)new TcPermission(
+ "urn:x-localinstance:/content.graph", "read")));
+ } catch (EntityAlreadyExistsException ex) {
+ log.debug("The graph for the request log already exists");
+ }
+
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+ log.info("The example service is being activated");
+ }
+
+ /**
+ * This method return an RdfViewable, this is an RDF serviceUri with associated
+ * presentational information.
+ */
+ @GET
+ public RdfViewable serviceEntry(@Context final UriInfo uriInfo,
+ @QueryParam("iri") final UriRef iri,
+ @HeaderParam("user-agent") String userAgent) throws Exception {
+ final String resourcePath = uriInfo.getAbsolutePath().toString();
+ //The URI at which this service was accessed accessed, this will be the
+ //central serviceUri in the response
+ final UriRef serviceUri = new UriRef(resourcePath);
+ //the in memory graph to which the triples for the response are added
+ final MGraph responseGraph = new IndexedMGraph();
+ //A union graph containing both the response specif triples as well
+ //as the log-graph
+ final UnionMGraph resultGraph = new UnionMGraph(responseGraph, getRequestLogGraph());
+ //This GraphNode represents the service within our result graph
+ final GraphNode node = new GraphNode(serviceUri, resultGraph);
+ //The triples will be added to the first graph of the union
+ //i.e. to the in-memory responseGraph
+ node.addProperty(RDF.type, Ontology.ResourceResolver);
+ node.addProperty(RDFS.comment, new PlainLiteralImpl("A Resource Resolver"));
+ if (iri != null) {
+ node.addProperty(Ontology.describes, iri);
+ addResourceDescription(iri, responseGraph);
+ logRequest(iri, userAgent);
+ }
+ //What we return is the GraphNode we created with a template path
+ return new RdfViewable("ResourceResolver", node, ResourceResolver.class);
+ }
+
+
+ /**
+ * Add the description of a serviceUri to the specified MGraph using SiteManager.
+ * The description includes the metadata provided by the SiteManager.
+ *
+ */
+ private void addResourceDescription(UriRef iri, MGraph mGraph) {
+ final Entity entity = siteManager.getEntity(iri.getUnicodeString());
+ if (entity != null) {
+ final RdfValueFactory valueFactory = new RdfValueFactory(mGraph);
+ final Representation representation = entity.getRepresentation();
+ if (representation != null) {
+ valueFactory.toRdfRepresentation(representation);
+ }
+ final Representation metadata = entity.getMetadata();
+ if (metadata != null) {
+ valueFactory.toRdfRepresentation(metadata);
+ }
+ }
+ }
+
+ /**
+ * Logs a request to the log-graph
+ */
+ private void logRequest(final UriRef iri, final String userAgent) {
+ //writing to a persistent graph requires some special permission
+ //by executing the code in a do-priviledged section
+ //the user doesn't need this permissions, anonymous users are thus not
+ //asked to log in
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ final MGraph logGraph = getRequestLogGraph();
+ GraphNode loggedRequest = new GraphNode(new BNode(), logGraph);
+ loggedRequest.addProperty(RDF.type, Ontology.LoggedRequest);
+ loggedRequest.addPropertyValue(DC.date, new Date());
+ loggedRequest.addPropertyValue(Ontology.userAgent, userAgent);
+ loggedRequest.addProperty(Ontology.requestedEntity, iri);
+ return null;
+ }
+ });
+
+ }
+
+ /**
+ * This returns the existing MGraph for the log .
+ *
+ * @return the MGraph to which the requests are logged
+ */
+ private MGraph getRequestLogGraph() {
+ return tcManager.getMGraph(REQUEST_LOG_GRAPH_NAME);
+ }
+
+}
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/ResourceResolver.ttl
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/ResourceResolver.ttl?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/ResourceResolver.ttl (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/graphs/recipes/ResourceResolver.ttl Thu Feb 21 17:37:38 2013
@@ -0,0 +1,12 @@
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix recipe: <http://vocab.netlabs.org/recipe#> .
+
+[] a recipe:Recipe;
+ rdfs:label "Stanbol RdvViewable sample";
+ recipe:ingredient
+ [a recipe:Ingredient;
+ recipe:ingredientInverseProperty <http://stanbol.apache.org/ontology/entityhub/entityhub#about>],
+ [a recipe:Ingredient;
+ recipe:ingredientProperty <http://example.org/service-description#describes>];
+ recipe:recipeDomain "${package.replace(".","/")}/ResourceResolver" .
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/resource-resolver.css
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/resource-resolver.css?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/resource-resolver.css (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/example-service/styles/resource-resolver.css Thu Feb 21 17:37:38 2013
@@ -0,0 +1,3 @@
+h1 {
+ color: green
+}
\ No newline at end of file
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/ResourceResolver.ftl
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/ResourceResolver.ftl?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/ResourceResolver.ftl (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/ResourceResolver.ftl Thu Feb 21 17:37:38 2013
@@ -0,0 +1,65 @@
+<@namespace ont="http://example.org/service-description#" />
+<@namespace ehub="http://stanbol.apache.org/ontology/entityhub/entityhub#" />
+<@namespace cc="http://creativecommons.org/ns#" />
+<@namespace dct="http://purl.org/dc/terms/" />
+
+<html>
+ <head>
+ <title>Example Application - Apache Stanbol</title>
+ <link type="text/css" rel="stylesheet" href="example-service/styles/resource-resolver.css" />
+ </head>
+
+ <body>
+ <h1>Resolve resource</h1>
+
+ <form action="<@ldpath path="."/>">
+ IRI of entity to look up (e.g. http://dbpedia.org/resource/Paris) <br/>
+ <label for="iri" /><input type="text" name="iri"
+ value="<@ldpath path="ont:describes"/>" size="90"/><br/>
+ WARNING: all requests are logged, information about your request will
+ be shown to any user requesting the same resource<br/>
+ <input type="submit" value="look up" />
+ </form>
+
+ <@ldpath path="ont:describes">
+ <p>
+ Note: you can also get an rdf representation of this description
+ by setting a respective Accept header, e.g.<br/>
+ <code>curl -H "Accept: text/turtle" <@ldpath path="^ont:describes"/>?iri=<@ldpath path="."/></code>
+ <#if evalLDPath("rdfs:label")??>
+ <h2>Resource Description</h2>
+ <h3>Labels:</h3>
+ <ul>
+ <@ldpath path="rdfs:label"><li><@ldpath path="."/></l...@ldpath>
+ </ul>
+ <h3>Comment</h3>
+ <div><@ldpath path="rdfs:comment"/></div>
+ <@ldpath path="^ehub:about">
+ <h2>Resource Metadata</h2>
+ <div>
+ Is cached locally: <@ldpath path="ehub:isChached"/>
+ </div>
+ <div>
+ License: <@ldpath path="dct:license"/>
+ </div>
+ <div>
+ Attribution URL: <a href="<@ldpath path="cc:attributionURL"/>" >
+ <@ldpath path="cc:attributionURL"/></a>
+ </div>
+ </...@ldpath>
+ </#if>
+ <h2>Logged Requests for this Entity</h2>
+ <ol>
+ <@ldpath path="^ont:requestedEntity">
+ <li class="LoggedRequest">
+ Date: <@ldpath path="dc:date"/><br/>
+ Agent: <@ldpath path="ont:userAgent"/><br/>
+ </li>
+ </...@ldpath>
+ </ol>
+ </p>
+ </...@ldpath>
+ <#include "/html/includes/footer.ftl">
+ </body>
+</html>
+
Added: stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/footer.ftl
URL: http://svn.apache.org/viewvc/stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/footer.ftl?rev=1448739&view=auto
==============================================================================
--- stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/footer.ftl (added)
+++ stanbol/trunk/development/archetypes/statefull-webmodule/src/main/resources/archetype-resources/src/main/resources/templates/html/includes/footer.ftl Thu Feb 21 17:37:38 2013
@@ -0,0 +1 @@
+<div>Thank you for trying out this example application.</div>
\ No newline at end of file
Modified: stanbol/trunk/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/pom.xml?rev=1448739&r1=1448738&r2=1448739&view=diff
==============================================================================
--- stanbol/trunk/pom.xml (original)
+++ stanbol/trunk/pom.xml Thu Feb 21 17:37:38 2013
@@ -85,6 +85,8 @@
<module>launchers/stable</module>
<module>launchers/full-war</module>
+
+ <module>development/archetypes/statefull-webmodule</module>
</modules>
<profiles>