Document issue with OSGi base URIs
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / KernelUtils.java
index 6e47873b35557f772ac7d702433652bdb342a3fa..b35b4be09311b8392531f1fe2e6ae306bc88adf9 100644 (file)
@@ -65,6 +65,13 @@ class KernelUtils implements KernelConstants {
                return Paths.get(uri);
        }
 
+       public static Path getOsgiConfigurationPath(String relativePath) {
+               URI uri = getOsgiConfigurationUri(relativePath);
+               if (uri == null) // no data area available
+                       return null;
+               return Paths.get(uri);
+       }
+
        public static URI getOsgiInstanceUri(String relativePath) {
                String osgiInstanceBaseUri = getFrameworkProp(OSGI_INSTANCE_AREA);
                if (osgiInstanceBaseUri == null) // no data area available
@@ -75,6 +82,16 @@ class KernelUtils implements KernelConstants {
                return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : ""));
        }
 
+       public static URI getOsgiConfigurationUri(String relativePath) {
+               String osgiInstanceBaseUri = getFrameworkProp(OSGI_CONFIGURATION_AREA);
+               if (osgiInstanceBaseUri == null) // no data area available
+                       return null;
+
+               if (!osgiInstanceBaseUri.endsWith("/"))
+                       osgiInstanceBaseUri = osgiInstanceBaseUri + "/";
+               return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : ""));
+       }
+
        static String getFrameworkProp(String key, String def) {
                String value;
                if (CmsActivator.getBundleContext() != null)
@@ -121,6 +138,7 @@ class KernelUtils implements KernelConstants {
                if (uri == null)
                        throw new IllegalArgumentException("URI cannot be null");
                try {
+                       // FIXME does not work if URI contains illegal characters (such as spaces, etc.)
                        return new URI(uri);
                } catch (URISyntaxException e) {
                        throw new IllegalArgumentException("Badly formatted URI " + uri, e);