Index: pom.xml
===================================================================
--- pom.xml	(revision 0)
+++ pom.xml	(revision 1)
@@ -8,4 +8,5 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<neo4j-version>1.7.1</neo4j-version>
+		<restlet-version>2.0.14</restlet-version>
 	</properties>
 	<repositories>
@@ -21,4 +22,9 @@
 			</snapshots>
 		</repository>
+        <repository>
+            <id>maven-restlet</id>
+            <name>Public online Restlet repository</name>
+            <url>http://maven.restlet.org</url>
+        </repository>
 	</repositories>
 	<dependencies>
@@ -39,4 +45,38 @@
 			<version>${neo4j-version}</version>
 		</dependency>
+		<dependency>
+			<groupId>org.restlet.jee</groupId>
+			<artifactId>org.restlet</artifactId>
+			<version>${restlet-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.restlet.jee</groupId>
+			<artifactId>org.restlet.ext.servlet</artifactId>
+			<version>${restlet-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.restlet.jee</groupId>
+			<artifactId>org.restlet.ext.json</artifactId>
+			<version>${restlet-version}</version>
+		</dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+        </dependency>
 	</dependencies>
+	<build>
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.apache.maven.plugins</groupId>
+					<artifactId>maven-compiler-plugin</artifactId>
+					<configuration>
+						<source>1.6</source>
+						<target>1.6</target>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
 </project>
Index: src/main/java/de/mpiwg/itgroup/annotations/AnnotationServerDb.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/AnnotationServerDb.java	(revision 1)
+++ src/main/java/de/mpiwg/itgroup/annotations/AnnotationServerDb.java	(revision 1)
@@ -0,0 +1,67 @@
+package de.mpiwg.itgroup.annotations;
+
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.factory.GraphDatabaseFactory;
+import org.neo4j.kernel.AbstractGraphDatabase;
+import org.neo4j.server.WrappingNeoServerBootstrapper;
+
+public class AnnotationServerDb {
+
+    private static String DB_PATH = "target/neo4j-annotation-db";
+    private static GraphDatabaseService graphDb;
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        AnnotationServerDb db = new AnnotationServerDb();
+        db.createDb();
+        // do something
+        AbstractGraphDatabase graphdb = (AbstractGraphDatabase) graphDb;
+        WrappingNeoServerBootstrapper srv;
+        srv = new WrappingNeoServerBootstrapper( graphdb );
+        System.out.println("Starting server...");
+        srv.start();
+        // The server is now running
+        try {
+            Thread.sleep(300*1000);
+        } catch (InterruptedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        // until we stop it:
+        System.out.println("Stopping server...");
+        srv.stop();        
+        db.shutDown();
+    }
+
+    /**
+     * 
+     */
+    public void createDb() {
+        System.out.println();
+        System.out.println("Starting database "+DB_PATH+" ...");
+        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
+        registerShutdownHook(graphDb);
+    }
+
+    public void shutDown() {
+        System.out.println();
+        System.out.println("Shutting down database ...");
+        // START SNIPPET: shutdownServer
+        graphDb.shutdown();
+        // END SNIPPET: shutdownServer
+    }
+
+    private static void registerShutdownHook(final GraphDatabaseService graphDb) {
+        // Registers a shutdown hook for the Neo4j instance so that it
+        // shuts down nicely when the VM exits (even if you "Ctrl-C" the
+        // running example before it's completed)
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                graphDb.shutdown();
+            }
+        });
+    }
+}
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorInfo.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorInfo.java	(revision 1)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorInfo.java	(revision 1)
@@ -0,0 +1,52 @@
+package de.mpiwg.itgroup.annotations.restlet;
+
+import java.io.InputStream;
+
+import org.apache.log4j.Logger;
+import org.restlet.data.Form;
+import org.restlet.data.MediaType;
+import org.restlet.representation.InputRepresentation;
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+import org.restlet.resource.Options;
+import org.restlet.resource.ServerResource;
+
+
+
+
+
+public class AnnotatorInfo extends ServerResource {
+
+private Logger logger = Logger.getRootLogger();
+	
+	/**
+	 * Erlaubt cross scripting bei Aufruf aus Javascript
+	 * @param entity
+	 */
+	@Options
+	public void doOptions(Representation entity) {
+	    Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");
+	    if (responseHeaders == null) {
+	        responseHeaders = new Form();
+	        getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
+	    }
+	    responseHeaders.add("Access-Control-Allow-Origin", "*");
+	    responseHeaders.add("Access-Control-Allow-Methods", "POST,OPTIONS,GET");
+	    responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
+	    responseHeaders.add("Access-Control-Allow-Credentials", "false");
+	    responseHeaders.add("Access-Control-Max-Age", "60");
+	}
+
+
+	
+	@Get("html")
+	public Representation getHTML(){
+		InputStream is = getClass().getResourceAsStream("/de/mpiwg/itgroup/annotationManager/staticPages/main.html");
+		
+		Representation rep = new InputRepresentation(is,MediaType.TEXT_HTML);
+		return rep;
+		
+	}
+	
+}
+
Index: src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java
===================================================================
--- src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java	(revision 1)
+++ src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java	(revision 1)
@@ -0,0 +1,189 @@
+package de.mpiwg.itgroup.annotations.restlet;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.servlet.ServletContext;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.restlet.Application;
+import org.restlet.Context;
+import org.restlet.Restlet;
+import org.restlet.routing.Router;
+import org.restlet.security.ChallengeAuthenticator;
+
+import scala.sys.process.ProcessBuilderImpl.Dummy;
+
+public class RestServer extends Application {
+
+    public static Logger logger = Logger.getRootLogger();
+    
+    private ChallengeAuthenticator authenticator;
+
+    /**
+     * Properties holding consumer keys and secrets
+     */
+    private Properties consumerKeys;
+    public final String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property";
+
+    /**
+     * constructor
+     * 
+     * @param parentContext
+     */
+    public RestServer(Context parentContext) {
+        super(parentContext);
+
+        Logger rl = Logger.getRootLogger();
+        BasicConfigurator.configure();
+        // read consumerKeys from webapp
+        consumerKeys = new Properties();
+        ServletContext sc = (ServletContext) getContext().getServerDispatcher()
+                .getContext().getAttributes()
+                .get("org.restlet.ext.servlet.ServletContext");
+        if (sc != null) {
+            InputStream ps = sc.getResourceAsStream(CONSUMER_KEYS_PATH);
+            if (ps == null) {
+                // try as file
+                File pf = new File(sc.getRealPath(CONSUMER_KEYS_PATH));
+                if (pf != null) {
+                    rl.debug("trying file for consumer keys: "+pf);
+                    try {
+                        ps = new FileInputStream(pf);
+                    } catch (FileNotFoundException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+            }
+            if (ps != null) {
+                rl.debug("loading consumer keys from "+CONSUMER_KEYS_PATH);
+                try {
+                    consumerKeys.load(ps);
+                } catch (IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                rl.debug("consumer keys: "+consumerKeys);
+            } else {
+                rl.error("Unable to get resource "+CONSUMER_KEYS_PATH);
+            }
+        } else {
+            rl.error("Unable to get ServletContext!");
+        }
+        
+    }
+    
+    /**
+     * returns consumer secret for consumer key.
+     * returns null if consumer key doesn't exist.
+     * @param consumerKey
+     * @return
+     */
+    public String getConsumerSecret(String consumerKey) {
+        return consumerKeys.getProperty(consumerKey);
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.restlet.Application#createInboundRoot()
+     */
+    @Override
+    public Restlet createInboundRoot() {
+        //this.authenticator = createAuthenticator();
+
+        // String target = "{rh}/{rf}/XX";
+        // Redirector redirector = new
+        // Redirector(getContext().createChildContext(), target,
+        // Redirector.MODE_CLIENT_SEE_OTHER);
+
+        Router router = new Router(getContext());
+        /*
+        router.attach("/annotator/annotations", AnnotatorAnnotations.class);
+        router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class);
+        router.attach("/annotator/search", AnnotatorSearch.class);
+        
+        // router.attach("",redirector);
+        router.attach("/annotator", ExtendedAnnotationInput.class);
+        */
+        router.attach("/", AnnotatorInfo.class);
+        //authenticator.setNext(router);
+        //return authenticator;
+        
+        return router;
+    }
+
+    /**
+     * Hole den vollen Benutzernamen aus dem LDAP
+     * 
+     * @param creator
+     * @return
+     */
+    public String getUserNameFromLdap(String creator) {
+        String retString = creator; // falls nichts gefunden wird einfach den
+                                    // creator zurueckgeben
+        Hashtable<String, String> env = new Hashtable<String, String>();
+        String sp = "com.sun.jndi.ldap.LdapCtxFactory";
+        env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
+
+        String ldapUrl = "ldap://ldapreplik.mpiwg-berlin.mpg.de/dc=mpiwg-berlin,dc=mpg,dc=de"; // TODO should go into config file
+        env.put(javax.naming.Context.PROVIDER_URL, ldapUrl);
+
+        DirContext dctx;
+        try {
+            dctx = new InitialDirContext(env);
+        } catch (NamingException e1) {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+            return retString;
+        }
+
+        String base = "ou=People";
+
+        SearchControls sc = new SearchControls();
+        String[] attributeFilter = { "cn", "mail" };
+        sc.setReturningAttributes(attributeFilter);
+        sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+        String filter = "(uid=" + creator + ")";
+
+        try {
+            NamingEnumeration<SearchResult> results = dctx.search(base, filter,
+                    sc);
+            while (results.hasMore()) {
+                SearchResult sr = (SearchResult) results.next();
+                javax.naming.directory.Attributes attrs = sr.getAttributes();
+
+                Attribute attr = attrs.get("cn");
+                retString = (String) attr.get();
+            }
+        } catch (NamingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+            dctx.close();
+        } catch (NamingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return retString;
+    }
+
+}
Index: src/main/resources/annotator-info.html
===================================================================
--- src/main/resources/annotator-info.html	(revision 1)
+++ src/main/resources/annotator-info.html	(revision 1)
@@ -0,0 +1,6 @@
+<html>
+<body>
+<h2>Annotation manager</h2>
+<p><a href="annotations">Annotations overview</a></p>
+</body>
+</html>
Index: src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- src/main/webapp/META-INF/MANIFEST.MF	(revision 1)
+++ src/main/webapp/META-INF/MANIFEST.MF	(revision 1)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+
Index: src/main/webapp/WEB-INF/consumerkeys.property.template
===================================================================
--- src/main/webapp/WEB-INF/consumerkeys.property.template	(revision 1)
+++ src/main/webapp/WEB-INF/consumerkeys.property.template	(revision 1)
@@ -0,0 +1,2 @@
+# consumer keys and secrets for annotation server clients
+# format: consumerKey = consumerSecret
Index: src/main/webapp/WEB-INF/etc.jaasAuth.conf
===================================================================
--- src/main/webapp/WEB-INF/etc.jaasAuth.conf	(revision 1)
+++ src/main/webapp/WEB-INF/etc.jaasAuth.conf	(revision 1)
@@ -0,0 +1,10 @@
+BasicJaasAuthenticationApplication {
+    com.sun.security.auth.module.LdapLoginModule REQUIRED
+    userProvider="ldap://ldap.mpiwg-berlin.mpg.de/ou=people,dc=mpiwg-berlin,dc=mpg,dc=de"
+    userFilter="(&(uid={USERNAME})(objectClass=inetOrgPerson))"
+    debug=true
+    useSSL=false
+;
+};
+
+
Index: src/main/webapp/WEB-INF/web.xml
===================================================================
--- src/main/webapp/WEB-INF/web.xml	(revision 1)
+++ src/main/webapp/WEB-INF/web.xml	(revision 1)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="WebApp_ID" version="2.4"
+xmlns="http://java.sun.com/xml/ns/j2ee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+    <display-name>RESTfulJavaWebServices-Restlet</display-name>
+    <!-- Application classname -->
+    <context-param>
+        <param-name>org.restlet.application</param-name>
+        <param-value>de.mpiwg.itgroup.annotations.restlet.RestServer</param-value>
+    </context-param>
+    <!-- Restletadapter -->
+    <servlet>
+        <servlet-name>RestletServlet</servlet-name>
+        <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
+    </servlet>
+    <!-- Catchallrequests -->
+    <servlet-mapping>
+        <servlet-name>RestletServlet</servlet-name>
+        <!-- <url-pattern>/annotator/*</url-pattern> -->
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>
Index: src/main/webapp/WEB-INF/web.xml.template
===================================================================
--- src/main/webapp/WEB-INF/web.xml.template	(revision 1)
+++ src/main/webapp/WEB-INF/web.xml.template	(revision 1)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="WebApp_ID" version="2.4"
+xmlns="http://java.sun.com/xml/ns/j2ee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+    <display-name>RESTfulJavaWebServices-Restlet</display-name>
+    <!-- Application classname -->
+    <context-param>
+        <param-name>org.restlet.application</param-name>
+        <param-value>de.mpiwg.itgroup.annotationManager.restlet.RestServer</param-value>
+    </context-param>
+    <context-param>
+        <param-name>de.mpiwg.itgroup.annotationManager.jaas.configFilePath</param-name>
+        <param-value>file:///etc/jaasAuth.conf</param-value>
+    </context-param>
+    <context-param>
+        <param-name>de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser</param-name>
+        <param-value>USERNAME</param-value>
+    </context-param>
+    <context-param>
+        <param-name>de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword</param-name>
+        <param-value>PASSWORD</param-value>
+    </context-param>
+    <context-param>
+        <param-name>de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL</param-name>
+        <param-value>jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111</param-value>
+    </context-param>
+    <!-- Restletadapter -->
+    <servlet>
+        <servlet-name>RestletServlet</servlet-name>
+        <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
+    </servlet>
+    <!-- Catchallrequests -->
+    <servlet-mapping>
+        <servlet-name>RestletServlet</servlet-name>
+        <url-pattern>/annotator/*</url-pattern>
+    </servlet-mapping>
+</web-app>
