You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/04/25 08:48:24 UTC
svn commit: r651504 [1/2] - in /incubator/sling/trunk/launchpad/base: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/sling/ src/main/java/org/apache/sling/launcher/
src/main/java/org/apache/sling/...
Author: cziegeler
Date: Thu Apr 24 23:48:10 2008
New Revision: 651504
URL: http://svn.apache.org/viewvc?rev=651504&view=rev
Log:
SLING-391: Create common base module for launchpad stuff.
Added:
incubator/sling/trunk/launchpad/base/
incubator/sling/trunk/launchpad/base/DISCLAIMER
incubator/sling/trunk/launchpad/base/LICENSE (with props)
incubator/sling/trunk/launchpad/base/NOTICE (with props)
incubator/sling/trunk/launchpad/base/pom.xml (with props)
incubator/sling/trunk/launchpad/base/src/
incubator/sling/trunk/launchpad/base/src/main/
incubator/sling/trunk/launchpad/base/src/main/java/
incubator/sling/trunk/launchpad/base/src/main/java/org/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/Main.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingBridge.java (with props)
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/webapp/SlingServlet.java (with props)
incubator/sling/trunk/launchpad/base/src/main/resources/
incubator/sling/trunk/launchpad/base/src/main/resources/WEB-INF/
incubator/sling/trunk/launchpad/base/src/main/resources/WEB-INF/jcr-client.properties (with props)
incubator/sling/trunk/launchpad/base/src/main/resources/jre-1.5.properties (with props)
incubator/sling/trunk/launchpad/base/src/main/resources/jre-1.6.properties (with props)
incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties (with props)
Added: incubator/sling/trunk/launchpad/base/DISCLAIMER
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/DISCLAIMER?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/DISCLAIMER (added)
+++ incubator/sling/trunk/launchpad/base/DISCLAIMER Thu Apr 24 23:48:10 2008
@@ -0,0 +1,7 @@
+Apache Sling is an effort undergoing incubation at The Apache Software Foundation (ASF),
+sponsored by the Apache Jackrabbit PMC. Incubation is required of all newly accepted
+projects until a further review indicates that the infrastructure, communications,
+and decision making process have stabilized in a manner consistent with other
+successful ASF projects. While incubation status is not necessarily a reflection of
+the completeness or stability of the code, it does indicate that the project has yet
+to be fully endorsed by the ASF.
\ No newline at end of file
Added: incubator/sling/trunk/launchpad/base/LICENSE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/LICENSE?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/LICENSE (added)
+++ incubator/sling/trunk/launchpad/base/LICENSE Thu Apr 24 23:48:10 2008
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
Propchange: incubator/sling/trunk/launchpad/base/LICENSE
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/launchpad/base/NOTICE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/NOTICE?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/NOTICE (added)
+++ incubator/sling/trunk/launchpad/base/NOTICE Thu Apr 24 23:48:10 2008
@@ -0,0 +1,10 @@
+Apache Sling Launchpad App
+Copyright 2007-2008 The Apache Software Foundation
+
+Based on source code originally developed by
+Day Software (http://www.day.com/).
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
Propchange: incubator/sling/trunk/launchpad/base/NOTICE
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/launchpad/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/pom.xml?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/pom.xml (added)
+++ incubator/sling/trunk/launchpad/base/pom.xml Thu Apr 24 23:48:10 2008
@@ -0,0 +1,83 @@
+<?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>1-incubator-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.launchpad.base</artifactId>
+ <packaging>jar</packaging>
+ <version>2.0.0-incubator-SNAPSHOT</version>
+
+ <name>Sling - Launchpad Base</name>
+ <description>
+ This module contains the common classes and configuration files used by the various
+ launchpad modules..
+ </description>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/launchpad/base
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/launchpad/base
+ </developerConnection>
+ <url>
+ http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base
+ </url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.equinox.http</groupId>
+ <artifactId>servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.osgi.log</artifactId>
+ <version>2.0.0-incubator-SNAPSHOT</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+</project>
+
Propchange: incubator/sling/trunk/launchpad/base/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java Thu Apr 24 23:48:10 2008
@@ -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.InputStream;
+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.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/corebundles"). These
+ * bundles are installed first.
+ */
+ public static final String PATH_CORE_BUNDLES = "resources/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 = "resources/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;
+
+ 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.
+ */
+ public void start(BundleContext context) throws Exception {
+
+ // 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]);
+ }
+
+ // install bundles
+ List<Bundle> installed = new LinkedList<Bundle>();
+ installBundles(context, byLocation, PATH_CORE_BUNDLES, installed);
+ installBundles(context, byLocation, PATH_BUNDLES, installed);
+
+ // set start levels on the bundles and start them
+ startBundles(context, installed);
+ }
+
+ /** 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) {
+
+ 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;
+ }
+
+ // 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(BundleContext context, List<Bundle> bundles) {
+
+ // the start level service to set the initial start level
+ ServiceReference ref = context.getServiceReference(StartLevel.class.getName());
+ StartLevel startLevel = (ref != null)
+ ? (StartLevel) context.getService(ref)
+ : null;
+
+ // start all bundles
+ for (Bundle bundle : bundles) {
+
+ if (startLevel != null) {
+ startLevel.setBundleStartLevel(bundle, 1);
+ }
+
+ try {
+ bundle.start();
+ } catch (BundleException be) {
+ logger.log(Logger.LOG_ERROR, "Bundle "
+ + bundle.getSymbolicName() + " could not be started", be);
+ }
+ }
+
+ // release the start level service
+ if (ref != null) {
+ context.ungetService(ref);
+ }
+ }
+
+}
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/BootstrapInstaller.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java Thu Apr 24 23:48:10 2008
@@ -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/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextConnection.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java Thu Apr 24 23:48:10 2008
@@ -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/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ContextProtocolHandler.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java Thu Apr 24 23:48:10 2008
@@ -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/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/ResourceProvider.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java Thu Apr 24 23:48:10 2008
@@ -0,0 +1,1012 @@
+/*
+ * 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.UUID;
+import java.util.Map.Entry;
+
+import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.Logger;
+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 a basic servlet for Project Sling. The
+ * tasks of this servlet are as follows:
+ * <ul>
+ * <li>The {@link #init()} method launches Apache <code>Felix</code> as the
+ * OSGi framework implementation we use.
+ * <li>Registers as a service listener interested for services of type
+ * <code>javax.servlet.Servlet</code>.
+ * <li>Handles requests by delegating to a servlet which is expected to be
+ * registered with the framework as a service of type
+ * <code>javax.servlet.Servlet</code>. If no delegatee servlet has been
+ * registered request handlings results in a temporary unavailability of the
+ * servlet.
+ * </ul>
+ * <p>
+ * <b>Request Handling</b>
+ * <p>
+ * This servlet handles request by forwarding to a delegatee servlet. The
+ * delegatee servlet is automatically retrieved from the service registry by the
+ * {@link #getDelegatee()}. This method also makes sure, the such a servlet
+ * actually exits by throwing an <code>UnvailableException</code> if not and
+ * also makes sure the servlet is initialized.
+ * <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>${<prop-name>}</code>
+ * where <code><prop-name></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>
+ * <b>Logging</b>
+ * <p>
+ * This servlet logs through the servlet container logging mechanism by calling
+ * the <code>GenericServlet.log</code> methods. Bundles launched within the
+ * framework provided by this servlet may use whatever logging mechanism they
+ * choose to use. The Day Commons OSGI Log Bundle provides an OSGi Log Service
+ * implementation, which also provides access to Apache Commons Logging, SLF4J
+ * and Log4J logging. It is recommended that this bundle is used to setup and
+ * configure logging for systems based on this servlet.
+ */
+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 framework property containing the identifier of the
+ * running Sling instance (value is "sling.id"). This value of this property
+ * is managed by this class and cannot be overwritten by the configuration
+ * file(s).
+ */
+ public static final String SLING_ID = "sling.id";
+
+ /**
+ * The name of the file used to persist the value of the
+ * {@link #SLING_ID Sling instance identifier} (value is "sling.id").
+ */
+ public static final String SLING_ID_FILE = SLING_ID;
+
+ /**
+ * 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(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);
+
+ // ensure the instance ID
+ props.put(SLING_ID, getInstanceId(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 Felix(logger, props, activators);
+ tmpFelix.start();
+
+ // only assign field if start succeeds
+ this.felix = tmpFelix;
+
+ // log sucess message
+ this.logger.log(Logger.LOG_INFO, "Sling Instance "
+ + props.get(SLING_ID) + " 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() {
+ // shutdown the Felix container
+ if (felix != null) {
+ String label = "Sling Instance "
+ + felix.getBundleContext().getProperty(SLING_ID);
+ logger.log(Logger.LOG_INFO, "Shutting down " + label);
+ felix.stopAndWait();
+ logger.log(Logger.LOG_INFO, label + " stopped");
+ felix = null;
+ }
+ }
+
+ // ---------- 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 = System.getProperty(SLING_HOME);
+ if (slingHome == null || slingHome.length() == 0) {
+
+ // no system property, ensure default setting
+ slingHome = props.get(SLING_HOME);
+ if (slingHome == null || slingHome.length() == 0) {
+ slingHome = "sling";
+ this.logger.log(Logger.LOG_INFO,
+ "sling.home is not defined. Using '" + slingHome + "'");
+ }
+ }
+
+ // 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");
+ }
+ }
+
+ /**
+ * Returns the Sling Instance Identifier. The value is read from the
+ * <code>${sling.home}/sling.id</code> file if existing and valid.
+ * Otherwise a new id is created as a random UUID and then stored in the
+ * file.
+ *
+ * @return the Sling Instance Identifier
+ */
+ private String getInstanceId(Map<String, String> props) {
+ String slingId = null;
+
+ // try to read the id from the id file first
+ File idFile = new File(props.get(SLING_HOME), SLING_ID_FILE);
+ if (idFile.exists() && idFile.length() >= 36) {
+ FileInputStream fin = null;
+ try {
+ fin = new FileInputStream(idFile);
+ byte[] rawBytes = new byte[36];
+ if (fin.read(rawBytes) == 36) {
+ String rawString = new String(rawBytes, "ISO-8859-1");
+
+ // roundtrip to ensure correct format of UUID value
+ slingId = UUID.fromString(rawString).toString();
+ }
+ } catch (Throwable t) {
+ logger.log(Logger.LOG_ERROR,
+ "Failed reading UUID from id file " + idFile
+ + ", creating new id", t);
+ } finally {
+ if (fin != null) {
+ try {
+ fin.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+ }
+
+ // no sling id yet or failure to read file: create an id and store
+ if (slingId == null) {
+ slingId = UUID.randomUUID().toString();
+
+ idFile.delete();
+ idFile.getParentFile().mkdirs();
+ FileOutputStream fout = null;
+ try {
+ fout = new FileOutputStream(idFile);
+ fout.write(slingId.getBytes("ISO-8859-1"));
+ fout.flush();
+ } catch (Throwable t) {
+ logger.log(Logger.LOG_ERROR, "Failed writing UUID to id file "
+ + idFile, t);
+ } finally {
+ if (fout != null) {
+ try {
+ fout.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+ }
+
+ return slingId;
+ }
+
+ // ---------- 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>${<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;
+ }
+}
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/Sling.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java?rev=651504&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java (added)
+++ incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java Thu Apr 24 23:48:10 2008
@@ -0,0 +1,98 @@
+/*
+ * 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.main;
+
+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;
+
+import org.apache.sling.launcher.app.ResourceProvider;
+import org.apache.sling.launcher.app.Sling;
+
+/**
+ * The <code>ClassLoaderResourceProvider</code> TODO
+ */
+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(Sling.CONFIG_PROPERTIES);
+ 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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.sling.core.launcher.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/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launcher/app/main/ClassLoaderResourceProvider.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url