Venice now groks Cascading StyleSheets; the stylesheet is generated by a

special servlet and cached at runtime; various JSP pages and formatter classes
have been updated to respect the stylesheet settings
This commit is contained in:
Eric J. Bowersox
2001-10-31 02:13:02 +00:00
parent 6397f4212c
commit ec878e9dfc
50 changed files with 954 additions and 317 deletions

View File

@@ -0,0 +1,86 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.util;
public final class AnyCharMatcher
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private char[] charset;
private int[] locs;
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public AnyCharMatcher(char[] charset)
{
this.charset = charset;
this.locs = new int[charset.length];
} // end constructor
public AnyCharMatcher(String charset)
{
this.charset = charset.toCharArray();
this.locs = new int[charset.length()];
} // end constructor
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public final int get(String str)
{
int numindexes = 0;
int i;
for (i=0; i<charset.length; i++)
{ // locate the index of the first HTML character
int tmp = str.indexOf(charset[i]);
if (tmp>=0)
locs[numindexes++] = tmp;
} // end for
if (numindexes==0)
return -1; // no characters found
else if (numindexes==1)
return locs[0]; // only one found
int rc = locs[0];
for (i=1; i<numindexes; i++)
{ // this loop determines the lowest possible return value
if (rc==0)
return 0; // can't get any lower!
if (locs[i]<rc)
rc = locs[i]; // this is now the lowest
} // end for
return rc;
} // end get
} // end class AnyCharMatcher

View File

@@ -0,0 +1,175 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.util;
import java.io.*;
/* Some concepts in here borrowed from Apache Jakarta Avalon Excalibur 4.0 */
public class IOUtil
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
public static int DEFAULT_BUFSIZE = 4096;
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------
*/
public static void shutdown(InputStream stm)
{
try
{ // close the stream
stm.close();
} // end try
catch (IOException e)
{ // throw away the exception
} // end catch
} // end shutdown
public static void shutdown(OutputStream stm)
{
try
{ // close the stream
stm.close();
} // end try
catch (IOException e)
{ // throw away the exception
} // end catch
} // end shutdown
public static void shutdown(Reader rdr)
{
try
{ // close the stream
rdr.close();
} // end try
catch (IOException e)
{ // throw away the exception
} // end catch
} // end shutdown
public static void shutdown(Writer wr)
{
try
{ // close the stream
wr.close();
} // end try
catch (IOException e)
{ // throw away the exception
} // end catch
} // end shutdown
public static void copy(InputStream input, OutputStream output, int bufsize) throws IOException
{
byte[] buffer = new byte[bufsize];
int rd = input.read(buffer);
while (rd>=0)
{ // simple read-write loop to shove data out the door
if (rd>0)
output.write(buffer,0,rd);
rd = input.read(buffer);
} // end while
} // end copy
public static void copy(InputStream input, OutputStream output) throws IOException
{
copy(input,output,DEFAULT_BUFSIZE);
} // end copy
public static void copy(Reader input, Writer output, int bufsize) throws IOException
{
char[] buffer = new char[bufsize];
int rd = input.read(buffer);
while (rd>=0)
{ // simple read-write loop to shove data out the door
if (rd>0)
output.write(buffer,0,rd);
rd = input.read(buffer);
} // end while
} // end copy
public static void copy(Reader input, Writer output) throws IOException
{
copy(input,output,DEFAULT_BUFSIZE);
} // end copy
public static StringBuffer load(Reader input, int bufsize) throws IOException
{
StringWriter wr = new StringWriter();
try
{ // copy from reader to StringWriter
copy(input,wr,bufsize);
return wr.getBuffer();
} // end try
finally
{ // make sure and close the StringWriter before we go
shutdown(wr);
} // end finally
} // end load
public static StringBuffer load(Reader input) throws IOException
{
return load(input,DEFAULT_BUFSIZE);
} // end load
public static StringBuffer load(File file, int bufsize) throws IOException
{
FileReader rdr = new FileReader(file);
try
{ // load from the string reader
return load(rdr,bufsize);
} // end try
finally
{ // make sure and close the reader before we go
shutdown(rdr);
} // end finally
} // end load
public static StringBuffer load(File file) throws IOException
{
return load(file,DEFAULT_BUFSIZE);
} // end load
} // end class IOUtil

View File

