annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java @ 3:47b53ae385d1

merging old code
author casties
date Fri, 29 Jun 2012 20:38:27 +0200
parents 6556943c4fb9
children 3599b29c393f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
1 package de.mpiwg.itgroup.annotations.restlet;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
2
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
3 import java.io.File;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
4 import java.io.FileInputStream;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
5 import java.io.FileNotFoundException;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
6 import java.io.IOException;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
7 import java.io.InputStream;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
8 import java.util.Hashtable;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
9 import java.util.Properties;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
10
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
11 import javax.naming.NamingEnumeration;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
12 import javax.naming.NamingException;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
13 import javax.naming.directory.Attribute;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
14 import javax.naming.directory.DirContext;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
15 import javax.naming.directory.InitialDirContext;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
16 import javax.naming.directory.SearchControls;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
17 import javax.naming.directory.SearchResult;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
18 import javax.servlet.ServletContext;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
19
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
20 import org.apache.log4j.BasicConfigurator;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
21 import org.apache.log4j.Logger;
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
22 import org.neo4j.graphdb.GraphDatabaseService;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
23 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
24 import org.neo4j.kernel.AbstractGraphDatabase;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
25 import org.neo4j.server.WrappingNeoServerBootstrapper;
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
26 import org.restlet.Application;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
27 import org.restlet.Context;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
28 import org.restlet.Restlet;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
29 import org.restlet.routing.Router;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
30 import org.restlet.security.ChallengeAuthenticator;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
31
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
32 import scala.sys.process.ProcessBuilderImpl.Dummy;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
33
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
34 public class RestServer extends Application {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
35
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
36 public static Logger logger = Logger.getRootLogger();
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
37
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
38 private ChallengeAuthenticator authenticator;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
39
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
40 /**
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
41 * Properties holding consumer keys and secrets
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
42 */
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
43 private Properties consumerKeys;
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
44 public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property";
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
45
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
46 private GraphDatabaseService graphDb;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
47 public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
48 public String DB_PATH = "WEB-INF/neo4j-annotation-db";
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
49
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
50 /**
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
51 * constructor
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
52 *
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
53 * @param parentContext
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
54 */
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
55 public RestServer(Context parentContext) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
56 super(parentContext);
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
57 // TODO: is this the right place to run the log4j configurator?
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
58 BasicConfigurator.configure();
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
59
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
60 ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes()
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
61 .get("org.restlet.ext.servlet.ServletContext");
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
62 if (sc != null) {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
63 // look for database service in context
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
64 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
65 if (graphDb == null) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
66 /*
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
67 * open database
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
68 */
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
69 String dbFn = getResourcePath(sc, DB_PATH);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
70 if (dbFn != null) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
71 logger.debug("opening DB " + dbFn);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
72 graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbFn);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
73 // store in context
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
74 sc.setAttribute(GRAPHDB_KEY, graphDb);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
75 WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper((AbstractGraphDatabase) graphDb);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
76 logger.debug("Starting DB admin server...");
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
77 srv.start();
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
78 } else {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
79 logger.error("Unable to get resource " + DB_PATH);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
80 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
81 }
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
82 /*
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
83 * read consumerKeys from webapp
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
84 */
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
85 consumerKeys = new Properties();
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
86 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
87 if (ps != null) {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
88 logger.debug("loading consumer keys from " + CONSUMER_KEYS_PATH);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
89 try {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
90 consumerKeys.load(ps);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
91 } catch (IOException e) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
92 // TODO Auto-generated catch block
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
93 e.printStackTrace();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
94 }
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
95 logger.debug("consumer keys: " + consumerKeys);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
96 } else {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
97 logger.error("Unable to get resource " + CONSUMER_KEYS_PATH);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
98 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
99 } else {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
100 logger.error("Unable to get ServletContext!");
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
101 }
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
102
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
103 }
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
104
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
105 /**
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
106 * returns consumer secret for consumer key. returns null if consumer key
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
107 * doesn't exist.
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
108 *
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
109 * @param consumerKey
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
110 * @return
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
111 */
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
112 public String getConsumerSecret(String consumerKey) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
113 return consumerKeys.getProperty(consumerKey);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
114 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
115
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
116 /*
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
117 * (non-Javadoc)
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
118 *
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
119 * @see org.restlet.Application#createInboundRoot()
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
120 */
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
121 @Override
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
122 public Restlet createInboundRoot() {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
123 // this.authenticator = createAuthenticator();
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
124
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
125 Router router = new Router(getContext());
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
126
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
127 router.attach("/annotator/annotations", AnnotatorAnnotations.class);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
128 router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class);
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
129 // router.attach("/annotator/search", AnnotatorSearch.class);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
130
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
131 // router.attach("",redirector); router.attach("/annotator",
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
132 // ExtendedAnnotationInput.class);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
133
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
134 router.attach("/", AnnotatorInfo.class);
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
135 // authenticator.setNext(router);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
136 // return authenticator;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
137
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
138 return router;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
139 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
140
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
141 /**
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
142 * Hole den vollen Benutzernamen aus dem LDAP
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
143 *
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
144 * @param creator
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
145 * @return
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
146 */
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
147 public String getUserNameFromLdap(String creator) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
148 String retString = creator; // falls nichts gefunden wird einfach den
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
149 // creator zurueckgeben
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
150 Hashtable<String, String> env = new Hashtable<String, String>();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
151 String sp = "com.sun.jndi.ldap.LdapCtxFactory";
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
152 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
153
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
154 // TODO: should go into config file
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
155 String ldapUrl = "ldap://ldapreplik.mpiwg-berlin.mpg.de/dc=mpiwg-berlin,dc=mpg,dc=de";
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
156 env.put(javax.naming.Context.PROVIDER_URL, ldapUrl);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
157
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
158 DirContext dctx;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
159 try {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
160 dctx = new InitialDirContext(env);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
161 } catch (NamingException e1) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
162 // TODO Auto-generated catch block
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
163 e1.printStackTrace();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
164 return retString;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
165 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
166
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
167 String base = "ou=People";
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
168
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
169 SearchControls sc = new SearchControls();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
170 String[] attributeFilter = { "cn", "mail" };
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
171 sc.setReturningAttributes(attributeFilter);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
172 sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
173
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
174 String filter = "(uid=" + creator + ")";
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
175
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
176 try {
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
177 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc);
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
178 while (results.hasMore()) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
179 SearchResult sr = (SearchResult) results.next();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
180 javax.naming.directory.Attributes attrs = sr.getAttributes();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
181
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
182 Attribute attr = attrs.get("cn");
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
183 retString = (String) attr.get();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
184 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
185 } catch (NamingException e) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
186 // TODO Auto-generated catch block
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
187 e.printStackTrace();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
188 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
189
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
190 try {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
191 dctx.close();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
192 } catch (NamingException e) {
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
193 // TODO Auto-generated catch block
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
194 e.printStackTrace();
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
195 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
196 return retString;
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
197 }
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
198
3
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
199 /**
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
200 * returns resource from path (in webapp) as InputStream.
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
201 *
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
202 * @param sc
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
203 * @param path
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
204 * @return
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
205 */
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
206 protected InputStream getResourceAsStream(ServletContext sc, String path) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
207 InputStream ps = sc.getResourceAsStream(path);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
208 if (ps == null) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
209 // try as file
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
210 File pf = new File(sc.getRealPath(path));
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
211 if (pf != null) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
212 logger.debug("trying file for: " + pf);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
213 try {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
214 ps = new FileInputStream(pf);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
215 } catch (FileNotFoundException e) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
216 logger.error(e);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
217 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
218 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
219 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
220 return ps;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
221 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
222
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
223 /**
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
224 * get a real file name for a web app file pathname.
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
225 *
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
226 * If filename starts with "/" its treated as absolute else the path is
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
227 * appended to the base directory of the web-app.
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
228 *
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
229 * @param filename
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
230 * @param sc
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
231 * @return
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
232 */
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
233 public static String getResourcePath(ServletContext sc, String filename) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
234 File f = new File(filename);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
235 // is the filename absolute?
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
236 if (!f.isAbsolute()) {
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
237 // relative path -> use getRealPath to resolve in webapp
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
238 filename = sc.getRealPath(filename);
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
239 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
240 return filename;
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
241 }
47b53ae385d1 merging old code
casties
parents: 1
diff changeset
242
1
6556943c4fb9 include neo4j and restlet
casties
parents:
diff changeset
243 }