sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r931485 - in /sling/trunk/contrib/extensions/rewriter: ./ src/main/java/org/apache/sling/rewriter/impl/ src/main/resources/META-INF/
Date Wed, 07 Apr 2010 09:58:48 GMT
Author: cziegeler
Date: Wed Apr  7 09:58:47 2010
New Revision: 931485

URL: http://svn.apache.org/viewvc?rev=931485&view=rev
Log:
Add web console plugin to display current rewriter configuration

Added:
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/rewriter/NOTICE
    sling/trunk/contrib/extensions/rewriter/pom.xml
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
    sling/trunk/contrib/extensions/rewriter/src/main/resources/META-INF/NOTICE

Modified: sling/trunk/contrib/extensions/rewriter/NOTICE
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/NOTICE?rev=931485&r1=931484&r2=931485&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/NOTICE (original)
+++ sling/trunk/contrib/extensions/rewriter/NOTICE Wed Apr  7 09:58:47 2010
@@ -1,5 +1,5 @@
 Apache Sling Rewriter
-Copyright 2009 The Apache Software Foundation
+Copyright 2009-2010 The Apache Software Foundation
 
 Apache Sling is based on source code originally developed 
 by Day Software (http://www.day.com/).

Modified: sling/trunk/contrib/extensions/rewriter/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/pom.xml?rev=931485&r1=931484&r2=931485&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/pom.xml (original)
+++ sling/trunk/contrib/extensions/rewriter/pom.xml Wed Apr  7 09:58:47 2010
@@ -70,6 +70,9 @@
                             org.apache.sling.rewriter.impl,
                             org.apache.sling.rewriter.impl.components
                         </Private-Package>
+                        <DynamicImport-Package>
+                            org.apache.felix.webconsole
+                        </DynamicImport-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -114,6 +117,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <version>2.0.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java?rev=931485&r1=931484&r2=931485&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
Wed Apr  7 09:58:47 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.rewriter.impl;
 
+import java.io.PrintWriter;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -176,6 +177,51 @@ public class ProcessorConfigurationImpl 
         this.descString = this.buildDescString();
     }
 
