This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 99b33cecf4 FELIX-6638 : Migrate WebConsole to Jakarta Servlet API
99b33cecf4 is described below

commit 99b33cecf431f884a0630c52c690a63bea39c90d
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Sat Sep 2 11:54:57 2023 +0200

    FELIX-6638 : Migrate WebConsole to Jakarta Servlet API
---
 .../felix/webconsole/AbstractWebConsolePlugin.java |  34 +++----
 .../felix/webconsole/DefaultBrandingPlugin.java    | 101 +--------------------
 .../servlet/BrandingPluginImpl.java}               |  34 ++-----
 .../webconsole/internal/servlet/OsgiManager.java   |  20 ++--
 .../org/apache/felix/webconsole/package-info.java  |   2 +-
 5 files changed, 42 insertions(+), 149 deletions(-)

diff --git 
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
 
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 7febb000b2..7d58ac7d5d 100644
--- 
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++ 
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -138,9 +138,9 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
 
     private BundleContext bundleContext;
 
-    private static volatile BrandingPlugin brandingPlugin = 
DefaultBrandingPlugin.getInstance();
+    private static volatile BrandingPlugin BRANDING_PLUGIN = 
DefaultBrandingPlugin.getInstance();
 
-    private static volatile int logLevel;
+    private static volatile int LOGLEVEL;
 
 
     //---------- HttpServlet Overwrites 
