You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2009/07/20 22:26:00 UTC

svn commit: r795995 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole: WebConsoleConstants.java internal/core/BundlesServlet.java internal/servlet/OsgiManager.java

Author: cziegeler
Date: Mon Jul 20 20:26:00 2009
New Revision: 795995

URL: http://svn.apache.org/viewvc?rev=795995&view=rev
Log:
FELIX-1275 : Add new constant for plugin root and use plugin root to create inter bundle links.

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java?rev=795995&r1=795994&r2=795995&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java Mon Jul 20 20:26:00 2009
@@ -64,6 +64,19 @@
     public static final String ATTR_APP_ROOT = "felix.webconsole.appRoot";
 
     /**
+     * The name of the request attribute providing the absolute path of the
+     * current plugin (value is "felix.webconsole.pluginRoot"). This consists of
+     * the servlet context path (from <code>ServletRequest.getContextPath()</code>),
+     * the configured path of the web console root (<code>/system/console</code>
+     * by default) and the plugin label {@link #PLUGIN_LABEL}.
+     * <p>
+     * The type of this request attribute is <code>String</code>.
+     *
+     * @since 1.2.12
+     */
+    public static final String ATTR_PLUGIN_ROOT = "felix.webconsole.pluginRoot";
+
+    /**
      * The name of the request attribute providing a mapping of labels to page
      * titles of registered console plugins (value is "felix.webconsole.labelMap").
      * This map may be used to render a navigation of the console plugins as the

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java?rev=795995&r1=795994&r2=795995&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java Mon Jul 20 20:26:00 2009
@@ -114,7 +114,8 @@
         }
         if ( reqInfo.extension.equals("json")  )
         {
-            this.renderJSON(response, reqInfo.bundle);
+            final String pluginRoot = ( String ) request.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT );
+            this.renderJSON(response, reqInfo.bundle, pluginRoot);
 
             // nothing more to do
             return;
@@ -207,7 +208,8 @@
             } catch (InterruptedException e) {
                 // we ignore this
             }
-            this.renderJSON(resp, null);
+            final String pluginRoot = ( String ) req.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT );
+            this.renderJSON(resp, null, pluginRoot);
         }
         else
         {
@@ -300,7 +302,8 @@
             pw.println( "<div id='plugin_content'/>");
             Util.startScript( pw );
             pw.print( "renderBundles(");
-            writeJSON(pw, reqInfo.bundle);
+            final String pluginRoot = ( String ) request.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT );
+            writeJSON(pw, reqInfo.bundle, pluginRoot );
             pw.println(");" );
             Util.endScript( pw );
         }
@@ -319,16 +322,16 @@
         pw.println( "</form></div");
     }
 
-    private void renderJSON( final HttpServletResponse response, final Bundle bundle ) throws IOException
+    private void renderJSON( final HttpServletResponse response, final Bundle bundle, final String pluginRoot ) throws IOException
     {
         response.setContentType( "application/json" );
         response.setCharacterEncoding( "UTF-8" );
 
         final PrintWriter pw = response.getWriter();
-        writeJSON(pw, bundle);
+        writeJSON(pw, bundle, pluginRoot);
     }
 
-    private void writeJSON( final PrintWriter pw, final Bundle bundle) throws IOException
+    private void writeJSON( final PrintWriter pw, final Bundle bundle, final String pluginRoot) throws IOException
     {
         final Bundle[] allBundles = this.getBundles();
         final String statusLine = this.getStatusLine(allBundles);
@@ -351,7 +354,7 @@
 
             for ( int i = 0; i < bundles.length; i++ )
             {
-                bundleInfo( jw, bundles[i], bundle != null );
+                bundleInfo( jw, bundles[i], bundle != null, pluginRoot );
             }
 
             jw.endArray();
@@ -426,7 +429,7 @@
         return buffer.toString();
     }
 
-    private void bundleInfo( JSONWriter jw, Bundle bundle, boolean details ) throws JSONException
+    private void bundleInfo( JSONWriter jw, Bundle bundle, boolean details, final String pluginRoot ) throws JSONException
     {
         jw.object();
         jw.key( "id" );
@@ -460,7 +463,7 @@
 
         if ( details )
         {
-            bundleDetails( jw, bundle );
+            bundleDetails( jw, bundle, pluginRoot );
         }
 
         jw.endObject();
@@ -542,7 +545,7 @@
     }
 
 
-    private void bundleDetails( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void bundleDetails( JSONWriter jw, Bundle bundle, final String pluginRoot ) throws JSONException
     {
         Dictionary headers = bundle.getHeaders();
 
@@ -569,11 +572,11 @@
 
         if ( bundle.getState() == Bundle.INSTALLED )
         {
-            listImportExportsUnresolved( jw, bundle );
+            listImportExportsUnresolved( jw, bundle, pluginRoot );
         }
         else
         {
-            listImportExport( jw, bundle );
+            listImportExport( jw, bundle, pluginRoot );
         }
 
         listServices( jw, bundle );
@@ -591,7 +594,7 @@
     }
 
 
-    private void listImportExport( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void listImportExport( JSONWriter jw, Bundle bundle, final String pluginRoot ) throws JSONException
     {
         PackageAdmin packageAdmin = getPackageAdmin();
         if ( packageAdmin == null )
@@ -683,7 +686,7 @@
                 for ( int i = 0; i < packages.length; i++ )
                 {
                     ExportedPackage ep = packages[i];
-                    collectImport( val, ep.getName(), ep.getVersion(), false, ep );
+                    collectImport( val, ep.getName(), ep.getVersion(), false, ep, pluginRoot );
                 }
             }
             else
@@ -701,14 +704,14 @@
             for ( Iterator ui = usingBundles.values().iterator(); ui.hasNext(); )
             {
                 Bundle usingBundle = ( Bundle ) ui.next();
-                val.put( getBundleDescriptor( usingBundle ) );
+                val.put( getBundleDescriptor( usingBundle, pluginRoot ) );
             }
             keyVal( jw, "Importing Bundles", val );
         }
     }
 
 
-    private void listImportExportsUnresolved( JSONWriter jw, Bundle bundle ) throws JSONException
+    private void listImportExportsUnresolved( JSONWriter jw, Bundle bundle, final String pluginRoot ) throws JSONException
     {
         Dictionary dict = bundle.getHeaders();
 
@@ -802,7 +805,7 @@
                             }
                         }
 
-                        collectImport( val, r4Import.getName(), r4Import.getVersion(), r4Import.isOptional(), ep );
+                        collectImport( val, r4Import.getName(), r4Import.getVersion(), r4Import.isOptional(), ep, pluginRoot );
                     }
                 }
                 else
@@ -925,7 +928,8 @@
     }
 
 
-    private void collectImport( JSONArray array, String name, Version version, boolean optional, ExportedPackage export )
+    private void collectImport( JSONArray array, String name, Version version, boolean optional,
+            ExportedPackage export, final String pluginRoot )
     {
         StringBuffer val = new StringBuffer();
         boolean bootDel = isBootDelegated( name );
@@ -937,7 +941,7 @@
 
         if ( export != null )
         {
-            val.append( getBundleDescriptor( export.getExportingBundle() ) );
+            val.append( getBundleDescriptor( export.getExportingBundle(), pluginRoot ) );
 
             if ( bootDel )
             {
@@ -1015,10 +1019,10 @@
     }
 
 
-    private String getBundleDescriptor( Bundle bundle )
+    private String getBundleDescriptor( Bundle bundle, final String pluginRoot )
     {
         StringBuffer val = new StringBuffer();
-        val.append("<a href='").append("./").append(bundle.getBundleId()).append("'>");
+        val.append("<a href='").append(pluginRoot).append('/').append(bundle.getBundleId()).append("'>");
         if ( bundle.getSymbolicName() != null )
         {
             // list the bundle name if not null

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=795995&r1=795994&r2=795995&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java Mon Jul 20 20:26:00 2009
@@ -307,6 +307,7 @@
             // the official request attributes
             req.setAttribute( WebConsoleConstants.ATTR_LABEL_MAP, labelMap );
             req.setAttribute( WebConsoleConstants.ATTR_APP_ROOT, request.getContextPath() + request.getServletPath() );
+            req.setAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT, request.getContextPath() + request.getServletPath() + '/' + label);
 
             // deprecated request attributes
             req.setAttribute( ATTR_LABEL_MAP_OLD, labelMap );