FELIX-1988 Apply 16.license_plugin.patch by Valentin Valchev (thanks)
FELIX-1910 Refactor LicenseServlet to support on-demand loading of licenses (part of 16.license_plugin.patch)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@911770 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
index 20de138..cac6186 100644
--- a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -165,3 +165,10 @@
 config.del.config=Configuration: 
 config.del.bundle=Bundle: 
 config.unbind.ask=Are you sure to unbind this configuration ?
+
+
+# License plugin
+license.status.ok=The following bundles contains license files.
+license.status.none=No bundles with license files available
+license.resources=Bundle Resources: 
+license.resources.embedded=Embedded {0}: 
\ No newline at end of file
diff --git a/webconsole/src/main/resources/res/ui/license.css b/webconsole/src/main/resources/res/ui/license.css
index f371c35..b2bcba4 100644
--- a/webconsole/src/main/resources/res/ui/license.css
+++ b/webconsole/src/main/resources/res/ui/license.css
@@ -13,37 +13,28 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ /* CSS Document */
+ */
+
 #licenseContent {
-    position: relative;
-    margin-top: 25px; padding : 5px;
-    width: 100%;
-    padding: 5px;
+	width: 100%;
 }
-
 #licenseLeft {
-    width: 300px;
-    border-right: 1px black solid;
+	float: left;
+	width: 25%;
+	padding: 0;
+	margin-right: 1em;
 }
-
+#licenseLeft a {
+	display: block;
+	width: 100%;
+	margin: 0;
+	text-decoration: none;
+}
 #licenseRight {
-    position: absolute;
-    top: 5px;
-    left: 305px;
-    padding: 5px;
-    width: 650px;
-    border-left: 1px black solid;
+	float: left;
+	width: 70%;
 }
-
-#licenseClear {
-    clear: both;
-    height: 1px;
+#licenseDetails {
+	width: 100%;
+	height: 100%;
 }
-
-.licenseButtons {
-    padding: 5px;
-}
-
-.licenseDetails {
-    padding: 5px;
-}
\ No newline at end of file
diff --git a/webconsole/src/main/resources/res/ui/license.js b/webconsole/src/main/resources/res/ui/license.js
index a8cbb1f..35018d4 100644
--- a/webconsole/src/main/resources/res/ui/license.js
+++ b/webconsole/src/main/resources/res/ui/license.js
@@ -15,6 +15,9 @@
  * limitations under the License.
  */
 
+var licenseButtons = false;
+var licenseDetails = false;
+
 function displayBundle(/* String */ bundleId)
 {
     var theBundleData = bundleData[bundleId];
@@ -25,7 +28,6 @@
 
     var title = theBundleData.title;
     
-    var licenseButtons = document.getElementById('licenseButtons');
     if (licenseButtons) {
         
         var innerHTML = "";
@@ -36,47 +38,42 @@
             for (var idx in entry)
             {
                 var descr = entry[idx];
-                buttons += "<a href='javascript:displayFile(\"" + bundleId + "\", \"" + name + "\", " + idx + ");'"
-                   + " >" + descr.url + "</a> ";
+				var jar = descr.jar ? '&jar=' + descr.jar : ''; // inner jar attribute
+				buttons += '<a href="' + pluginRoot + '?bid=' + bundleId + '&url=' + descr.path + jar + '" target="licenseDetails">' + descr.url + '</a> ';
             }
             if (buttons)
             {
+				// apply i18n
+				name =  '__res__' == name ? i18n.resources : i18n.resources_emb.msgFormat( name );
                 innerHTML += name + ": " + buttons + "<br />";
             }
         }
-        
-        if (!innerHTML)
-        {
-            innerHTML = "<em>The Bundle contains neither LICENSE nor NOTICE files</em>";
-        }
-        
-        licenseButtons.innerHTML = "<h1>" + title + "</h1>" + innerHTML;
+
+        licenseButtons.html("<h1>" + title + "</h1>" + innerHTML);
     }
     
-    var licenseDetails = document.getElementById('licenseDetails');
-    if (licenseDetails)
-    {
-        licenseDetails.innerHTML = "";
-    }
+    licenseDetails.html("");
+	$("#licenseLeft a").removeClass('ui-state-default ui-corner-all');
+	$("#licenseLeft #" +bundleId).addClass('ui-state-default ui-corner-all');
 }
 
-function displayFile ( /* String */ bundleId, /* String */ name, /* int */ idx )
-{
-    var theBundleData = bundleData[bundleId];
-    if (!theBundleData)
-    {
-        return;
-    }
-    
-    var file = theBundleData.files[name][idx];
-    if (!file)
-    {
-        return;
-    }
-    
-    var licenseDetails = document.getElementById('licenseDetails');
-    if (licenseDetails)
-    {
-        licenseDetails.innerHTML = "<h3>" + name + ": " + file.url + "</h3><pre>" + file.data + "</pre>";
-    }
-}
+
+$(document).ready(function() {
+	// init elements cache
+	licenseButtons = $("#licenseButtons");
+	licenseDetails = $("#licenseDetails")
+
+	// render list of bundles
+	var txt = "";
+	for(id in bundleData) {
+		txt += '<a id="' + id + '" href="javascript:displayBundle(\'' + id + '\')">' + bundleData[id]['title'] + '</a>';
+	}
+	if (txt) {
+		$("#licenseLeft").html(txt);
+	} else {
+		$(".statline").html(i18n.status_none);
+	}
+
+	// display first element
+	for(i in bundleData) {displayBundle(i);break;}
+});
\ No newline at end of file
diff --git a/webconsole/src/main/resources/templates/license.html b/webconsole/src/main/resources/templates/license.html
new file mode 100644
index 0000000..2d59c89
--- /dev/null
+++ b/webconsole/src/main/resources/templates/license.html
@@ -0,0 +1,28 @@
+<script type="text/javascript" src="res/ui/license.js"></script>
+<script type="text/javascript">
+// <![CDATA[
+var bundleData = ${__data__};
+// i18n
+var i18n = {
+	status_ok    : '${license.status.ok}', // The following bundles contains license files.
+	status_none  : '${license.status.none}', // No bundles with license files available
+	resources    : '${license.resources}', // 'Bundle Resources'
+	resources_emb: '${license.resources.embedded}' // 'Embedded {0}'
+}
+// ]]>
+</script>
+
+<!-- status line -->
+<p class="statline">${license.status.ok}</p>
+
+<div id="licenseContent">
+	<div id="licenseLeft" class="ui-widget-content ui-corner-all">
+		<!-- here comes the bundles links -->
+	</div>
+	<div id="licenseRight">
+		<div id="licenseButtons">&nbsp;</div> 
+		<br />
+		<iframe id="licenseDetails" name="licenseDetails" frameborder="0" class="ui-widget-content"></iframe>
+	</div>
+	<div class="ui-helper-clearfix">&nbsp;</div>
+</div>