]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/src/org/simantics/district/maps/server/Activator.java
Enhancements to district functionalities and code
[simantics/district.git] / org.simantics.maps.server / src / org / simantics / district / maps / server / Activator.java
1 package org.simantics.district.maps.server;
2
3 import java.io.IOException;
4 import java.net.URI;
5 import java.net.URISyntaxException;
6 import java.net.URL;
7 import java.nio.file.Path;
8 import java.nio.file.Paths;
9
10 import org.eclipse.core.runtime.FileLocator;
11 import org.osgi.framework.BundleActivator;
12 import org.osgi.framework.BundleContext;
13
14 public class Activator implements BundleActivator {
15
16     public static final String PLUGIN_ID = "org.simantics.maps.server";
17     private static BundleContext context;
18
19     static BundleContext getContext() {
20         return context;
21     }
22
23     /*
24      * (non-Javadoc)
25      * 
26      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
27      * BundleContext)
28      */
29     public void start(BundleContext bundleContext) throws Exception {
30         Activator.context = bundleContext;
31     }
32
33     /*
34      * (non-Javadoc)
35      * 
36      * @see
37      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
38      */
39     public void stop(BundleContext bundleContext) throws Exception {
40         Activator.context = null;
41     }
42
43     public static Path getNodeJSRoot() throws IOException, URISyntaxException {
44         return resolvePath("/node");
45     }
46     
47     public static Path getTileserverMapnikRoot() throws IOException, URISyntaxException {
48         return resolvePath("/server");
49     }
50     
51     private static Path resolvePath(String entry) throws IOException, URISyntaxException {
52         URL entryURL = getContext().getBundle().getEntry(entry);
53         URL entryFileURL = FileLocator.toFileURL(entryURL);
54         URI encodedUri = new URI(entryFileURL.getProtocol(), entryFileURL.getPath(), null).normalize();
55         return Paths.get(encodedUri);
56     }
57
58 }