You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/05/17 22:11:25 UTC
svn commit: r775748 - in /incubator/sling/trunk/bundles/commons/mime: ./
src/main/java/org/apache/sling/commons/mime/internal/
src/main/resources/OSGI-INF/ src/main/resources/OSGI-INF/metatype/
Author: fmeschbe
Date: Sun May 17 20:11:24 2009
New Revision: 775748
URL: http://svn.apache.org/viewvc?rev=775748&view=rev
Log:
SLING-965 Add support to add MIME type mappings by configuration
Added:
incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/
incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/
incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties (with props)
Modified:
incubator/sling/trunk/bundles/commons/mime/pom.xml
incubator/sling/trunk/bundles/commons/mime/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
Modified: incubator/sling/trunk/bundles/commons/mime/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/commons/mime/pom.xml?rev=775748&r1=775747&r2=775748&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/commons/mime/pom.xml (original)
+++ incubator/sling/trunk/bundles/commons/mime/pom.xml Sun May 17 20:11:24 2009
@@ -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>
Modified: incubator/sling/trunk/bundles/commons/mime/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/commons/mime/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java?rev=775748&r1=775747&r2=775748&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/commons/mime/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java (original)
+++ incubator/sling/trunk/bundles/commons/mime/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeServiceImpl.java Sun May 17 20:11:24 2009
@@ -32,6 +32,7 @@
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 @@
* 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 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 @@
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 @@
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 @@
}
}
+ // 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());
Added: incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=775748&view=auto
==============================================================================
--- incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties Sun May 17 20:11:24 2009
@@ -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
Propchange: incubator/sling/trunk/bundles/commons/mime/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
svn:eol-style = native