@@ -7,7 +7,7 @@
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Community System.
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
@@ -17,8 +17,24 @@
*/
package com.silverwrist.util;
import java.util.*;
public class StringUtil
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static final String VAR_START = "${";
private static final String VAR_END = "}";
private static final char[] HTML_ENCODE_CHARS = { '"', '&', '<', '>' };
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------
*/
public static String encodeStringSQL(String str)
{
if (str==null)
@@ -46,10 +62,16 @@ public class StringUtil
{
if (str==null)
return null;
AnyCharMatcher nhc = new AnyCharMatcher(HTML_ENCODE_CHARS);
int ndx = nhc.get(str);
if (ndx<0)
return str; // trivial short-circuit case
StringBuffer buf = new StringBuffer();
for (int i=0; i<str.length(); i++)
{ // loop through the string encoding each character in turn
switch (str.charAt(i))
while (ndx>=0)
{ // append the matched "head" and then the encoded character
if (ndx>0)
buf.append(str.substring(0,ndx));
switch (str.charAt(ndx++))
{
case '"':
buf.append("&quot;");
@@ -67,14 +89,16 @@ public class StringUtil
buf.append("&gt;");
break;
default:
buf.append(str.charAt(i));
break;
} // end switch
} // end for
if (ndx==str.length())
return buf.toString(); // munched the entire string - all done!
str = str.substring(ndx);
ndx = nhc.get(str);
} // end while
buf.append(str); // append the unmatched tail
return buf.toString();
} // end encodeHTML
@@ -101,22 +125,55 @@ public class StringUtil
// break off the tail end
ndx += find.length();
if (ndx==work.length())
work = null;
else
work = work.substring(ndx);
// do the next find
if (work!=null)
ndx = work.indexOf(find);
else
ndx = -1;
return b.toString(); // entire string munched - we're done!
work = work.substring(ndx);
ndx = work.indexOf(find);
} // end while
if (work!=null)
b.append(work);
// append the unmatched "tail" of the work string and then return result
b.append(work);
return b.toString();
} // end replaceAllInstances
public static String replaceAllVariables(String base, Map vars)
{
String work = base;
boolean did_replace, retest;
retest = true;
do
{ // main loop for replacing all variables
did_replace = false;
Iterator it = vars.keySet().iterator();
while (it.hasNext())
{ // variable start is there...
if (retest)
{ // only perform this test on the first iteration and after we know we've replaced a variable
if (work.indexOf(VAR_START)<0)
return work; // no more variables in text - all done!
retest = false;
} // end if
// get variable name and see if it's present
String vname = it.next().toString();
if (work.indexOf(VAR_START + vname + VAR_END)>=0)
{ // OK, this variable is in place
work = replaceAllInstances(work,VAR_START + vname + VAR_END,vars.get(vname).toString());
did_replace = true;
retest = true;
} // end if
} // end while
} while (did_replace); // end do
return work; // all done!
} // end replaceAllVariables
} // end class StringUtil

View File

@@ -0,0 +1,56 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.venice.servlets.format.RenderConfig;
import com.silverwrist.venice.servlets.format.RenderData;
public class StyleSheet extends HttpServlet
{
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "StyleSheet applet - Generates a Cascading Stylesheet for Venice's use\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
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();
} // end doGet
} // end class StyleSheet

View File