----------------------------------------
@@ -450,7 +450,7 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
      */
     public void log( int level, String message )
     {
-        if ( logLevel >= level )
+        if ( LOGLEVEL >= level )
         {
             ServletConfig config = getServletConfig();
             if ( config != null )
@@ -484,7 +484,7 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
      */
     public void log( int level, String message, Throwable t )
     {
-        if ( logLevel >= level )
+        if ( LOGLEVEL >= level )
         {
             ServletConfig config = getServletConfig();
             if ( config != null )
@@ -655,12 +655,12 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
         r.put("head.title", title);
         r.put("head.label", getLabel());
         r.put("head.cssLinks", getCssLinks(appRoot));
-        r.put("brand.name", brandingPlugin.getBrandName());
-        r.put("brand.product.url", brandingPlugin.getProductURL());
-        r.put("brand.product.name", brandingPlugin.getProductName());
-        r.put("brand.product.img", toUrl( brandingPlugin.getProductImage(), 
appRoot ));
-        r.put("brand.favicon", toUrl( brandingPlugin.getFavIcon(), appRoot ));
-        r.put("brand.css", toUrl( brandingPlugin.getMainStyleSheet(), appRoot 
));
+        r.put("brand.name", BRANDING_PLUGIN.getBrandName());
+        r.put("brand.product.url", BRANDING_PLUGIN.getProductURL());
+        r.put("brand.product.name", BRANDING_PLUGIN.getProductName());
+        r.put("brand.product.img", toUrl( BRANDING_PLUGIN.getProductImage(), 
appRoot ));
+        r.put("brand.favicon", toUrl( BRANDING_PLUGIN.getFavIcon(), appRoot ));
+        r.put("brand.css", toUrl( BRANDING_PLUGIN.getMainStyleSheet(), appRoot 
));
         pw.println( getHeader() );
 
         return pw;
@@ -851,7 +851,7 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
      */
     @Deprecated
     public static BrandingPlugin getBrandingPlugin() {
-        return AbstractWebConsolePlugin.brandingPlugin;
+        return AbstractWebConsolePlugin.BRANDING_PLUGIN;
     }
 
     /**
@@ -865,11 +865,11 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
      * @deprecated
      */
     @Deprecated
-    public static final void setBrandingPlugin(BrandingPlugin brandingPlugin) {
-        if(brandingPlugin == null){
-            AbstractWebConsolePlugin.brandingPlugin = 
DefaultBrandingPlugin.getInstance();
+    public static final void setBrandingPlugin(final BrandingPlugin 
brandingPlugin) {
+        if (brandingPlugin == null){
+            AbstractWebConsolePlugin.BRANDING_PLUGIN = 
DefaultBrandingPlugin.getInstance();
         } else {
-            AbstractWebConsolePlugin.brandingPlugin = brandingPlugin;
+            AbstractWebConsolePlugin.BRANDING_PLUGIN = brandingPlugin;
         }
     }
 
@@ -883,8 +883,8 @@ public abstract class AbstractWebConsolePlugin extends 
HttpServlet {
      * @param logLevel the maximum allowed log level. If message is logged with
      *        lower level it will not be forwarded to the logger.
      */
-    public static final void setLogLevel( int logLevel ) {
-        AbstractWebConsolePlugin.logLevel = logLevel;
+    public static final void setLogLevel( final int logLevel ) {
+        AbstractWebConsolePlugin.LOGLEVEL = logLevel;
     }
 
     private final String getHeader() {
diff --git 
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
 
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
index cd9359e640..032384f706 100644
--- 
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
+++ 
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
@@ -18,9 +18,7 @@
  */
 package org.apache.felix.webconsole;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
+import org.apache.felix.webconsole.internal.servlet.BrandingPluginImpl;
 
 /**
  * The <code>DefaultBrandingPlugin</code> class is the default implementation
@@ -88,61 +86,17 @@ import java.util.Properties;
  * @deprecated Plugins should never use the branding plugin directly
  */
 @Deprecated
-public class DefaultBrandingPlugin implements BrandingPlugin {
+public class DefaultBrandingPlugin extends BrandingPluginImpl implements 
BrandingPlugin {
 
-    /**
-     * The name of the bundle entry providing branding properties for this
-     * default branding plugin (value is "/META-INF/webconsole.properties").
-     */
-    private static final String BRANDING_PROPERTIES = 
"/META-INF/webconsole.properties";
-
-    private static DefaultBrandingPlugin instance;
-
-    private final String brandName;
-
-    private final String productName;
-
-    private final String productURL;
-
-    private final String productImage;
-
-    private final String vendorName;
-
-    private final String vendorURL;
-
-    private final String vendorImage;
-
-    private final String favIcon;
-
-    private final String mainStyleSheet;
+    private static volatile DefaultBrandingPlugin instance;
 
     private DefaultBrandingPlugin() {
-        Properties props = new Properties();
-
-        // try to load the branding properties
-        try (InputStream ins = getClass().getResourceAsStream( 
BRANDING_PROPERTIES )) {
-            if ( ins != null ) {
-                props.load( ins );
-            }
-        } catch ( IOException ignore ) {
-            // ignore - will use defaults
-        }
-
-        // set the fields from the properties now
-        brandName = props.getProperty( "webconsole.brand.name", "Apache Felix 
Web Console" );
-        productName = props.getProperty( "webconsole.product.name", "Apache 
Felix" );
-        productURL = props.getProperty( "webconsole.product.url", 
"https://felix.apache.org"; );
-        productImage = props.getProperty( "webconsole.product.image", 
"/res/imgs/logo.png" );
-        vendorName = props.getProperty( "webconsole.vendor.name", "The Apache 
Software Foundation" );
-        vendorURL = props.getProperty( "webconsole.vendor.url", 
"https://www.apache.org"; );
-        vendorImage = props.getProperty( "webconsole.vendor.image", 
"/res/imgs/logo.png" );
-        favIcon = props.getProperty( "webconsole.favicon", 
"/res/imgs/favicon.ico" );
-        mainStyleSheet = props.getProperty( "webconsole.stylesheet", 
"/res/ui/webconsole.css" );
+        super();
     }
 
     /**
      * Retrieves the shared instance
-     * 
+     *
      * @return the singleton instance of the object
      */
     public static DefaultBrandingPlugin getInstance() {
@@ -151,49 +105,4 @@ public class DefaultBrandingPlugin implements 
BrandingPlugin {
         }
         return instance;
     }
-
-    @Override
-    public String getBrandName() {
-        return brandName;
-    }
-
-    @Override
-    public String getProductName() {
-        return productName;
-    }
-
-    @Override
-    public String getProductURL() {
-        return productURL;
-    }
-
-    @Override
-    public String getProductImage() {
-        return productImage;
-    }
-
-    @Override
-    public String getVendorName() {
-        return vendorName;
-    }
-
-    @Override
-    public String getVendorURL() {
-        return vendorURL;
-    }
-
-    @Override
-    public String getVendorImage() {
-        return vendorImage;
-    }
-
-    @Override
-    public String getFavIcon() {
-        return favIcon;
-    }
-
-    @Override
-    public String getMainStyleSheet() {
-        return mainStyleSheet;
-    }
 }
diff --git 
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
 
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/BrandingPluginImpl.java
similarity index 84%
copy from 
webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
copy to 
webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/BrandingPluginImpl.java
index cd9359e640..61b05721ac 100644
--- 
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
+++ 
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/BrandingPluginImpl.java
@@ -16,15 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.webconsole;
+package org.apache.felix.webconsole.internal.servlet;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.felix.webconsole.spi.BrandingPlugin;
+
 /**
- * The <code>DefaultBrandingPlugin</code> class is the default implementation
- * of the {@link BrandingPlugin} interface. The singleton instance of this
+ * This is an implementation of the {@link BrandingPlugin} interface. The 
singleton instance of this
  * class is used as branding plugin if no BrandingPlugin service is registered
  * in the system.
  * <p>
@@ -84,11 +85,8 @@ import java.util.Properties;
  * through the class loader of this class, the properties overwrite the default
  * settings according to the property names listed above. The easiest way to
  * add such a properties file is to provide a fragment bundle with the file.
- *
- * @deprecated Plugins should never use the branding plugin directly
  */
-@Deprecated
-public class DefaultBrandingPlugin implements BrandingPlugin {
+public class BrandingPluginImpl implements BrandingPlugin {
 
     /**
      * The name of the bundle entry providing branding properties for this
@@ -96,8 +94,6 @@ public class DefaultBrandingPlugin implements BrandingPlugin {
      */
     private static final String BRANDING_PROPERTIES = 
"/META-INF/webconsole.properties";
 
-    private static DefaultBrandingPlugin instance;
-
     private final String brandName;
 
     private final String productName;
@@ -116,15 +112,15 @@ public class DefaultBrandingPlugin implements 
BrandingPlugin {
 
     private final String mainStyleSheet;
 
-    private DefaultBrandingPlugin() {
-        Properties props = new Properties();
+    public BrandingPluginImpl() {
+        final Properties props = new Properties();
 
         // try to load the branding properties
-        try (InputStream ins = getClass().getResourceAsStream( 
BRANDING_PROPERTIES )) {
+        try (final InputStream ins = getClass().getResourceAsStream( 
BRANDING_PROPERTIES )) {
             if ( ins != null ) {
                 props.load( ins );
             }
-        } catch ( IOException ignore ) {
+        } catch ( final IOException ignore ) {
             // ignore - will use defaults
         }
 
@@ -140,18 +136,6 @@ public class DefaultBrandingPlugin implements 
BrandingPlugin {
         mainStyleSheet = props.getProperty( "webconsole.stylesheet", 
"/res/ui/webconsole.css" );
     }
 
-    /**
-     * Retrieves the shared instance
-     * 
-     * @return the singleton instance of the object
-     */
-    public static DefaultBrandingPlugin getInstance() {
-        if ( instance == null ) {
-            instance = new DefaultBrandingPlugin();
-        }
-        return instance;
-    }
-
     @Override
     public String getBrandName() {
         return brandName;
diff --git 
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
 
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index 2c1001f381..c52a78c004 100644
--- 
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ 
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -856,11 +856,9 @@ public class OsgiManager extends GenericServlet {
     }
 
     private HttpServletResponse wrapResponse(final HttpServletRequest request,
-        final HttpServletResponse response, final AbstractWebConsolePlugin 
plugin)
-    {
+        final HttpServletResponse response, final AbstractWebConsolePlugin 
plugin) {
         final Locale locale = request.getLocale();
-        final ResourceBundle resourceBundle = 
resourceBundleManager.getResourceBundle(
-            plugin.getBundle(), locale);
+        final ResourceBundle resourceBundle = 
resourceBundleManager.getResourceBundle(plugin.getBundle(), locale);
         return new FilteringResponseWrapper(response, resourceBundle, request);
     }
 
@@ -883,18 +881,20 @@ public class OsgiManager extends GenericServlet {
         }
 
         @Override
-        public BrandingPlugin addingService(ServiceReference<BrandingPlugin> 
reference) {
+        public BrandingPlugin addingService(final 
ServiceReference<BrandingPlugin> reference) {
             final BrandingPlugin plugin = super.addingService(reference);
-            if (plugin instanceof org.apache.felix.webconsole.BrandingPlugin) {
-                
AbstractWebConsolePlugin.setBrandingPlugin((org.apache.felix.webconsole.BrandingPlugin)plugin);
-            } else {
-                AbstractWebConsolePlugin.setBrandingPlugin(new 
BrandingPluginAdapter(plugin));
+            if (plugin != null) {
+                if (plugin instanceof 
org.apache.felix.webconsole.BrandingPlugin) {
+                    
AbstractWebConsolePlugin.setBrandingPlugin((org.apache.felix.webconsole.BrandingPlugin)plugin);
+                } else {
+                    AbstractWebConsolePlugin.setBrandingPlugin(new 
BrandingPluginAdapter(plugin));
+                }
             }
             return plugin;
         }
 
         @Override
-        public void removedService(ServiceReference<BrandingPlugin> reference, 
BrandingPlugin service) {
+        public void removedService(final ServiceReference<BrandingPlugin> 
reference, BrandingPlugin service) {
             AbstractWebConsolePlugin.setBrandingPlugin(null);
             try {
                 super.removedService(reference, service);
diff --git 
a/webconsole/src/main/java/org/apache/felix/webconsole/package-info.java 
b/webconsole/src/main/java/org/apache/felix/webconsole/package-info.java
index 0ad2996c24..10596eeaed 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/package-info.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/package-info.java
@@ -16,6 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
[email protected]("3.5.0")
[email protected]("3.5.1")
 package org.apache.felix.webconsole;
 

Reply via email to