Author: cziegeler
Date: Fri Aug 13 11:30:39 2010
New Revision: 985159

URL: http://svn.apache.org/viewvc?rev=985159&view=rev
Log:
SLING-1651 - Integrate RunMode module into new Settings Module
SLING-983 - Add sling.properties file to configuration status page

Added:
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
   (with props)
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
   (with props)
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
   (with props)
Modified:
    sling/trunk/bundles/engine/pom.xml
    
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
    sling/trunk/bundles/extensions/settings/   (props changed)
    sling/trunk/bundles/extensions/settings/pom.xml
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
    
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java

Modified: sling/trunk/bundles/engine/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/pom.xml?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- sling/trunk/bundles/engine/pom.xml (original)
+++ sling/trunk/bundles/engine/pom.xml Fri Aug 13 11:30:39 2010
@@ -152,7 +152,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>3.0.0</version>
+            <version>1.2.0</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
 (original)
+++ 
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
 Fri Aug 13 11:30:39 2010
@@ -18,26 +18,15 @@
  */
 package org.apache.sling.engine.impl;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.io.PrintWriter;
-import java.net.URL;
 import java.util.Dictionary;
 import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.apache.felix.webconsole.ConfigurationPrinter;
-import org.apache.felix.webconsole.ModeAwareConfigurationPrinter;
 import org.apache.sling.engine.impl.filter.SlingFilterChainHelper;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * This is a configuration printer for the web console which
@@ -46,8 +35,6 @@ import org.slf4j.LoggerFactory;
  */
 public class WebConsoleConfigPrinter implements ConfigurationPrinter {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(WebConsoleConfigPrinter.class);
-
     private final SlingFilterChainHelper requestFilterChain;
     private final SlingFilterChainHelper innerFilterChain;
 
@@ -59,7 +46,6 @@ public class WebConsoleConfigPrinter imp
 
     private static final class Registration {
         public ServiceRegistration filterPlugin;
-        public ServiceRegistration propertiesPlugin;
     }
 
     public static Object register(final BundleContext bundleContext,
@@ -77,33 +63,6 @@ public class WebConsoleConfigPrinter imp
         reg.filterPlugin = 
bundleContext.registerService(ConfigurationPrinter.class.getName(),
                 filterPrinter,
                 serviceProps);
-
-        // if the properties are available, we register the second plugin
-        final String propUrl = 
bundleContext.getProperty("sling.properties.url");
-        if ( propUrl != null ) {
-            // try to read properties
-            Properties props = null;
-            try {
-                final URL url = new URL(propUrl);
-                final InputStream is = url.openStream();
-                final Properties tmp = new Properties();
-                tmp.load(is);
-                props = tmp;
-            } catch (IOException ioe) {
-                LOGGER.warn("Unable to read sling properties from " + propUrl, 
ioe);
-            }
-            if ( props != null ) {
-                final PropsPlugin propertiesPrinter = new PropsPlugin(props);
-                final Dictionary<String, String> serviceProps2 = new 
Hashtable<String, String>();
-                serviceProps2.put(Constants.SERVICE_DESCRIPTION,
-                    "Apache Sling Sling Properties Configuration Printer");
-                serviceProps2.put(Constants.SERVICE_VENDOR, "The Apache 
Software Foundation");
-
-                reg.propertiesPlugin = 
bundleContext.registerService(ConfigurationPrinter.class.getName(),
-                        propertiesPrinter,
-                        serviceProps2);
-            }
-        }
         return reg;
     }
 
@@ -114,10 +73,6 @@ public class WebConsoleConfigPrinter imp
                 registration.filterPlugin.unregister();
                 registration.filterPlugin = null;
             }
-            if ( registration.propertiesPlugin != null) {
-                registration.propertiesPlugin.unregister();
-                registration.propertiesPlugin = null;
-            }
         }
     }
 
