From 7bc0584cfd7111f3b19490ba74e06cdbdadf2827 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Thu, 1 Nov 2001 02:12:51 +0000 Subject: [PATCH] added an "off" switch for the CSS support --- .../venice/servlets/StyleSheet.java | 18 +++++--- .../venice/servlets/Variables.java | 2 + .../venice/servlets/format/RenderConfig.java | 46 +++++++++++-------- .../venice/servlets/format/RenderData.java | 6 +++ web/format/base.jsp | 4 +- 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/com/silverwrist/venice/servlets/StyleSheet.java b/src/com/silverwrist/venice/servlets/StyleSheet.java index f34b19e..db1147f 100644 --- a/src/com/silverwrist/venice/servlets/StyleSheet.java +++ b/src/com/silverwrist/venice/servlets/StyleSheet.java @@ -44,12 +44,18 @@ public class StyleSheet extends HttpServlet ServletContext ctxt = getServletContext(); RenderData rdat = RenderConfig.createRenderData(ctxt,request,response); String stylesheet = Variables.getStyleSheetData(ctxt,rdat); - response.setContentType("text/css"); - response.setContentLength(stylesheet.length()); - PrintWriter out = response.getWriter(); - out.write(stylesheet); - out.flush(); - response.flushBuffer(); + if (stylesheet!=null) + { // send back the stylesheet + response.setContentType("text/css"); + response.setContentLength(stylesheet.length()); + PrintWriter out = response.getWriter(); + out.write(stylesheet); + out.flush(); + response.flushBuffer(); + + } // end if + else // no stylesheet data + response.sendError(HttpServletResponse.SC_NOT_FOUND,"stylesheets not enabled"); } // end doGet diff --git a/src/com/silverwrist/venice/servlets/Variables.java b/src/com/silverwrist/venice/servlets/Variables.java index cef3412..f62325b 100644 --- a/src/com/silverwrist/venice/servlets/Variables.java +++ b/src/com/silverwrist/venice/servlets/Variables.java @@ -329,6 +329,8 @@ public class Variables public static String getStyleSheetData(ServletContext ctxt, RenderData rdat) throws IOException { + if (!(rdat.useStyleSheet())) + return null; String data = null; SoftReference r = (SoftReference)(ctxt.getAttribute(STYLESHEET_ATTRIBUTE)); if (r!=null) diff --git a/src/com/silverwrist/venice/servlets/format/RenderConfig.java b/src/com/silverwrist/venice/servlets/format/RenderConfig.java index fa17121..88878d0 100644 --- a/src/com/silverwrist/venice/servlets/format/RenderConfig.java +++ b/src/com/silverwrist/venice/servlets/format/RenderConfig.java @@ -136,26 +136,25 @@ public class RenderConfig implements ColorSelectors logger.debug("Font face: " + font_face); String stylesheet_loc = render_sect_h.getSubElementText("stylesheet"); - if (stylesheet_loc==null) - { // no tag - bail out now! - logger.fatal(" section has no element"); - throw new ConfigException("no found in section",render_sect); - - } // end if - - if (!(stylesheet_loc.startsWith("/"))) - stylesheet_loc = root_file_path + stylesheet_loc; - if (logger.isDebugEnabled()) - logger.debug("Stylesheet location: " + stylesheet_loc); - - // Test to make sure the stylesheet is actually present. - stylesheet = new File(stylesheet_loc); - if (!(stylesheet.exists() && stylesheet.canRead())) - { // it's not there - bail out! - logger.fatal("unable to read stylesheet file: " + stylesheet_loc); - throw new ConfigException("stylesheet " + stylesheet_loc + " cannot be read",render_sect); + if (stylesheet_loc!=null) + { // we're using Cascading Stylesheets - load it and test for existence + if (!(stylesheet_loc.startsWith("/"))) + stylesheet_loc = root_file_path + stylesheet_loc; + if (logger.isDebugEnabled()) + logger.debug("Stylesheet location: " + stylesheet_loc); + + // Test to make sure the stylesheet is actually present. + stylesheet = new File(stylesheet_loc); + if (!(stylesheet.exists() && stylesheet.canRead())) + { // it's not there - bail out! + logger.fatal("unable to read stylesheet file: " + stylesheet_loc); + throw new ConfigException("stylesheet " + stylesheet_loc + " cannot be read",render_sect); + + } // end if } // end if + else // no stylesheet + stylesheet = null; Element colors_sect = render_sect_h.getSubElement("colors"); if (colors_sect==null) @@ -554,6 +553,9 @@ public class RenderConfig implements ColorSelectors synchronized String loadStyleSheetData() throws IOException { + if (stylesheet==null) + return null; + // Load the stylesheet data. StringBuffer raw_data = IOUtil.loadText(stylesheet); stylesheet_time = stylesheet.lastModified(); @@ -588,10 +590,18 @@ public class RenderConfig implements ColorSelectors boolean hasStyleSheetChanged() { + if (stylesheet==null) + return false; return (stylesheet_time!=stylesheet.lastModified()); } // end hasStyleSheetChanged + boolean useStyleSheet() + { + return (stylesheet!=null); + + } // end useStyleSheet + /*-------------------------------------------------------------------------------- * Static operations for use by VeniceServlet *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/servlets/format/RenderData.java b/src/com/silverwrist/venice/servlets/format/RenderData.java index be9f941..9ff4e58 100644 --- a/src/com/silverwrist/venice/servlets/format/RenderData.java +++ b/src/com/silverwrist/venice/servlets/format/RenderData.java @@ -318,6 +318,12 @@ public class RenderData implements ColorSelectors } // end hasStyleSheetChanged + public boolean useStyleSheet() + { + return rconf.useStyleSheet(); + + } // end useStyleSheet + public String formatDateForDisplay(Date date) { if (display_date==null) diff --git a/web/format/base.jsp b/web/format/base.jsp index c9f7f29..cbea91c 100644 --- a/web/format/base.jsp +++ b/web/format/base.jsp @@ -37,7 +37,9 @@ <%= rdat.getTitleTag(basedat.getTitle(rdat)) %> <%= rdat.getStdBaseFontTag(3) %> - " TYPE="text/css"> + <% if (rdat.useStyleSheet()) { %> + " TYPE="text/css"> + <% } // end if %> <% if (rdat.noSmartTags()) { %> <% } // end if %>