ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1536534 - /ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java
Date Mon, 28 Oct 2013 21:25:54 GMT
Author: jawi
Date: Mon Oct 28 21:25:53 2013
New Revision: 1536534

URL: http://svn.apache.org/r1536534
Log:
Play nice in an OSGi-context:

- properly unregister the registered resources when stopping this bundle;
- introduced a proper constant value.


Modified:
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java?rev=1536534&r1=1536533&r2=1536534&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java
(original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinResourceHandler.java
Mon Oct 28 21:25:53 2013
@@ -27,55 +27,57 @@ import javax.servlet.http.HttpServletRes
 import org.osgi.framework.BundleContext;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.HttpService;
-import org.osgi.service.http.NamespaceException;
 
 public class VaadinResourceHandler {
+    private static final String RESOURCE_PATH = "/VAADIN";
+
+    // Injected by Felix DM...
     private volatile HttpService m_http;
-    private HttpContext m_context;
-    private BundleContext m_bundleContext;
+    private volatile BundleContext m_bundleContext;
+
+    public void start() throws Exception {
+        final HttpContext context = m_http.createDefaultHttpContext();
 
-    public void start() {
-        m_context = m_http.createDefaultHttpContext();
-        try {
-            m_http.registerResources("/VAADIN", "/VAADIN", new HttpContext() {
-                public String getMimeType(String name) {
-                    return m_context.getMimeType(name);
+        m_http.registerResources(RESOURCE_PATH, RESOURCE_PATH, new HttpContext() {
+            public String getMimeType(String name) {
+                return context.getMimeType(name);
+            }
+
+            /**
+             * ACE uses a slightly modified version of the 'reindeer' theme. To avoid having
to copy all resources in
+             * the Vaadin jar, we only override the files we changed and do replace the theme
name 'ace' with 'reindeer'
+             * before we go looking for the original files.
+             * 
+             * When updating to a new Vaadin version, usually you need to copy the styles.css
file from the original
+             * archive again and append the ACE changes to the end, as this file tends to
change considerably between
+             * versions.
+             */
+            public URL getResource(String name) {
+                URL resource = null;
+                // fix for ACE-156
+                if (!name.startsWith("/")) {
+                    name = "/".concat(name);
                 }
 
-                /**
-                 * ACE uses a slightly modified version of the 'reindeer' theme. To avoid
having to copy all resources
-                 * in the Vaadin jar, we only override the files we changed and do replace
the theme name 'ace' with
-                 * 'reindeer' before we go looking for the original files.
-                 * 
-                 * When updating to a new Vaadin version, usually you need to copy the styles.css
file from the original
-                 * archive again and append the ACE changes to the end, as this file tends
to change considerably
-                 * between versions.
-                 */
-                public URL getResource(String name) {
-                    URL resource = null;
-                    String prefix = "/VAADIN/";
-                    // fix for ACE-156
-                    if (!name.startsWith("/")) {
-                        name = "/" + name;
-                    }
-                    if (name.startsWith(prefix)) {
-                        String originalName = name.replace("/ace/", "/reindeer/");
-                        resource = m_bundleContext.getBundle().getEntry(originalName);
-                        if (resource == null) {
-                            // try to find the resource in the Vaadin bundle instead
-                            resource = com.vaadin.Application.class.getResource(originalName);
-                        }
+                String prefix = RESOURCE_PATH.concat("/");
+                if (name.startsWith(prefix)) {
+                    String originalName = name.replace("/ace/", "/reindeer/");
+                    resource = m_bundleContext.getBundle().getEntry(originalName);
+                    if (resource == null) {
+                        // try to find the resource in the Vaadin bundle instead
+                        resource = com.vaadin.Application.class.getResource(originalName);
                     }
-                    return resource;
                 }
+                return resource;
+            }
 
-                public boolean handleSecurity(HttpServletRequest request, HttpServletResponse
response) throws IOException {
-                    return m_context.handleSecurity(request, response);
-                }
-            });
-        }
-        catch (NamespaceException e) {
-            e.printStackTrace();
-        }
+            public boolean handleSecurity(HttpServletRequest request, HttpServletResponse
response) throws IOException {
+                return context.handleSecurity(request, response);
+            }
+        });
+    }
+
+    public void stop() throws Exception {
+        m_http.unregister(RESOURCE_PATH);
     }
 }



Mime
View raw message