Author: justin
Date: Thu Jul 14 18:57:22 2011
New Revision: 1146847
URL: http://svn.apache.org/viewvc?rev=1146847&view=rev
Log:
SLING-2088 - initial implementation
Added:
sling/trunk/launchpad/testing-war/src/main/webapp/WEB-INF/web.xml
Modified:
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
sling/trunk/launchpad/testing-war/pom.xml
Modified:
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java?rev=1146847&r1=1146846&r2=1146847&view=diff
==============================================================================
---
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
(original)
+++
sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java
Thu Jul 14 18:57:22 2011
@@ -22,6 +22,8 @@ import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.GenericServlet;
import javax.servlet.Servlet;
@@ -437,6 +439,8 @@ public class SlingServlet extends Generi
}
}
+
+ slingHome = substVars(slingHome, null, null, null);
log("Setting sling.home=" + slingHome + " (" + source + ")");
return slingHome;
@@ -490,4 +494,126 @@ public class SlingServlet extends Generi
startingSling = null;
}
}
+
+ // ---------- Property file variable substition support
--------------------
+
+ /**
+ * The starting delimiter of variable names (value is "${").
+ */
+ private static final String DELIM_START = "${";
+
+ /**
+ * The ending delimiter of variable names (value is "}").
+ */
+ private static final String DELIM_STOP = "}";
+
+ /**
+ * This method performs property variable substitution on the specified
+ * value. If the specified value contains the syntax
+ * <tt>${<prop-name>}</tt>, where <tt><prop-name></tt>
+ * refers to either a configuration property or a system property, then the
+ * corresponding property value is substituted for the variable
placeholder.
+ * Multiple variable placeholders may exist in the specified value as well
+ * as nested variable placeholders, which are substituted from inner most
to
+ * outer most. Configuration properties override system properties.
+ *
+ * @param val The string on which to perform property substitution.
+ * @param currentKey The key of the property being evaluated used to detect
+ * cycles.
+ * @param cycleMap Map of variable references used to detect nested cycles.
+ * @param configProps Set of configuration properties.
+ * @return The value of the specified string after system property
+ * substitution.
+ * @throws IllegalArgumentException If there was a syntax error in the
+ * property placeholder syntax or a recursive variable
+ * reference.
+ */
+ private static String substVars(String val, String currentKey,
+ Map<String, String> cycleMap, Map<String, String> configProps)
+ throws IllegalArgumentException {
+ // If there is currently no cycle map, then create
+ // one for detecting cycles for this invocation.
+ if (cycleMap == null) {
+ cycleMap = new HashMap<String, String>();
+ }
+
+ // Put the current key in the cycle map.
+ cycleMap.put(currentKey, currentKey);
+
+ // Assume we have a value that is something like:
+ // "leading ${foo.${bar}} middle ${baz} trailing"
+
+ // Find the first ending '}' variable delimiter, which
+ // will correspond to the first deepest nested variable
+ // placeholder.
+ int stopDelim = val.indexOf(DELIM_STOP);
+
+ // Find the matching starting "${" variable delimiter
+ // by looping until we find a start delimiter that is
+ // greater than the stop delimiter we have found.
+ int startDelim = val.indexOf(DELIM_START);
+ while (stopDelim >= 0) {
+ int idx = val.indexOf(DELIM_START, startDelim
+ + DELIM_START.length());
+ if ((idx < 0) || (idx > stopDelim)) {
+ break;
+ } else if (idx < stopDelim) {
+ startDelim = idx;
+ }
+ }
+
+ // If we do not have a start or stop delimiter, then just
+ // return the existing value.
+ if ((startDelim < 0) && (stopDelim < 0)) {
+ return val;
+ }
+ // At this point, we found a stop delimiter without a start,
+ // so throw an exception.
+ else if (((startDelim < 0) || (startDelim > stopDelim))
+ && (stopDelim >= 0)) {
+ throw new IllegalArgumentException(
+ "stop delimiter with no start delimiter: " + val);
+ }
+
+ // At this point, we have found a variable placeholder so
+ // we must perform a variable substitution on it.
+ // Using the start and stop delimiter indices, extract
+ // the first, deepest nested variable placeholder.
+ String variable = val.substring(startDelim + DELIM_START.length(),
+ stopDelim);
+
+ // Verify that this is not a recursive variable reference.
+ if (cycleMap.get(variable) != null) {
+ throw new IllegalArgumentException("recursive variable reference: "
+ + variable);
+ }
+
+ // Get the value of the deepest nested variable placeholder.
+ // Try to configuration properties first.
+ String substValue = (configProps != null)
+ ? configProps.get(variable)
+ : null;
+ if (substValue == null) {
+ // Ignore unknown property values.
+ substValue = System.getProperty(variable, "");
+ }
+
+ // Remove the found variable from the cycle map, since
+ // it may appear more than once in the value and we don't
+ // want such situations to appear as a recursive reference.
+ cycleMap.remove(variable);
+
+ // Append the leading characters, the substituted value of
+ // the variable, and the trailing characters to get the new
+ // value.
+ val = val.substring(0, startDelim) + substValue
+ + val.substring(stopDelim + DELIM_STOP.length(), val.length());
+
+ // Now perform substitution again, since there could still
+ // be substitutions to make.
+ val = substVars(val, currentKey, cycleMap, configProps);
+
+ // Return the value.
+ return val;
+ }
}
Modified: sling/trunk/launchpad/testing-war/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing-war/pom.xml?rev=1146847&r1=1146846&r2=1146847&view=diff
==============================================================================
--- sling/trunk/launchpad/testing-war/pom.xml (original)
+++ sling/trunk/launchpad/testing-war/pom.xml Thu Jul 14 18:57:22 2011
@@ -64,7 +64,7 @@
<!--
Sling home directory when starting with jetty:run
-->
- <jetty.sling.home>target/sling</jetty.sling.home>
+ <jetty.sling.home>target/sling-test</jetty.sling.home>
<!--
Defines which tests are for the "integration-testing" phase
@@ -153,7 +153,7 @@
<systemProperties>
<systemProperty>
- <name>sling.home</name>
+ <name>test.sling.home</name>
<value>${jetty.sling.home}</value>
</systemProperty>
</systemProperties>
@@ -179,6 +179,7 @@
<groupId>org.apache.sling</groupId>
<artifactId>maven-launchpad-plugin</artifactId>
<version>2.0.11-SNAPSHOT</version>
+ <extensions>true</extensions>
<executions>
<execution>
<id>prepare-package</id>
@@ -447,19 +448,19 @@
<scope>test</scope>
</dependency>
- <!-- The test services bundles -->
- <dependency>
- <groupId>org.apache.sling</groupId>
-
<artifactId>org.apache.sling.launchpad.test-bundles</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <type>partialbundlelist</type>
- </dependency>
+ <!-- The test services bundles -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.launchpad.test-bundles</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <type>partialbundlelist</type>
+ </dependency>
<!-- The basic Sling WebApp -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.launchpad.base</artifactId>
- <version>2.3.0</version>
+ <version>2.3.1-SNAPSHOT</version>
<classifier>webapp</classifier>
<type>war</type>
<scope>runtime</scope>
Added: sling/trunk/launchpad/testing-war/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing-war/src/main/webapp/WEB-INF/web.xml?rev=1146847&view=auto
==============================================================================
--- sling/trunk/launchpad/testing-war/src/main/webapp/WEB-INF/web.xml (added)
+++ sling/trunk/launchpad/testing-war/src/main/webapp/WEB-INF/web.xml Thu Jul
14 18:57:22 2011
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>Sling Launchpad Web Application</display-name>
+
+ <!-- The Felix Http Service Listener Proxy for HTTP Session events -->
+ <listener>
+ <listener-class>
+ org.apache.sling.launchpad.webapp.SlingSessionListener
+ </listener-class>
+ </listener>
+
+ <servlet>
+ <display-name>Sling Servlet</display-name>
+ <servlet-name>sling</servlet-name>
+ <servlet-class>
+ org.apache.sling.launchpad.webapp.SlingServlet
+ </servlet-class>
+
+ <!--
+ Any init-params defined for the servlet will overwrite
+ the default settings in the sling.properties file.
+
+ The most important init-param to be set here is the
+ sling.home parameter defining where Sling will place
+ its files such as the bundle cache, logs, configuration,
+ etc.
+
+ If the sling.home parameter is not set a default value is
+ set as ${user.dir}/sling/${context.path} where ${user.dir}
+ is the current working directory and ${context.path} is the
+ servlet context path with slashes replaced by underscores and
+ the root context represented as just a single underscore.
+
+ Example: For Sling deployed in the root context, the default
+ sling.home would be sling/_. For Sling deployed in the context
+ /sling/i1, the default sling.home would be sling/_sling_i1.
+ -->
+
+ <init-param>
+ <param-name>sling.home</param-name>
+ <param-value>${test.sling.home}/sling</param-value>
+ </init-param>
+
+ <load-on-startup>100</load-on-startup>
+ </servlet>
+
+ <!-- Default Mapping for the Context -->
+ <servlet-mapping>
+ <servlet-name>sling</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- Overwrite Mappings which may be present in default web.xml files -->
+ <servlet-mapping>
+ <servlet-name>sling</servlet-name>
+ <url-pattern>*.jsp</url-pattern>
+ </servlet-mapping>
+
+</web-app>