@@ -160,61 +115,4 @@ public class WebConsoleConfigPrinter imp
         pw.println("Component Filters:");
         printFilterChain(pw, innerFilterChain.getFilterListEntries());
     }
-
-    public static final class PropsPlugin implements 
ModeAwareConfigurationPrinter {
-
-        private static String HEADLINE = "Apache Sling Launchpad Properties";
-
-        private final Properties props;
-
-        public PropsPlugin(final Properties props) {
-            this.props = props;
-        }
-
-        /**
-         * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
-         */
-        public String getTitle() {
-            return "Sling Properties";
-        }
-
-        /**
-         * Print out the servlet filter chains.
-         * @see 
org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
-         */
-        public void printConfiguration(PrintWriter pw) {
-            pw.println(HEADLINE);
-            pw.println();
-            SortedSet<Object> keys = new TreeSet<Object>( props.keySet() );
-            for ( Iterator<Object> ki = keys.iterator(); ki.hasNext(); ) {
-                final Object key = ki.next();
-                pw.print( key );
-                pw.print(" = ");
-                final Object value = props.get(key);
-                if ( value != null ) {
-                    pw.print(value.toString());
-                }
-                pw.println();
-            }
-        }
-
-        public void printConfiguration(PrintWriter printWriter, String mode) {
-            if ( mode != ConfigurationPrinter.MODE_ZIP ) {
-                this.printConfiguration(printWriter);
-            } else {
-                // write into byte array first
-                String contents = null;
-                try {
-                    final ByteArrayOutputStream baos = new 
ByteArrayOutputStream();
-                    this.props.store(baos , HEADLINE);
-                    contents = baos.toString("8859_1");
-                } catch (IOException ioe) {
-                    // if something goes wrong here we default to text output
-                    this.printConfiguration(printWriter);
-                    return;
-                }
-                printWriter.write(contents);
-            }
-        }
-    }
 }

Propchange: sling/trunk/bundles/extensions/settings/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug 13 11:30:39 2010
@@ -0,0 +1 @@
+target

Modified: sling/trunk/bundles/extensions/settings/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/pom.xml?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/pom.xml (original)
+++ sling/trunk/bundles/extensions/settings/pom.xml Fri Aug 13 11:30:39 2010
@@ -89,11 +89,13 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.shell</artifactId>
             <version>1.0.0</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>1.2.0</version>
+            <version>3.0.0</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>

Modified: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
 (original)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/SlingSettingsService.java
 Fri Aug 13 11:30:39 2010
@@ -19,10 +19,16 @@
 package org.apache.sling.settings;
 
 import java.net.URL;
