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 384bf2a7af68b2e8c0192758afd5d4708488a338 Author: Felix Meschberger <[email protected]> AuthorDate: Sun May 17 20:11:24 2009 +0000 SLING-965 Add support to add MIME type mappings by configuration git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/commons/mime@775748 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 5 +++ .../commons/mime/internal/MimeTypeServiceImpl.java | 36 ++++++++++++++++------ .../OSGI-INF/metatype/metatype.properties | 36 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index b8591c8..8c76cdc 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,11 @@ </reporting> <dependencies> <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.osgi</artifactId> + <version>2.0.2-incubator</version> + </dependency> + <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.core</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 47e7947..2d45685 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 @@ -32,6 +32,7 @@ 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.apache.sling.commons.osgi.OsgiUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleListener; @@ -43,13 +44,14 @@ import org.osgi.service.log.LogService; * The <code>MimeTypeServiceImpl</code> is the official implementation of the * {@link MimeTypeService} interface. * - * @scr.component immediate="false" metatype="no" + * @scr.component immediate="false" label="%mime.service.name" + * description="%mime.service.description" * @scr.property name="service.vendor" value="The Apache Software Foundation" - * @scr.property name="service.description" value="Sling Servlet" + * @scr.property name="service.description" value="Apache Sling MIME Type Service" + * @scr.service interface="org.apache.sling.commons.mime.MimeTypeService" * @scr.reference name="MimeTypeProvider" * interface="org.apache.sling.commons.mime.MimeTypeProvider" * cardinality="0..n" policy="dynamic" - * @scr.service interface="org.apache.sling.commons.mime.MimeTypeService" */ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener { @@ -57,6 +59,9 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener { public static final String MIME_TYPES = "/META-INF/mime.types"; + /** @scr.property cardinality="-2147483647" type="String" */ + private static final String PROP_MIME_TYPES = "mime.types"; + /** @scr.reference cardinality="0..1" policy="dynamic" */ private LogService logService; @@ -115,6 +120,15 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener { return ext; } + public void registerMimeType(String line) { + String[] parts = line.split("\\s+"); + if (parts.length > 1) { + String[] extensions = new String[parts.length - 1]; + System.arraycopy(parts, 1, extensions, 0, extensions.length); + this.registerMimeType(parts[0], extensions); + } + } + public void registerMimeType(String mimeType, String... extensions) { if (mimeType == null || mimeType.length() == 0 || extensions == null || extensions.length == 0) { @@ -170,12 +184,7 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener { continue; } - String[] parts = line.split("\\s+"); - if (parts.length > 1) { - String[] extensions = new String[parts.length - 1]; - System.arraycopy(parts, 1, extensions, 0, extensions.length); - this.registerMimeType(parts[0], extensions); - } + registerMimeType(line); } } @@ -251,6 +260,15 @@ public class MimeTypeServiceImpl implements MimeTypeService, BundleListener { } } + // register configuration properties + String[] configTypes = OsgiUtil.toStringArray(context.getProperties().get( + PROP_MIME_TYPES)); + if (configTypes != null) { + for (String configType : configTypes) { + registerMimeType(configType); + } + } + try { MimeTypeWebConsolePlugin plugin = new MimeTypeWebConsolePlugin(this); plugin.activate(context.getBundleContext()); diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties new file mode 100644 index 0000000..b8a8461 --- /dev/null +++ b/src/main/resources/OSGI-INF/metatype/metatype.properties @@ -0,0 +1,36 @@ +# +# 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. +# + + +# +# This file contains localization strings for configuration labels and +# descriptions as used in the metatype.xml descriptor generated by the +# the Felix SCR plugin + +mime.service.name = Apache Sling MIME Type Service +mime.service.description = The Sling MIME Type Service provides support for \ + maintaining and configuring MIME Type mappings. +mime.types.name = MIME Types +mime.types.description = Configures additional MIME type mappings in the \ + traditional mime.types file format: Each property is a blank space separated \ + list of strings where the first string is the MIME type and the rest of the \ + strings are filename extensions referring to the MIME type. Using this \ + property additional MIME type mappings may be defined. Existing MIME type \ + mappings cannot be redefined and setting such mappings in this property \ + has no effect. For a list of existing mappings refer to the MIME Types page. \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
