]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/src/org/simantics/district/maps/server/Activator.java
Some cleaning and fixing of district functionalities
[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     private static Activator defaultt;
19
20     static BundleContext getContext() {
21         return context;
22     }
23
24     /*
25      * (non-Javadoc)
26      * 
27      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
28      * BundleContext)
29      */
30     public void start(BundleContext bundleContext) throws Exception {
31         Activator.context = bundleContext;
32         Activator.defaultt = this;
33     }
34
35     /*
36      * (non-Javadoc)
37      * 
38      * @see
39      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
40      */
41     public void stop(BundleContext bundleContext) throws Exception {
42         Activator.context = null;
43         Activator.defaultt = null;
44     }
45
46     public static Path getNodeJSRoot() throws IOException, URISyntaxException {
47         return resolvePath("/node");
48     }
49     
50     public static Path getTileserverMapnikRoot() throws IOException, URISyntaxException {
51         return resolvePath("/server");
52     }
53     
54     private static Path resolvePath(String entry) throws IOException, URISyntaxException {
55         URL entryURL = getContext().getBundle().getEntry(entry);
56         URL entryFileURL = FileLocator.toFileURL(entryURL);
57         URI encodedUri = new URI(entryFileURL.getProtocol(), entryFileURL.getPath(), null).normalize();
58         return Paths.get(encodedUri);
59     }
60
61     public static Activator getDefault() {
62         return defaultt;
63     }
64
65 }