+import java.util.Set;
 
 /**
  * The <code>SlingSettingsService</code> provides basic Sling settings.
+ * - Sling home : If the Sling launchpad is used
+ * - Sling Id : A unique id of the installation
  *
+ * Run Mode Support
+ * A run mode is simply a string like "author", "test", "development",...
+ * The server can have a set of active run modes.
  */
 public interface SlingSettingsService {
 
@@ -55,6 +61,14 @@ public interface SlingSettingsService {
     String SLING_HOME_URL = "sling.home.url";
 
     /**
+     * The name of the framework property defining the set of used
+     * run modes.
+     * The value is a comma separated list of run modes.
+     */
+    String RUN_MODES_PROPERTY = "sling.run.modes";
+
+
+    /**
      * The identifier of the running Sling instance.
      */
     String getSlingId();
@@ -70,4 +84,12 @@ public interface SlingSettingsService {
      * property.
      */
     URL getSlingHome();
+
+    /**
+     * Return the set of activate run modes.
+     * This set might be empty.
+     * @return A non modifiable set of run modes.
+     */
+    Set<String> getRunModes();
+
 }

Modified: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
 (original)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/Activator.java
 Fri Aug 13 11:30:39 2010
@@ -41,7 +41,7 @@ public class Activator implements Bundle
      * @see 
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
     public void start(BundleContext context) throws Exception {
-        final Object service = new SlingSettingsServiceImpl(context);
+        final SlingSettingsService service = new 
SlingSettingsServiceImpl(context);
         final Dictionary<String, String> props = new Hashtable<String, 
String>();
         props.put(Constants.SERVICE_PID, service.getClass().getName());
         props.put(Constants.SERVICE_DESCRIPTION,
@@ -50,12 +50,42 @@ public class Activator implements Bundle
         serviceRegistration = context.registerService(new String[] {
                                                
SlingSettingsService.class.getName()},
                                            service, props);
+        try {
+            SlingPropertiesPrinter.initPlugin(context);
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingSettingsPrinter.initPlugin(context, service);
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            RunModeCommand.initPlugin(context, service.getRunModes());
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
     }
 
     /**
      * @see 
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
      */
     public void stop(BundleContext context) throws Exception {
+        try {
+            RunModeCommand.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingSettingsPrinter.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
+        try {
+            SlingPropertiesPrinter.destroyPlugin();
+        } catch (Throwable ignore) {
+            // we just ignore this
+        }
         if ( serviceRegistration != null ) {
             serviceRegistration.unregister();
             serviceRegistration = null;

Added: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java?rev=985159&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
 (added)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
 Fri Aug 13 11:30:39 2010
@@ -0,0 +1,101 @@
+/*
+ * 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.settings.impl;
+
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Set;
+
+import org.apache.felix.shell.Command;
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Run mode command for the shell.
+ */
+public class RunModeCommand implements Command {
+
+    private static ServiceRegistration pluginReg;
+
+    public static void initPlugin(final BundleContext bundleContext,
+            final Set<String> modes) {
+        final RunModeCommand command = new RunModeCommand(modes);
+
+        final Dictionary<String, String> props = new Hashtable<String, 
String>();
+        props.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Sling Run Mode Shell Command");
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        pluginReg = 
bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                command,
+                props);
+    }
+
+    public static void destroyPlugin() {
+        if ( pluginReg != null) {
+            pluginReg.unregister();
+            pluginReg = null;
+        }
+    }
+
+    private static final String CMD_NAME = "runmodes";
+
+    /** @scr.reference */
+    private Set<String> modes;
+
+    public RunModeCommand(final Set<String> modes) {
+        this.modes = modes;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getName()
+     */
+    public String getName() {
+        return CMD_NAME;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getShortDescription()
+     */
+    public String getShortDescription() {
+        return "lists current run modes";
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#getUsage()
+     */
+    public String getUsage() {
+        return CMD_NAME;
+    }
+
+    /**
+     * @see org.apache.felix.shell.Command#execute(java.lang.String, 
java.io.PrintStream, java.io.PrintStream)
+     */
+    public void execute(String command, PrintStream out, PrintStream err) {
+        out.print("Current Run Modes: ");
+        if (modes == null || modes.size() == 0) {
+            out.println("-");
+        } else {
+            out.println(modes);
+        }
+    }
+}

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/RunModeCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java?rev=985159&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
 (added)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
 Fri Aug 13 11:30:39 2010
@@ -0,0 +1,144 @@
+/*
+ * 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.settings.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.ModeAwareConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is a configuration printer for the web console which
+ * prints out the Sling properties from Launchpad if available.
+ *
+ */
+public class SlingPropertiesPrinter implements ModeAwareConfigurationPrinter {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SlingPropertiesPrinter.class);
+
+    private static ServiceRegistration propertiesPlugin;
+
+    public static void initPlugin(final BundleContext bundleContext) {
+        // if the properties are available, we register the sling properties 
plugin
+        final String propUrl = 
bundleContext.getProperty("sling.properties.url");
+        if ( propUrl != null ) {
+            // try to read properties
+            Properties props = null;
+            try {
+                final URL url = new URL(propUrl);
+                final InputStream is = url.openStream();
+                final Properties tmp = new Properties();
+                tmp.load(is);
+                props = tmp;
+            } catch (IOException ioe) {
+                LOGGER.warn("Unable to read sling properties from " + propUrl, 
ioe);
+            }
+            if ( props != null ) {
+                final SlingPropertiesPrinter propertiesPrinter = new 
SlingPropertiesPrinter(props);
+                final Dictionary<String, String> serviceProps2 = new 
Hashtable<String, String>();
+                serviceProps2.put(Constants.SERVICE_DESCRIPTION,
+                    "Apache Sling Sling Properties Configuration Printer");
+                serviceProps2.put(Constants.SERVICE_VENDOR, "The Apache 
Software Foundation");
+
+                propertiesPlugin = 
bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                        propertiesPrinter,
+                        serviceProps2);
+            }
+        }
+    }
+
+    public static void destroyPlugin() {
+        if ( propertiesPlugin != null) {
+            propertiesPlugin.unregister();
+            propertiesPlugin = null;
+        }
+    }
+
+    private static String HEADLINE = "Apache Sling Launchpad Properties";
+
+    private final Properties props;
+
+    public SlingPropertiesPrinter(final Properties props) {
+        this.props = props;
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Sling Properties";
+    }
+
+    /**
+     * Print out the servlet filter chains.
+     * @see 
org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter pw) {
+        pw.println(HEADLINE);
+        pw.println();
+        SortedSet<Object> keys = new TreeSet<Object>( props.keySet() );
+        for ( Iterator<Object> ki = keys.iterator(); ki.hasNext(); ) {
+            final Object key = ki.next();
+            pw.print( key );
+            pw.print(" = ");
+            final Object value = props.get(key);
+            if ( value != null ) {
+                pw.print(value.toString());
+            }
+            pw.println();
+        }
+    }
+
+    /**
+     * @see 
org.apache.felix.webconsole.ModeAwareConfigurationPrinter#printConfiguration(java.io.PrintWriter,
 java.lang.String)
+     */
+    public void printConfiguration(PrintWriter printWriter, String mode) {
+        if ( mode != ConfigurationPrinter.MODE_ZIP ) {
+            this.printConfiguration(printWriter);
+        } else {
+            // write into byte array first
+            String contents = null;
+            try {
+                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                this.props.store(baos , HEADLINE);
+                contents = baos.toString("8859_1");
+            } catch (IOException ioe) {
+                // if something goes wrong here we default to text output
+                this.printConfiguration(printWriter);
+                return;
+            }
+            printWriter.write(contents);
+        }
+    }
+}

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingPropertiesPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java?rev=985159&view=auto
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
 (added)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
 Fri Aug 13 11:30:39 2010
@@ -0,0 +1,96 @@
+/*
+ * 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.settings.impl;
+
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.sling.settings.SlingSettingsService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This is a configuration printer for the web console which
+ * prints out the sling settings.
+ *
+ */
+public class SlingSettingsPrinter implements ConfigurationPrinter {
+
+    private static ServiceRegistration pluginReg;
+
+    public static void initPlugin(final BundleContext bundleContext,
+            final SlingSettingsService service) {
+        final SlingSettingsPrinter printer = new SlingSettingsPrinter(service);
+
+        final Dictionary<String, String> props = new Hashtable<String, 
String>();
+        props.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Sling Settings Configuration Printer");
+        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        pluginReg = 
bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                printer,
+                props);
+    }
+
+    public static void destroyPlugin() {
+        if ( pluginReg != null) {
+            pluginReg.unregister();
+            pluginReg = null;
+        }
+    }
+
+    private static String HEADLINE = "Apache Sling Settings";
+
+    private final SlingSettingsService settings;
+
+    public SlingSettingsPrinter(final SlingSettingsService settings) {
+        this.settings = settings;
+    }
+
+    /**
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Sling Settings";
+    }
+
+    /**
+     * Print out the servlet filter chains.
+     * @see 
org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter pw) {
+        pw.println(HEADLINE);
+        pw.println();
+        pw.print("Sling ID = ");
+        pw.print(this.settings.getSlingId());
+        pw.println();
+        pw.print("Sling Home = ");
+        pw.print(this.settings.getSlingHomePath());
+        pw.println();
+        pw.print("Sling Home URL = ");
+        pw.print(this.settings.getSlingHome());
+        pw.println();
+        pw.print("Run Modes = ");
+        pw.print(this.settings.getRunModes());
+        pw.println();
+    }
+}

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java?rev=985159&r1=985158&r2=985159&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
 (original)
+++ 
sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
 Fri Aug 13 11:30:39 2010
@@ -24,6 +24,9 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 
 import org.apache.sling.settings.SlingSettingsService;
@@ -45,20 +48,33 @@ public class SlingSettingsServiceImpl
     private String slingId;
 
     /** The sling home */
-    private final String slingHome;
+    private String slingHome;
 
     /** The sling home url */
     private URL slingHomeUrl;
 
+    private Set<String> runModes;
+
+    /** The name of the data file holding the sling id. */
     private static final String DATA_FILE = "sling.id.file";
 
     /**
      * Create the service and search the Sling home urls and
      * get/create a sling id.
+     * Setup run modes
      * @param context The bundle context
      */
     public SlingSettingsServiceImpl(final BundleContext context) {
-        // get sling home and sling home url
+        this.setupSlingHome(context);
+        this.setupSlingId(context);
+        this.setupRunModes(context);
+
+    }
+
+    /**
+     * Get sling home and sling home url
+     */
+    private void setupSlingHome(final BundleContext context) {
         this.slingHome = context.getProperty(SLING_HOME);
         final String url = context.getProperty(SLING_HOME_URL);
         if ( url != null ) {
@@ -68,7 +84,12 @@ public class SlingSettingsServiceImpl
                 logger.error("Sling home url is not a url: {}", url);
             }
         }
+    }
 
+    /**
+     * Get / create sling id
+     */
+    private void setupSlingId(final BundleContext context) {
         // try to read the id from the id file first
         final File idFile = context.getDataFile(DATA_FILE);
         if ( idFile == null ) {
@@ -98,7 +119,30 @@ public class SlingSettingsServiceImpl
         }
     }
 
-    /** Read the id from a file. */
+    /**
+     * Set up run modes.
+     */
+    private void setupRunModes(final BundleContext context) {
+        final String prop = context.getProperty(RUN_MODES_PROPERTY);
+        if (prop == null || prop.trim().length() == 0) {
+            this.runModes = Collections.emptySet();
+        } else {
+            final Set<String> modesSet = new HashSet<String>();
+            final String[] modes = prop.split(",");
+            for(int i=0; i < modes.length; i++) {
+                modesSet.add(modes[i].trim());
+            }
+            // make the set unmodifiable and synced
+            // we propably don't need a synced set as it is read only
+            this.runModes = 
Collections.synchronizedSet(Collections.unmodifiableSet(modesSet));
+            logger.info("Active run modes {}", this.runModes);
+        }
+    }
+
+
+    /**
+     * Read the id from a file.
+     */
     private String readSlingId(final File idFile) {
         if (idFile.exists() && idFile.length() >= 36) {
             FileInputStream fin = null;
@@ -129,7 +173,9 @@ public class SlingSettingsServiceImpl
         return null;
     }
 
-    /** Write the sling id file. */
+    /**
+     * Write the sling id file.
+     */
     private void writeSlingId(final File idFile, final String id) {
         idFile.delete();
         idFile.getParentFile().mkdirs();
@@ -181,4 +227,11 @@ public class SlingSettingsServiceImpl
     public String getSlingHomePath() {
         return this.slingHome;
     }
+
+    /**
+     * @see org.apache.sling.settings.SlingSettingsService#getRunModes()
+     */
+    public Set<String> getRunModes() {
+        return this.runModes;
+    }
 }


Reply via email to