You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/05/29 04:24:45 UTC

[sling-org-apache-sling-app-cms] 01/06: Adding a webconsole for displaying the registered services for the transformer

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit 2bcb3146afe6721c2586e13654531755aba545ec
Author: Dan Klco <dk...@apache.org>
AuthorDate: Wed May 29 00:13:46 2019 -0400

    Adding a webconsole for displaying the registered services for the
    transformer
---
 transformer/pom.xml                                |  4 +
 .../internal/TransformerWebConsole.java            | 96 ++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/transformer/pom.xml b/transformer/pom.xml
index 4d60565..7b4644d 100644
--- a/transformer/pom.xml
+++ b/transformer/pom.xml
@@ -84,6 +84,10 @@
             <artifactId>servlet-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.component.annotations</artifactId>
         </dependency>
diff --git a/transformer/src/main/java/org/apache/sling/cms/transformer/internal/TransformerWebConsole.java b/transformer/src/main/java/org/apache/sling/cms/transformer/internal/TransformerWebConsole.java
new file mode 100644
index 0000000..597897f
--- /dev/null
+++ b/transformer/src/main/java/org/apache/sling/cms/transformer/internal/TransformerWebConsole.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.cms.transformer.internal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.sling.cms.transformer.FileThumbnailTransformer;
+import org.apache.sling.cms.transformer.ThumbnailProvider;
+import org.apache.sling.cms.transformer.TransformationHandler;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Simple web console plugin for listing out the registered thumbnail providers
+ * and transformation handler
+ */
+@Component(property = { Constants.SERVICE_DESCRIPTION + "=Web Console Plugin for Apache Sling CMS Transformer",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+        WebConsoleConstants.PLUGIN_LABEL + "=" + TransformerWebConsole.CONSOLE_LABEL,
+        WebConsoleConstants.PLUGIN_TITLE + "=" + TransformerWebConsole.CONSOLE_TITLE,
+        WebConsoleConstants.CONFIG_PRINTER_MODES + "=always",
+        WebConsoleConstants.PLUGIN_CATEGORY + "=Status" }, service = { Servlet.class })
+public class TransformerWebConsole extends AbstractWebConsolePlugin {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 4819043498961127418L;
+    public static final String CONSOLE_LABEL = "slingcms-transformer";
+    public static final String CONSOLE_TITLE = "Sling CMS Transformer";
+
+    @Reference
+    private FileThumbnailTransformer fileThumbnailTransformer;
+
+    @Override
+    public String getTitle() {
+        return CONSOLE_TITLE;
+    }
+
+    @Override
+    public String getLabel() {
+        return CONSOLE_LABEL;
+    }
+
+    @Override
+    protected void renderContent(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
+            throws IOException {
+        PrintWriter pw = httpServletResponse.getWriter();
+        pw.println("<div id='content' class='ui-widget'><br>");
+        pw.println("<pre>");
+        pw.println("Registered Thumbnail Providers");
+        pw.println("========================");
+        List<ThumbnailProvider> providers = ((FileThumbnailTransformerImpl) fileThumbnailTransformer)
+                .getThumbnailProviders();
+        Lists.reverse(providers).forEach(p -> pw.println(p.getClass().getName()));
+        pw.println("</pre><br/>");
+        pw.println("<pre>");
+        pw.println("Registered Transformation Handlers");
+        pw.println("========================");
+
+        List<TransformationHandler> handlers = ((FileThumbnailTransformerImpl) fileThumbnailTransformer).getHandlers();
+        handlers.forEach(h -> {
+            pw.println(h.getClass().getName());
+        });
+        pw.println("</pre>");
+        pw.println("</div>");
+    }
+
+}