FELIX-1636 only render header/footer if the request is plain HTML plugin
request indicated by the absence of any extension or the extension being
".html". Any request containing a non-".html" extension is directly handled
by the renderContent method without rendering any header and footer.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818395 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 591ea3c..cc356f4 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -101,23 +101,49 @@
{
if ( !spoolResource( request, response ) )
{
- // start the html response, write the header, open body and main div
- PrintWriter pw = startResponse( request, response );
+ // detect if this is an html request
+ if ( isHtmlRequest(request) )
+ {
+ // start the html response, write the header, open body and main div
+ PrintWriter pw = startResponse( request, response );
- // render top navigation
- renderTopNavigation( request, pw );
+ // render top navigation
+ renderTopNavigation( request, pw );
- // wrap content in a separate div
- pw.println( "<div id='content'>" );
- renderContent( request, response );
- pw.println( "</div>" );
+ // wrap content in a separate div
+ pw.println( "<div id='content'>" );
+ renderContent( request, response );
+ pw.println( "</div>" );
- // close the main div, body, and html
- endResponse( pw );
+ // close the main div, body, and html
+ endResponse( pw );
+ }
+ else
+ {
+ renderContent( request, response );
+ }
}
}
+ /**
+ * Detects whether this request is intended to have the headers and
+ * footers of this plugin be rendered or not. The decision is taken based
+ * on whether and what extension the request URI has: If the request URI
+ * has no extension or the the extension is <code>.html</code>, the request
+ * is assumed to be rendered with header and footer. Otherwise the
+ * headers and footers are omitted and the
+ * {@link #renderContent(HttpServletRequest, HttpServletResponse)}
+ * method is called without any decorations and without setting any
+ * response headers.
+ */
+ protected boolean isHtmlRequest( final HttpServletRequest request )
+ {
+ final String requestUri = request.getRequestURI();
+ return requestUri.endsWith( ".html" ) || requestUri.lastIndexOf( '.' ) < 0;
+ }
+
+
//---------- AbstractWebConsolePlugin API ----------------------------------
public void activate( BundleContext bundleContext )