You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:23:50 UTC
[sling-org-apache-sling-commons-mime] 09/22: SLING-965 add web
console plugin to display known mime type mappings
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.commons.mime-2.1.0-incubator
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-mime.git
commit 7dbdfcd894954cefb06f0bd924524b2dc82719c2
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Sun May 17 17:14:57 2009 +0000
SLING-965 add web console plugin to display known mime type mappings
git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/commons/mime@775718 13f79535-47bb-0310-9956-ffa450edef68
---
LICENSE | 32 ++++
NOTICE | 4 +
pom.xml | 9 +
.../commons/mime/internal/MimeTypeServiceImpl.java | 46 ++++-
.../mime/internal/MimeTypeWebConsolePlugin.java | 193 +++++++++++++++++++++
src/main/resources/META-INF/LICENSE | 32 ++++
src/main/resources/META-INF/NOTICE | 4 +
src/main/resources/res/jquery.treeTable.css | 43 +++++
src/main/resources/res/jquery.treeTable.min.js | 10 ++
9 files changed, 372 insertions(+), 1 deletion(-)
diff --git a/LICENSE b/LICENSE
index d645695..ef13dba 100644
--- a/LICENSE
+++ b/LICENSE
@@ -200,3 +200,35 @@
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.
+
+
+APACHE SLING SUBCOMPONENTS:
+
+Apache Sling includes subcomponents with separate copyright notices and
+license terms. Your use of these subcomponents is subject to the terms
+and conditions of the following licenses.
+
+JQuery TreeTable plugin
+
+ Copyright (c) 2009 Ludo van den Boom
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
diff --git a/NOTICE b/NOTICE
index 6c93777..97c463f 100644
--- a/NOTICE
+++ b/NOTICE
@@ -6,3 +6,7 @@ by Day Software (http://www.day.com/).
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software developed by
+Copyright (c) 2009 Ludo van den Boom (http://blog.cubicphuse.nl/)
+Licensed under the MIT License
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f32126c..b8591c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,6 +88,15 @@
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.webconsole</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
diff --git a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
index f11f084..47e7947 100644
--- a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
@@ -23,20 +23,25 @@ import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Dictionary;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.sling.commons.mime.MimeTypeProvider;
import org.apache.sling.commons.mime.MimeTypeService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.log.LogService;
/**
- * The <code>MimeTypeServiceImpl</code> TODO
+ * The <code>MimeTypeServiceImpl</code> is the official implementation of the
+ * {@link MimeTypeService} interface.
*
* @scr.component immediate="false" metatype="no"
* @scr.property name="service.vendor" value="The Apache Software Foundation"
@@ -63,6 +68,10 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener {
private List<MimeTypeProvider> typeProviderList = new ArrayList<MimeTypeProvider>();
+ private MimeTypeWebConsolePlugin webConsolePlugin;
+
+ private ServiceRegistration webConsolePluginService;
+
/**
* @see org.apache.sling.commons.mime.MimeTypeService#getMimeType(java.lang.String)
*/
@@ -241,10 +250,35 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener {
this.registerMimeType(bundles[i].getEntry(MIME_TYPES));
}
}
+
+ try {
+ MimeTypeWebConsolePlugin plugin = new MimeTypeWebConsolePlugin(this);
+ plugin.activate(context.getBundleContext());
+
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put(WebConsoleConstants.PLUGIN_LABEL, plugin.getLabel());
+
+ webConsolePluginService = context.getBundleContext().registerService(
+ WebConsoleConstants.SERVICE_NAME, plugin, props);
+ webConsolePlugin = plugin;
+ } catch (Throwable t) {
+ // don't care, we thus don't have the console plugin
+ }
}
protected void deactivate(ComponentContext context) {
context.getBundleContext().removeBundleListener(this);
+
+ if (webConsolePluginService != null) {
+ webConsolePluginService.unregister();
+ webConsolePluginService = null;
+
+ }
+
+ if (webConsolePlugin != null) {
+ webConsolePlugin.deactivate();
+ webConsolePlugin = null;
+ }
}
protected void bindMimeTypeProvider(MimeTypeProvider mimeTypeProvider) {
@@ -268,4 +302,14 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener {
this.registerMimeType(event.getBundle().getEntry(MIME_TYPES));
}
}
+
+ // ---------- plugin support -----------------------------------------------
+
+ Map<String, String> getMimeMap() {
+ return mimeTab;
+ }
+
+ Map<String, String> getExtensionMap() {
+ return extensionMap;
+ }
}
diff --git a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePlugin.java
new file mode 100644
index 0000000..2945f59
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePlugin.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 1997-2009 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.commons.mime.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+
+class MimeTypeWebConsolePlugin extends AbstractWebConsolePlugin {
+
+ /** Serial Version */
+ private static final long serialVersionUID = -2025952303202431607L;
+
+ private static final String LABEL = "mimetypes";
+
+ private static final String TITLE = "MIME Types";
+
+ private final MimeTypeServiceImpl mimeTypeService;
+
+ MimeTypeWebConsolePlugin(MimeTypeServiceImpl mimeTypeService) {
+ this.mimeTypeService = mimeTypeService;
+ }
+
+ @Override
+ public String getLabel() {
+ return LABEL;
+ }
+
+ @Override
+ public String getTitle() {
+ return TITLE;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+
+ if (!spoolResource(request, response)) {
+ super.doGet(request, response);
+ }
+ }
+
+ @Override
+ protected void renderContent(HttpServletRequest req, HttpServletResponse res)
+ throws IOException {
+
+ Map<String, Set<String>> mimetab = new TreeMap<String, Set<String>>();
+
+ Map<String, String> extMap = mimeTypeService.getExtensionMap();
+
+ int numExt = 0;
+ for (Entry<String, String> entry : mimeTypeService.getMimeMap().entrySet()) {
+ String ext = entry.getKey();
+ String mime = entry.getValue();
+
+ Set<String> extList = mimetab.get(mime);
+ if (extList == null) {
+ extList = new HashSet<String>();
+ mimetab.put(mime, extList);
+ }
+
+ if (ext.equals(extMap.get(mime))) {
+ ext = "*" + ext + "*";
+ }
+
+ extList.add(ext);
+
+ numExt++;
+ }
+
+ PrintWriter pw = res.getWriter();
+
+ String resLoc = getLabel() + "/res";
+ pw.println("<link href='" + resLoc
+ + "/jquery.treeTable.css' rel='stylesheet' type='text/css' />");
+ pw.println("<script type='text/javascript' src='" + resLoc
+ + "/jquery.treeTable.min.js'></script>");
+ pw.println("<script type='text/javascript'>");
+ pw.println(" $(document).ready(function() {");
+ pw.println(" $('#mimetabtable').treeTable({ treeColumn: 1 });");
+ pw.println(" });");
+ pw.println("</script>");
+
+ pw.println("<div id='plugin_content'>");
+ pw.println("<div class='fullwidth'>");
+ pw.println("<div class='statusline'>Statistic: " + mimetab.size()
+ + " MIME Types, " + numExt + " Extensions</div>");
+ pw.println("</div>");
+
+ pw.println("<div class='table'>");
+ pw.println("<table id='mimetabtable' class='tablelayout'>");
+
+ pw.println("<colgroup>");
+ pw.println("<col width='20px'>");
+ pw.println("<col width='50%'>");
+ pw.println("<col width='50%'>");
+ pw.println("</colgroup>");
+
+ pw.println("<thead>");
+ pw.println("<tr>");
+ pw.println("<th colspan='2'>Mime Type</th>");
+ pw.println("<th'>Extensions</th>");
+ pw.println("</tr>");
+ pw.println("</thead>");
+
+ pw.println("<tbody>");
+
+ String currentMajor = null;
+
+ for (Entry<String, Set<String>> entry : mimetab.entrySet()) {
+ String major = getMajorType(entry.getKey());
+
+ if (!major.equals(currentMajor)) {
+ currentMajor = major;
+ pw.println("<tr id='" + currentMajor + "'>");
+ pw.println("<td> </td>");
+ pw.println("<td>" + currentMajor + "</td>");
+ pw.println("<td>--</td>");
+ pw.println("</tr>");
+ }
+
+ pw.println("<tr id='" + entry.getKey().replace('/', '-')
+ + "' class='child-of-" + currentMajor + "'>");
+ pw.println("<td> </td>");
+ pw.println("<td>" + entry.getKey() + "</td>");
+ pw.println("<td>" + entry.getValue() + "</td>");
+ pw.println("</tr>");
+ }
+
+ pw.println("</tbody>");
+ pw.println("</table>");
+ pw.println("</div>");
+ pw.println("</div>");
+ }
+
+ private String getMajorType(String type) {
+ int slash = type.indexOf('/');
+ return (slash > 0) ? type.substring(0, slash) : type;
+ }
+
+ private boolean spoolResource(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+
+ String pi = request.getPathInfo();
+ int rPi = pi.indexOf("/res/");
+ if (rPi >= 0) {
+ pi = pi.substring(rPi);
+ InputStream ins = getClass().getResourceAsStream(pi);
+ if (ins != null) {
+ try {
+ response.setContentType(getServletContext().getMimeType(pi));
+ OutputStream out = response.getOutputStream();
+ byte[] buf = new byte[2048];
+ int rd;
+ while ((rd = ins.read(buf)) >= 0) {
+ out.write(buf, 0, rd);
+ }
+ return true;
+ } finally {
+ try {
+ ins.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/resources/META-INF/LICENSE b/src/main/resources/META-INF/LICENSE
index d645695..ef13dba 100644
--- a/src/main/resources/META-INF/LICENSE
+++ b/src/main/resources/META-INF/LICENSE
@@ -200,3 +200,35 @@
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.
+
+
+APACHE SLING SUBCOMPONENTS:
+
+Apache Sling includes subcomponents with separate copyright notices and
+license terms. Your use of these subcomponents is subject to the terms
+and conditions of the following licenses.
+
+JQuery TreeTable plugin
+
+ Copyright (c) 2009 Ludo van den Boom
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/main/resources/META-INF/NOTICE b/src/main/resources/META-INF/NOTICE
index 6c93777..97c463f 100644
--- a/src/main/resources/META-INF/NOTICE
+++ b/src/main/resources/META-INF/NOTICE
@@ -6,3 +6,7 @@ by Day Software (http://www.day.com/).
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software developed by
+Copyright (c) 2009 Ludo van den Boom (http://blog.cubicphuse.nl/)
+Licensed under the MIT License
\ No newline at end of file
diff --git a/src/main/resources/res/jquery.treeTable.css b/src/main/resources/res/jquery.treeTable.css
new file mode 100644
index 0000000..647df57
--- /dev/null
+++ b/src/main/resources/res/jquery.treeTable.css
@@ -0,0 +1,43 @@
+/* jQuery TreeTable Core 2.0 stylesheet
+ *
+ * This file contains styles that are used to display the tree table. Each tree
+ * table is assigned the +treeTable+ class.
+ * ========================================================================= */
+
+/* jquery.treeTable.collapsible
+ * ------------------------------------------------------------------------- */
+.treeTable tr td .expander {
+ background-position: left center;
+ background-repeat: no-repeat;
+ cursor: pointer;
+ padding: 0;
+ zoom: 1; /* IE7 Hack */
+}
+
+.treeTable tr.collapsed td .expander {
+ background-image: url(../../res/imgs/arrow_right.png);
+}
+
+.treeTable tr.expanded td .expander {
+ background-image: url(../../res/imgs/arrow_down.png);
+}
+
+/* jquery.treeTable.sortable
+ * ------------------------------------------------------------------------- */
+.treeTable tr.selected, .treeTable tr.accept {
+ background-color: #3875d7;
+ color: #fff;
+}
+
+.treeTable tr.collapsed.selected td .expander, .treeTable tr.collapsed.accept td .expander {
+ background-image: url(../../res/imgs/arrow_right.png);
+}
+
+.treeTable tr.expanded.selected td .expander, .treeTable tr.expanded.accept td .expander {
+ background-image: url(../../res/imgs/arrow_down.png);
+}
+
+.treeTable .ui-draggable-dragging {
+ color: #000;
+ z-index: 1;
+}
\ No newline at end of file
diff --git a/src/main/resources/res/jquery.treeTable.min.js b/src/main/resources/res/jquery.treeTable.min.js
new file mode 100644
index 0000000..6ba8137
--- /dev/null
+++ b/src/main/resources/res/jquery.treeTable.min.js
@@ -0,0 +1,10 @@
+/* jQuery treeTable Plugin 2.2.1 - http://ludo.cubicphuse.nl/jquery-plugins/treeTable/ */
+(function($){var options;$.fn.treeTable=function(opts){options=$.extend({},$.fn.treeTable.defaults,opts);return this.each(function(){$(this).addClass("treeTable").find("tbody tr").each(function(){if(!options.expandable||$(this)[0].className.search("child-of-")==-1){initialize($(this));}});});};$.fn.treeTable.defaults={childPrefix:"child-of-",expandable:true,indent:19,initialState:"collapsed",treeColumn:0};$.fn.collapse=function(){$(this).addClass("collapsed");childrenOf($(this)).each(fun [...]
+$(this).hide();});return this;};$.fn.expand=function(){$(this).removeClass("collapsed").addClass("expanded");childrenOf($(this)).each(function(){initialize($(this));if($(this).is(".expanded.parent")){$(this).expand();}
+$(this).show();});return this;};$.fn.appendBranchTo=function(destination){var node=$(this);var parent=parentOf(node);var ancestorNames=$.map(ancestorsOf($(destination)),function(a){return a.id;});if($.inArray(node[0].id,ancestorNames)==-1&&(!parent||(destination.id!=parent[0].id))&&destination.id!=node[0].id){indent(node,ancestorsOf(node).length*options.indent*-1);if(parent){node.removeClass(options.childPrefix+parent[0].id);}
+node.addClass(options.childPrefix+destination.id);move(node,destination);indent(node,ancestorsOf(node).length*options.indent);}
+return this;};$.fn.reverse=function(){return this.pushStack(this.get().reverse(),arguments);};$.fn.toggleBranch=function(){if($(this).hasClass("collapsed")){$(this).expand();}else{$(this).removeClass("expanded").collapse();}
+return this;};function ancestorsOf(node){var ancestors=[];while(node=parentOf(node)){ancestors[ancestors.length]=node[0];}
+return ancestors;};function childrenOf(node){return $("table.treeTable tbody tr."+options.childPrefix+node[0].id);};function indent(node,value){var cell=$(node.children("td")[options.treeColumn]);var padding=parseInt(cell.css("padding-left"),10)+value;cell.css("padding-left",+padding+"px");childrenOf(node).each(function(){indent($(this),value);});};function initialize(node){if(!node.hasClass("initialized")){node.addClass("initialized");var childNodes=childrenOf(node);if(!node.hasClass("p [...]
+if(node.hasClass("parent")){var cell=$(node.children("td")[options.treeColumn]);var padding=parseInt(cell.css("padding-left"),10)+options.indent;childNodes.each(function(){$($(this).children("td")[options.treeColumn]).css("padding-left",padding+"px");});if(options.expandable){cell.prepend('<span style="margin-left: -'+options.indent+'px; padding-left: '+options.indent+'px" class="expander"></span>');$(cell[0].firstChild).click(function(){node.toggleBranch();});if(!(node.hasClass("expande [...]
+if(node.hasClass("collapsed")){node.collapse();}else if(node.hasClass("expanded")){node.expand();}}}}};function move(node,destination){node.insertAfter(destination);childrenOf(node).reverse().each(function(){move($(this),node[0]);});};function parentOf(node){var classNames=node[0].className.split(' ');for(key in classNames){if(classNames[key].match("child-of-")){return $("#"+classNames[key].substring(9));}}};})(jQuery);
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.