Merge pull request #2 from cschneider/SLING-7612
SLING-7612: Use Declarative Services to register optional components
diff --git a/README.md b/README.md
index 71c4bea..7d4a6e8 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+[<img src="http://sling.apache.org/res/logos/sling.png"/>](http://sling.apache.org)
+
+ [![Build Status](https://builds.apache.org/buildStatus/icon?job=sling-org-apache-sling-commons-mime-1.8)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-commons-mime-1.8) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-commons-mime-1.8.svg)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-org-apache-sling-commons-mime-1.8/test_results_analyzer/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.sling/org.apache.sling.commons.mime/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.sling%22%20a%3A%22org.apache.sling.commons.mime%22) [![JavaDocs](https://www.javadoc.io/badge/org.apache.sling/org.apache.sling.commons.mime.svg)](https://www.javadoc.io/doc/org.apache.sling/org.apache.sling.commons.mime) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
+
# Apache Sling Commons MIME type mapping support
This module is part of the [Apache Sling](https://sling.apache.org) project.
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 e5e37c3..6af9e3a 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
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -40,10 +39,11 @@
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.log.LogService;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The <code>MimeTypeServiceImpl</code> is the official implementation of the
@@ -60,7 +60,7 @@
public static final String CORE_MIME_TYPES = "/META-INF/core_mime.types";
public static final String MIME_TYPES = "/META-INF/mime.types";
-
+
@ObjectClassDefinition(name = "Apache Sling MIME Type Service",
description = "The Sling MIME Type Service provides support for " +
"maintaining and configuring MIME Type mappings.")
@@ -77,9 +77,8 @@
String[] mime_types();
}
- @Reference(cardinality=ReferenceCardinality.OPTIONAL, policy=ReferencePolicy.DYNAMIC)
- private volatile LogService logService;
-
+ private Logger log = LoggerFactory.getLogger(this.getClass());
+
private Map<String, String> mimeTab = new HashMap<>();
private Map<String, String> extensionMap = new HashMap<>();
@@ -147,8 +146,8 @@
String oldMimeType = mimeTab.get(extension);
if (oldMimeType == null) {
- log(LogService.LOG_DEBUG, "registerMimeType: Add mapping "
- + extension + "=" + mimeType, null);
+ log.debug("registerMimeType: Add mapping "
+ + extension + "=" + mimeType);
this.mimeTab.put(extension, mimeType);
@@ -158,10 +157,10 @@
} else {
- log(LogService.LOG_INFO,
+ log.info(
"registerMimeType: Ignoring mapping " + extension + "="
+ mimeType + ": Mapping " + extension + "="
- + oldMimeType + " already exists", null);
+ + oldMimeType + " already exists");
}
@@ -247,7 +246,7 @@
try {
this.registerMimeType(event.getBundle().getEntry(MIME_TYPES));
} catch (IllegalStateException ie) {
- log(LogService.LOG_INFO, "bundleChanged: an issue while registering the mime type occurred", null);
+ log.info("bundleChanged: an issue while registering the mime type occurred");
}
}
}
@@ -285,7 +284,7 @@
this.registerMimeType(ins);
} catch (IOException ioe) {
// log but don't actually care
- this.log(LogService.LOG_WARNING, "An error occurred reading "
+ log.warn("An error occurred reading "
+ mimetypes, ioe);
} finally {
if (ins != null) {
@@ -315,19 +314,4 @@
}
}
- private void log(int level, String message, Throwable t) {
- LogService log = this.logService;
- if (log != null) {
- log.log(level, message, t);
- } else {
- PrintStream out = (level == LogService.LOG_ERROR)
- ? System.err
- : System.out;
- out.println(message);
- if (t != null) {
- t.printStackTrace(out);
- }
- }
- }
-
}