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