You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2016/11/24 14:05:10 UTC
svn commit: r1771140 - in
/sling/trunk/contrib/extensions/contextaware-config/impl/src:
main/java/org/apache/sling/caconfig/management/impl/console/
test/java/org/apache/sling/caconfig/management/impl/console/
Author: sseifert
Date: Thu Nov 24 14:05:10 2016
New Revision: 1771140
URL: http://svn.apache.org/viewvc?rev=1771140&view=rev
Log:
SLING-6307 Context-Aware Config: Web Console Configuration Printer
Added:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java (with props)
Removed:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationResolverWebConsolePlugin.java
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java Thu Nov 24 14:05:10 2016
@@ -0,0 +1,167 @@
+/*
+ * 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.caconfig.management.impl.console;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.sling.caconfig.resource.spi.CollectionInheritanceDecider;
+import org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy;
+import org.apache.sling.caconfig.resource.spi.ContextPathStrategy;
+import org.apache.sling.caconfig.spi.ConfigurationInheritanceStrategy;
+import org.apache.sling.caconfig.spi.ConfigurationMetadataProvider;
+import org.apache.sling.caconfig.spi.ConfigurationOverrideProvider;
+import org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy;
+import org.apache.sling.commons.osgi.Order;
+import org.apache.sling.commons.osgi.ServiceUtil;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Web console configuration printer.
+ */
+@Component(service=ConfigurationPrinter.class,
+property={Constants.SERVICE_DESCRIPTION + "=Apache Sling Context-Aware Configuration Resolver Console Configuration Printer",
+ WebConsoleConstants.PLUGIN_LABEL + "=" + CAConfigConfigurationPrinter.LABEL,
+ WebConsoleConstants.PLUGIN_TITLE + "=" + CAConfigConfigurationPrinter.TITLE,
+ WebConsoleConstants.CONFIG_PRINTER_MODES + "=" + ConfigurationPrinter.MODE_ALWAYS})
+@SuppressWarnings("deprecation")
+public class CAConfigConfigurationPrinter implements ConfigurationPrinter {
+
+ public static final String LABEL = "slingcaconfig";
+ public static final String TITLE = "Sling Context-Aware Configuration";
+
+ private BundleContext bundleContext;
+
+ @Activate
+ private void activate(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ @Override
+ public String getTitle() {
+ return TITLE;
+ }
+
+ @Override
+ public void printConfiguration(PrintWriter pw) {
+ printSPISection(pw, ContextPathStrategy.class, "Context Path Strategies");
+ printSPISection(pw, ConfigurationResourceResolvingStrategy.class, "Configuration Resource Resolving Strategies");
+ printSPISection(pw, CollectionInheritanceDecider.class, "Collection Inheritance Deciders");
+ printSPISection(pw, ConfigurationInheritanceStrategy.class, "Configuration Inheritance Strategies");
+ printSPISection(pw, ConfigurationPersistenceStrategy.class, "Configuration Persistance Strategies");
+ printSPISection(pw, ConfigurationMetadataProvider.class, "Configuration Metadata Providers",
+ new ConfigurationMetadataPrinter());
+ printSPISection(pw, ConfigurationOverrideProvider.class, "Configuration Override Providers",
+ new ConfigurationOverridePrinter());
+ }
+
+ @SafeVarargs
+ private final <T> void printSPISection(PrintWriter pw, Class<T> clazz, String title, ServiceConfigurationPrinter<T>... serviceConfigPrinters) {
+ Collection<ServiceReference<T>> serviceReferences = getServiceReferences(clazz);
+
+ pw.println(title);
+ pw.println(StringUtils.repeat('-', title.length()));
+
+ if (serviceReferences.isEmpty()) {
+ pw.println("(none)");
+ }
+ else {
+ for (ServiceReference<T> serviceReference : serviceReferences) {
+ pw.print(ServiceConfigurationPrinter.BULLET);
+ pw.print(getServiceClassName(serviceReference));
+ pw.print(" [");
+ pw.print(getServiceRanking(serviceReference));
+ if (!isEnabled(serviceReference)) {
+ pw.print(", disabled");
+ }
+ pw.print("]");
+ pw.println();
+ for (ServiceConfigurationPrinter<T> serviceConfigPrinter : serviceConfigPrinters) {
+ serviceConfigPrinter.printConfiguration(pw, serviceReference, bundleContext);
+ }
+ }
+ }
+ pw.println();
+ }
+
+ private <T> Collection<ServiceReference<T>> getServiceReferences(Class<T> clazz) {
+ try {
+ SortedMap<Comparable<Object>,ServiceReference<T>> sortedServices = new TreeMap<>();
+ Collection<ServiceReference<T>> serviceReferences = bundleContext.getServiceReferences(clazz, null);
+ for (ServiceReference<T> serviceReference : serviceReferences) {
+ Map<String,Object> props = new HashMap<>();
+ for (String property : serviceReference.getPropertyKeys()) {
+ props.put(property, serviceReference.getProperty(property));
+ }
+ sortedServices.put(
+ ServiceUtil.getComparableForServiceRanking(props, Order.DESCENDING),
+ serviceReference
+ );
+ }
+ return sortedServices.values();
+ }
+ catch (InvalidSyntaxException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private <T> String getServiceClassName(ServiceReference<T> serviceReference) {
+ Object service = bundleContext.getService(serviceReference);
+ String serviceClassName = service.getClass().getName();
+ bundleContext.ungetService(serviceReference);
+ return serviceClassName;
+ }
+
+ private <T> int getServiceRanking(ServiceReference<T> serviceReference) {
+ Integer serviceRanking = (Integer)serviceReference.getProperty(Constants.SERVICE_RANKING);
+ if (serviceRanking == null) {
+ return 0;
+ }
+ else {
+ return serviceRanking;
+ }
+ }
+
+ private <T> boolean isEnabled(ServiceReference<T> serviceReference) {
+ Object enabledObject = (Object)serviceReference.getProperty("enabled");
+ if (enabledObject != null) {
+ if (enabledObject instanceof Boolean) {
+ return ((Boolean)enabledObject).booleanValue();
+ }
+ else {
+ return BooleanUtils.toBoolean(enabledObject.toString());
+ }
+ }
+ return true;
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java Thu Nov 24 14:05:10 2016
@@ -0,0 +1,80 @@
+/*
+ * 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.caconfig.management.impl.console;
+
+import java.io.PrintWriter;
+import java.lang.reflect.Array;
+
+import org.apache.sling.caconfig.spi.ConfigurationMetadataProvider;
+import org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata;
+import org.apache.sling.caconfig.spi.metadata.PropertyMetadata;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Print configuration metadata provided by a {@link ConfigurationMetadata}.
+ */
+class ConfigurationMetadataPrinter implements ServiceConfigurationPrinter<ConfigurationMetadataProvider> {
+
+ @Override
+ public void printConfiguration(PrintWriter pw, ServiceReference<ConfigurationMetadataProvider> serviceReference, BundleContext bundleContext) {
+ ConfigurationMetadataProvider service = bundleContext.getService(serviceReference);
+
+ for (String configName : service.getConfigurationNames()) {
+ ConfigurationMetadata metadata = service.getConfigurationMetadata(configName);
+ pw.print(INDENT);
+ pw.print(BULLET);
+ pw.println(metadata.getName());
+
+ for (PropertyMetadata<?> property : metadata.getPropertyMetadata().values()) {
+ pw.print(INDENT_2);
+ pw.print(BULLET);
+ pw.print(property.getName());
+
+ pw.print("(");
+ pw.print(property.getType().getSimpleName());
+ pw.print(")");
+
+ if (property.getDefaultValue() != null) {
+ pw.print(" = ");
+ printValue(pw, property.getDefaultValue());
+ }
+
+ pw.println();
+ }
+ }
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+ private void printValue(PrintWriter pw, Object value) {
+ if (value.getClass().isArray()) {
+ for (int i=0; i<Array.getLength(value); i++) {
+ if (i > 0) {
+ pw.print(", ");
+ }
+ printValue(pw, Array.get(value, i));
+ }
+ }
+ else {
+ pw.print(value);
+ }
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationMetadataPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java Thu Nov 24 14:05:10 2016
@@ -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.
+ */
+package org.apache.sling.caconfig.management.impl.console;
+
+import java.io.PrintWriter;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.caconfig.spi.ConfigurationOverrideProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Print override strings from a {@link ConfigurationOverrideProvider}.
+ */
+class ConfigurationOverridePrinter implements ServiceConfigurationPrinter<ConfigurationOverrideProvider> {
+
+ @Override
+ public void printConfiguration(PrintWriter pw, ServiceReference<ConfigurationOverrideProvider> serviceReference, BundleContext bundleContext) {
+ ConfigurationOverrideProvider service = bundleContext.getService(serviceReference);
+
+ for (String overrideString : service.getOverrideStrings()) {
+ if (StringUtils.isBlank(overrideString)) {
+ continue;
+ }
+ pw.print(INDENT);
+ pw.print(BULLET);
+ pw.println(overrideString);
+ }
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationOverridePrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java Thu Nov 24 14:05:10 2016
@@ -0,0 +1,334 @@
+/*
+ * 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.caconfig.management.impl.console;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.caconfig.management.ConfigurationData;
+import org.apache.sling.caconfig.management.ConfigurationManager;
+import org.apache.sling.caconfig.management.ValueInfo;
+import org.apache.sling.xss.XSSAPI;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Web console plugin to test configuration resolution.
+ */
+@Component(service=Servlet.class,
+ property={Constants.SERVICE_DESCRIPTION + "=Apache Sling Context-Aware Configuration Web Console Plugin",
+ WebConsoleConstants.PLUGIN_LABEL + "=" + ConfigurationWebConsolePlugin.LABEL,
+ WebConsoleConstants.PLUGIN_TITLE + "=" + ConfigurationWebConsolePlugin.TITLE,
+ WebConsoleConstants.PLUGIN_CATEGORY + "=Sling"})
+@SuppressWarnings("serial")
+public class ConfigurationWebConsolePlugin extends AbstractWebConsolePlugin {
+
+ public static final String LABEL = "slingcaconfig";
+ public static final String TITLE = "Context-Aware Configuration";
+
+ private static final Logger log = LoggerFactory.getLogger(ConfigurationWebConsolePlugin.class);
+
+ @Reference(policyOption = ReferencePolicyOption.GREEDY)
+ private ResourceResolverFactory resolverFactory;
+
+ @Reference(policyOption = ReferencePolicyOption.GREEDY)
+ private ConfigurationManager configurationManager;
+
+ @Reference(policyOption = ReferencePolicyOption.GREEDY)
+ private XSSAPI xss;
+
+ @Override
+ public String getLabel() {
+ return LABEL;
+ }
+
+ @Override
+ public String getTitle() {
+ return TITLE;
+ }
+
+ @Override
+ protected void renderContent(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ final PrintWriter pw = response.getWriter();
+
+ info(pw, "Configurations are managed in the resource tree. Use this tool to test configuration resolutions.");
+
+ pw.println("<br/>");
+
+ printResolutionTestTool(request, pw);
+ }
+
+ private String getParameter(final HttpServletRequest request, final String name, final String defaultValue) {
+ String value = request.getParameter(name);
+ if ( value != null && !value.trim().isEmpty() ) {
+ return value.trim();
+ }
+ return defaultValue;
+ }
+
+ private void printResolutionTestTool(HttpServletRequest request, PrintWriter pw) {
+ final String path = this.getParameter(request, "path", null);
+ final String configName = this.getParameter(request, "configName", null);
+ final boolean resourceCollection = BooleanUtils.toBoolean(this.getParameter(request, "resourceCollection", "false"));
+
+ ResourceResolver resolver = null;
+ try {
+ Resource contentResource = null;
+ if (path != null) {
+ resolver = getResolver();
+ if (resolver != null) {
+ contentResource = resolver.getResource(path);
+ }
+ }
+
+ pw.println("<form method='get'>");
+
+ tableStart(pw, "Test Configuration Resolution", 2);
+
+ String alertMessage = null;
+ if (path != null) {
+ if (resolver == null) {
+ alertMessage = "Unable to access repository - please check system configuration.";
+ }
+ else if (contentResource == null) {
+ alertMessage = "Path does not exist.";
+ }
+ }
+ textField(pw, "Content Path", "path", path, alertMessage);
+
+ tableRows(pw);
+ textField(pw, "Config Name", "configName", configName);
+
+ tableRows(pw);
+ checkboxField(pw, "Resource collection", "resourceCollection", resourceCollection);
+
+ tableRows(pw);
+ pw.println("<td></td>");
+ pw.println("<td><input type='submit' value='Resolve'/></td>");
+ tableEnd(pw);
+
+ pw.println("</form>");
+
+ pw.println("<br/>");
+
+ if (contentResource != null) {
+
+ // resolve configuration
+ Collection<ConfigurationData> configDatas;
+ if (resourceCollection) {
+ configDatas = configurationManager.getCollection(contentResource, configName);
+ }
+ else {
+ ConfigurationData configData = configurationManager.get(contentResource, configName);
+ if (configData != null) {
+ configDatas = Collections.singletonList(configData);
+ }
+ else {
+ configDatas = Collections.emptyList();
+ }
+ }
+
+ tableStart(pw, "Result", 6);
+
+ if (configDatas.size() == 0) {
+ pw.println("<td colspan='6'>");
+ alertDiv(pw, "No matching item found.");
+ pw.println("<br/> </td>");
+ }
+ else {
+
+ pw.println("<th>Property</th>");
+ pw.println("<th>Effective Value</th>");
+ pw.println("<th>Value</th>");
+ pw.println("<th>Default</th>");
+ pw.println("<th>Inherited</th>");
+ pw.println("<th>Overwritten</th>");
+
+ for (ConfigurationData data : configDatas) {
+ tableRows(pw);
+ pw.println("<td colspan='6' style='background-color:#f3f3f3'>");
+ pw.print("Path: " + xss.encodeForHTML(data.getResourcePath()));
+ pw.println("</td>");
+
+ for (String propertyName : data.getPropertyNames()) {
+ ValueInfo<?> valueInfo = data.getValueInfo(propertyName);
+ tableRows(pw);
+ td(pw, propertyName);
+ td(pw, valueInfo.getEffectiveValue());
+ td(pw, valueInfo.getValue());
+ td(pw, valueInfo.isDefault());
+
+ String title = null;
+ if (valueInfo.isInherited()) {
+ title = "Source path: " + valueInfo.getConfigSourcePath();
+ }
+ td(pw, valueInfo.isInherited(), title);
+
+ td(pw, valueInfo.isOverridden());
+ }
+
+ }
+
+ }
+
+ tableEnd(pw);
+ }
+
+ }
+ finally {
+ if (resolver != null) {
+ resolver.close();
+ }
+ }
+ }
+
+ private void info(PrintWriter pw, String text) {
+ pw.print("<p class='statline ui-state-highlight'>");
+ pw.print(xss.encodeForHTML(text));
+ pw.println("</p>");
+ }
+
+ private void tableStart(PrintWriter pw, String title, int colspan) {
+ pw.println("<table class='nicetable ui-widget'>");
+ pw.println("<thead class='ui-widget-header'>");
+ pw.println("<tr>");
+ pw.print("<th colspan=");
+ pw.print(String.valueOf(colspan));
+ pw.print(">");
+ pw.print(xss.encodeForHTML(title));
+ pw.println("</th>");
+ pw.println("</tr>");
+ pw.println("</thead>");
+ pw.println("<tbody class='ui-widget-content'>");
+ pw.println("<tr>");
+ }
+
+ private void tableEnd(PrintWriter pw) {
+ pw.println("</tr>");
+ pw.println("</tbody>");
+ pw.println("</table>");
+ }
+
+ private void tableRows(PrintWriter pw) {
+ pw.println("</tr>");
+ pw.println("<tr>");
+ }
+
+ private void textField(PrintWriter pw, String label, String fieldName, String value, String... alertMessages) {
+ pw.print("<td style='width:20%'>");
+ pw.print(xss.encodeForHTMLAttr(label));
+ pw.println("</td>");
+ pw.print("<td><input name='");
+ pw.print(xss.encodeForHTMLAttr(fieldName));
+ pw.print("' value='");
+ pw.print(xss.encodeForHTMLAttr(StringUtils.defaultString(value)));
+ pw.print("' style='width:100%'/>");
+ for (String alertMessage : alertMessages) {
+ alertDiv(pw, alertMessage);
+ }
+ pw.println("</td>");
+ }
+
+ private void checkboxField(PrintWriter pw, String label, String fieldName, boolean checked) {
+ pw.print("<td style='width:20%'>");
+ pw.print(xss.encodeForHTMLAttr(label));
+ pw.println("</td>");
+ pw.print("<td><input type='checkbox' name='");
+ pw.print(xss.encodeForHTMLAttr(fieldName));
+ pw.print("' value='true'");
+ if (checked) {
+ pw.print(" checked");
+ }
+ pw.print("/></td>");
+ }
+
+ private void alertDiv(PrintWriter pw, String text) {
+ if (StringUtils.isBlank(text)) {
+ return;
+ }
+ pw.println("<div>");
+ pw.println("<span class='ui-icon ui-icon-alert' style='float:left'></span>");
+ pw.print("<span style='float:left'>");
+ pw.print(xss.encodeForHTML(text));
+ pw.println("</span>");
+ pw.println("</div>");
+ }
+
+ private void td(PrintWriter pw, Object value, String... title) {
+ pw.print("<td");
+ if (title.length > 0 && !StringUtils.isBlank(title[0])) {
+ pw.print(" title='");
+ pw.print(xss.encodeForHTML(title[0]));
+ pw.print("'");
+ }
+ pw.print(">");
+
+ if (value != null) {
+ if (value.getClass().isArray()) {
+ for (int i = 0; i < Array.getLength(value); i++) {
+ Object itemValue = Array.get(value, i);
+ pw.print(xss.encodeForHTML(ObjectUtils.defaultIfNull(itemValue, "").toString()));
+ pw.println("<br>");
+ }
+ }
+ else {
+ pw.print(xss.encodeForHTML(value.toString()));
+ }
+ }
+
+ if (title.length > 0 && !StringUtils.isBlank(title[0])) {
+ pw.print("<span class='ui-icon ui-icon-info' style='float:left'></span>");
+ }
+ pw.print("</td>");
+ }
+
+ private ResourceResolver getResolver() {
+ try {
+ return resolverFactory.getServiceResourceResolver(null);
+ }
+ catch (final LoginException ex) {
+ log.warn("Unable to get resource resolver - please ensure a system user is configured: {}", ex.getMessage());
+ return null;
+ }
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java Thu Nov 24 14:05:10 2016
@@ -0,0 +1,60 @@
+/*
+ * 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.caconfig.management.impl.console;
+
+import java.io.PrintWriter;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Print additional configuration per service.
+ * @param <T> Service type
+ */
+interface ServiceConfigurationPrinter<T> {
+
+ /**
+ * Bullet character
+ */
+ String BULLET = "- ";
+
+ /**
+ * Indentation 1 step
+ */
+ String INDENT = " ";
+
+ /**
+ * Indentation 2 steps
+ */
+ String INDENT_2 = INDENT + INDENT;
+
+ /**
+ * Indentation 3 steps
+ */
+ String INDENT_3 = INDENT_2 + INDENT;
+
+ /**
+ * Print configuration
+ * @param printWriter Print writer
+ * @param serviceReference Service reference
+ * @param bundleContext Bundle context
+ */
+ void printConfiguration(PrintWriter printWriter, ServiceReference<T> serviceReference, BundleContext bundleContext);
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ServiceConfigurationPrinter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java?rev=1771140&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java Thu Nov 24 14:05:10 2016
@@ -0,0 +1,100 @@
+/*
+ * 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.caconfig.management.impl.console;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.caconfig.impl.ConfigurationTestUtils;
+import org.apache.sling.caconfig.impl.def.DefaultConfigurationInheritanceStrategy;
+import org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy;
+import org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexer;
+import org.apache.sling.caconfig.spi.ConfigurationMetadataProvider;
+import org.apache.sling.caconfig.spi.ConfigurationOverrideProvider;
+import org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata;
+import org.apache.sling.caconfig.spi.metadata.PropertyMetadata;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSortedSet;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CAConfigConfigurationPrinterTest {
+
+ private static final String SAMPLE_CONFIG_NAME = "sample.config.Name";
+ private static final String SAMPLE_OVERRIDE_STRING = "[/sample]override/string='abc'";
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ @Mock
+ private ConfigurationMetadataProvider configurationMetadataProvider;
+ @Mock
+ private ConfigurationOverrideProvider configurationOverrideProvider;
+
+ private CAConfigConfigurationPrinter underTest;
+
+ @Before
+ public void setUp() {
+ context.registerService(ConfigurationMetadataProvider.class, configurationMetadataProvider);
+ context.registerInjectActivateService(new ConfigurationMetadataProviderMultiplexer());
+ context.registerService(ConfigurationOverrideProvider.class, configurationOverrideProvider);
+ ConfigurationTestUtils.registerConfigurationResolver(context);
+ underTest = context.registerInjectActivateService(new CAConfigConfigurationPrinter());
+
+ ConfigurationMetadata configMetadata = new ConfigurationMetadata(SAMPLE_CONFIG_NAME);
+ configMetadata.setPropertyMetadata(ImmutableMap.<String,PropertyMetadata<?>>of(
+ "prop1", new PropertyMetadata<>("prop1", "defValue"),
+ "prop2", new PropertyMetadata<>("prop2", String.class),
+ "prop3", new PropertyMetadata<>("prop3", 5)));
+ when(configurationMetadataProvider.getConfigurationMetadata(SAMPLE_CONFIG_NAME)).thenReturn(configMetadata);
+ when(configurationMetadataProvider.getConfigurationNames()).thenReturn(ImmutableSortedSet.of(SAMPLE_CONFIG_NAME));
+
+ when(configurationOverrideProvider.getOverrideStrings()).thenReturn(ImmutableList.of(SAMPLE_OVERRIDE_STRING));
+ }
+
+ @Test
+ public void testPrintConfiguration() {
+ StringWriter sw = new StringWriter();
+ underTest.printConfiguration(new PrintWriter(sw));
+ String result = sw.toString();
+
+ // test existance of some strategy names
+ assertTrue(StringUtils.contains(result, DefaultConfigurationInheritanceStrategy.class.getName()));
+ assertTrue(StringUtils.contains(result, DefaultConfigurationPersistenceStrategy.class.getName()));
+
+ // ensure config metadata
+ assertTrue(StringUtils.contains(result, SAMPLE_CONFIG_NAME));
+
+ // ensure overrides strings
+ assertTrue(StringUtils.contains(result, SAMPLE_OVERRIDE_STRING));
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Nov 24 14:05:10 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/caconfig/management/impl/console/CAConfigConfigurationPrinterTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
RE: svn commit: r1771140 - in
/sling/trunk/contrib/extensions/contextaware-config/impl/src:
main/java/org/apache/sling/caconfig/management/impl/console/
test/java/org/apache/sling/caconfig/management/impl/console/
Posted by Stefan Seifert <ss...@pro-vision.de>.
ah, i've looked for a non-deprecated felix API for this but did not find it.
will give it a try.
stefan
>-----Original Message-----
>From: Chetan Mehrotra [mailto:chetan.mehrotra@gmail.com]
>Sent: Thursday, November 24, 2016 3:19 PM
>To: dev
>Subject: Re: svn commit: r1771140 - in
>/sling/trunk/contrib/extensions/contextaware-config/impl/src:
>main/java/org/apache/sling/caconfig/management/impl/console/
>test/java/org/apache/sling/caconfig/management/impl/console/
>
>On Thu, Nov 24, 2016 at 7:35 PM, <ss...@apache.org> wrote:
>> +@SuppressWarnings("deprecation")
>> +public class CAConfigConfigurationPrinter implements
>ConfigurationPrinter {
>> +
>
>May be use Felix Inventory API [1] as thats the newer way replacing
>config printer
>
>Chetan Mehrotra
>[1] http://felix.apache.org/documentation/subprojects/apache-felix-
>inventory.html
Re: svn commit: r1771140 - in /sling/trunk/contrib/extensions/contextaware-config/impl/src:
main/java/org/apache/sling/caconfig/management/impl/console/ test/java/org/apache/sling/caconfig/management/impl/console/
Posted by Chetan Mehrotra <ch...@gmail.com>.
On Thu, Nov 24, 2016 at 7:35 PM, <ss...@apache.org> wrote:
> +@SuppressWarnings("deprecation")
> +public class CAConfigConfigurationPrinter implements ConfigurationPrinter {
> +
May be use Felix Inventory API [1] as thats the newer way replacing
config printer
Chetan Mehrotra
[1] http://felix.apache.org/documentation/subprojects/apache-felix-inventory.html