incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1076290 - /sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java
Date Wed, 02 Mar 2011 16:51:14 GMT
Author: fmeschbe
Date: Wed Mar  2 16:51:14 2011
New Revision: 1076290

URL: http://svn.apache.org/viewvc?rev=1076290&view=rev
Log:
SLING-2013 Support relative home property. To be resolved against sling.home if present or
against current user directory if sling.home is not set. Also support default assumption (repository.xml
is configuration inside home directory) if config property is missing or empty.

Modified:
    sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java

Modified: sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java?rev=1076290&r1=1076289&r2=1076290&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepository.java
Wed Mar  2 16:51:14 2011
@@ -38,6 +38,7 @@ import org.apache.sling.jcr.base.Abstrac
 import org.apache.sling.jcr.jackrabbit.server.impl.security.AdministrativeCredentials;
 import org.apache.sling.jcr.jackrabbit.server.impl.security.AnonCredentials;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 
 /**
@@ -98,6 +99,19 @@ public class SlingServerRepository exten
         String configURLObj = (String) environment.get(REPOSITORY_CONFIG_URL);
         String home = (String) environment.get(REPOSITORY_HOME_DIR);
 
+        // ensure absolute home (path)
+        File homeFile = new File(home);
+        if (!homeFile.isAbsolute()) {
+            BundleContext context = getComponentContext().getBundleContext();
+            String slingHomePath = context.getProperty("sling.home");
+            if (slingHomePath != null) {
+                homeFile = new File(slingHomePath, home);
+            } else {
+                homeFile = homeFile.getAbsoluteFile();
+            }
+            home = homeFile.getAbsolutePath();
+        }
+
         // somewhat dirty hack to have the derby.log file in a sensible
         // location, but don't overwrite anything already set
         if (System.getProperty("derby.stream.error.file") == null) {
@@ -108,36 +122,41 @@ public class SlingServerRepository exten
         InputStream ins = null;
         try {
 
-            // check whether the URL is a file path
-            File configFile = new File(configURLObj);
-            if (configFile.canRead()) {
+            RepositoryConfig crc;
+            if (configURLObj != null && configURLObj.length() > 0) {
+                // check whether the URL is a file path
+                File configFile = new File(configURLObj);
+                if (configFile.canRead()) {
 
-                ins = new FileInputStream(configFile);
-                log(LogService.LOG_INFO, "Using configuration file " + configFile.getAbsolutePath());
+                    ins = new FileInputStream(configFile);
+                    log(LogService.LOG_INFO, "Using configuration file " + configFile.getAbsolutePath());
 
-            } else {
+                } else {
 
-                try {
+                    try {
 
-                    URL configURL = new URL(configURLObj);
-                    ins = configURL.openStream();
-                    log(LogService.LOG_INFO, "Using configuration URL " + configURL);
-
-                } catch (MalformedURLException mue) {
-
-                    log(LogService.LOG_INFO, "Configuration File "
-                        + configFile.getAbsolutePath()
-                        + " has been lost, trying to recreate");
+                        URL configURL = new URL(configURLObj);
+                        ins = configURL.openStream();
+                        log(LogService.LOG_INFO, "Using configuration URL " + configURL);
 
-                    final Bundle bundle = getComponentContext().getBundleContext().getBundle();
-                    SlingServerRepository.copyFile(bundle, "repository.xml", configFile);
+                    } catch (MalformedURLException mue) {
 
-                    ins = new FileInputStream(configFile);
-                    log(LogService.LOG_INFO, "Using configuration file " + configFile.getAbsolutePath());
+                        log(LogService.LOG_INFO, "Configuration File "
+                            + configFile.getAbsolutePath()
+                            + " has been lost, trying to recreate");
+
+                        final Bundle bundle = getComponentContext().getBundleContext().getBundle();
+                        SlingServerRepository.copyFile(bundle, "repository.xml", configFile);
+
+                        ins = new FileInputStream(configFile);
+                        log(LogService.LOG_INFO, "Using configuration file " + configFile.getAbsolutePath());
+                    }
                 }
+                crc = RepositoryConfig.create(ins, home);
+            } else {
+                crc = RepositoryConfig.create(homeFile);
             }
 
-            RepositoryConfig crc = RepositoryConfig.create(ins, home);
             return RepositoryImpl.create(crc);
 
         } catch (IOException ioe) {



Mime
View raw message