You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by vv...@apache.org on 2010/04/15 15:33:00 UTC

svn commit: r934400 - in /felix/trunk/webconsole/src/main: java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java resources/res/ui/license.css resources/res/ui/license.js

Author: vvalchev
Date: Thu Apr 15 13:32:59 2010
New Revision: 934400

URL: http://svn.apache.org/viewvc?rev=934400&view=rev
Log:
Fixed FELIX-2207 /License plugin should support Bundle-License manifest header/
https://issues.apache.org/jira/browse/FELIX-2207

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
    felix/trunk/webconsole/src/main/resources/res/ui/license.css
    felix/trunk/webconsole/src/main/resources/res/ui/license.js

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java?rev=934400&r1=934399&r2=934400&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java Thu Apr 15 13:32:59 2010
@@ -32,6 +32,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.felix.utils.manifest.Clause;
+import org.apache.felix.utils.manifest.Parser;
 import org.apache.felix.webconsole.DefaultVariableResolver;
 import org.apache.felix.webconsole.SimpleWebConsolePlugin;
 import org.apache.felix.webconsole.WebConsoleUtil;
@@ -118,6 +120,7 @@ public final class LicenseServlet extend
                 Bundle bundle = bundles[i];
 
                 JSONObject files = findResource(bundle, LICENSE_FILES);
+                addLicensesFromHeader(bundle, files);
                 if (files.length() > 0)
                 { // has resources
                     JSONObject data = new JSONObject();
@@ -141,6 +144,45 @@ public final class LicenseServlet extend
         return path.substring( path.lastIndexOf( '/' ) + 1 );
     }
 
+    private static final JSONObject addLicensesFromHeader(Bundle bundle, JSONObject files)
+        throws JSONException
+    {
+        String target = (String) bundle.getHeaders("").get("Bundle-License");
+        if (target != null)
+        {
+            Clause[] licenses = Parser.parseHeader(target);
+            for (int i = 0; licenses != null && i < licenses.length; i++)
+            {
+                final String name = licenses[i].getName();
+                if (!"<<EXTERNAL>>".equals(name))
+                {
+                    final String link = licenses[i].getAttribute("link");
+                    final String path;
+                    final String url;
+                    if (link == null)
+                    {
+                        path = name;
+                        url = getName(name);
+                    }
+                    else
+                    {
+                        path = link;
+                        url = name;
+                    }
+
+                    // skip entry URL is bundle resources, but doesn't exists
+                    if (path.indexOf("://") == -1 && null == bundle.getEntry(path))
+                        continue;
+
+                    JSONObject entry = new JSONObject();
+                    entry.put("path", path);
+                    entry.put("url", url);
+                    files.append("__res__", entry);
+                }
+            }
+        }
+        return files;
+    }
 
     private static final JSONObject findResource( Bundle bundle, String[] patterns ) throws IOException, JSONException
     {

Modified: felix/trunk/webconsole/src/main/resources/res/ui/license.css
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/license.css?rev=934400&r1=934399&r2=934400&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/license.css (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/license.css Thu Apr 15 13:32:59 2010
@@ -37,3 +37,8 @@
 	width: 100%;
 	padding: 1em;
 }
+#licenseDetails iframe {
+	width: 100%;
+	height: 35em;
+	border: none;
+}

Modified: felix/trunk/webconsole/src/main/resources/res/ui/license.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/license.js?rev=934400&r1=934399&r2=934400&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/license.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/license.js Thu Apr 15 13:32:59 2010
@@ -59,6 +59,7 @@ function displayBundle(/* String */ bund
                     link += descr.jar + "!/"; // inner jar attribute
                 }
                 link += descr.path;
+				if (descr.path.indexOf('http:') == 0 || descr.path.indexOf('ftp:') == 0) link = descr.path;
 
 				buttons += '<a href="' + link + '">' + descr.url + '</a> ';
 
@@ -79,7 +80,7 @@ function displayBundle(/* String */ bund
     }
     
     if (firstPage) {
-        $.get(firstPage, insertLicenseData);
+		openLicenseLink(firstPage);
     } else {
         licenseDetails.html("");
     }
@@ -88,11 +89,19 @@ function displayBundle(/* String */ bund
 	$("#licenseLeft #" +bundleIndex).addClass('ui-state-default ui-corner-all');
 
     $('#licenseButtons a').click(function() {
-        $.get(this.href, insertLicenseData);
-       return false;
+		openLicenseLink(this.href);
+		return false;
     });
 }
 
+function openLicenseLink(uri) {
+	if (uri.indexOf(window.location.href) == 0 || uri.indexOf(pluginRoot) == 0) { // local URI
+        $.get(uri, insertLicenseData);
+	} else {
+		licenseDetails.html( '<iframe frameborder="0" src="' + uri+ '"></iframe>' );
+	}
+}
+
 
 $(document).ready(function() {
 	// init elements cache