incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r734113 [3/6] - in /incubator/sling/whiteboard/fmeschbe/launchpad: ./ app/ app/src/ app/src/main/ app/src/main/assembly/ app/src/main/dist/ app/src/main/dist/bin/ app/src/main/dist/dos/ app/src/main/dist/unix/ app/src/main/java/ app/src/mai...
Date Tue, 13 Jan 2009 12:06:20 GMT
Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/pom.xml?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/pom.xml (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/pom.xml Tue Jan 13 04:04:51 2009
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>5-incubator-SNAPSHOT</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.launchpad.base</artifactId>
+    <version>2.0.3-incubator-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Sling - Launchpad Base</name>
+    <description>
+        This module contains the common classes and configuration files used by the various
+        launchpad modules..
+    </description>
+
+    <scm>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.3</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Category>
+                            sling
+                        </Bundle-Category>
+                        <Bundle-SymbolicName>
+                            system.bundle
+                        </Bundle-SymbolicName>
+                        <Private-Package>
+                            !org.apache.sling.launchpad.base.shared.*, *
+                        </Private-Package>
+                        <Import-Package>!*</Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                        <Embed-Dependency>
+                            org.apache.felix.framework;inline=org/**,
+                            org.osgi.core;inline=org/osgi/service/condpermadmin/**|
+                                org/osgi/service/permissionadmin/**,
+                            org.osgi.compendium;inline=org/osgi/service/log/**|
+                                org/osgi/service/http/**|
+                                org/osgi/service/device/**|
+                                org/osgi/service/cm/**|
+                                org/osgi/service/metatype/**|
+                                org/osgi/service/prefs/**|
+                                org/osgi/service/useradmin/**|
+                                org/osgi/service/wireadmin/**|
+                                org/osgi/service/io/**|
+                                org/osgi/service/provisioning/**|
+                                org/osgi/service/upnp/**|
+                                org/osgi/service/component/**|
+                                org/osgi/service/event/**|
+                                org/osgi/service/deploymentadmin/**|
+                                org/osgi/service/deploymentadmin/spi/**|
+                                org/osgi/service/application/**|
+                                info/dmtree/**| info/dmtree/notification/**|
+                                info/dmtree/notification/spi/**|
+                                info/dmtree/registry/**|
+                                info/dmtree/security/**| info/dmtree/spi/**|
+                                org/osgi/service/monitor/**|
+                                org/osgi/application/**|
+                                org/osgi/util/xml/**|
+                                org/osgi/util/position/**|
+                                org/osgi/util/measurement/**,
+                            servlet-api;inline=javax/servlet/**,
+                            servlet;inline=org/eclipse/**
+                        </Embed-Dependency>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>jar1</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                        <configuration>
+                            <classifier>shared</classifier>
+                            <includes>
+                                <include>org/apache/sling/launchpad/base/shared/**</include>
+                            </includes>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <!-- No javadocs -->
+                    <excludePackageNames>
+                        org.apache.sling
+                    </excludePackageNames>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>1.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>1.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>1.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.equinox.http</groupId>
+            <artifactId>servlet</artifactId>
+            <version>1.0.0-v20070606</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.log</artifactId>
+            <version>2.0.2-incubator</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+</project>
+

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,320 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.framework.Logger;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.startlevel.StartLevel;
+
+/**
+ * The <code>BootstrapInstaller</code> class is installed into the OSGi
+ * framework as an activator to be called when the framework is starting up.
+ * Upon startup all bundles from the {@link #PATH_CORE_BUNDLES} and the
+ * {@link #PATH_BUNDLES} location are checked whether they are already installed
+ * or not. If they are not installed, they are installed, their start level set
+ * to 1 and started. Any bundle already installed is not installed again and
+ * will also not be started here.
+ */
+class BootstrapInstaller implements BundleActivator {
+
+    /**
+     * The Bundle location scheme (protocol) used for bundles installed by this
+     * activator (value is "slinginstall:"). The path part of the Bundle
+     * location of Bundles installed by this class is the name (without the
+     * path) of the resource from which the Bundle was installed.
+     */
+    public static final String SCHEME = "slinginstall:";
+
+    /**
+     * The location the core Bundles (value is "resources"). These
+     * bundles are installed first.
+     */
+    public static final String PATH_BUNDLE_ROOT = "resources";
+    
+    /**
+     * The location the core Bundles (value is "resources/corebundles"). These
+     * bundles are installed first.
+     */
+    public static final String PATH_CORE_BUNDLES = "corebundles";
+
+    /**
+     * The location the additional Bundles (value is "resources/bundles"). These
+     * Bundles are installed after the {@link #PATH_CORE_BUNDLES core Bundles}.
+     */
+    public static final String PATH_BUNDLES = "bundles";
+
+    /**
+     * The {@link Logger} use for logging messages during installation and
+     * startup.
+     */
+    private final Logger logger;
+
+    /**
+     * The {@link ResourceProvider} used to access the Bundle jar files to
+     * install.
+     */
+    private final ResourceProvider resourceProvider;
+
+    /** The data file which works as a marker to detect the first startup. */
+    private static final String DATA_FILE = "bootstrapinstaller.ser";
+
+    BootstrapInstaller(Logger logger, ResourceProvider resourceProvider) {
+        this.logger = logger;
+        this.resourceProvider = resourceProvider;
+    }
+
+    /**
+     * Installs any Bundles missing in the current framework instance. The
+     * Bundles are verified by the Bundle location string. All missing Bundles
+     * are first installed and then started in the order of installation.
+     * Also install all deployment packages.
+     *
+     * This installation stuff is only performed during the first startup!
+     */
+    public void start(BundleContext context) throws Exception {
+        if (!isAlreadyInstalled(context)) {
+            // register deployment package support
+            final DeploymentPackageInstaller dpi =
+                new DeploymentPackageInstaller(context, logger, resourceProvider);
+            context.addFrameworkListener(dpi);
+            context.addServiceListener(dpi, "("
+                    + Constants.OBJECTCLASS + "=" + DeploymentPackageInstaller.DEPLOYMENT_ADMIN + ")");
+
+            // list all existing bundles
+            Bundle[] bundles = context.getBundles();
+            Map<String, Bundle> byLocation = new HashMap<String, Bundle>();
+            for (int i = 0; i < bundles.length; i++) {
+                byLocation.put(bundles[i].getLocation(), bundles[i]);
+            }
+
+            // the start level service to set the initial start level
+            ServiceReference ref = context.getServiceReference(StartLevel.class.getName());
+            StartLevel startLevelService = (ref != null)
+                    ? (StartLevel) context.getService(ref)
+                    : null;
+
+            // install bundles
+            List<Bundle> installed = new LinkedList<Bundle>();
+
+            Iterator<String> res = resourceProvider.getChildren(PATH_BUNDLE_ROOT);
+            while (res.hasNext()) {
+                String path = res.next();
+                // only consider folders
+                if (path.endsWith("/")) {
+                    
+                    // cut off trailing slash
+                    path = path.substring(0, path.length()-1);
+
+                    // calculate the startlevel of bundles contained
+                    int startLevel = getStartLevel(path);
+                    if (startLevel >= 0) {
+                        installBundles(context, byLocation, path, installed,
+                            startLevelService, startLevel);
+                    }
+                }
+            }
+
+            // release the start level service
+            if (ref != null) {
+                context.ungetService(ref);
+            }
+
+            // set start levels on the bundles and start them
+            startBundles(installed);
+            
+            // mark everything installed
+            markInstalled(context);
+        }
+    }
+
+    /** Nothing to be done on stop */
+    public void stop(BundleContext context) {
+    }
+
+    /**
+     * Install the Bundles from JAR files found in the given <code>parent</code>
+     * path.
+     *
+     * @param context The <code>BundleContext</code> used to install the new
+     *            Bundles.
+     * @param currentBundles The currently installed Bundles indexed by their
+     *            Bundle location.
+     * @param parent The path to the location in which to look for JAR files to
+     *            install. Only resources whose name ends with <em>.jar</em>
+     *            are considered for installation.
+     * @param installed The list of Bundles installed by this method. Each
+     *            Bundle successfully installed is added to this list.
+     */
+    private void installBundles(BundleContext context,
+            Map<String, Bundle> currentBundles, String parent,
+            List<Bundle> installed, StartLevel startLevelService, int startLevel) {
+
+        Iterator<String> res = resourceProvider.getChildren(parent);
+        while (res.hasNext()) {
+
+            String path = res.next();
+
+            if (path.endsWith(".jar")) {
+
+                // check for an already installed Bundle with the given location
+                String location = SCHEME
+                    + path.substring(path.lastIndexOf('/') + 1);
+                if (currentBundles.containsKey(location)) {
+                    continue;
+                }
+
+                // try to access the JAR file, ignore if not possible
+                InputStream ins = resourceProvider.getResourceAsStream(path);
+                if (ins == null) {
+                    continue;
+                }
+
+                // install the JAR file as a bundle
+                Bundle newBundle;
+                try {
+                    newBundle = context.installBundle(location, ins);
+                    logger.log(Logger.LOG_INFO, "Bundle "
+                        + newBundle.getSymbolicName() + " installed from "
+                        + location);
+                } catch (BundleException be) {
+                    logger.log(Logger.LOG_ERROR, "Bundle installation from "
+                        + location + " failed", be);
+                    continue;
+                }
+                
+                // optionally set the start level
+                if (startLevel > 0) {
+                    startLevelService.setBundleStartLevel(newBundle, startLevel);
+                }
+
+                // finally add the bundle to the list for later start
+                installed.add(newBundle);
+            }
+        }
+    }
+
+    /**
+     * Starts the Bundles in the <code>bundles</code> list. If the framework
+     * provides an active <code>StartLevel</code> service, the start levels of
+     * the Bundles is first set to <em>1</em>.
+     */
+    private void startBundles(List<Bundle> bundles) {
+
+        // start all bundles
+        for (Bundle bundle : bundles) {
+            try {
+                bundle.start();
+            } catch (BundleException be) {
+                logger.log(Logger.LOG_ERROR, "Bundle "
+                    + bundle.getSymbolicName() + " could not be started", be);
+            }
+        }
+
+    }
+
+    private int getStartLevel(String path) {
+        String name = path.substring(path.lastIndexOf('/') + 1);
+        
+        // core bundles are installed at start level 1
+        if (PATH_CORE_BUNDLES.equals(name)) {
+            return 1;
+        }
+        
+        // bundles in the default location are started at the defualt
+        // framework start level
+        if (PATH_BUNDLES.equals(name)) {
+            return 0;
+        }
+        
+        // otherwise the name is the start level
+        try {
+            int level = Integer.parseInt(name);
+            if (level >= 0) {
+                return level;
+            }
+            
+            logger.log(Logger.LOG_ERROR, "Illegal Runlevel for " + path
+                + ", ignoring");
+        } catch (NumberFormatException nfe) {
+            logger.log(Logger.LOG_INFO, "Folder " + path
+                + " does not denote start level, ignoring");
+        }
+        
+        // no valid start level, ignore this location
+        return -1;
+    }
+    
+    private boolean isAlreadyInstalled(BundleContext context) {
+        final File dataFile = context.getDataFile(DATA_FILE);
+        if ( dataFile != null && dataFile.exists() ) {
+            try {
+                final FileInputStream fis = new FileInputStream(dataFile);
+                try {
+                    // only care for the first few bytes
+                    byte[] bytes = new byte[10];
+                    int len = fis.read(bytes);
+                    return Boolean.parseBoolean(new String(bytes, 0, len));
+                } finally {
+                    try {
+                        fis.close();
+                    } catch (IOException ignore) {}
+                }
+            } catch (IOException ioe) {
+                logger.log(Logger.LOG_ERROR, "IOException during reading of installed flag.", ioe);
+            }
+        }
+        
+        // fallback assuming not installed yet
+        return false;
+    }
+    
+    private void markInstalled(BundleContext context) {
+        final File dataFile = context.getDataFile(DATA_FILE);
+        try {
+            final FileOutputStream fos = new FileOutputStream(dataFile);
+            try {
+                fos.write("true".getBytes());
+            } finally {
+                try {
+                    fos.close();
+                } catch (IOException ignore) {}
+            }
+        } catch (IOException ioe) {
+            logger.log(Logger.LOG_ERROR, "IOException during writing of installed flag.", ioe);
+        }
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Pattern;
+
+
+/**
+ * The <code>ClassLoaderResourceProvider</code> TODO
+ */
+public class ClassLoaderResourceProvider extends ResourceProvider {
+
+    private final ClassLoader classLoader;
+
+    public ClassLoaderResourceProvider(ClassLoader classLoader) {
+        this.classLoader = (classLoader != null)
+                ? classLoader
+                : this.getClass().getClassLoader();
+    }
+
+    @Override
+    public Iterator<String> getChildren(String path) {
+        List<String> children;
+
+        URL url = this.classLoader.getResource(path);
+        if (url != null) {
+            Pattern pathPattern = Pattern.compile("^" + path + "/[^/]+/?$");
+
+            children = new ArrayList<String>();
+            try {
+                URLConnection conn = url.openConnection();
+                if (conn instanceof JarURLConnection) {
+                    JarFile jar = ((JarURLConnection) conn).getJarFile();
+                    Enumeration<JarEntry> entries = jar.entries();
+                    while (entries.hasMoreElements()) {
+                        String entry = entries.nextElement().getName();
+                        if (pathPattern.matcher(entry).matches()) {
+                            children.add(entry);
+                        }
+                    }
+                }
+            } catch (IOException ioe) {
+                // ignore for now
+            }
+        } else {
+            children = Collections.emptyList();
+        }
+
+        return children.iterator();
+    }
+
+    /**
+     * @see org.apache.sling.launcher.app.ResourceProvider#getResource(java.lang.String)
+     */
+    public URL getResource(String path) {
+        // ensure path
+        if (path == null || path.length() == 0) {
+            return null;
+        }
+
+        // remove leading slash
+        if (path.charAt(0) == '/') {
+            path = path.substring(1);
+        }
+
+        return (this.classLoader != null) ? this.classLoader.getResource(path) : null;
+    }
+
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ClassLoaderResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * The <code>ContextConnection</code> extends the
+ * <code>java.net.URLConnection</code> to provide access to a resource which
+ * is available from {@link ResourceProvider} provided to {@link Sling}.
+ * <p>
+ * This class is implemented by actually connecting to a resource URL which is
+ * provided by the resource provider and delegating the relevant method calls.
+ * Currently only {@link #getContentLength()}, {@link #getContentType()},
+ * {@link #getInputStream()} and {@link #getLastModified()} are supported.
+ */
+public class ContextConnection extends URLConnection {
+
+    /**
+     * The {@link ResourceProvider} to which requests for content access are
+     * delegated.
+     */
+    private final ResourceProvider resourceProvider;
+
+    /**
+     * The delegatee <code>URLConnection</code> to which some of the method
+     * calls are forwarded.
+     */
+    private URLConnection delegatee;
+
+    /**
+     * Creates an instance of this context connection.
+     *
+     * @param url The original URL whose path part is used to address the
+     *            resource from the resource provider.
+     * @param resourceProvider The {@link ResourceProvider} to which requests
+     *            for content access are delegated.
+     */
+    ContextConnection(URL url, ResourceProvider resourceProvider) {
+        super(url);
+        this.resourceProvider = resourceProvider;
+    }
+
+    /**
+     * Accesses the the resource from the underlaying resource provider at the
+     * URL's path.
+     */
+    public void connect() throws IOException {
+        if (!this.connected) {
+            URL contextURL = resourceProvider.getResource(url.getPath());
+            if (contextURL == null) {
+                throw new IOException("Resource " + url.getPath()
+                    + " does not exist");
+            }
+
+            delegatee = contextURL.openConnection();
+            connected = true;
+        }
+    }
+
+    /**
+     * Returns the length in bytes of the resource or -1 if this connection has
+     * not been connected yet.
+     */
+    public int getContentLength() {
+        return (delegatee == null) ? -1 : delegatee.getContentLength();
+    }
+
+    /**
+     * Returns a guess at the content type of the resource or <code>null</code>
+     * if this connection has not been connected yet.
+     */
+    public String getContentType() {
+        return (delegatee == null) ? null : delegatee.getContentType();
+    }
+
+    /**
+     * Returns a <code>InputStream</code> on the resource. If this connection
+     * is not connected yet, the conneciton is opened.
+     *
+     * @throws IOException may be thrown if an error occurrs opening the
+     *             connection or accessing the content as an
+     *             <code>InputStream</code>.
+     */
+    public InputStream getInputStream() throws IOException {
+        connect();
+        return delegatee.getInputStream();
+    }
+
+    /**
+     * Returns the last modification timestamp of the resource or -1 if this
+     * connection has not been connected yet.
+     */
+    public long getLastModified() {
+        return (delegatee == null) ? 0 : delegatee.getLastModified();
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.osgi.service.url.AbstractURLStreamHandlerService;
+
+/**
+ * The <code>ContextProtocolHandler</code> is a simple extension of the OSGi
+ * provided <code>AbstractURLStreamHandlerService</code> which simply returns
+ * an instance of the {@link ContextConnection} when trying to open the
+ * connection of the URL.
+ */
+public class ContextProtocolHandler extends AbstractURLStreamHandlerService {
+
+    /**
+     * The {@link ResourceProvider} to which requests for content access are
+     * delegated.
+     */
+    private final ResourceProvider resourceProvider;
+
+    /**
+     * Creates an instance of this protocol handler setting the servlet context
+     * which is queried to access content.
+     *
+     * @param resourceProvider The {@link ResourceProvider} to which requests
+     *            for content access are delegated.
+     */
+    public ContextProtocolHandler(ResourceProvider resourceProvider) {
+        this.resourceProvider = resourceProvider;
+    }
+
+    /**
+     * Returns an instance of the {@link ContextConnection} class to access the
+     * content of the <code>url</code>.
+     *
+     * @param url The URL whose content is requested.
+     */
+    public URLConnection openConnection(URL url) {
+        return new ContextConnection(url, resourceProvider);
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.felix.framework.Logger;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentException;
+
+/**
+ * This is the deployment package installer.
+ * It is a delayed service that runs as soon as the framework is started
+ * and the deployment admin is available.
+ * It looks then in {@link BootstrapInstaller#PATH_BUNDLES} for
+ * deloyment packages and tries to install/update them.
+ *
+ */
+public class DeploymentPackageInstaller implements ServiceListener, FrameworkListener {
+
+    public static final String DEPLOYMENT_ADMIN = DeploymentAdmin.class.getName();
+
+    public static final String EXTENSION = ".dp";
+
+    public static final String DATA_FILE = "dpi.data";
+
+    private boolean frameworkStarted = false;
+    private boolean serviceAvailable = false;
+    private boolean deployed = false;
+
+    private final BundleContext bundleContext;
+    private final Logger logger;
+    private final ResourceProvider resourceProvider;
+
+    private DeploymentAdmin deploymentAdmin;
+    private ServiceReference deploymentAdminReference;
+
+    public DeploymentPackageInstaller(final BundleContext bundleContext,
+            Logger logger, ResourceProvider resourceProvider) {
+        this.logger = logger;
+        this.resourceProvider = resourceProvider;
+        this.bundleContext = bundleContext;
+    }
+
+    /**
+     * Wait for the deployment admin service.
+     * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
+     */
+    public synchronized void serviceChanged(ServiceEvent event) {
+        if ( event.getType() == ServiceEvent.REGISTERED && !this.deployed ) {
+            this.deploymentAdminReference = this.bundleContext.getServiceReference(DEPLOYMENT_ADMIN);
+            this.deploymentAdmin = (DeploymentAdmin) this.bundleContext.getService(this.deploymentAdminReference);
+            this.serviceAvailable = true;
+            if ( this.frameworkStarted ) {
+                this.deploy();
+            }
+        }
+
+    }
+
+    /**
+     * Wait for the framework start.
+     * @see org.osgi.framework.FrameworkListener#frameworkEvent(org.osgi.framework.FrameworkEvent)
+     */
+    public synchronized void frameworkEvent(FrameworkEvent event) {
+        if (event.getType() == FrameworkEvent.STARTED && !this.deployed) {
+            this.frameworkStarted = true;
+            if ( this.serviceAvailable ) {
+                this.deploy();
+            }
+        }
+
+    }
+
+    /**
+     * Deploy the deployment packages.
+     */
+    @SuppressWarnings("unchecked")
+    private void deploy() {
+        ArrayList<String> installedPcks = null;
+        final File dataFile = this.bundleContext.getDataFile(DATA_FILE);
+        if ( dataFile != null && dataFile.exists() ) {
+            try {
+                final FileInputStream fis = new FileInputStream(dataFile);
+                try {
+                    final ObjectInputStream ois = new ObjectInputStream(fis);
+                    try {
+                        installedPcks = (ArrayList<String>) ois.readObject();
+                    } catch (ClassNotFoundException e) {
+                        // this can never happen so we just log
+                        logger.log(Logger.LOG_ERROR, "Class not found!", e);
+                    } finally {
+                        try {
+                            ois.close();
+                        } catch (IOException ignore) {}
+                    }
+                } finally {
+                    try {
+                        fis.close();
+                    } catch (IOException ignore) {}
+                }
+            } catch (IOException ioe) {
+                logger.log(Logger.LOG_ERROR, "IOException during reading of deployed packages.", ioe);
+            }
+        }
+        try {
+            Iterator<String> res = resourceProvider.getChildren(BootstrapInstaller.PATH_BUNDLES);
+            while (res.hasNext()) {
+
+                String path = res.next();
+
+                if ( path.endsWith(EXTENSION) ) {
+                    // check if we already installed this
+                    final int pos = path.lastIndexOf('/');
+                    final String name = path.substring(pos + 1);
+
+                    if ( installedPcks != null && installedPcks.contains(name) ) {
+                        continue;
+                    }
+
+                    // install this as a deployment package
+                    final InputStream ins = resourceProvider.getResourceAsStream(path);
+                    if (ins == null) {
+                        continue;
+                    }
+                    try {
+                        this.deploymentAdmin.installDeploymentPackage(ins);
+                        logger.log(Logger.LOG_INFO, "Deployment Package "
+                                + " installed from " + path);
+                    } catch (DeploymentException e) {
+                        logger.log(Logger.LOG_ERROR, "Deployment Package installation from "
+                                + path + " failed", e);
+                    }
+                    if ( installedPcks == null ) {
+                        installedPcks = new ArrayList<String>();
+                    }
+                    installedPcks.add(name);
+                }
+            }
+
+        } catch (Throwable t) {
+            logger.log(Logger.LOG_ERROR, "Unexpected error during package deployment.", t);
+        }
+        // update status
+        if ( installedPcks != null ) {
+            try {
+                final FileOutputStream fos = new FileOutputStream(dataFile);
+                try {
+                    final ObjectOutputStream oos = new ObjectOutputStream(fos);
+                    try {
+                        oos.writeObject(installedPcks);
+                    } finally {
+                        try {
+                            oos.close();
+                        } catch (IOException ignore) {}
+                    }
+                } finally {
+                    try {
+                        fos.close();
+                    } catch (IOException ignore) {}
+                }
+            } catch (IOException ioe) {
+                logger.log(Logger.LOG_ERROR, "IOException during writing deployed packages.", ioe);
+            }
+        }
+        // now clean up
+        this.deployed = true;
+        this.bundleContext.ungetService(this.deploymentAdminReference);
+        this.bundleContext.removeFrameworkListener(this);
+        this.bundleContext.removeServiceListener(this);
+        this.deploymentAdmin = null;
+        this.deploymentAdminReference = null;
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/DeploymentPackageInstaller.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
+
+/**
+ * The <code>ResourceProvider</code> defines a simple API to access resources
+ * from the environment depending on how Sling is launched.
+ */
+public abstract class ResourceProvider {
+
+    /**
+     * Returns an iterator of paths strings of the children of the given folder
+     * defined by its path.
+     */
+    public abstract Iterator<String> getChildren(String path);
+
+    /**
+     * Returns an URL to the resource with the given path or <code>null</code>
+     * if no such resource exists.
+     */
+    public abstract URL getResource(String path);
+
+    /**
+     * Returns an <code>InputStream</code> to the resource given by the path
+     * or <code>null</code> if no such resource exists.
+     */
+    public InputStream getResourceAsStream(String path) {
+        URL res = this.getResource(path);
+        if (res != null) {
+            try {
+                return res.openStream();
+            } catch (IOException ioe) {
+                // ignore this one
+            }
+        }
+
+        // no resource
+        return null;
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java?rev=734113&view=auto
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java (added)
+++ incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java Tue Jan 13 04:04:51 2009
@@ -0,0 +1,926 @@
+/*
+ * 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.
+ */
+package org.apache.sling.launcher.app;
+
+import static org.apache.felix.framework.util.FelixConstants.EMBEDDED_EXECUTION_PROP;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Map.Entry;
+
+import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.Logger;
+import org.apache.sling.launchpad.base.shared.Notifiable;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.service.url.URLConstants;
+import org.osgi.service.url.URLStreamHandlerService;
+
+/**
+ * The <code>Sling</code> serves as the starting point for Sling.
+ * <ul>
+ * <li>The {@link #Sling(Logger, ResourceProvider, Map)} method launches
+ * Apache <code>Felix</code> as the OSGi framework implementation we use.
+ * </ul>
+ * <p>
+ * <b>Launch Configuration</b>
+ * <p>
+ * The Apache <code>Felix</code> framework requires configuration parameters
+ * to be specified for startup. This servlet builds the list of parameters from
+ * three locations:
+ * <ol>
+ * <li>The <code>com/day/osgi/servlet/Sling.properties</code> is read from
+ * the servlet class path. This properties file contains default settings.</li>
+ * <li>Extensions of this servlet may provide additional properties to be
+ * loaded overwriting the {@link #loadPropertiesOverride(Map)} method.
+ * <li>Finally, web application init parameters are added to the properties and
+ * may overwrite existing properties of the same name(s).
+ * </ol>
+ * <p>
+ * After loading all properties, variable substitution takes place on the
+ * property values. A variable is indicated as <code>${&lt;prop-name&gt;}</code>
+ * where <code>&lt;prop-name&gt;</code> is the name of a system or
+ * configuration property (configuration properties override system properties).
+ * Variables may be nested and are resolved from inner-most to outer-most. For
+ * example, the property value <code>${outer-${inner}}</code> is resolved by
+ * first resolving <code>${inner}</code> and then resolving the property whose
+ * name is the catenation of <code>outer-</code> and the result of resolving
+ * <code>${inner}</code>.
+ * <p>
+ */
+public class Sling implements BundleActivator {
+
+    /** Pseduo class version ID to keep the IDE quite. */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * The name of the configuration property defining the Sling home directory
+     * (value is "sling.home"). This is a Platform file system directory below
+     * which all runtime data, such as the Felix bundle archives, logfiles, CRX
+     * repository, etc., is located.
+     * <p>
+     * The value of this property, if not set as a system property defaults to
+     * the <i>sling</i> directory in the current working directory.
+     *
+     * @see #SLING_HOME_URL
+     */
+    public static final String SLING_HOME = "sling.home";
+
+    /**
+     * The name of the configuration property defining the Sling home directory
+     * as an URL (value is "sling.home.url").
+     * <p>
+     * The value of this property is assigned the value of
+     * <code>new File(${sling.home}).toURI().toString()</code> before
+     * resolving the property variables.
+     *
+     * @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
+     * defining a list of bundles, which are installed into the framework when
+     * it has been launched (value is "org.apache.osgi.bundles").
+     * <p>
+     * This configuration property is generally set in the web application
+     * configuration and may be referenced in all property files (default, user
+     * supplied and web application parameters) used to build the framework
+     * configuration.
+     */
+    public static final String OSGI_FRAMEWORK_BUNDLES = "org.apache.osgi.bundles";
+
+    /**
+     * The property to be set to ignore the system properties when building the
+     * Felix framework properties (value is "sling.ignoreSystemProperties"). If
+     * this is property is set to <code>true</code> (case does not matter),
+     * the system properties will not be used by
+     * {@link #loadConfigProperties(Map)}.
+     */
+    public static final String SLING_IGNORE_SYSTEM_PROPERTIES = "sling.ignoreSystemProperties";
+
+    /**
+     * The name of the default launcher properties file to setup the environment
+     * for the <code>Felix</code> framework (value is "sling.properties").
+     * <p>
+     * Extensions of this class may overwrite some or all properties in this
+     * file through Web Application parameters or other properties files.
+     */
+    public static final String CONFIG_PROPERTIES = "sling.properties";
+
+    public static final String PROP_SYSTEM_PACKAGES = "org.apache.sling.launcher.system.packages";
+
+    /**
+     * The simple logger to log messages during startup and shutdown to
+     */
+    protected final Logger logger;
+
+    private ResourceProvider resourceProvider;
+
+    /**
+     * The <code>Felix</code> instance loaded on {@link #init()} and stopped
+     * on {@link #destroy()}.
+     */
+    private Felix felix;
+
+    /**
+     * The <code>BundleContext</code> of the OSGi framework system bundle.
+     * This is used for service registration and service access to get at the
+     * delegatee servlet.
+     */
+    private BundleContext bundleContext;
+
+    /**
+     * Initializes this servlet by loading the framework configuration
+     * properties, starting the OSGi framework (Apache Felix) and exposing the
+     * system bundle context and the <code>Felix</code> instance as servlet
+     * context attributes.
+     *
+     * @throws BundleException if the framework cannot be initialized.
+     */
+    public Sling(Notifiable notifiable, Logger logger,
+            ResourceProvider resourceProvider, Map<String, String> propOverwrite)
+            throws BundleException {
+    	
+        this.logger = logger;
+        this.resourceProvider = resourceProvider;
+
+        this.logger.log(Logger.LOG_INFO, "Starting Sling");
+
+        // read the default parameters
+        Map<String, String> props = this.loadConfigProperties(propOverwrite);
+
+        // check for auto-start bundles
+        this.setInstallBundles(props);
+
+        // ensure execution environment
+        this.setExecutionEnvironment(props);
+
+        // make sure Felix does not exit the VM when terminating ...
+        props.put(EMBEDDED_EXECUTION_PROP, "true");
+
+        // the custom activator list just contains this servlet
+        List<BundleActivator> activators = new ArrayList<BundleActivator>();
+        activators.add(this);
+        activators.add(new BootstrapInstaller(logger, resourceProvider));
+
+        // create the framework and start it
+        Felix tmpFelix = new SlingFelix(notifiable, logger, props, activators);
+        tmpFelix.start();
+
+        // only assign field if start succeeds
+        this.felix = tmpFelix;
+
+        // log sucess message
+        this.logger.log(Logger.LOG_INFO, "Sling started");
+    }
+
+    /**
+     * Destroys this servlet by shutting down the OSGi framework and hence the
+     * delegatee servlet if one is set at all.
+     */
+    public final void destroy() {
+        if (felix != null) {
+            // get a private copy of the reference and remove the class ref
+            Felix myFelix;
+            synchronized (this) {
+                myFelix = felix;
+                felix = null;
+            }
+
+            // shutdown the Felix container
+            if (myFelix != null) {
+                logger.log(Logger.LOG_INFO, "Shutting down Sling");
+                myFelix.stopAndWait();
+                logger.log(Logger.LOG_INFO, "Sling stopped");
+            }
+        }
+    }
+
+    // ---------- BundleActivator ----------------------------------------------
+
+    /**
+     * Called when the OSGi framework is being started. This implementation
+     * registers as a service listener for the
+     * <code>javax.servlet.Servlet</code> class and calls the
+     * {@link #doStartBundle()} method for implementations to execute more
+     * startup tasks. Additionally the <code>context</code> URL protocol
+     * handler is registered.
+     *
+     * @param bundleContext The <code>BundleContext</code> of the system
+     *            bundle of the OSGi framework.
+     * @throws Exception May be thrown if the {@link #doStartBundle()} throws.
+     */
+    public final void start(BundleContext bundleContext) throws Exception {
+        this.bundleContext = bundleContext;
+
+        // register the context URL handler
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        props.put(URLConstants.URL_HANDLER_PROTOCOL, new String[] { "context" });
+        ContextProtocolHandler contextHandler = new ContextProtocolHandler(
+            this.resourceProvider);
+        bundleContext.registerService(URLStreamHandlerService.class.getName(),
+            contextHandler, props);
+
+        // execute optional bundle startup tasks of an extension
+        this.doStartBundle();
+    }
+
+    /**
+     * Called when the OSGi framework is being shut down. This implementation
+     * first calls the {@link #doStopBundle()} method method before
+     * unregistering as a service listener and ungetting an servlet delegatee if
+     * one has been acquired.
+     *
+     * @param bundleContext The <code>BundleContext</code> of the system
+     *            bundle of the OSGi framework.
+     */
+    public final void stop(BundleContext bundleContext) {
+        // execute optional bundle stop tasks of an extension
+        try {
+            this.doStopBundle();
+        } catch (Exception e) {
+            this.logger.log(Logger.LOG_ERROR, "Unexpected exception caught", e);
+        }
+
+        // drop bundle context reference
+        this.bundleContext = null;
+    }
+
+    // ---------- Configuration Loading ----------------------------------------
+
+    /**
+     * Loads the configuration properties in the configuration property file
+     * associated with the framework installation; these properties are
+     * accessible to the framework and to bundles and are intended for
+     * configuration purposes. By default, the configuration property file is
+     * located in the <tt>conf/</tt> directory of the Felix installation
+     * directory and is called "<tt>config.properties</tt>". The
+     * installation directory of Felix is assumed to be the parent directory of
+     * the <tt>felix.jar</tt> file as found on the system class path property.
+     * The precise file from which to load configuration properties can be set
+     * by initializing the "<tt>felix.config.properties</tt>" system
+     * property to an arbitrary URL.
+     *
+     * @return A <tt>Properties</tt> instance or <tt>null</tt> if there was
+     *         an error.
+     */
+    private Map<String, String> loadConfigProperties(
+            Map<String, String> propOverwrite) throws BundleException {
+        // The config properties file is either specified by a system
+        // property or it is in the same directory as the Felix JAR file.
+        // Try to load it from one of these places.
+        Map<String, String> props = new HashMap<String, String>();
+
+        // Read the properties file.
+        this.load(props, CONFIG_PROPERTIES);
+
+        // resolve inclusions (and remove property)
+        this.loadIncludes(props, null);
+
+        // overwrite default properties with initial overwrites
+        if (propOverwrite != null) {
+            props.putAll(propOverwrite);
+        }
+
+        // check whether sling.home is overwritten by system property
+        String slingHome = props.get(SLING_HOME);
+        if (slingHome == null || slingHome.length() == 0) {
+            throw new BundleException("sling.home property is missing, cannot start");
+        }
+
+        // resolve variables and ensure sling.home is an absolute path
+        slingHome = substVars(slingHome, SLING_HOME, null, props);
+        File slingHomeFile = new File(slingHome).getAbsoluteFile();
+        slingHome = slingHomeFile.getAbsolutePath();
+
+        // overlay with ${sling.home}/sling.properties
+        this.logger.log(Logger.LOG_INFO, "Starting sling in " + slingHome);
+        File propFile = new File(slingHome, CONFIG_PROPERTIES);
+        this.load(props, propFile);
+
+        // create a copy of the properties to perform variable substitution
+        Map<String, String> origProps = props;
+        props = new HashMap<String, String>();
+        props.putAll(origProps);
+
+        // check system properties for any overrides (except sling.home !)
+        String ignoreSystemProperties = props.get(SLING_IGNORE_SYSTEM_PROPERTIES);
+        if (!"true".equalsIgnoreCase(ignoreSystemProperties)) {
+            for (String name : props.keySet()) {
+                String sysProp = System.getProperty(name);
+                if (sysProp != null) {
+                    props.put(name, sysProp);
+                }
+            }
+        }
+
+        // resolve inclusions again
+        this.loadIncludes(props, slingHome);
+
+        // overwrite properties, this is not persisted as such
+        this.loadPropertiesOverride(props);
+
+        // resolve boot delegation and system packages
+        this.resolve(props, "org.osgi.framework.bootdelegation",
+            "sling.bootdelegation.");
+        this.resolve(props, "org.osgi.framework.system.packages",
+            "sling.system.packages.");
+
+        // reset back the sling home property
+        // might have been overwritten by system properties, included
+        // files or the sling.properties file
+        origProps.put(SLING_HOME, slingHome);
+        props.put(SLING_HOME, slingHome);
+        props.put(SLING_HOME_URL, slingHomeFile.toURI().toString());
+
+        // Perform variable substitution for system properties.
+        for (Entry<String, String> entry : props.entrySet()) {
+            entry.setValue(substVars(entry.getValue(), entry.getKey(), null,
+                props));
+        }
+
+        // look for context:/ URLs to substitute
+        for (Entry<String, String> entry : props.entrySet()) {
+            String name = entry.getKey();
+            String value = entry.getValue();
+            if (value != null && value.startsWith("context:/")) {
+                String path = value.substring("context:/".length() - 1);
+
+                InputStream src = this.resourceProvider.getResourceAsStream(path);
+                if (src != null) {
+                    File target = new File(slingHome, path);
+                    OutputStream dest = null;
+                    try {
+                        // only copy file if not existing
+                        if (!target.exists()) {
+                            target.getParentFile().mkdirs();
+                            dest = new FileOutputStream(target);
+                            byte[] buf = new byte[2048];
+                            int rd;
+                            while ((rd = src.read(buf)) >= 0) {
+                                dest.write(buf, 0, rd);
+                            }
+                        }
+
+                        // after copying replace property and add url property
+                        entry.setValue(target.getAbsolutePath());
+
+                        // also set the new property on the unsubstituted props
+                        origProps.put(name, "${sling.home}" + path);
+
+                    } catch (IOException ioe) {
+                        this.logger.log(Logger.LOG_ERROR, "Cannot copy file "
+                            + value + " to " + target, ioe);
+                    } finally {
+                        if (dest != null) {
+                            try {
+                                dest.close();
+                            } catch (IOException ignore) {
+                            }
+                        }
+                        try {
+                            src.close();
+                        } catch (IOException ignore) {
+                        }
+                    }
+                }
+            }
+        }
+
+        // write the unsubstituted properties back to the overlay file
+        OutputStream os = null;
+        try {
+            // ensure parent folder(s)
+            propFile.getParentFile().mkdirs();
+
+            os = new FileOutputStream(propFile);
+
+            // copy the values into a temporary properties structure to store
+            Properties tmp = new Properties();
+            tmp.putAll(origProps);
+            tmp.store(os, "Overlay properties for configuration");
+        } catch (Exception ex) {
+            this.logger.log(Logger.LOG_ERROR,
+                "Error loading overlay properties from " + propFile, ex);
+        } finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException ex2) {
+                    // Nothing we can do.
+                }
+            }
+        }
+
+        return props;
+    }
+
+    /**
+     * Scans the properties for any properties starting with the given
+     * <code>prefix</code> (e.g. <code>sling.bootdelegation.</code>).
+     * <ol>
+     * <li>Each such property is checked, whether it actually starts with
+     * <code>prefix<b>class.</b></code>. If so, the rest of the property
+     * name is assumed to be a fully qualified class name which is check,
+     * whether it is visible. If so, the value of the property is appended to
+     * the value of the <code>osgiProp</code>. If the class cannot be loaded,
+     * the property is ignored.
+     * <li>Otherwise, if the property does not contain a fully qualified class
+     * name, the value of the property is simply appended to the
+     * <code>osgiProp</code>.
+     * </ol>
+     *
+     * @param props The <code>Properties</code> to be scanned.
+     * @param osgiProp The name of the property in <code>props</code> to which
+     *            any matching property values are appended.
+     * @param prefix The prefix of properties to handle.
+     */
+    private void resolve(Map<String, String> props, String osgiProp,
+            String prefix) {
+        final String propVal = props.get(osgiProp);
+        StringBuffer prop = new StringBuffer(propVal == null ? "" : propVal);
+        boolean mod = false;
+        for (Entry<String, String> pEntry : props.entrySet()) {
+            String key = pEntry.getKey();
+            if (key.startsWith(prefix)) {
+                if (key.indexOf("class.") == prefix.length()) {
+                    // prefix is followed by checker class name
+                    String className = key.substring(prefix.length()
+                        + "class.".length());
+                    try {
+                        Class.forName(className, true,
+                            this.getClass().getClassLoader());
+                    } catch (Throwable t) {
+                        // don't really care, but class checking failed, so we
+                        // do not add
+                        this.logger.log(Logger.LOG_DEBUG, "Class " + className
+                            + " not found. Ignoring '" + pEntry.getValue()
+                            + "' for property " + osgiProp);
+                        continue;
+                    }
+                }
+
+                // get here if class is known or no checker class
+                this.logger.log(Logger.LOG_DEBUG, "Adding '"
+                    + pEntry.getValue() + "' to property " + osgiProp);
+                if (prop.length() > 0) {
+                    prop.append(',');
+                }
+                prop.append(pEntry.getValue());
+                mod = true;
+            }
+        }
+
+        // replace the property with the modified property
+        if (mod) {
+            this.logger.log(Logger.LOG_DEBUG, "Setting property " + osgiProp
+                + " to " + prop.toString());
+            props.put(osgiProp, prop.toString());
+        }
+    }
+
+    private void setInstallBundles(Map<String, String> props) {
+        String prefix = "sling.install.";
+        Set<String> levels = new TreeSet<String>();
+        for (String key : props.keySet()) {
+            if (key.startsWith(prefix)) {
+                levels.add(key.substring(prefix.length()));
+            }
+        }
+
+        StringBuffer buf = new StringBuffer();
+        for (String level : levels) {
+            if (buf.length() > 0) {
+                buf.append(',');
+            }
+            buf.append(level);
+        }
+
+        props.put(prefix + "bundles", buf.toString());
+    }
+
+    /**
+     * Ensures sensible Execution Environment setting. If the
+     * <code>org.osgi.framework.executionenvironment</code> property is set in
+     * the configured properties or the system properties, we ensure that older
+     * settings for J2SE-1.2, J2SE-1.3 and J2SE-1.4 are included. If the
+     * property is neither set in the configuration properties nor in the system
+     * properties, the property is not set.
+     *
+     * @param props The configuration properties to check and optionally ammend.
+     */
+    private void setExecutionEnvironment(Map<String, String> props) {
+        // get the current Execution Environment setting
+        String ee = props.get(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+        if (ee == null) {
+            ee = System.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+        }
+
+        // if there is a setting, ensure J2SE-1.2/3/4/5 is included in the list
+        if (ee != null) {
+            int javaMinor;
+            try {
+                String specVString = System.getProperty("java.specification.version");
+                javaMinor = Version.parseVersion(specVString).getMinor();
+            } catch (IllegalArgumentException iae) {
+                // don't care, assume minimal sling version (1.5)
+                javaMinor = 5;
+            }
+
+            for (int i = 2; i <= javaMinor; i++) {
+                String exEnv = "J2SE-1." + i;
+                if (ee.indexOf(exEnv) < 0) {
+                    ee += "," + exEnv;
+                }
+            }
+
+            this.logger.log(Logger.LOG_INFO,
+                "Using Execution Environment setting: " + ee);
+            props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee);
+        } else {
+            this.logger.log(Logger.LOG_INFO,
+                "Not using Execution Environment setting");
+        }
+    }
+
+    // ---------- Extension support --------------------------------------------
+
+    /**
+     * Loads additional properties into the <code>properties</code> object.
+     * <p>
+     * This implementation does nothing and may be overwritten by extensions
+     * requiring additional properties to be set.
+     * <p>
+     * This method is called when the servlet is initialized to prepare the
+     * configuration for <code>Felix</code>. Implementations may add
+     * properties from implementation specific sources. Properties added here
+     * overwrite properties loaded from the default properties file and may be
+     * overwritten by parameters set in the web application.
+     * <p>
+     * The <code>properties</code> object has not undergone variable
+     * substition and properties added by this method may also contain values
+     * refererring to other properties.
+     * <p>
+     * The properties added in this method will not be persisted in the
+     * <code>sling.properties</code> file in the <code>sling.home</code>
+     * directory.
+     *
+     * @param properties The <code>Properties</code> object to which custom
+     *            properties may be added.
+     */
+    protected void loadPropertiesOverride(Map<String, String> properties) {
+    }
+
+    /**
+     * Returns the <code>BundleContext</code> of the system bundle of the OSGi
+     * framework launched by this servlet. This method only returns a non-<code>null</code>
+     * object after the system bundle of the framework has been started and
+     * before it is being stopped.
+     */
+    protected final BundleContext getBundleContext() {
+        return this.bundleContext;
+    }
+
+    /**
+     * Executes additional startup tasks and is called by the
+     * {@link #start(BundleContext)} method.
+     * <p>
+     * This implementation does nothing and may be overwritten by extensions
+     * requiring additional startup tasks.
+     *
+     * @throws Exception May be thrown in case of problems.
+     */
+    protected void doStartBundle() throws Exception {
+    }
+
+    /**
+     * Executes additional shutdown tasks and is called by the
+     * {@link #stop(BundleContext)} method.
+     * <p>
+     * This implementation does nothing and may be overwritten by extensions
+     * requiring additional shutdown tasks.
+     * <p>
+     * When overwriting this method, it must be made sure, that no exception may
+     * be thrown, otherwise unexpected behaviour may result.
+     */
+    protected void doStopBundle() {
+    }
+
+    // ---------- Property file support ----------------------------------------
+
+    /**
+     * Looks for <code>sling.include</code> and <code>sling.include.*</code>
+     * properties in the <code>props</code> and loads properties form the
+     * respective locations.
+     * <p>
+     * Each <code>sling.include</code> (or <code>sling.include.*</code>)
+     * property may contain a comma-separated list of resource and/or file names
+     * to be loaded from. The includes are loaded in alphabetical order of the
+     * property names.
+     * <p>
+     * Each reasource path is first tried to be loaded through the
+     * {@link #resourceProvider}. If that fails, the resource path is tested as
+     * a file. If relative <code>slingHome</code> is used as the parent if not
+     * <code>null</code>, otherwise the current working directory is used as
+     * the parent.
+     * <p>
+     * Any non-existing resource is silently ignored.
+     * <p>
+     * When the method returns, the <code>sling.include</code> and
+     * <code>sling.include.*</code> properties are not contained in the
+     * <code>props</code> any more.
+     *
+     * @param props The <code>Properties</code> containing the
+     *            <code>sling.include</code> and <code>sling.include.*</code>
+     *            properties. This is also the destination for the new
+     *            properties loaded.
+     * @param slingHome The parent directory used to resolve relative path names
+     *            if loading from a file. This may be <code>null</code> in
+     *            which case the current working directory is used as the
+     *            parent.
+     */
+    private void loadIncludes(Map<String, String> props, String slingHome) {
+        // Build the sort map of include properties first
+        // and remove include elements from the properties
+        SortedMap<String, String> includes = new TreeMap<String, String>();
+        for (Iterator<Entry<String, String>> pi = props.entrySet().iterator(); pi.hasNext();) {
+            Entry<String, String> entry = pi.next();
+            if (entry.getKey().startsWith("sling.include.")
+                || entry.getKey().equals("sling.include")) {
+                includes.put(entry.getKey(), entry.getValue());
+                pi.remove();
+            }
+        }
+
+        for (Iterator<Entry<String, String>> ii = includes.entrySet().iterator(); ii.hasNext();) {
+            Map.Entry<String, String> entry = ii.next();
+            String key = entry.getKey();
+            String include = entry.getValue();
+
+            // ensure variable resolution on this property
+            include = substVars(include, key, null, props);
+
+            StringTokenizer tokener = new StringTokenizer(include, ",");
+            while (tokener.hasMoreTokens()) {
+                String file = tokener.nextToken().trim();
+                InputStream is = this.resourceProvider.getResourceAsStream(file);
+                try {
+                    if (is == null && slingHome != null) {
+                        File resFile = new File(file);
+                        if (!resFile.isAbsolute()) {
+                            resFile = new File(slingHome, file);
+                        }
+                        if (resFile.canRead()) {
+                            is = new FileInputStream(resFile);
+                            file = resFile.getAbsolutePath(); // for logging
+                        }
+                    }
+
+                    if (is != null) {
+                        this.load(props, is);
+                    }
+                } catch (IOException ioe) {
+                    this.logger.log(Logger.LOG_ERROR,
+                        "Error loading config properties from " + file, ioe);
+                }
+            }
+        }
+    }
+
+    /**
+     * Load properties from the given resource file, which is accessed through
+     * the {@link #resourceProvider}. If the resource does not exist, nothing
+     * is loaded.
+     *
+     * @param props The <code>Properties</code> into which the loaded
+     *            properties are loaded
+     * @param resource The resource from which to load the resources
+     */
+    private void load(Map<String, String> props, String resource) {
+        InputStream is = this.resourceProvider.getResourceAsStream(resource);
+        if (is != null) {
+            try {
+                this.load(props, is);
+            } catch (IOException ioe) {
+                this.logger.log(Logger.LOG_ERROR,
+                    "Error loading config properties from " + resource, ioe);
+            }
+        }
+    }
+
+    /**
+     * Load properties from the given file. If the resource cannot be read from
+     * (e.g. because it does not exist), nothing is loaded.
+     *
+     * @param props The <code>Properties</code> into which the loaded
+     *            properties are loaded
+     * @param file The <code>File</code> to load the properties from
+     */
+    private void load(Map<String, String> props, File file) {
+        if (file != null && file.canRead()) {
+            try {
+                this.load(props, new FileInputStream(file));
+            } catch (IOException ioe) {
+                this.logger.log(Logger.LOG_ERROR,
+                    "Error loading config properties from "
+                        + file.getAbsolutePath(), ioe);
+            }
+        }
+    }
+
+    private void load(Map<String, String> props, InputStream ins)
+            throws IOException {
+        try {
+            Properties tmp = new Properties();
+            tmp.load(ins);
+
+            for (Map.Entry<Object, Object> entry : tmp.entrySet()) {
+                props.put((String) entry.getKey(), (String) entry.getValue());
+            }
+        } finally {
+            try {
+                ins.close();
+            } catch (IOException ioe2) {
+                // ignore
+            }
+        }
+    }
+
+    // ---------- 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>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</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;
+    }
+}

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/fmeschbe/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message