FELIX-1275 : Add new constant for plugin root and use plugin root to create inter bundle links.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@795995 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
index b917c44..d54e53e 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
@@ -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
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 5a709d2..3f20d0a 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -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
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 b0cfab6..05f0792 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
@@ -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 );