You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jv...@apache.org on 2008/11/19 12:43:59 UTC
svn commit: r718935 - in /incubator/sling/trunk:
jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/
launchpad/base/src/main/java/org/apache/sling/launcher/app/
launchpad/base/src/main/java/org/apache/sling/launcher/webapp/ laun...
Author: jvazquez
Date: Wed Nov 19 03:43:59 2008
New Revision: 718935
URL: http://svn.apache.org/viewvc?rev=718935&view=rev
Log:
RESOLVED - issue SLING-739: Improve the Sling Embedded repository config to make it more flexible
https://issues.apache.org/jira/browse/SLING-739
Modified:
incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java
incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml
Modified: incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java?rev=718935&r1=718934&r2=718935&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java (original)
+++ incubator/sling/trunk/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/Activator.java Wed Nov 19 03:43:59 2008
@@ -18,6 +18,8 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Hashtable;
import org.apache.sling.jcr.base.util.RepositoryAccessor;
@@ -65,7 +67,11 @@
private String slingContext;
protected String getRepositoryName() {
- return "jackrabbit";
+ String repoName = bundleContext.getProperty("sling.repository.name");
+ if (repoName != null)
+ return repoName; // the repository name is set
+ else
+ return "jackrabbit";
}
public void start(BundleContext context) {
@@ -167,28 +173,11 @@
}
private void initDefaultConfig(Hashtable<String, String> props, BundleContext bundleContext) throws IOException {
- File homeDir;
- String slingHomePath = bundleContext.getProperty("sling.home");
- if (slingHomePath != null) {
- homeDir = new File(slingHomePath, getRepositoryName());
- } else {
- homeDir = new File(getRepositoryName());
- }
-
- // make sure jackrabbit home exists
- log.info("Creating default config for Jackrabbit in " + homeDir);
- if (!homeDir.isDirectory()) {
- if (!homeDir.mkdirs()) {
- log.info("verifyConfiguration: Cannot create Jackrabbit home "
- + homeDir + ", failed creating default configuration");
- return;
- }
- }
-
- // ensure the configuration file (inside the home Dir !)
- File configFile = new File(homeDir, "repository.xml");
- SlingServerRepository.copyFile(bundleContext.getBundle(),
- "repository.xml", configFile);
+ File homeDir = getHomeDir(bundleContext);
+ if (homeDir == null)
+ return;
+
+ File configFile = getConfigFile(bundleContext, homeDir);
// default config values
props.put(SLING_CONTEXT, slingContext);
@@ -199,4 +188,58 @@
props.put(SlingServerRepository.REPOSITORY_REGISTRATION_NAME,
this.getRepositoryName());
}
+
+ private File getHomeDir(BundleContext bundleContext) throws IOException {
+ File homeDir;
+
+ String repoHomePath = bundleContext.getProperty("sling.repository.home");
+ String slingHomePath = bundleContext.getProperty("sling.home");
+
+ if (repoHomePath != null) {
+ homeDir = new File(repoHomePath, getRepositoryName());
+ } else if (slingHomePath != null) {
+ homeDir = new File(slingHomePath, getRepositoryName());
+ } else {
+ homeDir = new File(getRepositoryName());
+ }
+
+ // make sure jackrabbit home exists
+ log.info("Creating default config for Jackrabbit in " + homeDir);
+ if (!homeDir.isDirectory()) {
+ if (!homeDir.mkdirs()) {
+ log.info("verifyConfiguration: Cannot create Jackrabbit home "
+ + homeDir + ", failed creating default configuration");
+ return null;
+ }
+ }
+
+ return homeDir;
+ }
+
+ private File getConfigFile(BundleContext bundleContext, File homeDir) throws IOException {
+ File configFile;
+
+ String repoConfigFileUrl = bundleContext.getProperty("sling.repository.config.file.url");
+ if (repoConfigFileUrl != null) {
+ // the repository config file is set
+ URL configFileUrl = null;
+ try {
+ configFileUrl = new URL(repoConfigFileUrl);
+ } catch (MalformedURLException e) {
+ // this not an url, trying with "file:"
+ configFileUrl = new URL("file://" + repoConfigFileUrl);
+ }
+
+ // local support only
+ configFile = new File(configFileUrl.getFile());
+ if (configFile.canRead())
+ return configFile;
+ }
+
+ // ensure the configuration file (inside the home Dir !)
+ configFile = new File(homeDir, "repository.xml");
+ SlingServerRepository.copyFile(bundleContext.getBundle(), "repository.xml", configFile);
+ return configFile;
+ }
+
}
Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java?rev=718935&r1=718934&r2=718935&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java Wed Nov 19 03:43:59 2008
@@ -109,6 +109,28 @@
* @see #SLING_HOME
*/
public static final String SLING_HOME_URL = "sling.home.url";
+
+ /**
+ * The name of the configuration property defining the JCR home directory
+ * (value is "sling.repository.home").
+ * <p>
+ * The value of this property could be set as a system property, init-param in
+ * web.xml or property in sling.properties.
+ * <p>
+ * Default value to #SLING_HOME/repository_name
+ */
+ public static final String JCR_REPO_HOME = "sling.repository.home";
+
+ /**
+ * The name of the configuration property defining the URL of an existing
+ * repository config file (repository.xml).
+ * <p>
+ * The value of this property could be set as a system property, init-param in
+ * web.xml or property in sling.properties.
+ * <p>
+ * Default value to #SLING_HOME/repository_name/repository.xml
+ */
+ public static final String JCR_REPO_CONFIG_FILE_URL = "sling.repository.config.file.url";
/**
* The name of the configuration property defining a properties file
@@ -172,7 +194,7 @@
*/
public Sling(Logger logger, ResourceProvider resourceProvider,
Map<String, String> propOverwrite) throws BundleException {
-
+
this.logger = logger;
this.resourceProvider = resourceProvider;
Modified: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java?rev=718935&r1=718934&r2=718935&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java (original)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java Wed Nov 19 03:43:59 2008
@@ -18,6 +18,7 @@
import static org.apache.felix.framework.util.FelixConstants.LOG_LEVEL_PROP;
+import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -122,7 +123,7 @@
* The name of the configuration property defining the obr repository.
*/
private static final String OBR_REPOSITORY_URL = "obr.repository.url";
-
+
/**
* The <code>Felix</code> instance loaded on {@link #init()} and stopped
* on {@link #destroy()}.
@@ -284,18 +285,37 @@
// assume that this location is inside the webapp and create the correct
// full url
final String repoLocation = props.get(OBR_REPOSITORY_URL);
- if (repoLocation != null && repoLocation.indexOf(":/") < 1
- && repoLocation.startsWith("/")) {
- try {
- final URL url = getServletContext().getResource(repoLocation);
- // only if we get back a resource url, we update it
- if (url != null) {
- props.put(OBR_REPOSITORY_URL, url.toExternalForm());
- }
- } catch (MalformedURLException e) {
- // if an exception occurs, we ignore it
- }
+ if (insideWebapp(repoLocation)) {
+ final URL url = getUrl(repoLocation);
+ // only if we get back a resource url, we update it
+ if (url != null)
+ props.put(OBR_REPOSITORY_URL, url.toExternalForm());
+ }
+
+ // idem to jcr repo home
+ final String jcrRepoHome = props.get(Sling.JCR_REPO_HOME);
+ if (insideWebapp(jcrRepoHome)) {
+ // ensure exists
+ final URL webroot = getUrl("/");
+ File jcrRepoHomeDir = new File(webroot.getPath() + jcrRepoHome);
+ if (!jcrRepoHomeDir.isDirectory())
+ jcrRepoHomeDir.mkdirs();
+
+ final URL url = getUrl(jcrRepoHome);
+ // only if we get back a resource url, we update it
+ if (url != null)
+ props.put(Sling.JCR_REPO_HOME, url.getPath());
}
+
+ // idem to jcr repo config file
+ final String jcrRepoConfigFile = props.get(Sling.JCR_REPO_CONFIG_FILE_URL);
+ if (insideWebapp(jcrRepoConfigFile)) {
+ final URL url = getUrl(jcrRepoConfigFile);
+ // only if we get back a resource url, we update it
+ if (url != null)
+ props.put(Sling.JCR_REPO_CONFIG_FILE_URL, url.toExternalForm());
+ }
+
return props;
}
@@ -317,6 +337,21 @@
props.put(LOG_LEVEL_PROP, String.valueOf(logLevel));
}
}
+
+ private boolean insideWebapp(String path) {
+ if (path != null && path.indexOf(":/") < 1 && path.startsWith("/"))
+ return true;
+ else
+ return false;
+ }
+
+ private URL getUrl(String path) {
+ try {
+ return getServletContext().getResource(path);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
private static class ServletContextLogger extends Logger {
private ServletContext servletContext;
Modified: incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties?rev=718935&r1=718934&r2=718935&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties (original)
+++ incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties Wed Nov 19 03:43:59 2008
@@ -37,6 +37,19 @@
# property of such generated configurations.
sling.context.default = default
+#
+# The name of the JCR repository. Default is "jackrabbit".
+# sling.repository.name =
+
+#
+# The JCR repository home directory. Default is sling.home/sling.repository.name.
+# sling.repository.home =
+
+#
+# The JCR repository url config file (repository.xml). Default is repository.xml in
+# bundle Embedded JCR Repository
+# sling.repository.config.file.url =
+
#
# List of packages to append to the org.osgi.framework.system.packages property
Modified: incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml?rev=718935&r1=718934&r2=718935&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/sling/trunk/launchpad/webapp/src/main/webapp/WEB-INF/web.xml Wed Nov 19 03:43:59 2008
@@ -29,6 +29,36 @@
<servlet-class>
org.apache.sling.launcher.webapp.SlingServlet
</servlet-class>
+ <!--
+ The name of the JCR repository.
+ Default is "jackrabbit".
+ -->
+ <!--
+ <init-param>
+ <param-name>sling.repository.name</param-name>
+ <param-value></param-value>
+ </init-param>
+ -->
+ <!--
+ The JCR repository home directory.
+ Default is sling.home/sling.repository.name.
+ -->
+ <!--
+ <init-param>
+ <param-name>sling.repository.home</param-name>
+ <param-value></param-value>
+ </init-param>
+ -->
+ <!--
+ The JCR repository url config file (repository.xml).
+ Default is repository.xml in bundle Embedded JCR Repository.
+ -->
+ <!--
+ <init-param>
+ <param-name>sling.repository.config.file.url</param-name>
+ <param-value></param-value>
+ </init-param>
+ -->
<load-on-startup>100</load-on-startup>
</servlet>