diff --git a/conf-sso/sp/dynamo.xml b/conf-sso/sp/dynamo.xml index fe6ba46..6b51a9f 100644 --- a/conf-sso/sp/dynamo.xml +++ b/conf-sso/sp/dynamo.xml @@ -82,6 +82,10 @@ + + + + diff --git a/conf/dynamo-venice.xml b/conf/dynamo-venice.xml index 04ff89f..c9c0a8a 100644 --- a/conf/dynamo-venice.xml +++ b/conf/dynamo-venice.xml @@ -81,6 +81,10 @@ + + + + diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index e5dc8d3..8a63a0d 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -211,6 +211,30 @@ CREATE TABLE imagetype ( name VARCHAR(255) BINARY NOT NULL # image type name ); +# Table giving the names of all defined HTML checker profiles. +CREATE TABLE htmlprofiles ( + profid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, # profile identifier + nsid INT NOT NULL, # profile namespace ID + name VARCHAR(255) BINARY NOT NULL, # profile name + UNIQUE INDEX by_name (nsid, name) +); + +# Properties that make up each HTML checker profile. +CREATE TABLE htmlprops ( + profid INT NOT NULL, # profile identifier + nsid INT NOT NULL, # property namespace ID + prop_name VARCHAR(255) BINARY NOT NULL, # property name + prop_value VARCHAR(255), # property value + PRIMARY KEY (profid, nsid, prop_name) +); + +# Table that indicates which HTML tag sets are permitted in which profiles. +CREATE TABLE htmltagsets ( + profid INT NOT NULL, # profile identifier + tagset VARCHAR(64) NOT NULL, # tag set name + PRIMARY KEY (profid, tagset) +); + #### following this line are Venice-specific tables #### # The table which defines menus. diff --git a/src/baseutil/com/silverwrist/util/AnyCharMatcher.java b/src/baseutil/com/silverwrist/util/AnyCharMatcher.java index a454c0f..1a93f6d 100644 --- a/src/baseutil/com/silverwrist/util/AnyCharMatcher.java +++ b/src/baseutil/com/silverwrist/util/AnyCharMatcher.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -33,7 +33,6 @@ public final class AnyCharMatcher */ private char[] charset; // the set of characters to look for - private int[] locs; // a temporary array used for locations /*-------------------------------------------------------------------------------- * Constructors @@ -48,7 +47,6 @@ public final class AnyCharMatcher public AnyCharMatcher(char[] charset) { this.charset = charset; - this.locs = new int[charset.length]; } // end constructor @@ -60,7 +58,6 @@ public final class AnyCharMatcher public AnyCharMatcher(String charset) { this.charset = charset.toCharArray(); - this.locs = new int[charset.length()]; } // end constructor @@ -83,32 +80,22 @@ public final class AnyCharMatcher { if (str==null) return -1; - int numindexes = 0; - int i; - for (i=0; i0) && (i=0) - locs[numindexes++] = tmp; + { // found a matching character + found = true; + if (tmp=0) - locs[numindexes++] = tmp; + { // found a matching character + found = true; + if (tmp>rc) + rc = tmp; + + } // end if } // end for - if (numindexes==0) - return -1; // no characters found - else if (numindexes==1) - return locs[0]; // only one found - - int rc = locs[0]; - int limit = str.length() - 1; - for (i=1; irc) - rc = locs[i]; // this is now the highest - - } // end for - - return rc; + return (found ? rc : -1); } // end getLast diff --git a/src/dynamo-framework/com/silverwrist/dynamo/HTMLTagSet.java b/src/dynamo-framework/com/silverwrist/dynamo/HTMLTagSet.java new file mode 100644 index 0000000..c7b21de --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/HTMLTagSet.java @@ -0,0 +1,247 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo; + +import java.util.*; +import org.apache.commons.lang.enum.*; + +public final class HTMLTagSet extends ValuedEnum +{ + /*-------------------------------------------------------------------------------- + * The actual enumeration values + *-------------------------------------------------------------------------------- + */ + + // N.B.: The index values are from the old Venice code, for compatibility + + /** + * Denotes all tags that affect "inline" formatting only, such as <EM> and <B>. + * These are usually allowed. + */ + public static final HTMLTagSet INLINE = new HTMLTagSet("INLINE",1); + + /** + * Denotes the "A" tag. + */ + public static final HTMLTagSet ANCHOR = new HTMLTagSet("ANCHOR",2); + + /** + * Denotes all tags that affect "block-level" formatting, such as <P> and <Hn>. + */ + public static final HTMLTagSet BLOCK = new HTMLTagSet("BLOCK",3); + + /** + * Denotes all tags that cause "active" content to be included in the HTML document, such as + * <OBJECT>, <APPLET>, and <SCRIPT>. These are generally not allowed. + */ + public static final HTMLTagSet ACTIVECONTENT = new HTMLTagSet("ACTIVECONTENT",4); + + /** + * Denotes the tags that create clickable image maps, such as <AREA> and <MAP>. + */ + public static final HTMLTagSet IMAGEMAP = new HTMLTagSet("IMAGEMAP",5); + + /** + * Denotes the tags that are used for document-level formatting and structure, such as <HTML>, <BODY>, + * and <TITLE>. These are generally not allowed. + */ + public static final HTMLTagSet DOCUMENT = new HTMLTagSet("DOCUMENT",6); + + /** + * Denotes the <FONT> tag. + */ + public static final HTMLTagSet FONT = new HTMLTagSet("FONT",7); + + /** + * Denotes all tags that are used in conjunction with forms, such as <FORM>, <INPUT>, and <SELECT>. + */ + public static final HTMLTagSet FORMS = new HTMLTagSet("FORMS",8); + + /** + * Denotes all tags that are used in conjunction with tables, such as <TABLE>, <TR>, and <TD>. + */ + public static final HTMLTagSet TABLES = new HTMLTagSet("TABLES",9); + + /** + * Denotes the <DEL> and <INS> tags, which are used for change markup. + */ + public static final HTMLTagSet CHANGE = new HTMLTagSet("CHANGE",10); + + /** + * Denotes all tags related to frames, such as <FRAMESET> and <FRAME>. These are generally not allowed. + */ + public static final HTMLTagSet FRAMES = new HTMLTagSet("FRAMES",11); + + /** + * Denotes the <IMG> tag. + */ + public static final HTMLTagSet IMAGES = new HTMLTagSet("IMAGES",12); + + /** + * Denotes tags like <PRE>, which are used to preformat input text. + */ + public static final HTMLTagSet PREFORMAT = new HTMLTagSet("PREFORMAT",13); + + /** + * Denotes Netscape-specific inline formatting, such as the hated <BLINK>. + */ + public static final HTMLTagSet NSCP_INLINE = new HTMLTagSet("NSCP_INLINE",14); + + /** + * Denotes Netscape's layer tags, such as <LAYER> and <ILAYER>. These are generally not allowed. + */ + public static final HTMLTagSet NSCP_LAYERS = new HTMLTagSet("NSCP_LAYERS",15); + + /** + * Denotes Netscape-specific form tags, like <KEYGEN>. These are generally not allowed. + */ + public static final HTMLTagSet NSCP_FORMS = new HTMLTagSet("NSCP_FORMS",16); + + /** + * Denotes Netscape-specific block formatting tags, like <MULTICOL>. These are generally not allowed. + */ + public static final HTMLTagSet NSCP_BLOCK = new HTMLTagSet("NSCP_BLOCK",17); + + /** + * Denotes the Netscape <SERVER> tag, used for server-side execution. This is generally not allowed. + */ + public static final HTMLTagSet NSCP_SERVER = new HTMLTagSet("NSCP_SERVER",18); + + /** + * Denotes Microsoft-specific document formatting tags, such as <BGSOUND>. These are generally not allowed. + */ + public static final HTMLTagSet MSFT_DOCUMENT = new HTMLTagSet("MSFT_DOCUMENT",19); + + /** + * Denotes Microsoft-specific inline formatting tags, such as <COMMENT>. These are generally not allowed. + */ + public static final HTMLTagSet MSFT_INLINE = new HTMLTagSet("MSFT_INLINE",20); + + /** + * Denotes Microsoft-specific block formatting tags, such as <MARQUEE>. These are generally not allowed. + */ + public static final HTMLTagSet MSFT_BLOCK = new HTMLTagSet("MSFT_BLOCK",21); + + /** + * Denotes Microsoft-specific active-content tags, such as <XML>. These are generally not allowed. + */ + public static final HTMLTagSet MSFT_ACTIVECONTENT = new HTMLTagSet("MSFT_ACTIVECONTENT",22); + + /** + * Denotes constructs for server-side page use only, such as with Microsoft Active Server Pages and Sun Java + * Server Pages. These are generally not allowed. + */ + public static final HTMLTagSet SERVER = new HTMLTagSet("SERVER",23); + + /** + * Denotes tags used by the Sun Java Server and other Java-compatible servers for including server-side components. + * These are generally not allowed. + */ + public static final HTMLTagSet JAVASERVER = new HTMLTagSet("JAVASERVER",24); + + /** + * Denotes HTML comments. These are generally not allowed. + */ + public static final HTMLTagSet COMMENT = new HTMLTagSet("COMMENT",25); + + public static final HTMLTagSet _LAST = COMMENT; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + /** + * Internal constructor which creates a new element of this enumerated type. + * + * @param name The name of the HTMLTagSet to be created. + * @param value The numeric value to assign to the HTMLTagSet. + */ + private HTMLTagSet(String name, int value) + { + super(name,value); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Standard static method implementations + *-------------------------------------------------------------------------------- + */ + + /** + * Gets a HTMLTagSet by name. + * + * @param name The name of the HTMLTagSet to get; may be null. + * @return The HTMLTagSet object, or null if the HTMLTagSet + * does not exist. + */ + public static HTMLTagSet getEnum(String name) + { + return (HTMLTagSet)getEnum(HTMLTagSet.class,name); + + } // end getEnum + + /** + * Gets a HTMLTagSet by numeric value. + * + * @param code The numeric value of the HTMLTagSet to get. + * @return The HTMLTagSet object, or null if the HTMLTagSet + * does not exist. + */ + public static HTMLTagSet getEnum(int code) + { + return (HTMLTagSet)getEnum(HTMLTagSet.class,code); + + } // end getEnum + + /** + * Gets the Map of HTMLTagSet objects by name. + * + * @return The HTMLTagSet object Map. + */ + public static Map getEnumMap() + { + return getEnumMap(HTMLTagSet.class); + + } // end getEnumMap + + /** + * Gets the List of HTMLTagSet objects, in the order in which the objects are listed + * in the code above. + * + * @return The HTMLTagSet object List. + */ + public static List getEnumList() + { + return getEnumList(HTMLTagSet.class); + + } // end getEnumList + + /** + * Gets an iterator over all HTMLTagSet objects, in the order in which the objects are listed + * in the code above. + * + * @return The HTMLTagSet object iterator. + */ + public static Iterator iterator() + { + return iterator(HTMLTagSet.class); + + } // end iterator + +} // end class HTMLTagSet diff --git a/src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java b/src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java index 68d09cd..6c10081 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java @@ -31,7 +31,7 @@ import javax.servlet.http.HttpServletResponse; * @author Eric J. Bowersox <erbo@silcom.com> * @version X */ -public class HttpStatusCode extends ValuedEnum +public final class HttpStatusCode extends ValuedEnum { /*-------------------------------------------------------------------------------- * The actual enumeration values diff --git a/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java b/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java index 99c9f53..33ef448 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java @@ -74,4 +74,10 @@ public interface Namespaces public static final String GROUP_PERMISSIONS_NAMESPACE = "http://www.silverwrist.com/NS/dynamo/2002/12/27/group.permissions"; + /** + * Namespace for the base set of HTML Checker properties. + */ + public static final String HTMLCHECKER_PROPERTIES_NAMESPACE = + "http://www.silverwrist.com/NS/dynamo/2003/06/05/htmlchecker.properties"; + } // end interface Namespaces diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/AlreadyFinishedException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/AlreadyFinishedException.java new file mode 100644 index 0000000..9bec612 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/AlreadyFinishedException.java @@ -0,0 +1,33 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.except; + +public class AlreadyFinishedException extends HTMLCheckerRuntimeException +{ + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public AlreadyFinishedException() + { + super(AlreadyFinishedException.class,"DynamoExceptionMessages","htmlchecker.alreadyfinished"); + + } // end constructor + +} // end class AlreadyFinishedException diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/DynamoExceptionMessages.properties b/src/dynamo-framework/com/silverwrist/dynamo/except/DynamoExceptionMessages.properties index dca6589..818247a 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/except/DynamoExceptionMessages.properties +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/DynamoExceptionMessages.properties @@ -31,3 +31,5 @@ scriptingException=Error executing {0}[{1}]: {2} renderClass.creation=Unable to create object of class {0} at rendering time. dialogException.xmlLoadException=Error in XML dialog definition: {0} udfe.bad.itemType=No implementation exists for dialog item type "{0}". +htmlchecker.alreadyfinished=The HTML Checker is already in a finished state. +htmlchecker.notyetfinished=The HTML Checker is not yet in a finished state. diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/HTMLCheckerRuntimeException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/HTMLCheckerRuntimeException.java new file mode 100644 index 0000000..ecbb5d4 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/HTMLCheckerRuntimeException.java @@ -0,0 +1,39 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.except; + +public class HTMLCheckerRuntimeException extends ExternalRuntimeException +{ + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public HTMLCheckerRuntimeException(Class caller, String bundle, String message_id) + { + super(caller,bundle,message_id); + + } // end constructor + + public HTMLCheckerRuntimeException(Class caller, String bundle, String message_id, Throwable inner) + { + super(caller,bundle,message_id,inner); + + } // end constructor + +} // end class HtmlCheckerRuntimeException diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/NotYetFinishedException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/NotYetFinishedException.java new file mode 100644 index 0000000..8c1c670 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/NotYetFinishedException.java @@ -0,0 +1,33 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.except; + +public class NotYetFinishedException extends HTMLCheckerRuntimeException +{ + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public NotYetFinishedException() + { + super(NotYetFinishedException.class,"DynamoExceptionMessages","htmlchecker.notyetfinished"); + + } // end constructor + +} // end class NotYetFinishedException diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/CheckerObject.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/CheckerObject.java new file mode 100644 index 0000000..b1234b6 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/CheckerObject.java @@ -0,0 +1,1460 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.io.*; +import java.util.*; +import java.util.regex.*; +import org.apache.log4j.Logger; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.htmlcheck.tags.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class CheckerObject implements HTMLChecker, HTMLRewriterSite, HTMLTagSite +{ + /*-------------------------------------------------------------------------------- + * Internal class implementing counters for rewriters + *-------------------------------------------------------------------------------- + */ + + private static class CountingRewriter implements HTMLRewriter + { + /*==================================================================== + * Attributes + *==================================================================== + */ + + private HTMLRewriter m_inner; + private int m_count = 0; + + /*==================================================================== + * Constructor + *==================================================================== + */ + + CountingRewriter(HTMLRewriter inner) + { + m_inner = inner; + + } // end constructor + + /*==================================================================== + * Implementations from interface HTMLRewriter + *==================================================================== + */ + + public QualifiedNameKey getName() + { + return m_inner.getName(); + + } // end getName + + public MarkupData rewrite(String data, String prefix, String suffix, HTMLRewriterSite site) + { + MarkupData rc = m_inner.rewrite(data,prefix,suffix,site); + if (rc!=null) + m_count++; + return rc; + + } // end rewrite + + /*==================================================================== + * External operations + *==================================================================== + */ + + int getCount() + { + return m_count; + + } // end getCount + + void reset() + { + m_count = 0; + + } // end reset + + } // end class CountingRewriter + + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static Logger logger = Logger.getLogger(CheckerObject.class); + + private static final short ST_WHITESPACE = 0; + private static final short ST_CHARS = 1; + private static final short ST_LEFTANGLE = 2; + private static final short ST_TAG = 3; + private static final short ST_PAREN = 4; + private static final short ST_TAGQUOTE = 5; + private static final short ST_NEWLINE = 6; + private static final short ST_BRACKET = 7; + private static final short ST_BRACE = 8; + + private static final int MARGIN_SLOP = 5; + + private static Pattern P_INITIAL_COMMENT; + private static Pattern P_ALL_COMMENT; + private static Pattern P_OPEN_HTML; + private static Pattern P_CLOSE_HTML; + private static Pattern P_XML_CONSTRUCT; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private FrozenProfileObject m_profile; // the profile object we use + private MemoryObjectStore m_objstore; // memory object store (for context data) + private boolean m_started = false; // have we started the current parse? + private boolean m_finished = false; // have we finished the current parse? + private short m_state = ST_WHITESPACE; // current parser state + private short m_columns = 0; // current number of columns + private int m_lines = 0; // current number of lines + private int m_nobreak_count = 0; // "no-break" count + private int m_nesting = 0; // nesting level + private char m_quote_char = '\0'; // quote match character + private boolean m_wordbreak = false; // word break triggered? + private StringBuffer m_output_buffer = null; // the output buffer containing the checked text + private StringBuffer m_state_buffer = null; // intra-state buffer containing processed text + private ArrayList m_tag_stack = null; // HTML tag stack + private Reader m_do_reader = null; // reader data to insert + private HashMap m_counters = new HashMap(); // defined counters on rewriters + private HTMLRewriter[] m_string_rewriters; // the string rewriters + private HTMLRewriter[] m_word_rewriters; // the word rewriters + private HTMLRewriter[] m_tag_rewriters; // the tag rewriters + private HTMLRewriter[] m_paren_rewriters; // the parenthesis rewriters + private HTMLRewriter[] m_bracket_rewriters; // the bracket rewriters + private HTMLRewriter[] m_brace_rewriters; // the brace rewriters + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + CheckerObject(FrozenProfileObject profile) + { + m_profile = profile; + m_objstore = new MemoryObjectStore("HTML Checker"); + m_string_rewriters = processRewriterList(profile.getStringRewriters()); + m_word_rewriters = processRewriterList(profile.getWordRewriters()); + m_tag_rewriters = processRewriterList(profile.getTagRewriters()); + m_paren_rewriters = processRewriterList(profile.getParenRewriters()); + m_bracket_rewriters = processRewriterList(profile.getBracketRewriters()); + m_brace_rewriters = processRewriterList(profile.getBraceRewriters()); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + /** + * Returns true if this character belongs as part of a word, false if not. + * + * @param ch Character to be tested. + * @return See above. + */ + private static final boolean isWordChar(char ch) + { + return (Character.isLetter(ch) || (ch=='-') || (ch=='\'')); + + } // end isWordChar + + /** + * Returns the maximum length of a "run" of word characters or non-word characters in the + * buffer, beginning at the specified start point, before a character of the opposite classification. + * + * @param buf The buffer to look through. + * @param start The start position to look at. + * @return See above. + */ + private static final int getRunLength(StringBuffer buf, int start) + { + boolean word_char = isWordChar(buf.charAt(start)); + int l = 1; + while ((start+l)0) + m_tag_stack.clear(); + m_tag_stack = null; + + } // end killState + + /** + * Use the specified list of rewriters to attempt to rewrite the specified string data. The first rewriter in the + * list that returns a valid {@link com.silverwrist.dynamo.htmlcheck.MarkupData MarkupData} object takes precedence. + * + * @param rewriters Array of rewriters to try against the rewriter data. + * @param data String data to attempt to rewrite. + * @return A MarkupData object that contains the marked-up data to output, or + * null if no rewriter handled the data. + */ + private final MarkupData attemptRewrite(HTMLRewriter[] rewriters, String data, String prefix, String suffix) + { + MarkupData rc = null; + for (int i=0; (rc==null) && (itrue if the character output adds to the column counter, + * false if not. + */ + private final void emit(char ch, HTMLOutputFilter[] filters, boolean count_cols) + { + boolean handled = false; + if (filters.length>0) + { // look through all the output filters to see what we can do + for (int i=0; !handled && (i0)) + m_columns++; // adjust column indicator + + } // end emit + + /** + * Emits a character string to the output of the HTML checker, running it through a list of defined filters. + * + * @param s String to output. + * @param filters Array of filters to use to attempt to process the string. + * @param count_cols true if the characters output add to the column counter, + * false if not. + */ + private final void emit(String s, HTMLOutputFilter[] filters, boolean count_cols) + { + if ((s==null) || (s.length()==0)) + return; + + boolean real_count_cols = (count_cols && (m_profile.getWordWrapLength()>0)); + + if (filters.length==0) + { // if there are no filters, just append the entire string directly + m_output_buffer.append(s); + if (real_count_cols) + m_columns += (short)(s.length()); + return; + + } // end if + + String temp = s; + while ((temp!=null) && (temp.length()>0)) + { // We output as much of the string as we possibly can at once. For starters, + // assume we're going to output the whole thing. + int output_len = temp.length(); + + // Now look at each of the output filters to see if we should try outputting + // a lesser amount (i.e., does the string contain a "stopper" that one of the + // output filters would like to mogrify?) + int stopper = -1; + for (int i=0; (output_len>0) && (i=0) && (lnm0) + { // At least this many unaltered characters can be output, so copy them. + m_output_buffer.append(temp.substring(0,output_len)); + if (real_count_cols) + m_columns += (short)output_len; + + } // end if + + if (stopper>=0) + { // one of the output filters stopped us, so invoke it + char tmpch = temp.charAt(output_len++); + if (!(filters[stopper].tryOutputCharacter(m_output_buffer,tmpch))) + m_output_buffer.append(tmpch); + if (real_count_cols) + m_columns++; + + } // end if + + // Chop the string down the middle and go around again. + if (output_len==temp.length()) + temp = null; + else if (output_len>0) + temp = temp.substring(output_len); + + } // end while (still data left to append) + + } // end emit + + /** + * Emits a line break to the output of the HTML checker, resetting the column counter and advancing + * the line counter. + */ + private final void emitLineBreak() + { + emit("\r\n",m_profile.getRawOutputFilters(),false); + if (m_profile.getWordWrapLength()>0) + m_columns = 0; + m_lines++; + + } // end emitLineBreak + + /** + * If the current line of text contains more characters than will fit on the line, emit a line break. + * Disabled if the checker does not word-wrap. + */ + private final void emitPossibleLineBreak() + { + short wwl = m_profile.getWordWrapLength(); + if ((wwl>0) && (m_nobreak_count<=0) && (m_columns>=wwl)) + emitLineBreak(); + + } // end emitPossibleLineBreak + + /** + * Ensure that the current line has a certain number of characters of space left on it; if it does not, + * emit a line break. + * + * @param nchars Number of characters to reserve on the line. + */ + private final void ensureSpaceOnLine(int nchars) + { + short wwl = m_profile.getWordWrapLength(); + if ((wwl>0) && (m_nobreak_count<=0)) + { // line break might be required here + int remain_space = (int)(wwl - m_columns); + if (remain_spacetagslist.getMaxTagLength()) + return false; // tagname too long + + HTMLTag ht = tagslist.getTag(tagname); + if (ht==null) + return false; // tag not found! + + if (is_closing && !(ht.allowClose())) + return false; // tag does not allow the "close" form + + if (!(m_profile.isAllowed(ht.getTagSet()))) + // this tag is not allowed! but, if we're discarding ALL HTML tags or rejected HTML, then we're in the + // clear... + return (m_profile.getDiscardHTMLTags() || m_profile.getDiscardRejectedHTML()); + + if (!(m_profile.getDiscardHTMLTags()) && ht.balanceTags()) + { // manipulate the tag stack to properly balance tags + boolean valid = false; // is the tag balance valid? + if (is_closing) + { // hunt backwards through the stack to find a valid open for this close + int i = m_tag_stack.size(); + while ((--i)>=0) + { // look back through the stack... + HTMLTag foo = (HTMLTag)(m_tag_stack.get(i)); + if (foo.equals(ht)) + { // found a match! remove the object from the tag stack + m_tag_stack.remove(i); + valid = true; + break; + + } // end if + + } // end while + + } // end if + else + { // push this tag on the stack + m_tag_stack.add(ht); + valid = true; + + } // end else + + if (!valid) + return false; // tag couldn't balance properly - bug the hell out + + } // end if + + // Give the tag an opportunity to do its own rewriting. + String out_tag = ht.rewrite(tag,is_closing,this); + if ((out_tag==null) || m_profile.getDiscardHTMLTags()) + return true; // tag erased, or discarded + + // Emit the actual tag. + HTMLOutputFilter[] raw = m_profile.getRawOutputFilters(); + emit('<',raw,false); + emit(out_tag,raw,false); + emit('>',raw,false); + + // Does this tag cause a logical line break? + boolean llb = false; + if (m_wordbreak && !is_closing && (m_nobreak_count>0)) + llb = true; + else + llb = ht.causeLineBreak(is_closing); + if (llb) + m_columns = 0; // now at the start of a new line + + return true; // all handled! + + } // end handleHTML + + private final void doFlushChars() + { + if (m_state_buffer.length()>0) + { // look to see if we can rewrite the string + MarkupData md = attemptRewrite(m_string_rewriters,m_state_buffer.toString(),null,null); + if (md==null) + { // Break the big string into words and non-word characters. + boolean first = true; + while (m_state_buffer.length()>0) + { // get the initial run length of word/non-word characters + int sublen = getRunLength(m_state_buffer); + if (isWordChar(m_state_buffer.charAt(0))) + { // Strip off leading and trailing hyphens/apostrophes from the word. + int word_len = sublen; + int lead_len = 0, trail_len = 0; + final String hyph_apos = "'-"; + while ((word_len>0) && (hyph_apos.indexOf(m_state_buffer.charAt(lead_len))>=0)) + { // skip leading apostrophes/hyphens + lead_len++; + word_len--; + + } // end while + + while ((word_len>0) && (hyph_apos.indexOf(m_state_buffer.charAt(sublen - (trail_len + 1)))>=0)) + { // skip trailing apostrophes/hyphens + trail_len++; + word_len--; + + } // end while + + if (lead_len>0) + { // emit leading apostrophes and hyphens + if (first && (lead_len<=MARGIN_SLOP)) + ensureSpaceOnLine(lead_len + word_len); // keep initial run with word + else + ensureSpaceOnLine(lead_len); + emit(m_state_buffer.substring(0,lead_len),m_profile.getOutputFilters(),true); + m_state_buffer.delete(0,lead_len); + + } // end if + + if (word_len>0) + { // get the word off the front of the buffer + String word = m_state_buffer.substring(0,word_len); + m_state_buffer.delete(0,word_len); + + // try to rewrite the word + md = attemptRewrite(m_word_rewriters,word,null,null); + if (md==null) + { // output the word as usual + ensureSpaceOnLine(word_len); + emit(word,m_profile.getOutputFilters(),true); + + } // end if + else // output the marked-up data + emit(md); + + } // end if + + if (trail_len>0) + { // emit trailing apostrophes and hyphens + if ((trail_lenMARGIN_SLOP)) + ensureSpaceOnLine(trail_len); // keep trailing apostrophe/hyphen with word in some cases + emit(m_state_buffer.substring(0,trail_len),m_profile.getOutputFilters(),true); + m_state_buffer.delete(0,trail_len); + + } // end if + + } // end if + else + { // output the substring of non-word characters + if ((sublen==m_state_buffer.length()) && !first && (sublen<=MARGIN_SLOP)) + { // This is intended to handle a small run of non-word characters at the end of a string (i.e. followed + // by whitespace) that should stay on the same line with its preceding word, to eliminate "funnies" in + // punctuation formatting. + emit(m_state_buffer.toString(),m_profile.getOutputFilters(),true); + m_state_buffer.setLength(0); + break; + + } // end if + + // This is kind of the inverse of the above check; if we have a small run of non-word characters at the + // START of a word (preceded by whitespace and followed by at least one word character), then ensure that + // we can keep that word and its prefixing non-word characters on the same line (again, avoiding "funnies" + // in formatting). + if ((sublen0) + { // need to output some whitespace + boolean force_line_break = false; + short wwl = m_profile.getWordWrapLength(); + if ((wwl>0) && (m_nobreak_count<=0)) + { // adjust output if necessary for word-wrapping + int remain_space = (int)(wwl - m_columns); + if (remain_space0) // emit the spaces + emit(m_state_buffer.substring(0,output_len),m_profile.getOutputFilters(),true); + m_state_buffer.setLength(0); + + } // end if + + // Determine the next state. + if ((ch=='\r') || (ch=='\n')) + return ST_NEWLINE; + if ((ch=='<') && m_profile.getProcessAngles()) + return ST_LEFTANGLE; + if ((ch=='(') && m_profile.getProcessParens()) + { // start parenthesis + m_nesting = 0; + return ST_PAREN; + + } // end if + + if ((ch=='[') && m_profile.getProcessBrackets()) + { // start bracket + m_nesting = 0; + return ST_BRACKET; + + } // end if + + if ((ch=='{') && m_profile.getProcessBraces()) + { // start brace + m_nesting = 0; + return ST_BRACE; + + } // end if + + return ST_CHARS; + + } // end parseWhitespace + + private final short parseChars(PushbackReader r) throws IOException + { + String openers = m_profile.getOpeners(); + int ch = r.read(); + while ((ch!=-1) && !(Character.isWhitespace((char)ch)) && (openers.indexOf((char)ch)<0)) + { // while we're still reading non-newline whitespace characters... + if (ch=='\\') + { // allow backslash to escape the opening character of a special sequence + int ch2 = r.read(); + if ((ch2!=-1) && (openers.indexOf((char)ch2)>=0)) + m_state_buffer.append((char)ch2); + else + { // append the backslash and push back the second character we read + m_state_buffer.append('\\'); + if (ch2!=-1) + r.unread(ch2); + + } // end else + + } // end if + else // append the character + m_state_buffer.append((char)ch); + ch = r.read(); + + } // end while + + if (ch==-1) + return ST_CHARS; // end of input - stay in this state + r.unread(ch); // push back the character we just read + + // Flush the characters we've just read. + doFlushChars(); + + // Determine the next state. + if ((ch=='\r') || (ch=='\n')) + return ST_NEWLINE; + if ((ch=='<') && m_profile.getProcessAngles()) + return ST_LEFTANGLE; + if ((ch=='(') && m_profile.getProcessParens()) + { // start parenthesis + m_nesting = 0; + return ST_PAREN; + + } // end if + + if ((ch=='[') && m_profile.getProcessBrackets()) + { // start bracket + m_nesting = 0; + return ST_BRACKET; + + } // end if + + if ((ch=='{') && m_profile.getProcessBraces()) + { // start brace + m_nesting = 0; + return ST_BRACE; + + } // end if + + return ST_WHITESPACE; + + } // end parseChars + + private final short parseLeftAngle(PushbackReader r) throws IOException + { + // Read off the initial left angle bracket. + int ch = r.read(); + assert (ch=='<'); + + for (;;) + { // look for the character following the angle bracket + ch = r.read(); + if ((ch==-1) || (Character.isWhitespace((char)ch))) + { // switch back to whitespace mode + emit('<',m_profile.getOutputFilters(),true); + if (ch!=-1) + r.unread(ch); + return ST_WHITESPACE; + + } // end if + else if (ch=='<') // left angle - emit it and stay in this mode + emit('<',m_profile.getOutputFilters(),true); + else + break; // found the start of a tag + + } // end for (ever) + + // now hitting the start of the tag + r.unread(ch); + return ST_TAG; + + } // end parseLeftAngle + + private final short parseTag(PushbackReader r) throws IOException + { + int ch = r.read(); + while ((ch!=-1) && (ch!='>')) + { // append characters until we hit the end of the tag + m_state_buffer.append(ch); + if ((ch=='"') || (ch=='\'')) + { // we're inside a quote - do your number + m_quote_char = (char)ch; + return ST_TAGQUOTE; + + } // end if + + ch = r.read(); + + } // end while + + if (ch==-1) + return ST_TAG; // remain in same state + assert (ch=='>'); + + // Lift the completed tag out of the buffer. + String the_tag = m_state_buffer.toString(); + m_state_buffer.setLength(0); + + if (the_tag.length()==0) + { // pretend we've already read the <> and click to the characters state + m_state_buffer.append("<>"); + return ST_CHARS; + + } // end if + + // see if this is a comment + if (isHTMLComment(the_tag)) + { // must be complete if we are to process it + if (!isCompleteHTMLComment(the_tag)) + { // dump tag back into the buffer and try again + m_state_buffer.append(the_tag).append('>'); + return ST_TAG; + + } // end if + + if (!(m_profile.getDiscardHTMLComments())) + { // emit the comment + HTMLOutputFilter[] raw = m_profile.getRawOutputFilters(); + emit('<',raw,false); + emit(the_tag,raw,false); + emit('>',raw,false); + + } // end if + + return ST_WHITESPACE; // treat the comment as if it were whitespace + + } // end if + + // See if the tag can be handled as valid HTML. + if (handleHTML(the_tag)) + return ST_WHITESPACE; + + // See if one of our tag rewriters will handle it. + MarkupData md = attemptRewrite(m_tag_rewriters,the_tag,"<",">"); + if (md!=null) + { // emit the "tag" and click to whitespace mode + emit(md); + return ST_WHITESPACE; + + } // end if + + if (m_profile.getDiscardXMLConstructs() && isXMLConstruct(the_tag)) + return ST_WHITESPACE; // discard the XML constructs + + // Tag has been rejected...fake the initial character in the buffer, push back the last character, arrange the + // rejected string as a new StringReader + m_state_buffer.append('<'); + r.unread('>'); + m_do_reader = new StringReader(the_tag); + return ST_CHARS; + + } // end parseTag + + private final short parseDelimited(PushbackReader r, short state, HTMLRewriter[] rewriters, String prefix, + String suffix) throws IOException + { + char start_char = prefix.charAt(0); + char end_char = suffix.charAt(0); + + // Read off the initial delimiter. + int ch = r.read(); + assert (((char)ch)==start_char); + + ch = r.read(); + while (ch!=-1) + { // determine how to append data to the buffer + if (start_char==(char)ch) + { // open nesting + m_state_buffer.append((char)ch); + m_nesting++; + + } // end if + else if (end_char==(char)ch) + { // close nesting, maybe close the sequence + if (m_nesting==0) + break; + m_state_buffer.append((char)ch); + m_nesting--; + + } // end else if + else // just append the character to the buffer + m_state_buffer.append((char)ch); + + ch = r.read(); + + } // end while + + if (ch==-1) + return state; // keep it in the same state + assert (((char)ch)==end_char); + + String data = m_state_buffer.toString(); // lift the data clear + m_state_buffer.setLength(0); + + // can we rewrite this string? + MarkupData md = attemptRewrite(rewriters,data,prefix,suffix); + if (md!=null) + { // output the marked-up data and click to whitespace mode + emit(md); + m_nesting = 0; + return ST_WHITESPACE; + + } // end if + + // fake the initial character in the buffer, push back the last character, arrange the rejected string + // as a new StringReader + m_state_buffer.append(start_char); + r.unread(ch); + if (data.length()>0) + m_do_reader = new StringReader(data); + m_nesting = 0; + return ST_CHARS; + + } // end parseDelimited + + private final short parseTagQuote(PushbackReader r) throws IOException + { + for (;;) + { // copy characters across, scanning for EOF and the quote character + int ch = r.read(); + if (ch==-1) + return ST_TAGQUOTE; + m_state_buffer.append((char)ch); + if (m_quote_char==(char)ch) + break; + + } // end for (ever) + + m_quote_char = '\0'; + return ST_TAG; + + } // end parseTagQuote + + private final short parseNewlines(PushbackReader r) throws IOException + { + int ch = r.read(); + while ((ch=='\r') || (ch=='\n')) + { // append newlines to the state buffer + m_state_buffer.append((char)ch); + ch = r.read(); + + } // end while + + if (ch==-1) + return ST_NEWLINE; // EOF - stay in this state + r.unread(ch); // pushback character + + if (m_state_buffer.length()>0) + { // flush out all the newlines + char[] arr = m_state_buffer.toString().toCharArray(); + m_state_buffer.setLength(0); + + int crs = 0, line_breaks = 0; + for (int i=0; i0) + line_breaks++; + + if (m_profile.getRewrapLines()) + { // if we're rewrapping lines, do some fancy maneuvering + if (line_breaks<2) + { // single line breaks become just spaces + m_state_buffer.append(' '); + return ST_WHITESPACE; + + } // end if + else // compress all greater numbers down to 2 line breaks + line_breaks = 2; + + } // end if + + while ((line_breaks--)>0) + emitLineBreak(); // emit the line breaks + + } // end if + + // Figure out the next state to go to. + if (Character.isWhitespace((char)ch)) + return ST_WHITESPACE; + if ((ch=='<') && m_profile.getProcessAngles()) + return ST_LEFTANGLE; + if ((ch=='(') && m_profile.getProcessParens()) + { // start parenthesis + m_nesting = 0; + return ST_PAREN; + + } // end if + + if ((ch=='[') && m_profile.getProcessBrackets()) + { // start bracket + m_nesting = 0; + return ST_BRACKET; + + } // end if + + if ((ch=='{') && m_profile.getProcessBraces()) + { // start brace + m_nesting = 0; + return ST_BRACE; + + } // end if + + return ST_CHARS; + + } // end parseNewlines + + private final void parse(Reader r) + { + try + { // wrap the reader in a PushbackReader + PushbackReader pr = new PushbackReader(r,4); + boolean looping = true; + while (looping) + { // loop around on the current state + switch (m_state) + { // process for this state, get the next state + case ST_WHITESPACE: + m_state = parseWhitespace(pr); + break; + + case ST_CHARS: + m_state = parseChars(pr); + break; + + case ST_LEFTANGLE: + m_state = parseLeftAngle(pr); + break; + + case ST_TAG: + m_state = parseTag(pr); + break; + + case ST_PAREN: + m_state = parseDelimited(pr,ST_PAREN,m_paren_rewriters,"(",")"); + break; + + case ST_TAGQUOTE: + m_state = parseTagQuote(pr); + break; + + case ST_NEWLINE: + m_state = parseNewlines(pr); + break; + + case ST_BRACKET: + m_state = parseDelimited(pr,ST_BRACKET,m_bracket_rewriters,"[","]"); + break; + + case ST_BRACE: + m_state = parseDelimited(pr,ST_BRACE,m_brace_rewriters,"{","}"); + break; + + default: + throw new IllegalStateException("invalid parser state value"); + + } // end switch + + // If there's a "next" reader that's been set up, process the data it contains. + Reader next = m_do_reader; + m_do_reader = null; + if (next!=null) + parse(next); + + // See if we're at the end of input. + int ch = pr.read(); + if (ch==-1) + looping = false; // end of input + else + pr.unread(ch); + + } // end while + + } // end try + catch (IOException e) + { // just log the error... + logger.error("IO error parsing HTML",e); + + } // end catch + + } // end parse + + private final void recoverPartialTag(char opener) + { + String data = m_state_buffer.toString(); + m_state_buffer.setLength(0); + m_state_buffer.append(opener); + m_state = ST_CHARS; + m_nesting = 0; + if (data.length()>0) + parse(new StringReader(data)); + + } // end recoverPartialTag + + /*-------------------------------------------------------------------------------- + * Implementations from interface ObjectProvider + *-------------------------------------------------------------------------------- + */ + + /** + * Retrieves an object from this ObjectProvider. + * + * @param namespace The namespace to interpret the name relative to. + * @param name The name of the object to be retrieved. + * @return The object reference specified. + */ + public Object getObject(String namespace, String name) + { + return m_objstore.getObject(namespace,name); + + } // end getObject + + /*-------------------------------------------------------------------------------- + * Implementations from interface ObjectStore + *-------------------------------------------------------------------------------- + */ + + /** + * Sets an object into this ObjectStore. + * + * @param namespace The namespace to interpret the name relative to. + * @param name The name of the object to be set. + * @param value The object to set into the ObjectStore. + * @return The previous object that was set into the ObjectStore under this namespace and name, or + * null if there was no such object. + */ + public Object setObject(String namespace, String name, Object value) + { + return m_objstore.setObject(namespace,name,value); + + } // end setObject + + /** + * Removes an object from this ObjectStore. + * + * @param namespace The namespace to interpret the name relative to. + * @param name The name of the object to be removed. + * @return The previous object that was set into the ObjectStore under this namespace and name, or + * null if there was no such object. + */ + public Object removeObject(String namespace, String name) + { + return m_objstore.removeObject(namespace,name); + + } // end removeObject + + /** + * Returns a collection of all object namespaces that have been set into this ObjectStore. + * + * @return A java.util.Collection containing String objects specifying all the + * object namespaces. + */ + public Collection getNamespaces() + { + return m_objstore.getNamespaces(); + + } // end getNamespaces + + /** + * Returns a collection of all object names that have been set into this ObjectStore under a given + * namespace. + * + * @param namespace The namespace to look for names under. + * @return A {@link java.util.Collection Collection} containing {@link java.lang.String String} objects specifying + * all the object names for this namespace. + */ + public Collection getNamesForNamespace(String namespace) + { + return m_objstore.getNamesForNamespace(namespace); + + } // end getNamesForNamespace + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLChecker + *-------------------------------------------------------------------------------- + */ + + public void append(String str) + { + if (str!=null) + this.append(new StringReader(str)); + + } // end append + + public void append(Reader r) + { + if (m_finished) + throw new AlreadyFinishedException(); + if (!m_started) + { // initialize the parser state + initState(); + m_started = true; + + } // end if + + parse(r); // parse this reader's contents + + } // end append + + public void finish() + { + if (m_finished) + throw new AlreadyFinishedException(); + if (!m_started) + { // initialize the parser state + initState(); + m_started = true; + + } // end if + + // This is the "end parse" loop, in which we resolve any funny state the parser has found itself in and clear out + // the internal buffers. + boolean running; + do + { // what we do depends on the parser state... + running = false; // make sure we stop unless running is set to true here + + switch (m_state) + { + case ST_WHITESPACE: + case ST_NEWLINE: + break; // discard any whitespace or newlines at the end of output + + case ST_CHARS: + doFlushChars(); // flush the character buffer + break; + + case ST_LEFTANGLE: // just emit a '<' character + ensureSpaceOnLine(1); + emit('<',m_profile.getOutputFilters(),true); + break; + + case ST_TAG: + case ST_TAGQUOTE: + recoverPartialTag('<'); + running = true; + break; + + case ST_PAREN: + recoverPartialTag('('); + running = true; + break; + + case ST_BRACKET: + recoverPartialTag('['); + running = true; + break; + + case ST_BRACE: + recoverPartialTag('{'); + running = true; + break; + + } // end switch + + } while (running); // end do + + // Now close all the HTML tags that were left open. + for (int i=(m_tag_stack.size()-1); i>=0; i--) + { // get each tag object off the stack and close it + HTMLTag ht = (HTMLTag)(m_tag_stack.get(i)); + m_output_buffer.append(ht.makeClosingTag()); + + } // end for + + // deallocate some excess crap and mark the object as finished + killState(); + m_lines++; + m_finished = true; + + } // end finish + + public void reset() + { + // Reset all the items on our "worry list." + m_started = false; + m_finished = false; + m_state = ST_WHITESPACE; + m_columns = 0; + m_lines = 0; + m_nobreak_count = 0; + m_nesting = 0; + m_quote_char = '\0'; + m_wordbreak = false; + m_output_buffer = null; + killState(); + + // Also reset all the counters. + Iterator it = m_counters.values().iterator(); + while (it.hasNext()) + { // reset each counter in turn + CountingRewriter cr = (CountingRewriter)(it.next()); + cr.reset(); + + } // end while + + } // end reset + + public String getValue() + { + if (!m_finished) + throw new NotYetFinishedException(); + return m_output_buffer.toString(); + + } // end getValue + + public int getLength() + { + if (!m_finished) + throw new NotYetFinishedException(); + return m_output_buffer.length(); + + } // end getLength + + public int getLines() + { + if (!m_finished) + throw new NotYetFinishedException(); + return m_lines; + + } // end getLines + + public int getCounter(String namespace, String name) + { + if (!m_finished) + throw new NotYetFinishedException(); + CountingRewriter cr = (CountingRewriter)(m_counters.get(new QualifiedNameKey(namespace,name))); + return (cr==null) ? 0 : cr.getCount(); + + } // end getCounter + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLRewriterSite + *-------------------------------------------------------------------------------- + */ + + public String getAttribute(String namespace, String name) + { + return m_profile.getAttribute(namespace,name); + + } // end getAttribute + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLTagSite + *-------------------------------------------------------------------------------- + */ + + public void controlMessage(String message, Object data) + { + if (message.equals("NOBR")) + m_nobreak_count++; + else if (message.equals("/NOBR")) + m_nobreak_count--; + else if (message.equals("WBR")) + m_wordbreak = true; + else + logger.warn("CheckerObject.controlMessage(): unknown message " + message); + + } // end controlMessage + + /*-------------------------------------------------------------------------------- + * Static initializer + *-------------------------------------------------------------------------------- + */ + + static + { + try + { // pre-compile all our regex patterns + P_INITIAL_COMMENT = Pattern.compile("^!--"); + P_ALL_COMMENT = Pattern.compile("^!--.*--$"); + P_OPEN_HTML = Pattern.compile("^([A-Za-z]+)(?:\\s+.*)?$"); + P_CLOSE_HTML = Pattern.compile("^/([A-Za-z]+)$"); + P_XML_CONSTRUCT = Pattern.compile("^/?[-\\w]+:[-\\w]+(?:\\s+.*)?$"); + + } // end try + catch (PatternSyntaxException pe) + { // log an error, all we can do + logger.fatal("Pattern compilation error in CheckerObject",pe); + + } // end catch + + } // end static initializer + +} // end class CheckerObject diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeHTML.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeHTML.java new file mode 100644 index 0000000..4d7913f --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeHTML.java @@ -0,0 +1,128 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import com.silverwrist.util.*; +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class EncodeHTML implements HTMLCheckerConfigurator, HTMLOutputFilter +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final String ESCAPED_CHARACTERS = "<>&"; + + private static final AnyCharMatcher MATCHER = new AnyCharMatcher(ESCAPED_CHARACTERS); + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + EncodeHTML() + { // do nothing + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerConfigurator + *-------------------------------------------------------------------------------- + */ + + public void configure(HTMLCheckerProfile profile) + { + boolean enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "enable.HTML.filter",Boolean.FALSE))).booleanValue(); + if (enable) // add myself as an output filter + profile.addOutputFilter(this); + + } // end configure + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLOutputFilter + *-------------------------------------------------------------------------------- + */ + + /** + * Checks and possibly outputs a character. If the character ch is '<', + * '>', or '&', it appends the appropriate string to the string buffer + * buf and returns true. If not, it returns false + * and leaves the buffer alone. + * + * @param buf The string buffer to append the character equivalent to. + * @param ch The character to be checked and possibly output. + * @return true if the character matches and was output, false if not. + */ + public boolean tryOutputCharacter(StringBuffer buf, char ch) + { + switch (ch) + { // turn the HTML flag characters into appropriate entity escapes + case '<': + buf.append("<"); + return true; + + case '>': + buf.append(">"); + return true; + + case '&': + buf.append("&"); + return true; + + default: + break; + + } // end switch + + return false; // bail out! not one we handle! + + } // end tryOutputCharacter + + /** + * Returns true if the character ch is '<', '>', or '&', false if not. + * + * @param ch The character to be tested. + * @return true if the character ch is '<', '>', or '&', false if not. + */ + public boolean matchCharacter(char ch) + { + return (ESCAPED_CHARACTERS.indexOf(ch)>=0); + + } // end matchCharacter + + /** + * Given a character string, returns the total number of characters in that string, starting from the beginning, + * that are not handled by this filter before one that is appears. If none of the characters in this + * string are handled by the filter, the length of the string is returned. + * + * @param s The string to scan through. + * @return The length of the initial sequence of non-matching characters in this string. + */ + public int lengthNoMatch(String s) + { + int rc = MATCHER.get(s); + if (rc==-1) + rc = s.length(); + return rc; + + } // end lengthNoMatch + +} // end class EncodeHTML diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeSQL.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeSQL.java new file mode 100644 index 0000000..de5b579 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/EncodeSQL.java @@ -0,0 +1,109 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class EncodeSQL implements HTMLCheckerConfigurator, HTMLOutputFilter +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + EncodeSQL() + { // do nothing + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerConfigurator + *-------------------------------------------------------------------------------- + */ + + public void configure(HTMLCheckerProfile profile) + { + boolean enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "enable.SQL.filter",Boolean.FALSE))).booleanValue(); + if (enable) + { // add myself as an output filter + profile.addOutputFilter(this); + profile.addRawOutputFilter(this); + + } // end if + + } // end configure + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLOutputFilter + *-------------------------------------------------------------------------------- + */ + + /** + * Checks and possibly outputs a character. If the character ch is an apostrophe, it appends two + * apostrophes to the string buffer buf and returns true. If not, it returns + * false and leaves the buffer alone. + * + * @param buf The string buffer to append the character equivalent to. + * @param ch The character to be checked and possibly output. + * @return true if the character matches and was output, false if not. + */ + public boolean tryOutputCharacter(StringBuffer buf, char ch) + { + if (ch=='\'') + { // convert one apostrophe into two + buf.append("\'\'"); + return true; + + } // end if + + return false; + + } // end tryOutputCharacter + + /** + * Returns true if the character ch is an apostrophe, false if not. + * + * @param ch The character to be tested. + * @return true if the character ch is an apostrophe, false if not. + */ + public boolean matchCharacter(char ch) + { + return (ch=='\''); + + } // end matchCharacter + + /** + * Given a character string, returns the total number of characters in that string, starting from the beginning, + * that are not handled by this filter before one that is appears. If none of the characters in this + * string are handled by the filter, the length of the string is returned. + * + * @param s The string to scan through. + * @return The length of the initial sequence of non-matching characters in this string. + */ + public int lengthNoMatch(String s) + { + int rc = s.indexOf('\''); + if (rc<0) + rc = s.length(); + return rc; + + } // end lengthNoMatch + +} // end class EncodeSQL diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/FrozenProfileObject.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/FrozenProfileObject.java new file mode 100644 index 0000000..bca3aaf --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/FrozenProfileObject.java @@ -0,0 +1,280 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.*; +import com.silverwrist.dynamo.HTMLTagSet; +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class FrozenProfileObject +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final String NAMESPACE = Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE; + + private static final Short DEFAULT_WORDWRAP = new Short((short)0); + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private ProfileObject m_profile; // backreference + private boolean m_rewrap_lines; // re-word-wrap lines? + private boolean m_process_angles; // process angle-bracketed strings? + private boolean m_process_parens; // process parenthesized strings? + private boolean m_process_brackets; // process bracketed strings? + private boolean m_process_braces; // process braced strings? + private boolean m_discard_html_tags; // discard all HTML tags? + private boolean m_discard_rejected_html; // discard HTML tags that are rejected? + private boolean m_discard_html_comments; // discard HTML comments? + private boolean m_discard_xml_constructs; // discard XML constructs (namespaced tags)? + private short m_word_wrap_length; // word wrap length + private HTMLOutputFilter[] m_output_filters; // the output filters + private HTMLOutputFilter[] m_raw_output_filters; // the raw output filters + private HTMLRewriter[] m_string_rewriters; // the string rewriters + private HTMLRewriter[] m_word_rewriters; // the word rewriters + private HTMLRewriter[] m_tag_rewriters; // the tag rewriters + private HTMLRewriter[] m_paren_rewriters; // the parenthesis rewriters + private HTMLRewriter[] m_bracket_rewriters; // the bracket rewriters + private HTMLRewriter[] m_brace_rewriters; // the brace rewriters + private BitSet m_allowed_tag_set; // the allowed tag set + private String m_openers; // the set of recognized "opener" characters + private Hashtable m_attrs_cache = new Hashtable(); // cached attributes from the underlying profile + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + FrozenProfileObject(ProfileObject prof) throws DatabaseException + { + m_profile = prof; + m_rewrap_lines = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"rewrap.lines",Boolean.FALSE))).booleanValue(); + m_process_angles = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"process.angles",Boolean.TRUE))).booleanValue(); + m_process_parens = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"process.parens",Boolean.TRUE))).booleanValue(); + m_process_brackets = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"process.brackets",Boolean.FALSE))).booleanValue(); + m_process_braces = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"process.braces",Boolean.FALSE))).booleanValue(); + m_discard_html_tags = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"discard.html",Boolean.FALSE))).booleanValue(); + m_discard_rejected_html = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"discard.html.rejected", + Boolean.FALSE))).booleanValue(); + m_discard_html_comments = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"discard.html.comments", + Boolean.FALSE))).booleanValue(); + m_discard_xml_constructs = + ((Boolean)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"discard.xml",Boolean.FALSE))).booleanValue(); + m_word_wrap_length = + ((Short)(PropertyUtils.getPropertyDefault(prof,NAMESPACE,"word.wrap",DEFAULT_WORDWRAP))).shortValue(); + if (m_word_wrap_length<0) + m_word_wrap_length = 0; + m_output_filters = prof.getOutputFilters(); + m_raw_output_filters = prof.getRawOutputFilters(); + m_string_rewriters = prof.getStringRewriters(); + m_word_rewriters = prof.getWordRewriters(); + m_tag_rewriters = prof.getTagRewriters(); + m_paren_rewriters = prof.getParenRewriters(); + m_bracket_rewriters = prof.getBracketRewriters(); + m_brace_rewriters = prof.getBraceRewriters(); + + // Compute the allowed tag set. + Set set1 = prof.getAllowedTagSet(); + m_allowed_tag_set = new BitSet(HTMLTagSet._LAST.getValue()); + Iterator it = set1.iterator(); + while (it.hasNext()) + { // convert the set of objects into a set of bits + HTMLTagSet ts = (HTMLTagSet)(it.next()); + m_allowed_tag_set.set(ts.getValue()-1); + + } // end while + + // Construct the string full of "opener" characters. + StringBuffer buf = new StringBuffer(4); + if (m_process_angles) + buf.append('<'); + if (m_process_parens) + buf.append('('); + if (m_process_brackets) + buf.append('['); + if (m_process_braces) + buf.append('{'); + m_openers = buf.toString(); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + boolean getRewrapLines() + { + return m_rewrap_lines; + + } // end getRewrapLines + + boolean getProcessAngles() + { + return m_process_angles; + + } // end getProcessAngles + + boolean getProcessParens() + { + return m_process_parens; + + } // end getProcessParens + + boolean getProcessBrackets() + { + return m_process_brackets; + + } // end getProcessBrackets + + boolean getProcessBraces() + { + return m_process_braces; + + } // end getProcessBraces + + boolean getDiscardHTMLTags() + { + return m_discard_html_tags; + + } // end getDiscardHTMLTags + + boolean getDiscardRejectedHTML() + { + return m_discard_rejected_html; + + } // end getDiscardRejectedHTML + + boolean getDiscardHTMLComments() + { + return m_discard_html_comments; + + } // end getDiscardHTMLComments + + boolean getDiscardXMLConstructs() + { + return m_discard_xml_constructs; + + } // end getDiscardXMLConstructs + + short getWordWrapLength() + { + return m_word_wrap_length; + + } // end getWordWrapLength + + HTMLOutputFilter[] getOutputFilters() + { + return m_output_filters; + + } // end getOutputFilters + + HTMLOutputFilter[] getRawOutputFilters() + { + return m_raw_output_filters; + + } // end getOutputFilters + + HTMLRewriter[] getStringRewriters() + { + return m_string_rewriters; + + } // end getStringRewriters + + HTMLRewriter[] getWordRewriters() + { + return m_word_rewriters; + + } // end getWordRewriters + + HTMLRewriter[] getTagRewriters() + { + return m_tag_rewriters; + + } // end getTagRewriters + + HTMLRewriter[] getParenRewriters() + { + return m_paren_rewriters; + + } // end getParenRewriters + + HTMLRewriter[] getBracketRewriters() + { + return m_bracket_rewriters; + + } // end getBracketRewriters + + HTMLRewriter[] getBraceRewriters() + { + return m_brace_rewriters; + + } // end getBraceRewriters + + BitSet getAllowedTagSet() + { + return m_allowed_tag_set; + + } // end getAllowedTagSet + + String getOpeners() + { + return m_openers; + + } // end getOpeners + + boolean isAllowed(HTMLTagSet ts) + { + return m_allowed_tag_set.get(ts.getValue()-1); + + } // end isAllowed + + String getAttribute(String namespace, String name) + { + QualifiedNameKey key = new QualifiedNameKey(namespace,name); + String rc = (String)(m_attrs_cache.get(key)); + if (rc!=null) + return rc; + + Object tmp = PropertyUtils.getPropertyNoErr(m_profile,namespace,name); + if (tmp==null) + return null; + + rc = tmp.toString(); + m_attrs_cache.put(key,rc); + return rc; + + } // end getAttribute + +} // end class FrozenProfileObject diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerManager.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerManager.java new file mode 100644 index 0000000..e01af79 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerManager.java @@ -0,0 +1,224 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.*; +import org.apache.commons.collections.*; +import org.apache.log4j.Logger; +import org.w3c.dom.*; +import com.silverwrist.util.xml.*; +import com.silverwrist.dynamo.db.NamespaceCache; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +public class HTMLCheckerManager + implements NamedObject, ComponentInitialize, ComponentShutdown, HTMLCheckerService, HTMLCheckerConfigRegister +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static Logger logger = Logger.getLogger(HTMLCheckerManager.class); + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private String m_name; // name of this object + private ProfileOps m_ops; // profile operations + private NamespaceCache m_ns_cache; // namespace cache object + private ComponentShutdown m_hook_rt; // hook runtime services + private ComponentShutdown m_hook_init; // hook initialization services + private Vector m_configurators; // registered configurators + private ReferenceMap m_profiles; // profile map + private ReferenceMap m_frozen_profiles; // frozen profile map + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + public HTMLCheckerManager() + { + m_configurators = new Vector(); + m_profiles = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT); + m_frozen_profiles = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT); + m_configurators.add(new EncodeHTML()); + m_configurators.add(new EncodeSQL()); + m_configurators.add(new RewriteEMailAddresses()); + m_configurators.add(new RewriteURLs()); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface NamedObject + *-------------------------------------------------------------------------------- + */ + + public String getName() + { + return m_name; + + } // end getName + + /*-------------------------------------------------------------------------------- + * Implementations from interface ComponentInitialize + *-------------------------------------------------------------------------------- + */ + + /** + * Initialize the component. + * + * @param config_root Pointer to the section of the Dynamo XML configuration file that configures this + * particular component. This is to be considered "read-only" by the component. + * @param services An implementation of {@link com.silverwrist.dynamo.iface.ServiceProvider ServiceProvider} + * which provides initialization services to the component. This will include an implementation + * of {@link com.silverwrist.dynamo.iface.ObjectProvider ObjectProvider} which may be used to + * get information about other objects previously initialized by the application. + * @exception com.silverwrist.dynamo.except.ConfigException If an error is encountered in the component + * configuration. + */ + public void initialize(Element config_root, ServiceProvider services) throws ConfigException + { + logger.info("HTMLCheckerManager initializing"); + XMLLoader loader = XMLLoader.get(); + String conn_name = null; + String nscache_name = null; + try + { // verify the right node name + loader.verifyNodeName(config_root,"object"); + + // get the object's name + m_name = loader.getAttribute(config_root,"name"); + + // get the database configuration connection + DOMElementHelper config_root_h = new DOMElementHelper(config_root); + Element elt = loader.getSubElement(config_root_h,"database"); + conn_name = loader.getAttribute(elt,"connection"); + nscache_name = loader.getAttribute(elt,"namespaces"); + + } // end try + catch (XMLLoadException e) + { // error loading XML config data + throw new ConfigException(e); + + } // end catch + + // Get the database connection pool and namespace cache. + DBConnectionPool pool = GetObjectUtils.getDatabaseConnection(services,conn_name); + m_ns_cache = + (NamespaceCache)(GetObjectUtils.getDynamoComponent(services,NamespaceCache.class,nscache_name)); + + // Get the database operations object. + m_ops = ProfileOps.get(pool); + + // Register ourselves with the runtime services. + SingletonServiceProvider ssp = new SingletonServiceProvider("HTMLCheckerManager",HTMLCheckerService.class,this); + HookServiceProviders hooker = (HookServiceProviders)(services.queryService(HookServiceProviders.class)); + m_hook_rt = hooker.hookRuntimeServiceProvider(ssp); + + // Register ourselves with the init services. + ssp = new SingletonServiceProvider("HTMLCheckerManager",HTMLCheckerConfigRegister.class,this); + m_hook_init = hooker.hookInitServiceProvider(ssp); + + } // end initialize + + /*-------------------------------------------------------------------------------- + * Implementations from interface ComponentShutdown + *-------------------------------------------------------------------------------- + */ + + public void shutdown() + { + m_hook_rt.shutdown(); + m_hook_rt = null; + m_hook_init.shutdown(); + m_hook_init = null; + m_ns_cache = null; + m_ops.dispose(); + m_ops = null; + m_frozen_profiles.clear(); + m_profiles.clear(); + m_configurators.clear(); + + } // end shutdown + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerService + *-------------------------------------------------------------------------------- + */ + + public HTMLChecker createHTMLChecker(String profile_namespace, String profile_name) throws DatabaseException + { + QualifiedNameKey key = new QualifiedNameKey(profile_namespace,profile_name); + + FrozenProfileObject p = null; + synchronized (this) + { // retrieve profile from the internal cache + p = (FrozenProfileObject)(m_frozen_profiles.get(key)); + if (p==null) + { // OK, look up the profile object + ProfileObject profile = (ProfileObject)(m_profiles.get(key)); + if (profile==null) + { // get the index of the profile from the database + int prof_ndx = m_ops.getProfileIndex(m_ns_cache.namespaceNameToId(profile_namespace),profile_name); + + // create the profile object + profile = new ProfileObject(m_ops,m_ns_cache,prof_ndx); + + // Now we have to let the configurator objects have their way with it. + Iterator it = m_configurators.iterator(); + while (it.hasNext()) + { // run each configurator in turn + HTMLCheckerConfigurator conf = (HTMLCheckerConfigurator)(it.next()); + conf.configure(profile); + + } // end while + + m_profiles.put(key,profile); + + } // end if (need to get profile) + + // Freeze the profile. + p = new FrozenProfileObject(profile); + m_frozen_profiles.put(key,p); + + } // end if + + } // end synchronized block + + return new CheckerObject(p); + + } // end createHTMLChecker + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerConfigRegister + *-------------------------------------------------------------------------------- + */ + + public ComponentShutdown registerConfigurator(HTMLCheckerConfigurator cfg) + { + m_configurators.add(cfg); + return new ShutdownVectorRemove(m_configurators,cfg); + + } // end registerConfigurator + +} // end class HTMLCheckerManager diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerMessages.properties b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerMessages.properties new file mode 100644 index 0000000..d81d2c0 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/HTMLCheckerMessages.properties @@ -0,0 +1,20 @@ +# 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 . +# +# 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 , +# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +# +# Contributor(s): +# --------------------------------------------------------------------------------- +# This file has been localized for the en_US locale +no.profile=The specified profile was not found. +property.serialize=The value of property "{0}" could not be serialized. +property.deserialize=The value of property "{0}" could not be deserialized. diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/MarkupData.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/MarkupData.java new file mode 100644 index 0000000..b586cfe --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/MarkupData.java @@ -0,0 +1,96 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +public final class MarkupData +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private String m_prefix; + private String m_opentag; + private String m_body; + private String m_closetag; + private String m_suffix; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + public MarkupData(String prefix, String opentag, String body, String closetag, String suffix) + { + m_prefix = prefix; + m_opentag = opentag; + m_body = body; + m_closetag = closetag; + m_suffix = suffix; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Public getters + *-------------------------------------------------------------------------------- + */ + + public String getPrefix() + { + return m_prefix; + + } // end getPrefix + + public String getOpenTag() + { + return m_opentag; + + } // end getOpenTag + + public String getBody() + { + return m_body; + + } // end getBody + + public String getCloseTag() + { + return m_closetag; + + } // end getCloseTag + + public String getSuffix() + { + return m_suffix; + + } // end getSuffix + + public int getTotalLength() + { + int rc = 0; + if (m_prefix!=null) + rc += m_prefix.length(); + if (m_body!=null) + rc += m_body.length(); + if (m_suffix!=null) + rc += m_suffix.length(); + return rc; + + } // end getTotalLength + +} // end class MarkupData diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileObject.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileObject.java new file mode 100644 index 0000000..a656230 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileObject.java @@ -0,0 +1,244 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.*; +import org.apache.commons.collections.*; +import com.silverwrist.dynamo.db.NamespaceCache; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class ProfileObject implements HTMLCheckerProfile +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final HTMLOutputFilter[] OF_NULL = new HTMLOutputFilter[0]; + private static final HTMLRewriter[] R_NULL = new HTMLRewriter[0]; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private ProfileOps m_ops; // database operations object + private NamespaceCache m_ns_cache; // namespace cache object + private int m_index; // index of this profile + private ReferenceMap m_properties; // property cache + private Vector m_output_filters = null; // output filters + private Vector m_raw_output_filters = null; // raw output filters + private Vector m_string_rewriters = null; // string rewriters + private Vector m_word_rewriters = null; // word rewriters + private Vector m_tag_rewriters = null; // tag rewriters + private Vector m_paren_rewriters = null; // parenthesis rewriters + private Vector m_bracket_rewriters = null; // bracket rewriters + private Vector m_brace_rewriters = null; // brace rewriters + private Set m_allowed_tag_set = null; // allowed tag set + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + ProfileObject(ProfileOps ops, NamespaceCache nscache, int ndx) + { + m_ops = ops; + m_ns_cache = nscache; + m_index = ndx; + m_properties = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface ObjectProvider + *-------------------------------------------------------------------------------- + */ + + /** + * Retrieves an object from this ObjectProvider. + * + * @param namespace The namespace to interpret the name relative to. + * @param name The name of the object to be retrieved. + * @return The object reference specified. + */ + public Object getObject(String namespace, String name) + { + try + { // convert the namespace name to an ID here + PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name); + Object rc = null; + synchronized (this) + { // start by looking in the properties map + rc = m_properties.get(key); + if (rc==null) + { // no use - need to try the database + rc = m_ops.getProperty(m_index,key); + if (rc!=null) + m_properties.put(key,rc); + + } // end if + + } // end synchronized block + + if (rc==null) + throw new NoSuchObjectException(this.toString(),namespace,name); + return rc; + + } // end try + catch (DatabaseException e) + { // translate into our NoSuchObjectException but retain the DatabaseException + throw new NoSuchObjectException(this.toString(),namespace,name,e); + + } // end catch + + } // end getObject + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerProfile + *-------------------------------------------------------------------------------- + */ + + public void addOutputFilter(HTMLOutputFilter filter) + { + if (m_output_filters==null) + m_output_filters = new Vector(); + m_output_filters.add(filter); + + } // end addOutputFilter + + public void addRawOutputFilter(HTMLOutputFilter filter) + { + if (m_raw_output_filters==null) + m_raw_output_filters = new Vector(); + m_raw_output_filters.add(filter); + + } // end addRawOutputFilter + + public void addStringRewriter(HTMLRewriter rewriter) + { + if (m_string_rewriters==null) + m_string_rewriters = new Vector(); + m_string_rewriters.add(rewriter); + + } // end addStringRewriter + + public void addWordRewriter(HTMLRewriter rewriter) + { + if (m_word_rewriters==null) + m_word_rewriters = new Vector(); + m_word_rewriters.add(rewriter); + + } // end addWordRewriter + + public void addTagRewriter(HTMLRewriter rewriter) + { + if (m_tag_rewriters==null) + m_tag_rewriters = new Vector(); + m_tag_rewriters.add(rewriter); + + } // end addTagRewriter + + public void addParenRewriter(HTMLRewriter rewriter) + { + if (m_paren_rewriters==null) + m_paren_rewriters = new Vector(); + m_paren_rewriters.add(rewriter); + + } // end addParenRewriter + + public void addBracketRewriter(HTMLRewriter rewriter) + { + if (m_bracket_rewriters==null) + m_bracket_rewriters = new Vector(); + m_bracket_rewriters.add(rewriter); + + } // end addBracketRewriter + + public void addBraceRewriter(HTMLRewriter rewriter) + { + if (m_brace_rewriters==null) + m_brace_rewriters = new Vector(); + m_brace_rewriters.add(rewriter); + + } // end addBraceRewriter + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + HTMLOutputFilter[] getOutputFilters() + { + return (m_output_filters==null) ? OF_NULL : (HTMLOutputFilter[])(m_output_filters.toArray(OF_NULL)); + + } // end getOutputFilters + + HTMLOutputFilter[] getRawOutputFilters() + { + return (m_raw_output_filters==null) ? OF_NULL : (HTMLOutputFilter[])(m_raw_output_filters.toArray(OF_NULL)); + + } // end getOutputFilters + + HTMLRewriter[] getStringRewriters() + { + return (m_string_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_string_rewriters.toArray(R_NULL)); + + } // end getStringRewriters + + HTMLRewriter[] getWordRewriters() + { + return (m_word_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_word_rewriters.toArray(R_NULL)); + + } // end getWordRewriters + + HTMLRewriter[] getTagRewriters() + { + return (m_tag_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_tag_rewriters.toArray(R_NULL)); + + } // end getTagRewriters + + HTMLRewriter[] getParenRewriters() + { + return (m_paren_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_paren_rewriters.toArray(R_NULL)); + + } // end getParenRewriters + + HTMLRewriter[] getBracketRewriters() + { + return (m_bracket_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_bracket_rewriters.toArray(R_NULL)); + + } // end getBracketRewriters + + HTMLRewriter[] getBraceRewriters() + { + return (m_brace_rewriters==null) ? R_NULL : (HTMLRewriter[])(m_brace_rewriters.toArray(R_NULL)); + + } // end getBraceRewriters + + Set getAllowedTagSet() throws DatabaseException + { + if (m_allowed_tag_set==null) + m_allowed_tag_set = m_ops.getAllowedTagSet(m_index); + return m_allowed_tag_set; + + } // end getAllowedTagSet + +} // end class ProfileObject diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps.java new file mode 100644 index 0000000..06b7981 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps.java @@ -0,0 +1,61 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.*; +import com.silverwrist.dynamo.db.OpsBase; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +abstract class ProfileOps extends OpsBase +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + protected ProfileOps(DBConnectionPool pool) + { + super(pool); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Abstract operations + *-------------------------------------------------------------------------------- + */ + + abstract int getProfileIndex(int nsid, String name) throws DatabaseException; + + abstract Object getProperty(int profid, PropertyKey key) throws DatabaseException; + + abstract Set getAllowedTagSet(int profid) throws DatabaseException; + + /*-------------------------------------------------------------------------------- + * External static operations + *-------------------------------------------------------------------------------- + */ + + static ProfileOps get(DBConnectionPool pool) throws ConfigException + { + return (ProfileOps)get(pool,ProfileOps.class.getClassLoader(),ProfileOps.class.getName() + "_","ProfileOps"); + + } // end get + +} // end class ProfileOps diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps_mysql.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps_mysql.java new file mode 100644 index 0000000..6c14870 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/ProfileOps_mysql.java @@ -0,0 +1,190 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.sql.*; +import java.util.*; +import com.silverwrist.util.*; +import com.silverwrist.dynamo.HTMLTagSet; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +public class ProfileOps_mysql extends ProfileOps +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private PropertySerializer m_psz; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + public ProfileOps_mysql(DBConnectionPool pool) + { + super(pool); + m_psz = (PropertySerializer)(pool.queryService(PropertySerializer.class)); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class OpsBase + *-------------------------------------------------------------------------------- + */ + + public void dispose() + { + m_psz = null; + super.dispose(); + + } // end dispose + + /*-------------------------------------------------------------------------------- + * Abstract implementations from class ProfileOps + *-------------------------------------------------------------------------------- + */ + + int getProfileIndex(int nsid, String name) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try + { // get a connection + conn = getConnection(); + + // prepare a statement to look up the profile index + stmt = conn.prepareStatement("SELECT profid FROM htmlprofiles WHERE nsid = ? AND name = ?;"); + stmt.setInt(1,nsid); + stmt.setString(2,name); + rs = stmt.executeQuery(); + if (rs.next()) + return rs.getInt(1); + throw new DatabaseException(ProfileOps_mysql.class,"HTMLCheckerMessages","no.profile"); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end getProfileIndex + + Object getProperty(int profid, PropertyKey key) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String rc_str = null; + try + { // get a connection + conn = getConnection(); + + // look up the property + stmt = conn.prepareStatement("SELECT prop_value FROM htmlprops WHERE profid = ? AND nsid = ? " + + "AND prop_name = ?;"); + stmt.setInt(1,profid); + stmt.setInt(2,key.getNamespaceID()); + stmt.setString(3,key.getName()); + rs = stmt.executeQuery(); + if (!(rs.next())) + return null; // property not found + + rc_str = rs.getString(1); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + // Deserialize the property value. + Object rc = m_psz.deserializeProperty(rc_str); + if (rc!=null) + return rc; + + // deserialization exception - throw it + DatabaseException de = new DatabaseException(ProfileOps_mysql.class,"HTMLCheckerMessages","property.deserialize"); + de.setParameter(0,key.getName()); + throw de; + + } // end getProperty + + Set getAllowedTagSet(int profid) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try + { // get a connection + conn = getConnection(); + + // create and execute the statement + stmt = conn.prepareStatement("SELECT tagset FROM htmltagsets WHERE profid = ?;"); + stmt.setInt(1,profid); + rs = stmt.executeQuery(); + + // prepare the return value + HashSet rc = new HashSet(); + while (rs.next()) + { // convert strings to enum values and add them + HTMLTagSet ts = HTMLTagSet.getEnum(rs.getString(1)); + if (ts!=null) + rc.add(ts); + + } // end while + + return rc; + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end getAllowedTagSet + +} // end class ProfileOps_mysql diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteEMailAddresses.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteEMailAddresses.java new file mode 100644 index 0000000..fdf8c30 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteEMailAddresses.java @@ -0,0 +1,123 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.regex.*; +import org.apache.log4j.Logger; +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class RewriteEMailAddresses implements HTMLCheckerConfigurator, HTMLRewriter +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static Logger logger = Logger.getLogger(RewriteEMailAddresses.class); + + private static final String DEFAULT_TARGET = "Wander"; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private Pattern m_email_pattern; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + RewriteEMailAddresses() + { + try + { // pre-compile all our regex patterns + m_email_pattern = Pattern.compile("^[A-Za-z0-9!#$%*+-/=?^_`{|}~.]+@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$"); + + } // end try + catch (PatternSyntaxException pe) + { // log an error, all we can do + logger.fatal("Pattern compilation error in RewriteEMailAddresses",pe); + + } // end catch + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerConfigurator + *-------------------------------------------------------------------------------- + */ + + public void configure(HTMLCheckerProfile profile) + { + boolean enable = + ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.email.string",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addStringRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.email.tag",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addTagRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.email.paren",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addParenRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.email.bracket",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addBracketRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.email.brace",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addBraceRewriter(this); + + } // end configure + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLRewriter + *-------------------------------------------------------------------------------- + */ + + public QualifiedNameKey getName() + { + return null; + + } // end getName + + public MarkupData rewrite(String data, String prefix, String suffix, HTMLRewriterSite site) + { + if (!(m_email_pattern.matcher(data).matches())) + return null; + + // build the tag (the gnarliest part) + StringBuffer buf = new StringBuffer(""); + + return new MarkupData(prefix,buf.toString(),data,"",suffix); + + } // end rewrite + +} // end class RewriteEMailAddresses diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteURLs.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteURLs.java new file mode 100644 index 0000000..e1d9142 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/RewriteURLs.java @@ -0,0 +1,227 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck; + +import java.util.*; +import java.util.regex.*; +import org.apache.log4j.Logger; +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; + +class RewriteURLs implements HTMLCheckerConfigurator, HTMLRewriter +{ + /*-------------------------------------------------------------------------------- + * Internal class that contains matching information + *-------------------------------------------------------------------------------- + */ + + private static class Match + { + /*==================================================================== + * Attributes + *==================================================================== + */ + + private Pattern m_pat; + private String m_prefix; + + /*==================================================================== + * Constructors + *==================================================================== + */ + + Match(String pattern) throws PatternSyntaxException + { + m_pat = Pattern.compile(pattern); + m_prefix = null; + + } // end constructor + + Match(String pattern, String prefix) throws PatternSyntaxException + { + m_pat = Pattern.compile(pattern); + m_prefix = prefix; + + } // end constructor + + /*==================================================================== + * External operations + *==================================================================== + */ + + boolean match(String input) + { + return m_pat.matcher(input).matches(); + + } // end match + + String prefixate(String input) + { + if (m_prefix==null) + return input; + else + return m_prefix + input; + + } // end prefixate + + } // end class Match + + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static Logger logger = Logger.getLogger(RewriteURLs.class); + + private static final String DEFAULT_TARGET = "Wander"; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private List m_matchers; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + RewriteURLs() + { + ArrayList l = new ArrayList(); + try + { // pre-compile all our regex patterns + // recognize: http://[:]... + l.add(new Match("^http://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?(/.*)?")); + + // recognize: ftp://[:]... + l.add(new Match("^ftp://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?(/.*)?")); + + // recognize: gopher://[:]... + l.add(new Match("^gopher://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?(/.*)?")); + + // recognize: mailto: + l.add(new Match("^mailto:[A-Za-z0-9!#$%*+-/=?^_`{|}~.]+@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*")); + + // recognize: news: + l.add(new Match("^news:[A-Za-z0-9-_]+(\\.[A-Za-z0-9-_]+)*$")); + + // recognize: news: + l.add(new Match("^news:.*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$")); + + // recognize: nntp://[:]//
+ l.add(new + Match("^nntp://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?/[A-Za-z0-9-_]+(\\.[A-Za-z0-9-_]+)*/[0-9]+$")); + + // recognize: telnet://[:] + l.add(new Match("^telnet://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?$")); + + // recognize: tn3270://[:] + l.add(new Match("^tn3270://[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(:[0-9]+)?$")); + + // recognize "www.whatever" and tack http:// onto the front + l.add(new Match("^www\\.[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(/.*)?","http://")); + + // recognize "ftp.whatever" and tack ftp:// onto the front + l.add(new Match("^ftp\\.[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(/.*)?","ftp://")); + + // recognize "gopher.whatever" and tack gopher:// onto the front + l.add(new Match("^gopher\\.[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(/.*)?","gopher://")); + + } // end try + catch (PatternSyntaxException pe) + { // log an error, all we can do + logger.fatal("Pattern compilation error in RewriteEMailAddresses",pe); + + } // end catch + + l.trimToSize(); + m_matchers = Collections.unmodifiableList(l); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLCheckerConfigurator + *-------------------------------------------------------------------------------- + */ + + public void configure(HTMLCheckerProfile profile) + { + boolean enable = + ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.URL.string",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addStringRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.URL.tag",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addTagRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.URL.paren",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addParenRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.URL.bracket",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addBracketRewriter(this); + enable = ((Boolean)(PropertyUtils.getPropertyDefault(profile,Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE, + "rewrite.URL.brace",Boolean.FALSE))).booleanValue(); + if (enable) + profile.addBraceRewriter(this); + + } // end configure + + /*-------------------------------------------------------------------------------- + * Implementations from interface HTMLRewriter + *-------------------------------------------------------------------------------- + */ + + public QualifiedNameKey getName() + { + return null; + + } // end getName + + public MarkupData rewrite(String data, String prefix, String suffix, HTMLRewriterSite site) + { + Iterator it = m_matchers.iterator(); + while (it.hasNext()) + { // look for a matching element + Match x = (Match)(it.next()); + if (x.match(data)) + { // found it! build the tag for the markup + StringBuffer buf = new StringBuffer(""); + + return new MarkupData(prefix,buf.toString(),data,"",suffix); + + } // end if + + } // end while + + return null; // punt + + } // end rewrite + +} // end class RewriteURLs diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/A_Tag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/A_Tag.java new file mode 100644 index 0000000..05b9d4b --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/A_Tag.java @@ -0,0 +1,87 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import java.util.regex.*; +import org.apache.log4j.Logger; +import com.silverwrist.dynamo.HTMLTagSet; +import com.silverwrist.dynamo.Namespaces; + +class A_Tag extends BalancedTag +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static Logger logger = Logger.getLogger(A_Tag.class); + + private static final String DEFAULT_TARGET = "Wander"; + + private static Pattern TARGET_PATTERN; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + A_Tag() + { + super("A",false,HTMLTagSet.ANCHOR); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class HTMLTag + *-------------------------------------------------------------------------------- + */ + + public String rewrite(String tag_data, boolean is_closing, HTMLTagSite site) + { + if (is_closing) + return tag_data; + if (TARGET_PATTERN.matcher(tag_data).matches()) + return tag_data; + String target_window = site.getAttribute(Namespaces.HTMLCHECKER_PROPERTIES_NAMESPACE,"default.A.target"); + if (target_window==null) + target_window = DEFAULT_TARGET; + return tag_data + " target=\"" + target_window + "\""; + + } // end rewrite + + /*-------------------------------------------------------------------------------- + * Static initializer + *-------------------------------------------------------------------------------- + */ + + static + { + try + { // pre-compile all our regex patterns + TARGET_PATTERN = Pattern.compile("\\s+target\\s*=\\s*([\"']?)\\w+\\1(?:\\s+.*)?$",Pattern.CASE_INSENSITIVE); + + } // end try + catch (PatternSyntaxException pe) + { // log an error, all we can do + logger.fatal("Pattern compilation error in A_Tag",pe); + + } // end catch + + } // end static initializer + +} // end class A_Tag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/BalancedTag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/BalancedTag.java new file mode 100644 index 0000000..852825c --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/BalancedTag.java @@ -0,0 +1,46 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +class BalancedTag extends OpenCloseTag +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + BalancedTag(String tagname, boolean linebreak, HTMLTagSet set) + { + super(tagname,linebreak,set); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final boolean balanceTags() + { + return true; + + } // end balanceTags + +} // end class BalancedTag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTag.java new file mode 100644 index 0000000..0cde11a --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTag.java @@ -0,0 +1,119 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +public class HTMLTag +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private String m_tagname; + private boolean m_linebreak; + private HTMLTagSet m_set; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + HTMLTag(String tagname, boolean linebreak, HTMLTagSet set) + { + m_tagname = tagname; + m_linebreak = linebreak; + m_set = set; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class Object + *-------------------------------------------------------------------------------- + */ + + public boolean equals(Object obj) + { + if (!(obj instanceof HTMLTag)) + return false; + HTMLTag other = (HTMLTag)obj; + return m_tagname.equals(other.m_tagname); + + } // end equals + + public int hashCode() + { + return m_tagname.hashCode(); + + } // end hashCode + + public String toString() + { + return "<" + m_tagname + ">"; + + } // end toString + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public String getTagName() + { + return m_tagname; + + } // end getTagName + + public boolean allowClose() + { + return false; + + } // end allowClose + + public boolean balanceTags() + { + return false; + + } // end balanceTags + + public boolean causeLineBreak(boolean is_closing) + { + return m_linebreak; + + } // end causeLineBreak + + public String makeClosingTag() + { + throw new RuntimeException("cannot make closing tags of basic HTMLTag"); + + } // end makeClosingTag + + public HTMLTagSet getTagSet() + { + return m_set; + + } // end getTagSet + + public String rewrite(String tag_data, boolean is_closing, HTMLTagSite site) + { + return tag_data; + + } // end rewrite + +} // end class HTMLTag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTagSite.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTagSite.java new file mode 100644 index 0000000..1f84caf --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/HTMLTagSite.java @@ -0,0 +1,28 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.iface.ObjectProvider; + +public interface HTMLTagSite extends ObjectProvider +{ + public String getAttribute(String namespace, String name); + + public void controlMessage(String message, Object data); + +} // end interface HTMLTagSite diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/ListElementTag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/ListElementTag.java new file mode 100644 index 0000000..de5b661 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/ListElementTag.java @@ -0,0 +1,46 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +class ListElementTag extends OpenCloseTag +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + ListElementTag(String tagname, HTMLTagSet set) + { + super(tagname,true,set); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public boolean causeLineBreak(boolean is_closing) + { + return !is_closing; + + } // end causeLineBreak + +} // end class ListElementTag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/NOBR_Tag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/NOBR_Tag.java new file mode 100644 index 0000000..5870c10 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/NOBR_Tag.java @@ -0,0 +1,50 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +class NOBR_Tag extends BalancedTag +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + NOBR_Tag() + { + super("NOBR",false,HTMLTagSet.BLOCK); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class HTMLTag + *-------------------------------------------------------------------------------- + */ + + public String rewrite(String tag_data, boolean is_closing, HTMLTagSite site) + { + if (is_closing) + site.controlMessage("/NOBR",null); + else + site.controlMessage("NOBR",null); + return super.rewrite(tag_data,is_closing,site); + + } // end rewrite + +} // end class NOBR_Tag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/OpenCloseTag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/OpenCloseTag.java new file mode 100644 index 0000000..fef9f6b --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/OpenCloseTag.java @@ -0,0 +1,52 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +class OpenCloseTag extends HTMLTag +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + OpenCloseTag(String tagname, boolean linebreak, HTMLTagSet set) + { + super(tagname,linebreak,set); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final boolean allowClose() + { + return true; + + } // end allowClose + + public final String makeClosingTag() + { + return ""; + + } // end makeClosingTag + +} // end class OpenCloseTag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/TagsList.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/TagsList.java new file mode 100644 index 0000000..fa911f8 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/TagsList.java @@ -0,0 +1,215 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import java.util.*; +import com.silverwrist.dynamo.HTMLTagSet; + +public class TagsList +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static TagsList _self = null; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private HashMap m_tagname_to_object = new HashMap(); + private int m_tag_maxlen = 0; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + private TagsList() + { + install(new HTMLTag("!DOCTYPE",false,HTMLTagSet.DOCUMENT)); + install(new HTMLTag("%",false,HTMLTagSet.SERVER)); + install(new HTMLTag("%!",false,HTMLTagSet.SERVER)); + install(new HTMLTag("%=",false,HTMLTagSet.SERVER)); + install(new HTMLTag("?",false,HTMLTagSet.SERVER)); + install(new HTMLTag("?=",false,HTMLTagSet.SERVER)); + install(new HTMLTag("?PHP",false,HTMLTagSet.SERVER)); + install(new A_Tag()); + install(new BalancedTag("ABBR",false,HTMLTagSet.INLINE)); + install(new BalancedTag("ACRONYM",false,HTMLTagSet.INLINE)); + install(new BalancedTag("ADDRESS",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("APPLET",false,HTMLTagSet.ACTIVECONTENT)); + install(new HTMLTag("AREA",false,HTMLTagSet.IMAGEMAP)); + install(new BalancedTag("B",false,HTMLTagSet.INLINE)); + install(new HTMLTag("BASE",false,HTMLTagSet.DOCUMENT)); + install(new HTMLTag("BASEFONT",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("BDO",false,HTMLTagSet.INLINE)); + install(new BalancedTag("BEAN",false,HTMLTagSet.JAVASERVER)); + install(new HTMLTag("BGSOUND",false,HTMLTagSet.MSFT_DOCUMENT)); + install(new BalancedTag("BIG",false,HTMLTagSet.INLINE)); + install(new BalancedTag("BLINK",false,HTMLTagSet.NSCP_INLINE)); + install(new BalancedTag("BLOCKQUOTE",true,HTMLTagSet.BLOCK)); + install(new OpenCloseTag("BODY",true,HTMLTagSet.DOCUMENT)); + install(new HTMLTag("BR",true,HTMLTagSet.BLOCK)); + install(new OpenCloseTag("BUTTON",false,HTMLTagSet.FORMS)); + install(new BalancedTag("CAPTION",true,HTMLTagSet.TABLES)); + install(new BalancedTag("CENTER",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("CITE",false,HTMLTagSet.INLINE)); + install(new BalancedTag("CODE",false,HTMLTagSet.INLINE)); + install(new HTMLTag("COL",true,HTMLTagSet.TABLES)); + install(new OpenCloseTag("COLGROUP",true,HTMLTagSet.TABLES)); + install(new BalancedTag("COMMENT",false,HTMLTagSet.MSFT_INLINE)); + install(new ListElementTag("DD",HTMLTagSet.BLOCK)); + install(new BalancedTag("DEL",false,HTMLTagSet.CHANGE)); + install(new BalancedTag("DFN",false,HTMLTagSet.INLINE)); + install(new BalancedTag("DIR",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("DIV",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("DL",true,HTMLTagSet.BLOCK)); + install(new ListElementTag("DT",HTMLTagSet.BLOCK)); + install(new BalancedTag("EM",false,HTMLTagSet.INLINE)); + install(new BalancedTag("EMBED",false,HTMLTagSet.ACTIVECONTENT)); + install(new BalancedTag("FIELDSET",false,HTMLTagSet.FORMS)); + install(new BalancedTag("FONT",false,HTMLTagSet.FONT)); + install(new BalancedTag("FORM",false,HTMLTagSet.FORMS)); + install(new HTMLTag("FRAME",true,HTMLTagSet.FRAMES)); + install(new BalancedTag("FRAMESET",false,HTMLTagSet.FRAMES)); + install(new BalancedTag("H1",true,HTMLTagSet.FONT)); + install(new BalancedTag("H2",true,HTMLTagSet.FONT)); + install(new BalancedTag("H3",true,HTMLTagSet.FONT)); + install(new BalancedTag("H4",true,HTMLTagSet.FONT)); + install(new BalancedTag("H5",true,HTMLTagSet.FONT)); + install(new BalancedTag("H6",true,HTMLTagSet.FONT)); + install(new OpenCloseTag("HEAD",false,HTMLTagSet.DOCUMENT)); + install(new HTMLTag("HR",true,HTMLTagSet.BLOCK)); + install(new OpenCloseTag("HTML",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("I",false,HTMLTagSet.INLINE)); + install(new BalancedTag("IFRAME",true,HTMLTagSet.FRAMES)); + install(new BalancedTag("ILAYER",true,HTMLTagSet.NSCP_LAYERS)); + install(new HTMLTag("IMG",false,HTMLTagSet.IMAGES)); + install(new HTMLTag("INPUT",false,HTMLTagSet.FORMS)); + install(new BalancedTag("INS",false,HTMLTagSet.CHANGE)); + install(new HTMLTag("ISINDEX",false,HTMLTagSet.FORMS)); + install(new BalancedTag("KBD",false,HTMLTagSet.INLINE)); + install(new HTMLTag("KEYGEN",false,HTMLTagSet.NSCP_FORMS)); + install(new BalancedTag("LABEL",false,HTMLTagSet.FORMS)); + install(new BalancedTag("LAYER",true,HTMLTagSet.NSCP_LAYERS)); + install(new BalancedTag("LEGEND",false,HTMLTagSet.FORMS)); + install(new ListElementTag("LI",HTMLTagSet.BLOCK)); + install(new HTMLTag("LINK",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("LISTING",false,HTMLTagSet.MSFT_INLINE)); + install(new BalancedTag("MAP",false,HTMLTagSet.IMAGEMAP)); + install(new BalancedTag("MARQUEE",true,HTMLTagSet.MSFT_BLOCK)); + install(new BalancedTag("MENU",true,HTMLTagSet.BLOCK)); + install(new HTMLTag("META",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("MULTICOL",true,HTMLTagSet.NSCP_BLOCK)); + install(new NOBR_Tag()); + install(new BalancedTag("NOEMBED",false,HTMLTagSet.ACTIVECONTENT)); + install(new BalancedTag("NOFRAMES",false,HTMLTagSet.FRAMES)); + install(new BalancedTag("NOLAYER",false,HTMLTagSet.NSCP_LAYERS)); + install(new BalancedTag("NOSCRIPT",false,HTMLTagSet.ACTIVECONTENT)); + install(new BalancedTag("OBJECT",false,HTMLTagSet.ACTIVECONTENT)); + install(new BalancedTag("OL",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("OPTGROUP",false,HTMLTagSet.FORMS)); + install(new ListElementTag("OPTION",HTMLTagSet.FORMS)); + install(new OpenCloseTag("P",true,HTMLTagSet.BLOCK)); + install(new HTMLTag("PARAM",false,HTMLTagSet.ACTIVECONTENT)); + install(new HTMLTag("PLAINTEXT",false,HTMLTagSet.PREFORMAT)); + install(new BalancedTag("PRE",false,HTMLTagSet.PREFORMAT)); + install(new BalancedTag("Q",false,HTMLTagSet.INLINE)); + install(new HTMLTag("RT",false,HTMLTagSet.MSFT_ACTIVECONTENT)); + install(new BalancedTag("RUBY",false,HTMLTagSet.MSFT_ACTIVECONTENT)); + install(new BalancedTag("S",false,HTMLTagSet.INLINE)); + install(new BalancedTag("SAMP",false,HTMLTagSet.INLINE)); + install(new BalancedTag("SCRIPT",false,HTMLTagSet.ACTIVECONTENT)); + install(new BalancedTag("SELECT",false,HTMLTagSet.FORMS)); + install(new BalancedTag("SERVER",false,HTMLTagSet.NSCP_SERVER)); + install(new BalancedTag("SERVLET",false,HTMLTagSet.JAVASERVER)); + install(new BalancedTag("SMALL",false,HTMLTagSet.INLINE)); + install(new HTMLTag("SPACER",false,HTMLTagSet.NSCP_INLINE)); + install(new BalancedTag("SPAN",false,HTMLTagSet.INLINE)); + install(new BalancedTag("STRIKE",false,HTMLTagSet.INLINE)); + install(new BalancedTag("STRONG",false,HTMLTagSet.INLINE)); + install(new BalancedTag("STYLE",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("SUB",false,HTMLTagSet.INLINE)); + install(new BalancedTag("SUP",false,HTMLTagSet.INLINE)); + install(new BalancedTag("TABLE",true,HTMLTagSet.TABLES)); + install(new OpenCloseTag("TBODY",false,HTMLTagSet.TABLES)); + install(new BalancedTag("TD",true,HTMLTagSet.TABLES)); + install(new BalancedTag("TEXTAREA",true,HTMLTagSet.FORMS)); + install(new OpenCloseTag("TFOOT",false,HTMLTagSet.TABLES)); + install(new BalancedTag("TH",true,HTMLTagSet.TABLES)); + install(new OpenCloseTag("THEAD",false,HTMLTagSet.TABLES)); + install(new BalancedTag("TITLE",false,HTMLTagSet.DOCUMENT)); + install(new BalancedTag("TR",true,HTMLTagSet.TABLES)); + install(new BalancedTag("TT",false,HTMLTagSet.INLINE)); + install(new BalancedTag("U",false,HTMLTagSet.INLINE)); + install(new BalancedTag("UL",true,HTMLTagSet.BLOCK)); + install(new BalancedTag("VAR",false,HTMLTagSet.INLINE)); + install(new WBR_Tag()); + install(new BalancedTag("XML",false,HTMLTagSet.MSFT_ACTIVECONTENT)); + install(new BalancedTag("XMP",false,HTMLTagSet.NSCP_INLINE)); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private final void install(HTMLTag tag) + { + m_tagname_to_object.put(tag.getTagName(),tag); + int len = tag.getTagName().length(); + if (len>m_tag_maxlen) + m_tag_maxlen = len; + + } // end install + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public int getMaxTagLength() + { + return m_tag_maxlen; + + } // end getMaxTagLength + + public HTMLTag getTag(String name) + { + return (HTMLTag)(m_tagname_to_object.get(name.toUpperCase())); + + } // end getTag + + /*-------------------------------------------------------------------------------- + * External static operations + *-------------------------------------------------------------------------------- + */ + + public static synchronized TagsList get() + { + if (_self==null) + _self = new TagsList(); + return _self; + + } // end get + +} // end class TagsList diff --git a/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/WBR_Tag.java b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/WBR_Tag.java new file mode 100644 index 0000000..82197e3 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/htmlcheck/tags/WBR_Tag.java @@ -0,0 +1,47 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.htmlcheck.tags; + +import com.silverwrist.dynamo.HTMLTagSet; + +class WBR_Tag extends HTMLTag +{ + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + WBR_Tag() + { + super("WBR",false,HTMLTagSet.BLOCK); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class HTMLTag + *-------------------------------------------------------------------------------- + */ + + public String rewrite(String tag_data, boolean is_closing, HTMLTagSite site) + { + site.controlMessage("WBR",null); + return super.rewrite(tag_data,is_closing,site); + + } // end rewrite + +} // end class WBR_Tag diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLChecker.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLChecker.java new file mode 100644 index 0000000..bc5d9bb --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLChecker.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +import java.io.Reader; + +public interface HTMLChecker extends ObjectStore +{ + public void append(String str); + + public void append(Reader r); + + public void finish(); + + public void reset(); + + public String getValue(); + + public int getLength(); + + public int getLines(); + + public int getCounter(String namespace, String name); + +} // end interface HTMLChecker diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigRegister.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigRegister.java new file mode 100644 index 0000000..8cb039b --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigRegister.java @@ -0,0 +1,24 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +public interface HTMLCheckerConfigRegister +{ + public ComponentShutdown registerConfigurator(HTMLCheckerConfigurator cfg); + +} // end interface HTMLCheckerConfigRegister diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigurator.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigurator.java new file mode 100644 index 0000000..75bd0b0 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerConfigurator.java @@ -0,0 +1,24 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +public interface HTMLCheckerConfigurator +{ + public void configure(HTMLCheckerProfile profile); + +} // end interface HTMLCheckerConfigurator diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerProfile.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerProfile.java new file mode 100644 index 0000000..ce9afda --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerProfile.java @@ -0,0 +1,38 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +public interface HTMLCheckerProfile extends ObjectProvider +{ + public void addOutputFilter(HTMLOutputFilter filter); + + public void addRawOutputFilter(HTMLOutputFilter filter); + + public void addStringRewriter(HTMLRewriter rewriter); + + public void addWordRewriter(HTMLRewriter rewriter); + + public void addTagRewriter(HTMLRewriter rewriter); + + public void addParenRewriter(HTMLRewriter rewriter); + + public void addBracketRewriter(HTMLRewriter rewriter); + + public void addBraceRewriter(HTMLRewriter rewriter); + +} // end interface HTMLCheckerProfile diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerService.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerService.java new file mode 100644 index 0000000..b8af40d --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLCheckerService.java @@ -0,0 +1,26 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +import com.silverwrist.dynamo.except.DatabaseException; + +public interface HTMLCheckerService +{ + public HTMLChecker createHTMLChecker(String profile_namespace, String profile_name) throws DatabaseException; + +} // end interface HTMLCheckerService diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLOutputFilter.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLOutputFilter.java new file mode 100644 index 0000000..4e2e131 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLOutputFilter.java @@ -0,0 +1,28 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +public interface HTMLOutputFilter +{ + public boolean tryOutputCharacter(StringBuffer buf, char ch); + + public boolean matchCharacter(char ch); + + public int lengthNoMatch(String s); + +} // end interface HTMLOutputFilter diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriter.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriter.java new file mode 100644 index 0000000..317ec49 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriter.java @@ -0,0 +1,29 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +import com.silverwrist.dynamo.htmlcheck.MarkupData; +import com.silverwrist.dynamo.util.QualifiedNameKey; + +public interface HTMLRewriter +{ + public QualifiedNameKey getName(); + + public MarkupData rewrite(String data, String prefix, String suffix, HTMLRewriterSite site); + +} // end interface HTMLRewriter diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriterSite.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriterSite.java new file mode 100644 index 0000000..75d1cac --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/HTMLRewriterSite.java @@ -0,0 +1,24 @@ +/* + * 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 . + * + * 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 , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.dynamo.iface; + +public interface HTMLRewriterSite extends ObjectProvider +{ + public String getAttribute(String namespace, String name); + +} // end interface HTMLRewriterSite diff --git a/src/dynamo-framework/com/silverwrist/dynamo/util/PropertyUtils.java b/src/dynamo-framework/com/silverwrist/dynamo/util/PropertyUtils.java index ace1253..ace0620 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/util/PropertyUtils.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/util/PropertyUtils.java @@ -327,4 +327,19 @@ public class PropertyUtils } // end getPropertyNoErr + public static Object getPropertyDefault(ObjectProvider prov, String namespace, String name, Object def) + { + try + { // try to get it + return prov.getObject(namespace,name); + + } // end try + catch (NoSuchObjectException e) + { // we don't have the property - return the default value + return def; + + } // end catch + + } // end getPropertyNoErr + } // end class PropertyUtils