bdelacretaz closed pull request #2: Sling 7612
URL: https://github.com/apache/sling-org-apache-sling-commons-mime/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pom.xml b/pom.xml
index 248a628..c967ff3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,6 @@
                         <Bundle-DocURL>
                             http://sling.apache.org/site/mime-type-support.html
                         </Bundle-DocURL>
-                        
<Bundle-Activator>org.apache.sling.commons.mime.internal.Activator</Bundle-Activator>
                         <Import-Package>
                             javax.servlet.*;resolution:=optional,
                             org.apache.felix.webconsole;resolution:=optional,
diff --git 
a/src/main/java/org/apache/sling/commons/mime/internal/Activator.java 
b/src/main/java/org/apache/sling/commons/mime/internal/Activator.java
deleted file mode 100644
index c115dd5..0000000
--- a/src/main/java/org/apache/sling/commons/mime/internal/Activator.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.commons.mime.internal;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.sling.commons.mime.MimeTypeProvider;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Activator implements BundleActivator {
-
-    private final Logger logger = 
LoggerFactory.getLogger(this.getClass().getName());
-
-    private ServiceRegistration reg;
-
-    /**
-     * @see 
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
-     */
-    public void start(final BundleContext context) throws Exception {
-        try {
-            final Object provider = new TikaMimeTypeProvider();
-            final Dictionary<String, Object> props = new Hashtable<String, 
Object>();
-            props.put(Constants.SERVICE_DESCRIPTION, "Apache Tika MIME Type 
Provider");
-            props.put(Constants.SERVICE_VENDOR, "The Apache Software 
Foundation");
-
-            reg = context.registerService(MimeTypeProvider.class.getName(), 
provider, props);
-
-            logger.debug("Registered Apache Tika mime type provider");
-        } catch (final Throwable t) {
-            logger.debug("Unable to register Apache Tika mime type provider", 
t);
-        }
-    }
-
-    /**
-     * @see 
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
-     */
-    public void stop(final BundleContext context) throws Exception {
-        if ( reg != null ) {
-            reg.unregister();
-            reg = null;
-        }
-    }
-
-}
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 914390f..e5e37c3 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,9 +23,7 @@
 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;
 
@@ -36,7 +34,6 @@
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -91,8 +88,6 @@
 
     private List<MimeTypeProvider> typeProviderList = new ArrayList<>();
 
-    private ServiceRegistration webConsolePluginService;
-
     // --------- MimeTypeService interface
 
     @Override
@@ -222,31 +217,11 @@ protected void activate(final BundleContext context, 
final Config config) {
                 registerMimeType(configType);
             }
         }
-
-        try {
-            MimeTypeWebConsolePlugin plugin = new 
MimeTypeWebConsolePlugin(this);
-
-            Dictionary<String, String> props = new Hashtable<>();
-            props.put("felix.webconsole.label", 
MimeTypeWebConsolePlugin.LABEL);
-            props.put("felix.webconsole.title", 
MimeTypeWebConsolePlugin.TITLE);
-            props.put("felix.webconsole.category", "Sling");
-            props.put("felix.webconsole.css", 
MimeTypeWebConsolePlugin.CSS_REFS);
-
-            webConsolePluginService = context.registerService(
-                "javax.servlet.Servlet", plugin, props);
-        } catch (Throwable t) {
-            // don't care, we thus don't have the console plugin
-        }
     }
 
     @Deactivate
     protected void deactivate(final BundleContext context) {
         context.removeBundleListener(this);
-
-        if (webConsolePluginService != null) {
-            webConsolePluginService.unregister();
-            webConsolePluginService = null;
-        }
     }
 
     @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = 
ReferencePolicy.DYNAMIC)
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
index a5ce39a..c104354 100644
--- 
a/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePlugin.java
+++ 
b/src/main/java/org/apache/sling/commons/mime/internal/MimeTypeWebConsolePlugin.java
@@ -27,10 +27,23 @@
 import java.util.TreeMap;
 import java.util.Map.Entry;
 
+import javax.servlet.Servlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(
+        service = Servlet.class,
+        property = {
+                "felix.webconsole.label=" + MimeTypeWebConsolePlugin.LABEL,
+                "felix.webconsole.title=" + MimeTypeWebConsolePlugin.TITLE,
+                "felix.webconsole.category=Sling",
+                "felix.webconsole.css=" + MimeTypeWebConsolePlugin.CSS_REFS
+        }
+        )
 class MimeTypeWebConsolePlugin extends HttpServlet {
 
     /** Serial Version */
@@ -44,11 +57,8 @@
 
     static final String CSS_REFS = RES_LOC + "/jquery.treeTable.css";
 
-    private final MimeTypeServiceImpl mimeTypeService;
-
-    MimeTypeWebConsolePlugin(MimeTypeServiceImpl mimeTypeService) {
-        this.mimeTypeService = mimeTypeService;
-    }
+    @Reference
+    private MimeTypeServiceImpl mimeTypeService;
 
     @Override
     protected void doGet(HttpServletRequest request,
diff --git 
a/src/main/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProvider.java
 
b/src/main/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProvider.java
index 5f820bf..ed7fda7 100644
--- 
a/src/main/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProvider.java
+++ 
b/src/main/java/org/apache/sling/commons/mime/internal/TikaMimeTypeProvider.java
@@ -21,10 +21,18 @@
 import org.apache.tika.mime.MimeType;
 import org.apache.tika.mime.MimeTypeException;
 import org.apache.tika.mime.MimeTypes;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
 
 /**
  * MIME type provider based on Apache Tika.
  */
+@Component(
+        property = { //
+                Constants.SERVICE_DESCRIPTION + "=" + "Apache Tika MIME Type 
Provider",
+                Constants.SERVICE_VENDOR + "=" + "The Apache Software 
Foundation"
+        }
+        )
 public class TikaMimeTypeProvider implements MimeTypeProvider {
 
     private final Tika tika = new Tika();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to