FELIX-2118 Load the license data wrapped in <pre>-</pre> tages into a <div> to ensure IE can properly render the fixed-format data; in addition provide a WebConsoleUtil.setNoCache method to provide a means to inform the client to not cache the response.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@915255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
index 3e3e70a..2b4f098 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -222,6 +222,25 @@
}
/**
+ * Sets response headers to force the client to not cache the response
+ * sent back. This method must be called before the response is committed
+ * otherwise it will have no effect.
+ * <p>
+ * This method sets the <code>Cache-Control</code>, <code>Expires</code>,
+ * and <code>Pragma</code> headers.
+ *
+ * @param response The response for which to set the cache prevention
+ */
+ public static final void setNoCache(final HttpServletResponse response) {
+ response.setHeader("Cache-Control", "no-cache");
+ response.addHeader("Cache-Control", "no-store");
+ response.addHeader("Cache-Control", "must-revalidate");
+ response.addHeader("Cache-Control", "max-age=0");
+ response.setHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT");
+ response.setHeader("Pragma", "no-cache");
+ }
+
+ /**
* Escapes HTML special chars like: <>&\r\n and space
*
*
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
index 6c99f7e..c295aa2 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
@@ -113,16 +113,13 @@
}
else if ( request.getPathInfo().endsWith( ".nfo" ) )
{
+ WebConsoleUtil.setNoCache( response );
response.setContentType( "text/html; charset=utf-8" );
- // disable cache
- response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0");
- response.addHeader("Expires", "Mon, 2 Sun 2001 05:00:00 GMT");
- response.addHeader("Pragma", "no-cache");
String name = request.getPathInfo();
name = name.substring( name.lastIndexOf('/') + 1);
name = name.substring(0, name.length() - 4);
- name = URLDecoder.decode( name );
+ name = URLDecoder.decode( name, "UTF-8" );
ConfigurationWriter pw = new HtmlConfigurationWriter( response.getWriter() );
pw.println ( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" );
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
index 27295e3..d14a66b 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
@@ -227,6 +227,10 @@
return false;
}
+ // prepare the response
+ WebConsoleUtil.setNoCache( response );
+ response.setContentType( "text/plain" );
+
if ( pathInfo.innerJar == null )
{
final URL resource = bundle.getResource( pathInfo.licenseFile );
diff --git a/webconsole/src/main/resources/res/ui/license.js b/webconsole/src/main/resources/res/ui/license.js
index a4aa3a8..ca3744f 100644
--- a/webconsole/src/main/resources/res/ui/license.js
+++ b/webconsole/src/main/resources/res/ui/license.js
@@ -18,6 +18,19 @@
var licenseButtons = false;
var licenseDetails = false;
+/*
+ * Fuction called after receiving the license data from the server to insert
+ * it into the licenseDetails div
+ * Because IE does not properly support the white-space:pre CSS setting when
+ * DOM-loading data into a <pre> element, the licenseDetails element is a
+ * <div> into which we insert the data surrounded by <pre>-</pre> tags as
+ * innerHtml. This also works in IE.
+ */
+function insertLicenseData( /* String */ data )
+{
+ licenseDetails.html( "<pre>" + data + "</pre>" );
+}
+
function displayBundle(/* String */ bundleIndex)
{
var theBundleData = bundleData[bundleIndex];
@@ -66,7 +79,7 @@
}
if (firstPage) {
- licenseDetails.load(firstPage);
+ $.get(firstPage, insertLicenseData);
} else {
licenseDetails.html("");
}
@@ -75,7 +88,7 @@
$("#licenseLeft #" +bundleIndex).addClass('ui-state-default ui-corner-all');
$('#licenseButtons a').click(function() {
- licenseDetails.load(this.href);
+ $.get(this.href, insertLicenseData);
return false;
});
}
diff --git a/webconsole/src/main/resources/templates/license.html b/webconsole/src/main/resources/templates/license.html
index bbfdd07..8ad5f7a 100644
--- a/webconsole/src/main/resources/templates/license.html
+++ b/webconsole/src/main/resources/templates/license.html
@@ -22,7 +22,7 @@
<div id="licenseRight">
<div id="licenseButtons"> </div>
<br />
- <pre id="licenseDetails" class="ui-widget-content ui-corner-all"></pre>
+ <div id="licenseDetails" class="ui-widget-content ui-corner-all"></div>
</div>
<div class="ui-helper-clearfix"> </div>
</div>