FELIX-4947 Webconsole plugin for OSGi Subsystems

Honour the 'start' option when installing a new subsystem.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1688820 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/subsystems/src/main/java/org/apache/felix/webconsole/plugins/subsystem/internal/WebConsolePlugin.java b/webconsole-plugins/subsystems/src/main/java/org/apache/felix/webconsole/plugins/subsystem/internal/WebConsolePlugin.java
index 6ed8f08..e902d0e 100644
--- a/webconsole-plugins/subsystems/src/main/java/org/apache/felix/webconsole/plugins/subsystem/internal/WebConsolePlugin.java
+++ b/webconsole-plugins/subsystems/src/main/java/org/apache/felix/webconsole/plugins/subsystem/internal/WebConsolePlugin.java
@@ -146,6 +146,7 @@
         @SuppressWarnings("rawtypes")
         Map params = (Map) req.getAttribute( AbstractWebConsolePlugin.ATTR_FILEUPLOAD );
 
+        final boolean start = getParameter(params, "subsystemstart") != null;
         FileItem[] subsystemItems = getFileItems(params, "subsystemfile");
 
         for (final FileItem subsystemItem : subsystemItems)
@@ -187,7 +188,9 @@
                             InputStream is = new FileInputStream(file);
                             try
                             {
-                                ss.install("inputstream:" + subsystemItem.getName(), is);
+                                Subsystem nss = ss.install("inputstream:" + subsystemItem.getName(), is);
+                                if (start)
+                                    nss.start();
                             }
                             finally
                             {
@@ -277,13 +280,32 @@
     }
 
     @SuppressWarnings("rawtypes")
+    private FileItem getParameter(Map params, String name)
+    {
+        FileItem[] items = (FileItem[]) params.get(name);
+        if (items != null)
+        {
+            for (int i = 0; i < items.length; i++)
+            {
+                if (items[i].isFormField())
+                {
+                    return items[i];
+                }
+            }
+        }
+
+        // nothing found, fail
+        return null;
+    }
+
+    @SuppressWarnings("rawtypes")
     private FileItem[] getFileItems(Map params, String name)
     {
         final List<FileItem> files = new ArrayList<FileItem>();
-        FileItem[] items = (FileItem[]) params.get( name );
-        if ( items != null )
+        FileItem[] items = (FileItem[]) params.get(name);
+        if (items != null)
         {
-            for ( int i = 0; i < items.length; i++ )
+            for (int i = 0; i < items.length; i++)
             {
                 if (!items[i].isFormField() && items[i].getSize() > 0)
                 {
@@ -292,7 +314,7 @@
             }
         }
 
-        return files.toArray( new FileItem[files.size()] );
+        return files.toArray(new FileItem[files.size()]);
     }
 
     @Override