@@ -36,9 +36,15 @@ public class Top extends VeniceServlet
{
super.init(config); // required before we do anything else
ServletContext ctxt = config.getServletContext();
String root_file_path = ctxt.getRealPath("/");
if (!(root_file_path.endsWith("/")))
root_file_path += "/";
// Initialize LOG4J logging.
DOMConfigurator.configure(ctxt.getInitParameter("logging.config"));
String lconf = ctxt.getInitParameter("logging.config");
if (!(lconf.startsWith("/")))
lconf = root_file_path + lconf;
DOMConfigurator.configure(lconf);
// Initialize the Venice engine.
VeniceEngine engine = Variables.getVeniceEngine(ctxt);

View File

@@ -17,6 +17,8 @@
*/
package com.silverwrist.venice.servlets;
import java.io.*;
import java.lang.ref.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -36,6 +38,7 @@ public class Variables
protected static final String ENGINE_ATTRIBUTE = "com.silverwrist.venice.core.Engine";
protected static final String COUNTRYLIST_ATTRIBUTE = "com.silverwrist.venice.db.CountryList";
protected static final String LANGUAGELIST_ATTRIBUTE = "com.silverwrist.venice.db.LanguageList";
protected static final String STYLESHEET_ATTRIBUTE = "com.silverwrist.venice.rendering.StyleSheet";
// HttpSession ("session") attributes
protected static final String USERCTXT_ATTRIBUTE = "user.context";
@@ -60,13 +63,19 @@ public class Variables
public static VeniceEngine getVeniceEngine(ServletContext ctxt) throws ServletException
{
synchronized(engine_gate)
synchronized (engine_gate)
{ // we must synchronize efforts to access the engine
Object foo = ctxt.getAttribute(ENGINE_ATTRIBUTE);
if (foo!=null)
return (VeniceEngine)foo;
String root_file_path = ctxt.getRealPath("/");
if (!(root_file_path.endsWith("/")))
root_file_path += "/";
String cfgfile = ctxt.getInitParameter(ENGINE_INIT_PARAM); // get the config file name
if (!(cfgfile.startsWith("/")))
cfgfile = root_file_path + cfgfile;
logger.info("Initializing Venice engine using config file: " + cfgfile);
try
@@ -318,4 +327,22 @@ public class Variables
} // end flushCookies
public static String getStyleSheetData(ServletContext ctxt, RenderData rdat) throws IOException
{
String data = null;
SoftReference r = (SoftReference)(ctxt.getAttribute(STYLESHEET_ATTRIBUTE));
if (r!=null)
data = (String)(r.get());
if ((data==null) || rdat.hasStyleSheetChanged())
{ // construct or reconstruct the stylesheet data, save a soft reference to it
data = rdat.loadStyleSheetData();
r = new SoftReference(data);
ctxt.setAttribute(STYLESHEET_ATTRIBUTE,r);
} // end if
return data;
} // end getStyleSheetData
} // end class Variables

View File

@@ -91,7 +91,7 @@ public class AuditDataViewer implements ContentRender, ColorSelectors
rdat.writeContentHeader(out,title,null);
// Write the informational and navigational table
out.write("<TABLE WIDTH=\"100%\" BORDER=0><TR VALIGN=MIDDLE><TD ALIGN=LEFT>"
out.write("<TABLE WIDTH=\"100%\" BORDER=0><TR VALIGN=MIDDLE><TD ALIGN=LEFT CLASS=\"content\">"
+ rdat.getStdFontTag(CONTENT_FOREGROUND,2) + "\nDisplaying records <B>" + (offset+1)
+ "</B> to <B>" + last_index + "</B> of <B>" + total_count + "</B>\n"
+ "</FONT></TD><TD ALIGN=RIGHT>\n");
@@ -114,30 +114,30 @@ public class AuditDataViewer implements ContentRender, ColorSelectors
// Start writing the table containing the actual audit records.
String tb_font = rdat.getStdFontTag(CONTENT_FOREGROUND,2);
out.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=3>\n");
out.write("<TR>\n<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>Date/Time</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>Description</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>User</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>SIG</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>IP Address</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT COLSPAN=4 NOWRAP>" + tb_font + "<B>Additional Data</B></FONT></TH>\n</TR>\n");
out.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=3>\n<TR>\n<TH ALIGN=LEFT CLASS=\"content\" NOWRAP>"
+ tb_font + "<B>Date/Time</B></FONT></TH>\n<TH ALIGN=LEFT CLASS=\"content\" NOWRAP>"
+ tb_font + "<B>Description</B></FONT></TH>\n<TH ALIGN=LEFT CLASS=\"content\" NOWRAP>"
+ tb_font + "<B>User</B></FONT></TH>\n<TH ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ "<B>SIG</B></FONT></TH>\n<TH ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ "<B>IP Address</B></FONT></TH>\n<TH ALIGN=LEFT CLASS=\"content\" COLSPAN=4 NOWRAP>"
+ tb_font + "<B>Additional Data</B></FONT></TH>\n</TR>\n");
Iterator it = audit_list.iterator();
while (it.hasNext())
{ // display each record in turn
AuditData dat = (AuditData)(it.next());
out.write("<TR>\n<TD ALIGN=LEFT NOWRAP>" + tb_font
+ rdat.formatDateForDisplay(dat.getDateTime()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getDescription()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getUserName()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getSIGName()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
out.write("<TR>\n<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ rdat.formatDateForDisplay(dat.getDateTime())
+ "</FONT></TD>\n<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getDescription())
+ "</FONT></TD>\n<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getUserName())
+ "</FONT></TD>\n<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getSIGName())
+ "</FONT></TD>\n<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getIPAddress()) + "</FONT></TD>\n");
for (int i=0; i<AuditData.DATA_COUNT; i++)
{ // write the data values
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font);
out.write("<TD ALIGN=LEFT CLASS=\"content\" NOWRAP>" + tb_font);
if (dat.getData(i)!=null)
out.write(StringUtil.encodeHTML(dat.getData(i)));
else

View File

@@ -67,7 +67,7 @@ public abstract class CDBaseFormField implements CDFormField, ColorSelectors
public void renderHere(Writer out, RenderData rdat) throws IOException
{
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=RIGHT><FONT COLOR=\""
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=RIGHT CLASS=\"content\"><FONT COLOR=\""
+ rdat.getStdColor(enabled ? CONTENT_FOREGROUND : CONTENT_DISABLED) + "\">"
+ StringUtil.encodeHTML(caption));
if (caption2!=null)
@@ -75,7 +75,7 @@ public abstract class CDBaseFormField implements CDFormField, ColorSelectors
out.write(":</FONT>");
if (required)
out.write(rdat.getRequiredBullet());
out.write("</TD>\n<TD ALIGN=LEFT>");
out.write("</TD>\n<TD ALIGN=LEFT CLASS=\"content\">");
renderActualField(out,rdat);
out.write("</TD>\n</TR>\n");

View File

@@ -67,9 +67,9 @@ public abstract class CDBaseFormFieldReverse implements CDFormField, ColorSelect
public void renderHere(Writer out, RenderData rdat) throws IOException
{
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=RIGHT>");
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=RIGHT CLASS=\"content\">");
renderActualField(out,rdat);
out.write("</TD>\n<TD ALIGN=LEFT><FONT COLOR=\""
out.write("</TD>\n<TD ALIGN=LEFT CLASS=\"content\"><FONT COLOR=\""
+ rdat.getStdColor(enabled ? CONTENT_FOREGROUND : CONTENT_DISABLED) + "\">"
+ StringUtil.encodeHTML(caption));
if (caption2!=null)

View File

@@ -55,9 +55,9 @@ public class CDFormCategoryHeader implements CDFormField, ColorSelectors
public void renderHere(Writer out, RenderData rdat) throws IOException
{
out.write("<TR VALIGN=MIDDLE><TD ALIGN=RIGHT><FONT COLOR=\""
out.write("<TR VALIGN=MIDDLE><TD ALIGN=RIGHT CLASS=\"content\"><FONT COLOR=\""
+ rdat.getStdColor(enabled ? CONTENT_FOREGROUND : CONTENT_DISABLED) + "\"><B>"
+ StringUtil.encodeHTML(caption) + ":</B></FONT></TD><TD ALIGN=LEFT>");
+ StringUtil.encodeHTML(caption) + ":</B></FONT></TD><TD ALIGN=LEFT CLASS=\"content\">");
if (rtext==null)
out.write("&nbsp;");
else // display in the correct state

View File

@@ -45,14 +45,15 @@ public class CDPasswordFormField extends CDBaseFormField
protected void renderActualField(Writer out, RenderData rdat) throws IOException
{
out.write("<INPUT TYPE=PASSWORD NAME=\"" + getName() + "\" SIZE=" + String.valueOf(size));
out.write("<SPAN CLASS=\"cinput\"><INPUT TYPE=PASSWORD CLASS=\"cinput\" NAME=\"" + getName() + "\" SIZE="
+ String.valueOf(size));
out.write(" MAXLENGTH=" + String.valueOf(maxlength));
if (!isEnabled())
out.write(" DISABLED");
out.write(" VALUE=\"");
if (getValue()!=null)
out.write(getValue());
out.write("\">");
out.write("\"></SPAN>");
} // end renderActualField

View File

@@ -67,7 +67,7 @@ public abstract class CDPickListFormField extends CDBaseFormField
protected void renderActualField(Writer out, RenderData rdat) throws IOException
{
out.write("<SELECT NAME=\"" + getName() + "\" SIZE=1");
out.write("<SELECT CLASS=\"content\" NAME=\"" + getName() + "\" SIZE=1");
if (!isEnabled())
out.write(" DISABLED");
out.write(">\n");

View File

@@ -45,14 +45,15 @@ public class CDTextFormField extends CDBaseFormField
protected void renderActualField(Writer out, RenderData rdat) throws IOException
{
out.write("<INPUT TYPE=TEXT NAME=\"" + getName() + "\" SIZE=" + String.valueOf(size));
out.write("<SPAN CLASS=\"cinput\"><INPUT TYPE=TEXT CLASS=\"cinput\" NAME=\"" + getName() + "\" SIZE="
+ String.valueOf(size));
out.write(" MAXLENGTH=" + String.valueOf(maxlength));
if (!isEnabled())
out.write(" DISABLED");
out.write(" VALUE=\"");
if (getValue()!=null)
out.write(getValue());
out.write("\">");
out.write("\"></SPAN>");
} // end renderActualField

View File

@@ -31,30 +31,34 @@ public interface ColorSelectors
public static final int LEFT_FOREGROUND = 5;
public static final int CONTENT_BACKGROUND = 6;
public static final int LEFT_LINK = 6;
public static final int CONTENT_FOREGROUND = 7;
public static final int CONTENT_BACKGROUND = 7;
public static final int CONTENT_HEADER = 8;
public static final int CONTENT_FOREGROUND = 8;
public static final int CONTENT_DISABLED = 9;
public static final int CONTENT_HEADER = 9;
public static final int CONTENT_ERROR = 10;
public static final int CONTENT_DISABLED = 10;
public static final int SIDEBOX_TITLE_BACKGROUND = 11;
public static final int CONTENT_ERROR = 11;
public static final int SIDEBOX_TITLE_FOREGROUND = 12;
public static final int SIDEBOX_TITLE_BACKGROUND = 12;
public static final int SIDEBOX_CONTENT_BACKGROUND = 13;
public static final int SIDEBOX_TITLE_FOREGROUND = 13;
public static final int SIDEBOX_CONTENT_FOREGROUND = 14;
public static final int SIDEBOX_CONTENT_BACKGROUND = 14;
public static final int CONFIRM_TITLE_BACKGROUND = 15;
public static final int SIDEBOX_CONTENT_FOREGROUND = 15;
public static final int CONFIRM_TITLE_FOREGROUND = 16;
public static final int SIDEBOX_CONTENT_LINK = 16;
public static final int ERROR_TITLE_BACKGROUND = 17;
public static final int CONFIRM_TITLE_BACKGROUND = 17;
public static final int ERROR_TITLE_FOREGROUND = 18;
public static final int CONFIRM_TITLE_FOREGROUND = 18;
public static final int ERROR_TITLE_BACKGROUND = 19;
public static final int ERROR_TITLE_FOREGROUND = 20;
} // end class ColorSelectors

View File

@@ -154,15 +154,15 @@ public class ContentDialog implements Cloneable, ContentRender, ColorSelectors
if (error_message!=null)
{ // print the error message
out.write("<TABLE BORDER=0 ALIGN=CENTER CELLPADDING=6 CELLSPACING=0><TR VALIGN=TOP>"
+ "<TD ALIGN=CENTER>\n" + rdat.getStdFontTag(CONTENT_ERROR,3) + "<B>");
+ "<TD ALIGN=CENTER CLASS=\"content\">\n" + rdat.getStdFontTag(CONTENT_ERROR,3) + "<B>");
out.write(StringUtil.encodeHTML(error_message));
out.write("</B></FONT>\n</TD></TR></TABLE>\n");
} // end if
// Output the start of the form
out.write("<FORM NAME=\"" + formname + "\" METHOD=POST ACTION=\"");
out.write(rdat.getEncodedServletPath(action) + "\">" + rdat.getStdFontTag(CONTENT_FOREGROUND,2) + "\n");
out.write("<FORM NAME=\"" + formname + "\" METHOD=POST ACTION=\"" + rdat.getEncodedServletPath(action)
+ "\"><DIV CLASS=\"content\">" + rdat.getStdFontTag(CONTENT_FOREGROUND,2) + "\n");
enum = hidden_fields.keys();
while (enum.hasMoreElements())
@@ -204,7 +204,7 @@ public class ContentDialog implements Cloneable, ContentRender, ColorSelectors
if (command_order.size()>0)
{ // render the command buttons at the bottom
boolean is_first = true;
out.write("<DIV ALIGN=CENTER>");
out.write("<DIV ALIGN=CENTER CLASS=\"content\">");
enum = command_order.elements();
while (enum.hasMoreElements())
{ // render each of the command buttons in the list
@@ -221,7 +221,7 @@ public class ContentDialog implements Cloneable, ContentRender, ColorSelectors
} // end if
out.write("</FONT></FORM>\n");
out.write("</FONT></DIV></FORM>\n");
} // end renderHere

View File

@@ -23,7 +23,7 @@ import java.util.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
public class MenuSIG implements ComponentRender
public class MenuSIG implements ComponentRender, ColorSelectors
{
private String image_url;
private boolean image_url_needs_fixup = false;
@@ -67,6 +67,7 @@ public class MenuSIG implements ComponentRender
public void renderHere(Writer out, RenderData rdat) throws IOException
{
String hilite = "<FONT COLOR=\"" + rdat.getStdColor(LEFT_LINK) + "\">";
if (image_url!=null)
{ // display the image by URL
if (image_url_needs_fixup)
@@ -90,13 +91,13 @@ public class MenuSIG implements ComponentRender
SIGFeature ftr = (SIGFeature)(it.next());
out.write("<BR>\n<A HREF=\"" + rdat.getEncodedServletPath(ftr.getApplet() + "?sig="
+ String.valueOf(sigid)));
out.write("\">" + StringUtil.encodeHTML(ftr.getName()) + "</A>\n");
out.write("\">" + hilite + StringUtil.encodeHTML(ftr.getName()) + "</FONT></A>\n");
} // end while
if (show_unjoin)
out.write("<P>\n<A HREF=\"" + rdat.getEncodedServletPath("sigops?cmd=U&sig=" + String.valueOf(sigid))
+ "\">Unjoin</A>\n");
+ "\">" + hilite + "Unjoin</FONT></A>\n");
out.write("\n"); // all done...

View File

@@ -27,6 +27,7 @@ import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.silverwrist.util.DOMElementHelper;
import com.silverwrist.util.IOUtil;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.ConfigException;
import com.silverwrist.venice.core.UserContext;
@@ -58,6 +59,8 @@ public class RenderConfig implements ColorSelectors
private boolean allow_gzip;
private boolean no_smart_tags;
private String font_face;
private File stylesheet;
private long stylesheet_time = 0;
private String image_url;
private String static_url;
private String site_logo;
@@ -74,7 +77,7 @@ public class RenderConfig implements ColorSelectors
*--------------------------------------------------------------------------------
*/
protected RenderConfig(String config_file) throws ConfigException
protected RenderConfig(String config_file, String root_file_path) throws ConfigException
{
config = loadConfiguration(config_file);
@@ -132,6 +135,28 @@ public class RenderConfig implements ColorSelectors
if (logger.isDebugEnabled())
logger.debug("Font face: " + font_face);
String stylesheet_loc = render_sect_h.getSubElementText("stylesheet");
if (stylesheet_loc==null)
{ // no <stylesheet/> tag - bail out now!
logger.fatal("<rendering/> section has no <stylesheet/> element");
throw new ConfigException("no <stylesheet/> found in <rendering/> 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);
} // end if
Element colors_sect = render_sect_h.getSubElement("colors");
if (colors_sect==null)
{ // no <colors/> tag - bail out now!
@@ -485,11 +510,11 @@ public class RenderConfig implements ColorSelectors
void writeContentHeader(Writer out, String primary, String secondary) throws IOException
{
out.write(getStdFontTag(colors_array[CONTENT_HEADER],5) + "<B>" + StringUtil.encodeHTML(primary)
+ "</B></FONT>");
out.write("<SPAN CLASS=\"chead1\">" + getStdFontTag(colors_array[CONTENT_HEADER],5) + "<B>"
+ StringUtil.encodeHTML(primary) + "</B></FONT></SPAN>");
if (secondary!=null)
out.write("&nbsp;&nbsp;" + getStdFontTag(colors_array[CONTENT_HEADER],3) + "<B>"
+ StringUtil.encodeHTML(secondary) + "</B></FONT>");
out.write("&nbsp;&nbsp;<SPAN CLASS=\"chead2\">" + getStdFontTag(colors_array[CONTENT_HEADER],3) + "<B>"
+ StringUtil.encodeHTML(secondary) + "</B></FONT></SPAN>");
out.write("<HR ALIGN=LEFT SIZE=2 WIDTH=\"90%\" NOSHADE>\n");
} // end writeContentHeader
@@ -527,6 +552,46 @@ public class RenderConfig implements ColorSelectors
} // end getLeftMenu
synchronized String loadStyleSheetData() throws IOException
{
// Load the stylesheet data.
StringBuffer raw_data = IOUtil.load(stylesheet);
stylesheet_time = stylesheet.lastModified();
// Set up the replacements map to replace the various parameters.
HashMap vars = new HashMap();
vars.put("font",font_face);
vars.put("color.frame",colors_array[FRAME_BACKGROUND]);
vars.put("color.top.background",colors_array[TITLE_BACKGROUND]);
vars.put("color.top.foreground",colors_array[TITLE_FOREGROUND]);
vars.put("color.top.link",colors_array[TITLE_LINK]);
vars.put("color.left.background",colors_array[LEFT_BACKGROUND]);
vars.put("color.left.foreground",colors_array[LEFT_FOREGROUND]);
vars.put("color.left.link",colors_array[LEFT_LINK]);
vars.put("color.content.background",colors_array[CONTENT_BACKGROUND]);
vars.put("color.content.foreground",colors_array[CONTENT_FOREGROUND]);
vars.put("color.content.header",colors_array[CONTENT_HEADER]);
vars.put("color.disabled",colors_array[CONTENT_DISABLED]);
vars.put("color.error",colors_array[CONTENT_ERROR]);
vars.put("color.sidebox.top.background",colors_array[SIDEBOX_TITLE_BACKGROUND]);
vars.put("color.sidebox.top.foreground",colors_array[SIDEBOX_TITLE_FOREGROUND]);
vars.put("color.sidebox.background",colors_array[SIDEBOX_CONTENT_BACKGROUND]);
vars.put("color.sidebox.foreground",colors_array[SIDEBOX_CONTENT_FOREGROUND]);
vars.put("color.sidebox.link",colors_array[SIDEBOX_CONTENT_LINK]);
vars.put("color.dlg.confirm.title.background",colors_array[CONFIRM_TITLE_BACKGROUND]);
vars.put("color.dlg.confirm.title.foreground",colors_array[CONFIRM_TITLE_FOREGROUND]);
vars.put("color.dlg.error.title.background",colors_array[ERROR_TITLE_BACKGROUND]);
vars.put("color.dlg.error.title.foreground",colors_array[ERROR_TITLE_FOREGROUND]);
return StringUtil.replaceAllVariables(raw_data.toString(),vars);
} // end loadStyleSheet
boolean hasStyleSheetChanged()
{
return (stylesheet_time!=stylesheet.lastModified());
} // end hasStyleSheetChanged
/*--------------------------------------------------------------------------------
* Static operations for use by VeniceServlet
*--------------------------------------------------------------------------------
@@ -539,13 +604,20 @@ public class RenderConfig implements ColorSelectors
if (obj!=null)
return (RenderConfig)obj;
// Get the root file path.
String root_file_path = ctxt.getRealPath("/");
if (!(root_file_path.endsWith("/")))
root_file_path += "/";
// Get the parameter for the renderer's config file.
String cfgfile = ctxt.getInitParameter(CONFIG_FILE_PARAM);
if (!(cfgfile.startsWith("/")))
cfgfile = root_file_path + cfgfile;
logger.info("Initializing Venice rendering using config file: " + cfgfile);
try
{ // create the RenderConfig object and save it to attributes.
RenderConfig rconf = new RenderConfig(cfgfile);
RenderConfig rconf = new RenderConfig(cfgfile,root_file_path);
ctxt.setAttribute(ATTR_NAME,rconf);
return rconf;
@@ -588,6 +660,7 @@ public class RenderConfig implements ColorSelectors
m.put("title-link",new Integer(TITLE_LINK));
m.put("left-bg",new Integer(LEFT_BACKGROUND));
m.put("left-fg",new Integer(LEFT_FOREGROUND));
m.put("left-link",new Integer(LEFT_LINK));
m.put("content-bg",new Integer(CONTENT_BACKGROUND));
m.put("content-fg",new Integer(CONTENT_FOREGROUND));
m.put("content-hdr",new Integer(CONTENT_HEADER));
@@ -597,6 +670,7 @@ public class RenderConfig implements ColorSelectors
m.put("sidebox-title-fg",new Integer(SIDEBOX_TITLE_FOREGROUND));
m.put("sidebox-content-bg",new Integer(SIDEBOX_CONTENT_BACKGROUND));
m.put("sidebox-content-fg",new Integer(SIDEBOX_CONTENT_FOREGROUND));
m.put("sidebox-content-link",new Integer(SIDEBOX_CONTENT_LINK));
m.put("confirm-title-bg",new Integer(CONFIRM_TITLE_BACKGROUND));
m.put("confirm-title-fg",new Integer(CONFIRM_TITLE_FOREGROUND));
m.put("error-title-bg",new Integer(ERROR_TITLE_BACKGROUND));

View File

@@ -31,7 +31,7 @@ import com.silverwrist.venice.db.PostLinkRewriter;
import com.silverwrist.venice.db.UserNameRewriter;
import com.silverwrist.venice.servlets.format.menus.LeftMenu;
public class RenderData
public class RenderData implements ColorSelectors
{
/*--------------------------------------------------------------------------------
* Static data values
@@ -248,8 +248,9 @@ public class RenderData
if (urls.size()<nchoice)
nchoice = urls.size();
out.write(rconf.getStdFontTag("#3333AA",5) + "<B>" + StringUtil.encodeHTML(caption)
+ "</B></FONT>&nbsp;&nbsp;" + rconf.getStdFontTag("#3333AA",3));
out.write("<SPAN CLASS=\"chead1\">" + rconf.getStdFontTag(CONTENT_HEADER,5) + "<B>"
+ StringUtil.encodeHTML(caption) + "</B></FONT></SPAN>&nbsp;&nbsp;<SPAN CLASS=\"chead2\">"
+ rconf.getStdFontTag(CONTENT_HEADER,3));
for (int i=0; i<nchoice; i++)
{ // loop through all the choices
if (i==0)
@@ -270,7 +271,7 @@ public class RenderData
} // end for
out.write("]</FONT><HR ALIGN=LEFT SIZE=2 WIDTH=\"90%\" NOSHADE>\n");
out.write("]</FONT></SPAN><HR ALIGN=LEFT SIZE=2 WIDTH=\"90%\" NOSHADE>\n");
} // end writeContentSelectorHeader
@@ -304,6 +305,18 @@ public class RenderData
} // end getLeftMenu
public String loadStyleSheetData() throws IOException
{
return rconf.loadStyleSheetData();
} // end loadStyleSheetData
public boolean hasStyleSheetChanged()
{
return rconf.hasStyleSheetChanged();
} // end hasStyleSheetChanged
public String formatDateForDisplay(Date date)
{
if (display_date==null)

View File

@@ -71,6 +71,7 @@ public class SideBoxConferences implements ContentRender, ColorSelectors
public void renderHere(Writer out, RenderData rdat) throws IOException
{
String hilite = rdat.getStdColor(SIDEBOX_CONTENT_LINK);
if (hotlist.size()>0)
{ // display the list of conferences
out.write("<TABLE ALIGN=CENTER BORDER=0 CELLPADDING=0 CELLSPACING=2>\n");
@@ -82,10 +83,11 @@ public class SideBoxConferences implements ContentRender, ColorSelectors
String href = "confdisp?sig=" + conf.getEnclosingSIG().getSIGID() + "&conf=" + conf.getConfID();
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=14><IMG SRC=\""
+ rdat.getFullImagePath("purple-ball.gif")
+ "\" ALT=\"*\" WIDTH=14 HEIGHT=14 BORDER=0></TD>\n");
out.write("<TD ALIGN=LEFT>\n" + rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,2) + "<B><A HREF=\""
+ rdat.getEncodedServletPath(href) + "\">" + StringUtil.encodeHTML(conf.getName())
+ "</A></B> (" + StringUtil.encodeHTML(conf.getEnclosingSIG().getName()) + ")</FONT>\n");
+ "\" ALT=\"*\" WIDTH=14 HEIGHT=14 BORDER=0></TD>\n<TD ALIGN=LEFT CLASS=\"sidebox\">\n"
+ rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,2) + "<B><A HREF=\""
+ rdat.getEncodedServletPath(href) + "\"><FONT COLOR=\"" + hilite + "\">"
+ StringUtil.encodeHTML(conf.getName()) + "</FONT></A></B> ("
+ StringUtil.encodeHTML(conf.getEnclosingSIG().getName()) + ")</FONT>\n");
if (conf.anyUnread())
out.write("&nbsp;<A HREF=\"" + rdat.getEncodedServletPath(href + "&rnm=1") + "\"><IMG SRC=\""
+ rdat.getFullImagePath("tag_new.gif")
@@ -104,7 +106,8 @@ public class SideBoxConferences implements ContentRender, ColorSelectors
if (uc.isLoggedIn())
{ // write the link at the end
out.write("<P>" + rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,1) + "<B>[ <A HREF=\""
+ rdat.getEncodedServletPath("settings?cmd=H") + "\">Manage</A> ]</B></FONT>");
+ rdat.getEncodedServletPath("settings?cmd=H") + "\"><FONT COLOR=\"" + hilite
+ "\">Manage</FONT></A> ]</B></FONT>");
} // end if

View File

@@ -80,10 +80,10 @@ public class SideBoxSIGs implements ContentRender, ColorSelectors
SIGContext sig = (SIGContext)(it.next());
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=14><IMG SRC=\""
+ rdat.getFullImagePath("purple-ball.gif")
+ "\" ALT=\"*\" WIDTH=14 HEIGHT=14 BORDER=0></TD>\n");
out.write("<TD ALIGN=LEFT>\n" + rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,2) + "<B><A HREF=\""
+ rdat.getEncodedServletPath("sig/" + sig.getAlias()) + "\">"
+ StringUtil.encodeHTML(sig.getName()) + "</A></B></FONT>\n");
+ "\" ALT=\"*\" WIDTH=14 HEIGHT=14 BORDER=0></TD>\n<TD ALIGN=LEFT CLASS=\"sidebox\">\n"
+ "<A HREF=\"" + rdat.getEncodedServletPath("sig/" + sig.getAlias()) + "\">"
+ rdat.getStdFontTag(SIDEBOX_CONTENT_LINK,2) + "<B>" + StringUtil.encodeHTML(sig.getName())
+ "</B></FONT></A>\n");
if (sig.isAdmin())
out.write("&nbsp;<IMG SRC=\"" + rdat.getFullImagePath("tag_host.gif")
+ "\" ALT=\"Host!\" BORDER=0 WIDTH=40 HEIGHT=20>\n");
@@ -100,9 +100,12 @@ public class SideBoxSIGs implements ContentRender, ColorSelectors
if (uc.isLoggedIn())
{ // write the two links at the end
String hilite = rdat.getStdColor(SIDEBOX_CONTENT_LINK);
out.write("<P>" + rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,1) + "<B>[ <A HREF=\""
+ rdat.getEncodedServletPath("settings?cmd=S") + "\">Manage</A> | <A HREF=\""
+ rdat.getEncodedServletPath("sigops?cmd=C") + "\">Create New</A> ]</B></FONT>");
+ rdat.getEncodedServletPath("settings?cmd=S") + "\"><FONT COLOR=\"" + hilite
+ "\">Manage</FONT></A> | <A HREF=\""
+ rdat.getEncodedServletPath("sigops?cmd=C") + "\"><FONT COLOR=\"" + hilite
+ "\">Create New</FONT></A> ]</B></FONT>");
} // end if

View File

@@ -195,11 +195,11 @@ public class TopDisplay implements ContentRender, ColorSelectors
{ // draw in the outer framework of the sidebox
out.write("<TABLE ALIGN=CENTER WIDTH=200 BORDER=0 CELLPADDING=2 CELLSPACING=0>"
+ "<TR VALIGN=MIDDLE BGCOLOR=\"" + rdat.getStdColor(SIDEBOX_TITLE_BACKGROUND)
+ "\"><TD ALIGN=LEFT>\n");
out.write(rdat.getStdFontTag(SIDEBOX_TITLE_FOREGROUND,3) + "<B>"
+ StringUtil.encodeHTML(sideboxes[i].getPageTitle(rdat)) + "</B></FONT>\n");
out.write("</TD></TR><TR VALIGN=TOP BGCOLOR=\"" + rdat.getStdColor(SIDEBOX_CONTENT_BACKGROUND)
+ "\"><TD ALIGN=LEFT>\n");
+ "\"><TD ALIGN=LEFT CLASS=\"sideboxtop\">\n"
+ rdat.getStdFontTag(SIDEBOX_TITLE_FOREGROUND,3) + "<B>"
+ StringUtil.encodeHTML(sideboxes[i].getPageTitle(rdat))
+ "</B></FONT>\n</TD></TR><TR VALIGN=TOP BGCOLOR=\""
+ rdat.getStdColor(SIDEBOX_CONTENT_BACKGROUND) + "\"><TD ALIGN=LEFT CLASS=\"sidebox\">\n");
// Fill in the sidebox by calling down to the base.
if (sideboxes[i] instanceof ContentRender)

View File

@@ -21,10 +21,11 @@ import java.io.Writer;
import java.io.IOException;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.servlets.format.ColorSelectors;
import com.silverwrist.venice.servlets.format.ComponentRender;
import com.silverwrist.venice.servlets.format.RenderData;
abstract class LeftMenuItem implements ComponentRender
abstract class LeftMenuItem implements ComponentRender, ColorSelectors
{
/*--------------------------------------------------------------------------------
* Attributes
@@ -68,7 +69,7 @@ abstract class LeftMenuItem implements ComponentRender
StringBuffer buf = new StringBuffer();
if (disabled)
buf.append("<FONT COLOR=\"#CCCCCC\">");
buf.append("<FONT COLOR=\"").append(rdat.getStdColor(CONTENT_DISABLED)).append("\">");
else
{ // write the <A> tag
buf.append("<A HREF=\"");
@@ -76,14 +77,12 @@ abstract class LeftMenuItem implements ComponentRender
buf.append('"');
if (new_window)
buf.append(" TARGET=\"_blank\"");
buf.append('>');
buf.append("><FONT COLOR=\"").append(rdat.getStdColor(LEFT_LINK)).append("\">");
} // end else (writing <A> tag)
buf.append(text);
if (disabled)
buf.append("</FONT>");
else
buf.append(text).append("</FONT>");
if (!disabled)
buf.append("</A>");
buf.append("<BR>\n");
out.write(buf.toString());