+    void printConfiguration(final PrintWriter pw) {
+        if ( this.contentTypes != null ) {
+            pw.print("Content Types : ");
+            pw.println(Arrays.toString(this.contentTypes));
+        }
+        if ( this.resourceTypes != null ) {
+            pw.print("Resource Types : ");
+            pw.println(Arrays.toString(this.resourceTypes));
+        }
+        if ( this.paths != null ) {
+            pw.print("Paths : ");
+            pw.println(Arrays.toString(this.paths));
+        }
+        if ( this.extensions != null ) {
+            pw.print("Extensions : ");
+            pw.println(Arrays.toString(this.extensions));
+        }
+        pw.print("Order : ");
+        pw.println(this.order);
+        pw.print("Active : ");
+        pw.println(this.isActive);
+        pw.print("Valid : ");
+        pw.println(this.isValid);
+        pw.print("Process Error Response : ");
+        pw.println(this.processErrorResponse);
+        if ( this.isPipeline ) {
+            pw.println("Pipeline : ");
+            pw.println("    Generator : ");
+            pw.print("        ");
+            pw.println(this.generatorConfiguration);
+            pw.println("    Transformers : ");
+            for(int i=0; i<this.transformerConfigurations.length; i++) {
+                pw.print("        ");
+                pw.println(this.transformerConfigurations[i]);
+            }
+            pw.println("    Serializer : ");
+            pw.print("        ");
+            pw.println(this.serializerConfiguration);
+        } else {
+            pw.print("Configuration : ");
+            pw.println(this.processorConfig);
+        }
+
+    }
+
     private String buildDescString() {
         final StringBuilder sb = new StringBuilder();
         sb.append("ProcessorConfiguration: {");

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java?rev=931485&r1=931484&r2=931485&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
Wed Apr  7 09:58:47 2010
@@ -17,6 +17,7 @@
 package org.apache.sling.rewriter.impl;
 
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -131,6 +132,11 @@ public class ProcessorManagerImpl implem
         this.initProcessors();
 
         this.factoryCache.start();
+        try {
+            WebConsoleConfigPrinter.register(this.bundleContext, this);
+        } catch (Exception ignore) {
+            // ignore
+        }
     }
 
     /**
@@ -152,6 +158,11 @@ public class ProcessorManagerImpl implem
             this.adminSession.logout();
             this.adminSession = null;
         }
+        try {
+            WebConsoleConfigPrinter.unregister();
+        } catch (Exception ignore) {
+            // ignore
+        }
         this.bundleContext = null;
     }
 
@@ -288,6 +299,45 @@ public class ProcessorManagerImpl implem
         }
     }
 
+    private void printConfiguration(final PrintWriter pw, final ConfigEntry entry) {
+        if ( entry.config instanceof ProcessorConfigurationImpl ) {
+            ((ProcessorConfigurationImpl)entry.config).printConfiguration(pw);
+        } else {
+            pw.println(entry.config.toString());
+        }
+        pw.print("Resource path: ");
+        pw.println(entry.path);
+    }
+
+    synchronized void printConfiguration(final PrintWriter pw) {
+        pw.println("Current Apache Sling Rewriter Configuration");
+        pw.println("=================================================================");
+        pw.println("Active Configurations");
+        pw.println("-----------------------------------------------------------------");
+        // we process the configs in their order
+        for(final ProcessorConfiguration config : this.orderedProcessors) {
+            // search the corresponding full config
+            for(final Map.Entry<String, ConfigEntry[]> entry : this.processors.entrySet())
{
+                if ( entry.getValue().length > 0 && entry.getValue()[0].config
== config ) {
+                    pw.print("Configuration ");
+                    pw.println(entry.getKey());
+                    pw.println();
+                    printConfiguration(pw, entry.getValue()[0]);
+                    if ( entry.getValue().length > 1 ) {
+                        pw.println("Overriding configurations from the following resource
paths: ");
+                        for(int i=1; i < entry.getValue().length; i++) {
+                            pw.print("- ");
+                            pw.println(entry.getValue()[i].path);
+                        }
+                    }
+                    pw.println();
+                    pw.println();
+                    break;
+                }
+            }
+        }
+    }
+
     /**
      * updates a processor
      */

Added: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java?rev=931485&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
(added)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
Wed Apr  7 09:58:47 2010
@@ -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.rewriter.impl;
+
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * This is a configuration printer for the web console which
+ * prints out the currently configured processors/pipelines.
+ *
+ */
+public class WebConsoleConfigPrinter implements ConfigurationPrinter {
+
+    final ProcessorManagerImpl manager;
+
+    private static ServiceRegistration REG;
+
+    public WebConsoleConfigPrinter(final ProcessorManagerImpl manager) {
+        this.manager = manager;
+    }
+
+    public static void register(final BundleContext bundleContext,
+                                final ProcessorManagerImpl manager) {
+        final WebConsoleConfigPrinter printer = new WebConsoleConfigPrinter(manager);
+        final Dictionary<String, String> serviceProps = new Hashtable<String, String>();
+        serviceProps.put(Constants.SERVICE_DESCRIPTION,
+            "Apache Sling Rewriter Configuration Printer");
+        serviceProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+        REG = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                printer,
+                serviceProps);
+    }
+
+    public static void unregister() {
+        if ( REG != null) {
+            REG.unregister();
+            REG = null;
+        }
+    }
+
+    /**
+     * Return the title for the configuration printer
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+     */
+    public String getTitle() {
+        return "Rewriter";
+    }
+
+    /**
+     * Print out the rewriter configs.
+     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+     */
+    public void printConfiguration(PrintWriter pw) {
+        this.manager.printConfiguration(pw);
+    }
+}

Propchange: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/WebConsoleConfigPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/contrib/extensions/rewriter/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/resources/META-INF/NOTICE?rev=931485&r1=931484&r2=931485&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/resources/META-INF/NOTICE (original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/resources/META-INF/NOTICE Wed Apr  7
09:58:47 2010
@@ -1,5 +1,5 @@
 Apache Sling Rewriter
-Copyright 2009 The Apache Software Foundation
+Copyright 2009-2010 The Apache Software Foundation
 
 Apache Sling is based on source code originally developed 
 by Day Software (http://www.day.com/).



Mime
View raw message