FELIX-3111 : Separate OBR Plugin
FELIX-3107 : Separate Shell Plugin
FELIX-3099 : Separate Deployment Admin plugin
FELIX-3100 : Separate SCR plugin
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1169777 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java
new file mode 100644
index 0000000..ae665c9
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Activator.java
@@ -0,0 +1,110 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * Activator is the main starting class.
+ */
+public class Activator implements BundleActivator, ServiceTrackerCustomizer
+{
+
+ private ServiceTracker tracker;
+ private BundleContext context;
+
+ private SimpleWebConsolePlugin plugin;
+ private ServiceRegistration printerRegistration;
+
+ /**
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public final void start(BundleContext context) throws Exception
+ {
+ this.context = context;
+ this.tracker = new ServiceTracker(context, WebConsolePlugin.SCR_SERVICE, this);
+ this.tracker.open();
+ }
+
+ /**
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public final void stop(BundleContext context) throws Exception
+ {
+ if (tracker != null)
+ {
+ tracker.close();
+ tracker = null;
+ }
+ }
+
+ // - begin tracker
+ /**
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
+ */
+ public final void modifiedService(ServiceReference reference, Object service)
+ {/* unused */
+ }
+
+ /**
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
+ */
+ public final Object addingService(ServiceReference reference)
+ {
+ SimpleWebConsolePlugin plugin = this.plugin;
+ if (plugin == null)
+ {
+ this.plugin = plugin = new WebConsolePlugin().register(context);
+ printerRegistration = context.registerService(ConfigurationPrinter.SERVICE,
+ new ComponentConfigurationPrinter(context.getService(reference)), null);
+ }
+
+ return context.getService(reference);
+ }
+
+ /**
+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
+ * java.lang.Object)
+ */
+ public final void removedService(ServiceReference reference, Object service)
+ {
+ SimpleWebConsolePlugin plugin = this.plugin;
+
+ if (tracker.getTrackingCount() == 0 && plugin != null)
+ {
+ // remove service
+ plugin.unregister();
+ this.plugin = null;
+ // unregister configuration printer too
+ ServiceRegistration reg = printerRegistration;
+ if (reg != null)
+ {
+ reg.unregister();
+ printerRegistration = null;
+ }
+ }
+
+ }
+}
diff --git a/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java
new file mode 100644
index 0000000..8c85813
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ComponentConfigurationPrinter.java
@@ -0,0 +1,245 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.Reference;
+import org.apache.felix.scr.ScrService;
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.WebConsoleUtil;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentConstants;
+
+/**
+ * ComponentConfigurationPrinter prints the available SCR services.
+ */
+class ComponentConfigurationPrinter implements ConfigurationPrinter
+{
+
+ private final ScrService scrService;
+
+ ComponentConfigurationPrinter(Object scrService)
+ {
+ this.scrService = (ScrService)scrService;
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+ */
+ public String getTitle()
+ {
+ return "Declarative Services Components";
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+ */
+ public void printConfiguration(PrintWriter pw)
+ {
+ printComponents(pw, scrService.getComponents());
+ }
+
+ private static final void printComponents(final PrintWriter pw,
+ final Component[] components)
+ {
+ if (components == null || components.length == 0)
+ {
+ pw.println(" No Components Registered");
+ }
+ else
+ {
+ // order components by id
+ TreeMap componentMap = new TreeMap();
+ for (int i = 0; i < components.length; i++)
+ {
+ Component component = components[i];
+ componentMap.put(new Long(component.getId()), component);
+ }
+
+ // render components
+ for (Iterator ci = componentMap.values().iterator(); ci.hasNext();)
+ {
+ Component component = (Component) ci.next();
+ component(pw, component);
+ }
+ }
+ }
+
+ private static final void component(PrintWriter pw, Component component)
+ {
+
+ pw.print(component.getId());
+ pw.print("=[");
+ pw.print(component.getName());
+ pw.println("]");
+
+ pw.println(" Bundle" + component.getBundle().getSymbolicName() + " ("
+ + component.getBundle().getBundleId() + ")");
+ pw.println(" State=" + toStateString(component.getState()));
+ pw.println(" DefaultState="
+ + (component.isDefaultEnabled() ? "enabled" : "disabled"));
+ pw.println(" Activation=" + (component.isImmediate() ? "immediate" : "delayed"));
+
+ listServices(pw, component);
+ listReferences(pw, component);
+ listProperties(pw, component);
+
+ pw.println();
+ }
+
+ private static void listServices(PrintWriter pw, Component component)
+ {
+ String[] services = component.getServices();
+ if (services == null)
+ {
+ return;
+ }
+
+ pw.println(" ServiceType="
+ + (component.isServiceFactory() ? "service factory" : "service"));
+
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < services.length; i++)
+ {
+ if (i > 0)
+ {
+ buf.append(", ");
+ }
+ buf.append(services[i]);
+ }
+
+ pw.println(" Services=" + buf);
+ }
+
+ private static final void listReferences(PrintWriter pw, Component component)
+ {
+ Reference[] refs = component.getReferences();
+ if (refs != null)
+ {
+ for (int i = 0; i < refs.length; i++)
+ {
+
+ pw.println(" Reference=" + refs[i].getName() + ", "
+ + (refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied"));
+
+ pw.println(" Service Name: " + refs[i].getServiceName());
+
+ if (refs[i].getTarget() != null)
+ {
+ pw.println(" Target Filter: " + refs[i].getTarget());
+ }
+
+ pw.println(" Multiple: "
+ + (refs[i].isMultiple() ? "multiple" : "single"));
+ pw.println(" Optional: "
+ + (refs[i].isOptional() ? "optional" : "mandatory"));
+ pw.println(" Policy: " + (refs[i].isStatic() ? "static" : "dynamic"));
+
+ // list bound services
+ ServiceReference[] boundRefs = refs[i].getServiceReferences();
+ if (boundRefs != null && boundRefs.length > 0)
+ {
+ for (int j = 0; j < boundRefs.length; j++)
+ {
+ pw.print(" Bound Service: ID ");
+ pw.print(boundRefs[j].getProperty(Constants.SERVICE_ID));
+
+ String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
+ if (name == null)
+ {
+ name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
+ if (name == null)
+ {
+ name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
+ }
+ }
+ if (name != null)
+ {
+ pw.print(" (");
+ pw.print(name);
+ pw.print(")");
+ }
+ pw.println();
+ }
+ }
+ else
+ {
+ pw.println(" No Services bound");
+ }
+ }
+ }
+ }
+
+ private static final void listProperties(PrintWriter pw, Component component)
+ {
+ Dictionary props = component.getProperties();
+ if (props != null)
+ {
+
+ pw.println(" Properties=");
+ TreeSet keys = new TreeSet(Util.list(props.keys()));
+ for (Iterator ki = keys.iterator(); ki.hasNext();)
+ {
+ String key = (String) ki.next();
+ Object value = props.get(key);
+ value = WebConsoleUtil.toString(value);
+ if (value.getClass().isArray())
+ {
+ value = Arrays.asList((Object[]) value);
+ }
+ pw.println(" " + key + "=" + value);
+ }
+ }
+ }
+
+ static final String toStateString(int state)
+ {
+ switch (state)
+ {
+ case Component.STATE_DISABLED:
+ return "disabled";
+ case Component.STATE_ENABLED:
+ return "enabled";
+ case Component.STATE_UNSATISFIED:
+ return "unsatisfied";
+ case Component.STATE_ACTIVATING:
+ return "activating";
+ case Component.STATE_ACTIVE:
+ return "active";
+ case Component.STATE_REGISTERED:
+ return "registered";
+ case Component.STATE_FACTORY:
+ return "factory";
+ case Component.STATE_DEACTIVATING:
+ return "deactivating";
+ case Component.STATE_DESTROYED:
+ return "destroyed";
+ default:
+ return String.valueOf(state);
+ }
+ }
+}
diff --git a/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java
new file mode 100644
index 0000000..8e96845
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/Util.java
@@ -0,0 +1,66 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Enumeration;
+
+import org.apache.felix.scr.Component;
+
+class Util
+{
+
+ static final Comparator COMPONENT_COMPARATOR = new Comparator()
+ {
+ public int compare(Object o0, Object o1)
+ {
+ final Component c0 = (Component) o0;
+ final Component c1 = (Component) o1;
+ final int nameCmp = c0.getName().compareTo(c1.getName());
+ if (nameCmp != 0)
+ {
+ return nameCmp;
+ }
+ return (c0.getId() < c1.getId()) ? -1 : ((c0.getId() > c1.getId()) ? 1 : 0);
+ }
+ };
+
+ private Util()
+ {
+ // prevent instantiation
+ }
+
+ /**
+ * This method is the same as Collections#list(Enumeration). The reason to
+ * duplicate it here, is that it is missing in OSGi/Minimum execution
+ * environment.
+ *
+ * @param e the enumeration which to convert
+ * @return the list containing all enumeration entries.
+ */
+ public static final ArrayList list(Enumeration e)
+ {
+ ArrayList l = new ArrayList();
+ while (e.hasMoreElements())
+ {
+ l.add(e.nextElement());
+ }
+ return l;
+ }
+
+}
diff --git a/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
new file mode 100644
index 0000000..4af5c48
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
@@ -0,0 +1,620 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.Reference;
+import org.apache.felix.scr.ScrService;
+import org.apache.felix.webconsole.DefaultVariableResolver;
+import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleUtil;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONWriter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.metatype.MetaTypeInformation;
+import org.osgi.service.metatype.MetaTypeService;
+
+/**
+ * ComponentsServlet provides a plugin for managing Service Components Runtime.
+ */
+class WebConsolePlugin extends SimpleWebConsolePlugin
+{
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String LABEL = "components"; //$NON-NLS-1$
+ private static final String TITLE = "%components.pluginTitle"; //$NON-NLS-1$
+ private static final String CSS[] = { "/res/ui/bundles.css" }; // yes, it's correct! //$NON-NLS-1$
+ private static final String RES = "/" + LABEL + "/res/"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ // actions
+ private static final String OPERATION = "action"; //$NON-NLS-1$
+ private static final String OPERATION_ENABLE = "enable"; //$NON-NLS-1$
+ private static final String OPERATION_DISABLE = "disable"; //$NON-NLS-1$
+ //private static final String OPERATION_CONFIGURE = "configure";
+
+ // needed services
+ static final String SCR_SERVICE = "org.apache.felix.scr.ScrService"; //$NON-NLS-1$
+ private static final String META_TYPE_NAME = "org.osgi.service.metatype.MetaTypeService"; //$NON-NLS-1$
+ private static final String CONFIGURATION_ADMIN_NAME = "org.osgi.service.cm.ConfigurationAdmin"; //$NON-NLS-1$
+
+ // templates
+ private final String TEMPLATE;
+
+ /** Default constructor */
+ WebConsolePlugin()
+ {
+ super(LABEL, TITLE, CSS);
+
+ // load templates
+ TEMPLATE = readTemplateFile("/res/plugin.html"); //$NON-NLS-1$
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException
+ {
+ final RequestInfo reqInfo = new RequestInfo(request);
+ if (reqInfo.component == null && reqInfo.componentRequested)
+ {
+ response.sendError(404);
+ return;
+ }
+ if (!reqInfo.componentRequested)
+ {
+ response.sendError(500);
+ return;
+ }
+ String op = request.getParameter(OPERATION);
+ if (OPERATION_ENABLE.equals(op))
+ {
+ reqInfo.component.enable();
+ }
+ else if (OPERATION_DISABLE.equals(op))
+ {
+ reqInfo.component.disable();
+ }
+
+ final PrintWriter pw = response.getWriter();
+ response.setContentType("application/json"); //$NON-NLS-1$
+ response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+ renderResult(pw, null);
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ String path = request.getPathInfo();
+ // don't process if this is request to load a resource
+ if (!path.startsWith(RES))
+ {
+ final RequestInfo reqInfo = new RequestInfo(request);
+ if (reqInfo.component == null && reqInfo.componentRequested)
+ {
+ response.sendError(404);
+ return;
+ }
+ if (reqInfo.extension.equals("json")) //$NON-NLS-1$
+ {
+ response.setContentType("application/json"); //$NON-NLS-1$
+ response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+
+ this.renderResult(response.getWriter(), reqInfo.component);
+
+ // nothing more to do
+ return;
+ }
+ }
+ super.doGet(request, response);
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ protected void renderContent(HttpServletRequest request, HttpServletResponse response)
+ throws IOException
+ {
+ // get request info from request attribute
+ final RequestInfo reqInfo = getRequestInfo(request);
+
+ StringWriter w = new StringWriter();
+ PrintWriter w2 = new PrintWriter(w);
+ renderResult(w2, reqInfo.component);
+
+ // prepare variables
+ DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
+ vars.put("__drawDetails__", reqInfo.componentRequested ? Boolean.TRUE : Boolean.FALSE); //$NON-NLS-1$
+ vars.put("__data__", w.toString()); //$NON-NLS-1$
+
+ response.getWriter().print(TEMPLATE);
+
+ }
+
+ private void renderResult(final PrintWriter pw, final Component component)
+ throws IOException
+ {
+ final JSONWriter jw = new JSONWriter(pw);
+ try
+ {
+ jw.object();
+
+ final ScrService scrService = getScrService();
+ if (scrService == null)
+ {
+ jw.key("status"); //$NON-NLS-1$
+ jw.value(-1);
+ }
+ else
+ {
+ final Component[] components = scrService.getComponents();
+
+ if (components == null || components.length == 0)
+ {
+ jw.key("status"); //$NON-NLS-1$
+ jw.value(0);
+ }
+ else
+ {
+ // order components by name
+ sortComponents(components);
+
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append(components.length);
+ buffer.append(" component"); //$NON-NLS-1$
+ if (components.length != 1)
+ {
+ buffer.append('s');
+ }
+ buffer.append(" installed."); //$NON-NLS-1$
+ jw.key("status"); //$NON-NLS-1$
+ jw.value(components.length);
+
+ // render components
+ jw.key("data"); //$NON-NLS-1$
+ jw.array();
+ if (component != null)
+ {
+ component(jw, component, true);
+ }
+ else
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ component(jw, components[i], false);
+ }
+ }
+ jw.endArray();
+ }
+ }
+
+ jw.endObject();
+ }
+ catch (JSONException je)
+ {
+ throw new IOException(je.toString());
+ }
+ }
+
+ private void sortComponents(Component[] components)
+ {
+ Arrays.sort(components, Util.COMPONENT_COMPARATOR);
+ }
+
+ private void component(JSONWriter jw, Component component, boolean details)
+ throws JSONException
+ {
+ String id = String.valueOf(component.getId());
+ String name = component.getName();
+ int state = component.getState();
+
+ jw.object();
+
+ // component information
+ jw.key("id"); //$NON-NLS-1$
+ jw.value(id);
+ jw.key("name"); //$NON-NLS-1$
+ jw.value(name);
+ jw.key("state"); //$NON-NLS-1$
+ jw.value(ComponentConfigurationPrinter.toStateString(state));
+ jw.key("stateRaw"); //$NON-NLS-1$
+ jw.value(state);
+
+ final Dictionary props = component.getProperties();
+
+ final String pid = (String) (props != null ? props.get(Constants.SERVICE_PID)
+ : null);
+ if (pid != null)
+ {
+ jw.key("pid"); //$NON-NLS-1$
+ jw.value(pid);
+ if (isConfigurable(component.getBundle(), pid))
+ {
+ jw.key("configurable"); //$NON-NLS-1$
+ jw.value(pid);
+ }
+ }
+
+ // component details
+ if (details)
+ {
+ gatherComponentDetails(jw, component);
+ }
+
+ jw.endObject();
+ }
+
+ private void gatherComponentDetails(JSONWriter jw, Component component)
+ throws JSONException
+ {
+ jw.key("props"); //$NON-NLS-1$
+ jw.array();
+
+ keyVal(jw, "Bundle", component.getBundle().getSymbolicName() + " ("
+ + component.getBundle().getBundleId() + ")");
+ keyVal(jw, "Implementation Class", component.getClassName());
+ if (component.getFactory() != null)
+ {
+ keyVal(jw, "Component Factory Name", component.getFactory());
+ }
+ keyVal(jw, "Default State", component.isDefaultEnabled() ? "enabled" : "disabled");
+ keyVal(jw, "Activation", component.isImmediate() ? "immediate" : "delayed");
+
+ try
+ {
+ keyVal(jw, "Configuration Policy", component.getConfigurationPolicy());
+ }
+ catch (Throwable t)
+ {
+ // missing implementation of said method in the actually bound API
+ // ignore this and just don't display the information
+ }
+
+ listServices(jw, component);
+ listReferences(jw, component);
+ listProperties(jw, component);
+
+ jw.endArray();
+ }
+
+ private void listServices(JSONWriter jw, Component component)
+ {
+ String[] services = component.getServices();
+ if (services == null)
+ {
+ return;
+ }
+
+ keyVal(jw, "Service Type", component.isServiceFactory() ? "service factory"
+ : "service");
+
+ JSONArray buf = new JSONArray();
+ for (int i = 0; i < services.length; i++)
+ {
+ buf.put(services[i]);
+ }
+
+ keyVal(jw, "Services", buf);
+ }
+
+ private void listReferences(JSONWriter jw, Component component)
+ {
+ Reference[] refs = component.getReferences();
+ if (refs != null)
+ {
+ for (int i = 0; i < refs.length; i++)
+ {
+ JSONArray buf = new JSONArray();
+ buf.put(refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied");
+ buf.put("Service Name: " + refs[i].getServiceName());
+ if (refs[i].getTarget() != null)
+ {
+ buf.put("Target Filter: " + refs[i].getTarget());
+ }
+ buf.put("Multiple: " + (refs[i].isMultiple() ? "multiple" : "single"));
+ buf.put("Optional: " + (refs[i].isOptional() ? "optional" : "mandatory"));
+ buf.put("Policy: " + (refs[i].isStatic() ? "static" : "dynamic"));
+
+ // list bound services
+ ServiceReference[] boundRefs = refs[i].getServiceReferences();
+ if (boundRefs != null && boundRefs.length > 0)
+ {
+ for (int j = 0; j < boundRefs.length; j++)
+ {
+ final StringBuffer b = new StringBuffer();
+ b.append("Bound Service ID ");
+ b.append(boundRefs[j].getProperty(Constants.SERVICE_ID));
+
+ String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
+ if (name == null)
+ {
+ name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
+ if (name == null)
+ {
+ name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
+ }
+ }
+ if (name != null)
+ {
+ b.append(" (");
+ b.append(name);
+ b.append(")");
+ }
+ buf.put(b.toString());
+ }
+ }
+ else
+ {
+ buf.put("No Services bound");
+ }
+
+ keyVal(jw, "Reference " + refs[i].getName(), buf.toString());
+ }
+ }
+ }
+
+ private void listProperties(JSONWriter jw, Component component)
+ {
+ Dictionary props = component.getProperties();
+ if (props != null)
+ {
+ JSONArray buf = new JSONArray();
+ TreeSet keys = new TreeSet(Util.list(props.keys()));
+ for (Iterator ki = keys.iterator(); ki.hasNext();)
+ {
+ final String key = (String) ki.next();
+ final StringBuffer b = new StringBuffer();
+ b.append(key).append(" = ");
+
+ Object prop = props.get(key);
+ prop = WebConsoleUtil.toString(prop);
+ b.append(prop);
+ buf.put(b.toString());
+ }
+
+ keyVal(jw, "Properties", buf);
+ }
+
+ }
+
+ private void keyVal(JSONWriter jw, String key, Object value)
+ {
+ try
+ {
+ WebConsoleUtil.keyVal(jw, key, value);
+ }
+ catch (JSONException je)
+ {
+ // don't care
+ }
+ }
+
+ /**
+ * Check if the component with the specified pid is
+ * configurable
+ * @param providingBundle The Bundle providing the component. This may be
+ * theoretically be <code>null</code>.
+ * @param pid A non null pid
+ * @return <code>true</code> if the component is configurable.
+ */
+ private boolean isConfigurable(final Bundle providingBundle, final String pid)
+ {
+ // we first check if the config admin has something for this pid
+ final ConfigurationAdmin ca = this.getConfigurationAdmin();
+ if (ca != null)
+ {
+ try
+ {
+ // we use listConfigurations to not create configuration
+ // objects persistently without the user providing actual
+ // configuration
+ String filter = '(' + Constants.SERVICE_PID + '=' + pid + ')';
+ Configuration[] configs = ca.listConfigurations(filter);
+ if (configs != null && configs.length > 0)
+ {
+ return true;
+ }
+ }
+ catch (InvalidSyntaxException ise)
+ {
+ // should print message
+ }
+ catch (IOException ioe)
+ {
+ // should print message
+ }
+ }
+ // second check is using the meta type service
+ if (providingBundle != null)
+ {
+ final MetaTypeService mts = this.getMetaTypeService();
+ if (mts != null)
+ {
+ final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
+ if (mti != null)
+ {
+ return mti.getObjectClassDefinition(pid, null) != null;
+ }
+ }
+ }
+ return false;
+ }
+
+ private final ConfigurationAdmin getConfigurationAdmin()
+ {
+ return (ConfigurationAdmin) getService(CONFIGURATION_ADMIN_NAME);
+ }
+
+ final ScrService getScrService()
+ {
+ return (ScrService) getService(SCR_SERVICE);
+ }
+
+ private final MetaTypeService getMetaTypeService()
+ {
+ return (MetaTypeService) getService(META_TYPE_NAME);
+ }
+
+ private final class RequestInfo
+ {
+ public final String extension;
+ public final Component component;
+ public final boolean componentRequested;
+
+ protected RequestInfo(final HttpServletRequest request)
+ {
+ String info = request.getPathInfo();
+ // remove label and starting slash
+ info = info.substring(getLabel().length() + 1);
+
+ // get extension
+ if (info.endsWith(".json")) //$NON-NLS-1$
+ {
+ extension = "json"; //$NON-NLS-1$
+ info = info.substring(0, info.length() - 5);
+ }
+ else
+ {
+ extension = "html"; //$NON-NLS-1$
+ }
+
+ if (info.length() > 1 && info.startsWith("/")) //$NON-NLS-1$
+ {
+ this.componentRequested = true;
+ info = info.substring(1);
+ Component component = getComponentId(info);
+ if (component == null)
+ {
+ component = getComponentByName(info);
+ }
+ this.component = component;
+ }
+ else
+ {
+ this.componentRequested = false;
+ this.component = null;
+ }
+
+ request.setAttribute(WebConsolePlugin.this.getClass().getName(), this);
+ }
+
+ protected Component getComponentId(final String componentIdPar)
+ {
+ final ScrService scrService = getScrService();
+ if (scrService != null)
+ {
+ try
+ {
+ final long componentId = Long.parseLong(componentIdPar);
+ return scrService.getComponent(componentId);
+ }
+ catch (NumberFormatException nfe)
+ {
+ // don't care
+ }
+ }
+
+ return null;
+ }
+
+ protected Component getComponentByName(final String names)
+ {
+ if (names.length() > 0)
+ {
+ final ScrService scrService = getScrService();
+ if (scrService != null)
+ {
+
+ final int slash = names.lastIndexOf('/');
+ final String componentName;
+ final String pid;
+ if (slash > 0)
+ {
+ componentName = names.substring(0, slash);
+ pid = names.substring(slash + 1);
+ }
+ else
+ {
+ componentName = names;
+ pid = null;
+ }
+
+ Component[] components;
+ try
+ {
+ components = scrService.getComponents(componentName);
+ }
+ catch (Throwable t)
+ {
+ // not implemented in the used API version
+ components = null;
+ }
+
+ if (components != null)
+ {
+ if (pid != null)
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ Component component = components[i];
+ if (pid.equals(component.getProperties().get(
+ Constants.SERVICE_PID)))
+ {
+ return component;
+ }
+ }
+ }
+ else if (components.length > 0)
+ {
+ return components[0];
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+ }
+
+ static RequestInfo getRequestInfo(final HttpServletRequest request)
+ {
+ return (RequestInfo) request.getAttribute(WebConsolePlugin.class.getName());
+ }
+}
diff --git a/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
new file mode 100644
index 0000000..33732de
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
@@ -0,0 +1,49 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+# native2ascii -encoding utf-8 bundle_bg.raw_properties bundle_bg.properties
+
+# Components plugin
+components.pluginTitle=Компоненти
+scr.status.no_service=Declarative Service не е наличен!
+scr.status.no_components=Няма инсталирани компонент в момента!
+scr.status.ok=Брой инсталирани компоненти: {0}
+scr.action.enable=Enable
+scr.action.disable=Disable
+scr.action.configure=Конфигуриране
+scr.prop.bundle=Бъндъл
+scr.prop.defstate=Статус по подразбиране
+scr.prop.activation=Активация
+scr.prop.properties=Конфигурации
+scr.prop.class=Implementation Class
+scr.prop.componentfactory=Component Factory име
+scr.prop.configurationpolicy=Конфигурационна политика
+scr.serv.type=Тип на услугата
+scr.serv=Услуги
+scr.title.actions=Действия
+scr.title.status=Статус
+scr.title.name=Име
diff --git a/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
new file mode 100644
index 0000000..4165c7a
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_de.properties
@@ -0,0 +1,49 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+
+# Components plugin
+components.pluginTitle=Komponenten
+scr.status.no_service=Declarative Service ist Voraussetzung für diese Funktionalität!
+scr.status.no_components=Zur Zeit sind keine Komponenten installiert!
+scr.status.ok=Anzahl installierter Komponenten: {0}
+scr.action.enable=Aktivieren
+scr.action.disable=Deaktivieren
+scr.action.configure=Konfigurieren
+scr.prop.bundle=Bundle
+scr.prop.defstate=Default Status
+scr.prop.activation=Aktivierung
+scr.prop.properties=Eigenschaften
+scr.prop.class=Implementationsklasse
+scr.prop.componentfactory=Komponenten Factory Name
+scr.prop.configurationpolicy=Konfigurations Policy
+scr.serv.type=Dienst Typ
+scr.serv=Dienste
+scr.title.actions=Aktionen
+scr.title.status=Status
+scr.title.name=Name
diff --git a/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_ru.properties b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_ru.properties
new file mode 100644
index 0000000..d10d52e
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/native2ascii/OSGI-INF/l10n/bundle_ru.properties
@@ -0,0 +1,49 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+
+# Components plugin
+components.pluginTitle=Компоненты
+scr.status.no_service=Сервис Declarative Service не найден!
+scr.status.no_components=Нет установленных компонентов!
+scr.status.ok=Количество установленных компонентов: {0}
+scr.action.enable=Включить
+scr.action.disable=Выключить
+scr.action.configure=Конфигурировать
+scr.prop.bundle=Модуль
+scr.prop.defstate=Состояние по умолчанию
+scr.prop.activation=Активация
+scr.prop.properties=Конфигурации
+scr.prop.class=Класс реализации
+scr.prop.componentfactory=Имя фабрики компонентов
+scr.prop.configurationpolicy=Политика конфигурирования
+scr.serv.type=Тип сервиса
+scr.serv=Сервисы
+scr.title.actions=Действия
+scr.title.status=Состояние
+scr.title.name=Имя
diff --git a/webconsole-plugins/ds/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole-plugins/ds/src/main/resources/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..d6518c6
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,49 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+
+# Components plugin
+components.pluginTitle=Components
+scr.status.no_service=Declarative Service required for this function!
+scr.status.no_components=No components installed currently!
+scr.status.ok=Number of installed components: {0}
+scr.action.enable=Enable
+scr.action.disable=Disable
+scr.action.configure=Configure
+scr.prop.bundle=Bundle
+scr.prop.defstate=Default State
+scr.prop.activation=Activation
+scr.prop.properties=Properties
+scr.prop.class=Implementation Class
+scr.prop.componentfactory=Component Factory Name
+scr.prop.configurationpolicy=Configuration Policy
+scr.serv.type=Service Type
+scr.serv=Services
+scr.title.actions=Actions
+scr.title.status=Status
+scr.title.name=Name
diff --git a/webconsole-plugins/ds/src/main/resources/res/plugin.html b/webconsole-plugins/ds/src/main/resources/res/plugin.html
new file mode 100644
index 0000000..fa0f8c1
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/resources/res/plugin.html
@@ -0,0 +1,67 @@
+<script type="text/javascript" src="${pluginRoot}/res/plugin.js"></script>
+<script type="text/javascript">
+// <![CDATA[
+var drawDetails = ${__drawDetails__};
+var scrData = ${__data__};
+// i18n
+var i18n = {
+ 'Bundle' : '${scr.prop.bundle}',
+ 'Default State' : '${scr.prop.defstate}',
+ 'Activation' : '${scr.prop.activation}',
+ 'Service Type' : '${scr.serv.type}',
+ 'Services' : '${scr.serv}',
+ 'Properties' : '${scr.prop.properties}',
+ 'Implementation Class' : '${scr.prop.class}',
+ 'Component Factory Name' : '${scr.prop.componentfactory}',
+ 'Configuration Policy' : '${scr.prop.configurationpolicy}',
+ stat_no_service : "${scr.status.no_service}",
+ stat_no_components : "${scr.status.no_components}",
+ stat_ok : "${scr.status.ok}"
+}
+// ]]>
+</script>
+<p class="statline"> </p>
+
+
+<div id="scr"> <!-- data available -->
+ <!-- top header -->
+ <form method='post' enctype='multipart/form-data' action="${pluginRoot}">
+ <div class="ui-widget-header ui-corner-top buttonGroup">
+ <button class='reloadButton' type='button' name='reload'>${reload}</button>
+ </div>
+ </form>
+
+ <table id="plugin_table" class="tablesorter nicetable noauto">
+ <thead>
+ <tr>
+ <th class="col_Id">${id}</th>
+ <th class="col_Name">${scr.title.name}</th>
+ <th class="col_Status">${scr.title.status}</th>
+ <th class="col_Actions">${scr.title.actions}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td> </td> <!-- id -->
+ <td> <!-- name with arrow -->
+ <div class="bIcon ui-icon ui-icon-triangle-1-e" style="float:left" title="${scr.details.tip}"> </div>
+ </td>
+ <td> </td> <!-- status -->
+ <td>
+ <ul class="icons">
+ <li class="dynhover ui-helper-hidden" title="${scr.action.enable}"><span class="ui-icon ui-icon-play"> </span></li>
+ <li class="dynhover ui-helper-hidden" title="${scr.action.disable}"><span class="ui-icon ui-icon-stop"> </span></li>
+ <li class="dynhover ui-helper-hidden" title="${scr.action.configure}"><span class="ui-icon ui-icon-wrench"> </span></li>
+ </ul>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div> <!-- end data available -->
+
+<!-- bottom header -->
+<form method='post' enctype='multipart/form-data' action="${pluginRoot}">
+ <div class="ui-widget-header ui-corner-bottom buttonGroup">
+ <button class='reloadButton' type='button' name='reload'>${reload}</button>
+ </div>
+</form>
diff --git a/webconsole-plugins/ds/src/main/resources/res/plugin.js b/webconsole-plugins/ds/src/main/resources/res/plugin.js
new file mode 100644
index 0000000..d1fa357
--- /dev/null
+++ b/webconsole-plugins/ds/src/main/resources/res/plugin.js
@@ -0,0 +1,183 @@
+/*
+ * 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.
+ */
+function renderData( eventData ) {
+ switch(eventData.status) {
+ case -1: // no event admin
+ $('.statline').html(i18n.stat_no_service);
+ $('#scr').addClass('ui-helper-hidden');
+ break;
+ case 0: // no components
+ $('.statline').html(i18n.stat_no_components);
+ $('#scr').addClass('ui-helper-hidden');
+ break;
+ default:
+ $('.statline').html(i18n.stat_ok.msgFormat(eventData.status));
+ $('#scr').removeClass('ui-helper-hidden');
+
+ tableBody.empty();
+ for ( var idx in eventData.data ) {
+ entry( eventData.data[idx] );
+ }
+ if ( drawDetails ) renderDetails(eventData);
+ initStaticWidgets();
+ }
+}
+
+function getEntryId(/* Object */ dataEntry) {
+ var id = dataEntry.id;
+ if (id < 0) {
+ id = dataEntry.name;
+ if (dataEntry.pid) {
+ id += '/' + dataEntry.pid;
+ }
+ }
+ return id;
+}
+
+function entry( /* Object */ dataEntry ) {
+ var idPath = getEntryId(dataEntry);
+ var id = idPath.replace(/[./-]/g, '_');
+ var name = dataEntry.name;
+ var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
+
+ _.find('.bIcon').attr('id', 'img' + id).click(function() {
+ showDetails(idPath);
+ }).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>'));
+
+ _.find('td:eq(0)').text( dataEntry.id );
+ _.find('td:eq(2)').text( dataEntry.state );
+
+ // setup buttons
+ if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling
+ _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') });
+ } else {
+ _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') });
+ }
+ if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure
+ changeDataEntryState(dataEntry.pid, 'configure');
+ });
+}
+
+function changeDataEntryState(/* long */ id, /* String */ action) {
+ if ( action == 'configure') {
+ window.location = appRoot + '/configMgr/' + id;
+ return;
+ }
+ $.post(pluginRoot + '/' + id, {'action':action}, function(data) {
+ renderData(data);
+ }, 'json');
+}
+
+function showDetails( id ) {
+ $.get(pluginRoot + '/' + id + '.json', null, function(data) {
+ renderDetails(data);
+ }, 'json');
+}
+
+function hideDetails( id ) {
+ var __test__ = $('#img' + id);
+ $('#img' + id).each(function() {
+ $('#pluginInlineDetails').remove();
+ $(this).
+ removeClass('ui-icon-triangle-1-w').//left
+ removeClass('ui-icon-triangle-1-s').//down
+ addClass('ui-icon-triangle-1-e').//right
+ attr('title', 'Details').
+ unbind('click').click(function() {showDetails(id)});
+ });
+}
+
+function renderDetails( data ) {
+ data = data.data[0];
+ var id = getEntryId(data).replace(/[./-]/g, '_');
+ $('#pluginInlineDetails').remove();
+ var __test__ = $('#entry' + id);
+ $('#entry' + id + ' > td').eq(1).append('<div id="pluginInlineDetails"/>');
+ $('#img' + id).each(function() {
+ if ( drawDetails ) {
+ var ref = window.location.pathname;
+ ref = ref.substring(0, ref.lastIndexOf('/'));
+ $(this).
+ removeClass('ui-icon-triangle-1-e').//right
+ removeClass('ui-icon-triangle-1-s').//down
+ addClass('ui-icon-triangle-1-w').//left
+ attr('title', 'Back').
+ unbind('click').click(function() {window.location = ref});
+ } else {
+ $(this).
+ removeClass('ui-icon-triangle-1-w').//left
+ removeClass('ui-icon-triangle-1-e').//right
+ addClass('ui-icon-triangle-1-s').//down
+ attr('title', 'Hide Details').
+ unbind('click').click(function() {hideDetails(id)});
+ }
+ });
+ $('#pluginInlineDetails').append('<table border="0"><tbody></tbody></table>');
+ var details = data.props;
+ for (var idx in details) {
+ var prop = details[idx];
+ var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n
+
+ var txt = '<tr><td class="aligntop" noWrap="true" style="border:0px none">' + key + '</td><td class="aligntop" style="border:0px none">';
+ if (prop.value) {
+ if ( $.isArray(prop.value) ) {
+ var i = 0;
+ for(var pi in prop.value) {
+ var value = prop.value[pi];
+ if (i > 0) { txt = txt + '<br/>'; }
+ var span;
+ if (value.substring(0, 2) == '!!') {
+ txt = txt + '<span style="color: red;'> + value + '</span>';
+ } else {
+ txt = txt + value;
+ }
+ i++;
+ }
+ } else {
+ txt = txt + prop.value;
+ }
+ } else {
+ txt = txt + '\u00a0';
+ }
+ txt = txt + '</td></tr>';
+ $('#pluginInlineDetails > table > tbody').append(txt);
+ }
+}
+
+var tableBody = false;
+var tableEntryTemplate = false;
+var pluginTable = false;
+
+$(document).ready(function(){
+ pluginTable = $('#plugin_table');
+ tableBody = pluginTable.find('tbody');
+ tableEntryTemplate = tableBody.find('tr').clone();
+
+ renderData(scrData);
+
+ $('.reloadButton').click(document.location.reload);
+
+ pluginTable.tablesorter({
+ headers: {
+ 0: { sorter:'digit'},
+ 3: { sorter: false }
+ },
+ sortList: [[1,0]],
+ textExtraction:mixedLinksExtraction
+ });
+});
+