moved HTML Checker initialization and pooling to the GlobalSiteImpl - gradually

reducing the responsibilities of EnvEngine as well as the functions in
EngineBackend
This commit is contained in:
Eric J. Bowersox 2002-05-27 03:03:34 +00:00
parent 3ee3e4abeb
commit 0afe28588d
14 changed files with 648 additions and 221 deletions

View File

@ -12,7 +12,7 @@
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Contributor(s):
-->
@ -312,6 +312,68 @@
<file>WEB-INF/erbo.dict</file>
</dictionary>
<!-- This section provides the HTML Checker configurations used by the application. -->
<html-checker>
<config name="post-body">
<options wordwrap="55" angles="true" parens="true" discardHTML="false"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.HTMLEncodingFilter"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<output-filter type="raw" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.PostLinkRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.UserNameRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="paren" class="com.silverwrist.venice.db.UserNameRewriter"/>
<tag-set id="normal"/>
</config>
<config name="post-pseud">
<options wordwrap="0" angles="true" parens="false" discardHTML="false"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.HTMLEncodingFilter"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<output-filter type="raw" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<tag-set id="restricted"/>
</config>
<config name="preview">
<options wordwrap="55" angles="true" parens="true" discardHTML="false"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.HTMLEncodingFilter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="word" class="com.silverwrist.venice.htmlcheck.filters.SpellingRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.PostLinkRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.UserNameRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="paren" class="com.silverwrist.venice.db.UserNameRewriter"/>
<tag-set id="normal"/>
</config>
<config name="escaper">
<options wordwrap="0" angles="false" parens="false" discardHTML="false"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.HTMLEncodingFilter"/>
</config>
<config name="mail-post">
<options wordwrap="55" angles="true" parens="false" discardHTML="true" discardRejected="true"/>
<tag-set id="normal"/>
</config>
<config name="post-from-email">
<options wordwrap="55" rewrap="true" angles="true" parens="true" discardHTML="false"
discardRejected="true" discardComments="true" discardXML="true"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.HTMLEncodingFilter"/>
<output-filter type="normal" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<output-filter type="raw" class="com.silverwrist.venice.htmlcheck.filters.SQLEncodingFilter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="string" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.PostLinkRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.db.UserNameRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.EmailRewriter"/>
<rewriter type="tag" class="com.silverwrist.venice.htmlcheck.filters.URLRewriter"/>
<rewriter type="paren" class="com.silverwrist.venice.db.UserNameRewriter"/>
<tag-set id="normal"/>
<tag-set disallow="font"/>
</config>
</html-checker>
<!-- Settings for dealing with uploads -->
<upload>
<!-- Don't try to compress any file whose type falls in this list -->

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -35,6 +35,8 @@ public class StringUtil
private static final String VAR_START = "${";
private static final String VAR_END = "}";
private static final char[] HTML_ENCODE_CHARS = { '"', '&', '<', '>' };
private static final Set TRUE_STRINGS;
private static final Set FALSE_STRINGS;
/*--------------------------------------------------------------------------------
* External static operations
@ -322,4 +324,44 @@ public class StringUtil
} // end splitArray
public static final boolean isBooleanTrue(String test)
{
if (test==null)
return false;
return TRUE_STRINGS.contains(test.trim().toLowerCase());
} // end isBooleanTrue
public static final boolean isBooleanFalse(String test)
{
if (test==null)
return false;
return FALSE_STRINGS.contains(test.trim().toLowerCase());
} // end isBooleanTrue
/*--------------------------------------------------------------------------------
* Static initializer
*--------------------------------------------------------------------------------
*/
static
{ // Initialize the TRUE set.
HashSet tmp = new HashSet();
tmp.add("1");
tmp.add("true");
tmp.add("yes");
tmp.add("on");
TRUE_STRINGS = Collections.unmodifiableSet(tmp);
// Initialize the FALSE set.
tmp = new HashSet();
tmp.add("0");
tmp.add("false");
tmp.add("no");
tmp.add("off");
FALSE_STRINGS = Collections.unmodifiableSet(tmp);
} // end static initializer
} // end class StringUtil

View File

@ -601,7 +601,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
try
{ // preprocess the body argument through the HTML checker
HTMLChecker text_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_BODY);
HTMLChecker text_ch = env.getHTMLChecker("post-body");
text_ch.setContextValue("PostLinkDecoderContext",
new PostLinkDecoderContext(outer.getCommunity().realCommunityAlias(),conf_alias,
new_topic));

View File

@ -910,8 +910,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end if
// preprocess the pseud and title arguments through HTML checkers
HTMLChecker title_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_PSEUD);
HTMLChecker zp_pseud_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_PSEUD);
HTMLChecker title_ch = env.getHTMLChecker("post-pseud");
HTMLChecker zp_pseud_ch = env.getHTMLChecker("post-pseud");
try
{ // run arguments through the HTML checker
@ -1005,7 +1005,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
new_topic = 0;
else
new_topic = (short)(c.getTopTopic() + 1);
HTMLChecker rc = env.getEngine().createCheckerObject(EngineBackend.HTMLC_PREVIEW_BODY);
HTMLChecker rc = env.getHTMLChecker("preview");
rc.setContextValue("PostLinkDecoderContext",createDecoderContext(new_topic));
return rc;

View File

@ -11,7 +11,7 @@
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -91,7 +91,7 @@ class PostDeliveryAgent extends Thread
String real_pseud = null;
try
{ // run both arguments through the HTML checker
HTMLChecker mail_checker = env.getEngine().createCheckerObject(EngineBackend.HTMLC_MAIL_POST);
HTMLChecker mail_checker = env.getHTMLChecker("mail-post");
mail_checker.append(post_text);
mail_checker.finish();
real_text = mail_checker.getValue();

View File

@ -670,24 +670,24 @@ class TopicUserContextImpl implements TopicContext
} // end if
// figure out which HTML checkers to use
int pseud_ch_index = EngineBackend.HTMLC_POST_PSEUD;
int body_ch_index = EngineBackend.HTMLC_POST_BODY;
String pseud_ch_name = "post-pseud";
String body_ch_name = "post-body";
if (mode==POST_MODE_NORMAL)
{ // configure for normal posting
pseud_ch_index = EngineBackend.HTMLC_POST_PSEUD;
body_ch_index = EngineBackend.HTMLC_POST_BODY;
pseud_ch_name = "post-pseud";
body_ch_name = "post-body";
} // end if
else if (mode==POST_MODE_EMAIL)
{ // configure for E-mail posting
pseud_ch_index = EngineBackend.HTMLC_POST_PSEUD;
body_ch_index = EngineBackend.HTMLC_POST_BODY_EMAIL;
pseud_ch_name = "post-pseud";
body_ch_name = "post-from-email";
} // end else if
// preprocess the two arguments through HTML checkers
HTMLChecker pseud_ch = env.getEngine().createCheckerObject(pseud_ch_index);
HTMLChecker text_ch = env.getEngine().createCheckerObject(body_ch_index);
HTMLChecker pseud_ch = env.getHTMLChecker(pseud_ch_name);
HTMLChecker text_ch = env.getHTMLChecker(body_ch_name);
text_ch.setContextValue("PostLinkDecoderContext",env.getConference().createDecoderContext(topicnum));
try
{ // run both arguments through the HTML checker
@ -918,7 +918,7 @@ class TopicUserContextImpl implements TopicContext
public HTMLChecker getPreviewChecker()
{
HTMLChecker rc = env.getEngine().createCheckerObject(EngineBackend.HTMLC_PREVIEW_BODY);
HTMLChecker rc = env.getHTMLChecker("preview");
rc.setContextValue("PostLinkDecoderContext",env.getConference().createDecoderContext(topicnum));
return rc;

View File

@ -506,7 +506,7 @@ class UserContextImpl implements UserContext, UserBackend
{ // the confirmation number is wrong
logger.warn("...confirmation number incorrect");
ar = new AuditRecord(AuditRecord.VERIFY_FAIL,uid,remote_addr,"Invalid confirmation number");
env.saveAuditRecord(ar);
ar.store(env.getGlobalSite());
throw new AccessError("Confirmation number is incorrect. Please try again.");
} // end if

View File

@ -255,7 +255,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
private EnvEngine env = null; // my environment
private ObjectCache comm_objcache = new ObjectCache(new CommunityCoreDataCreator());
private ObjectCache conf_objcache = new ObjectCache(new ConferenceCoreDataCreator());
private HTMLCheckerConfig[] html_configs; // holder for HTML checker configurations
private int[] gp_ints; // global integer parameters
private MasterSideBox[] sideboxes; // master sidebox table
private Hashtable sidebox_ids = new Hashtable(); // maps sidebox IDs to MasterSideBox objects
@ -283,31 +282,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
*--------------------------------------------------------------------------------
*/
private static final Collection getDictionaryNames(Element sect, String app_root)
{
ArrayList rc = new ArrayList();
NodeList nl = sect.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // scan the element looking for <file/> elements
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("file")))
{ // extract the name of the file, possibly prefixing the application root directory
DOMElementHelper h = new DOMElementHelper((Element)n);
String fname = h.getElementText();
if (fname==null)
continue; // no file name???
if (!(fname.startsWith("/")))
fname = app_root + fname;
rc.add(fname);
} // end if
} // end for
return rc;
} // end getDictionaryNames
private final void checkInitialized()
{
if (globalsite==null)
@ -364,7 +338,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // get a database connection
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer();
@ -537,7 +511,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end if
Collection dictionary_tmp;
try
{ // first, verify that this is a valid configuration
XMLLoader loader = XMLLoader.get();
@ -559,7 +532,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
services_config = app_root + services_config;
// Create the global site.
globalsite = new GlobalSiteImpl(this,root);
globalsite = new GlobalSiteImpl(this,root,app_root);
// Get the <security/> section.
sect = loader.configGetSubSection(root_h,"security");
@ -584,12 +557,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end for
// Get the <dictionary/> section.
sect = loader.configGetSubSection(root_h,"dictionary");
// Retrieve the list of dictionary files.
dictionary_tmp = getDictionaryNames(sect,app_root);
// Get the <upload/> section.
sect = loader.configGetSubSection(root_h,"upload");
sect_h = new DOMElementHelper(sect);
@ -665,7 +632,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
Statement stmt = null;
try
{ // get a connection from the data pool
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
// load the global defaults
@ -685,114 +652,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end finally
// Here is where we create the HTML Checker and all the goodies it relies on.
// Start by creating some of the subsidiary objects that get added to HTML Checker configs.
EmailRewriter email_rewriter = new EmailRewriter();
HTMLEncodingFilter html_filter = new HTMLEncodingFilter();
SQLEncodingFilter sql_filter = new SQLEncodingFilter();
SpellingRewriter spell_rewriter = new SpellingRewriter();
URLRewriter url_rewriter = new URLRewriter();
PostLinkRewriter postlink_rewriter = new PostLinkRewriter(globalsite);
UserNameRewriter username_rewriter = new UserNameRewriter(globalsite);
// Create the LazyLexicon that holds our dictionary files, and add it to the SpellingRewriter.
LazyTreeLexicon lex = new LazyTreeLexicon((String[])(dictionary_tmp.toArray(new String[0])));
spell_rewriter.addDictionary(lex);
html_configs = new HTMLCheckerConfig[6]; // create the array
// Create the HTML checker config used to post body text to the database.
HTMLCheckerConfig cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)55);
cfg.setProcessAngles(true);
cfg.setProcessParens(true);
cfg.setDiscardHTMLTags(false);
cfg.addOutputFilter(html_filter);
cfg.addOutputFilter(sql_filter);
cfg.addRawOutputFilter(sql_filter);
cfg.addStringRewriter(email_rewriter);
cfg.addStringRewriter(url_rewriter);
cfg.addTagRewriter(postlink_rewriter);
cfg.addTagRewriter(username_rewriter);
cfg.addTagRewriter(email_rewriter);
cfg.addTagRewriter(url_rewriter);
cfg.addParenRewriter(username_rewriter);
cfg.configureNormalTagSet();
html_configs[HTMLC_POST_BODY] = cfg;
// Create the HTML checker config used to post pseuds and topic names to the database.
cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)0);
cfg.setProcessAngles(true);
cfg.setProcessParens(false);
cfg.setDiscardHTMLTags(false);
cfg.addOutputFilter(html_filter);
cfg.addOutputFilter(sql_filter);
cfg.addRawOutputFilter(sql_filter);
cfg.configureRestrictedTagSet();
html_configs[HTMLC_POST_PSEUD] = cfg;
// Create the HTML checker config used to preview body text.
cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)55);
cfg.setProcessAngles(true);
cfg.setProcessParens(true);
cfg.setDiscardHTMLTags(false);
cfg.addOutputFilter(html_filter);
cfg.addStringRewriter(email_rewriter);
cfg.addStringRewriter(url_rewriter);
cfg.addWordRewriter(spell_rewriter);
cfg.addTagRewriter(postlink_rewriter);
cfg.addTagRewriter(username_rewriter);
cfg.addTagRewriter(email_rewriter);
cfg.addTagRewriter(url_rewriter);
cfg.addParenRewriter(username_rewriter);
cfg.configureNormalTagSet();
html_configs[HTMLC_PREVIEW_BODY] = cfg;
// Create the HTML checker config used to escape body text and pseuds for putting back in the post box.
cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)0);
cfg.setProcessAngles(false);
cfg.setProcessParens(false);
cfg.setDiscardHTMLTags(false);
cfg.addOutputFilter(html_filter);
html_configs[HTMLC_ESCAPE_BODY_PSEUD] = cfg;
// Create the HTML Checker used to strip HTML from posts that are sent via E-mail.
cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)55);
cfg.setProcessAngles(true);
cfg.setProcessParens(false);
cfg.setDiscardHTMLTags(true);
cfg.setDiscardRejectedHTML(true);
cfg.configureNormalTagSet();
html_configs[HTMLC_MAIL_POST] = cfg;
// Create the HTML checker config used to post body text to the database from an E-mail message.
cfg = HTMLCheckerCreator.create();
cfg.setWordWrapLength((short)55);
cfg.setRewrapLines(true);
cfg.setProcessAngles(true);
cfg.setProcessParens(true);
cfg.setDiscardHTMLTags(false);
cfg.setDiscardRejectedHTML(true);
cfg.setDiscardHTMLComments(true);
cfg.setDiscardXMLConstructs(true);
cfg.addOutputFilter(html_filter);
cfg.addOutputFilter(sql_filter);
cfg.addRawOutputFilter(sql_filter);
cfg.addStringRewriter(email_rewriter);
cfg.addStringRewriter(url_rewriter);
cfg.addTagRewriter(postlink_rewriter);
cfg.addTagRewriter(username_rewriter);
cfg.addTagRewriter(email_rewriter);
cfg.addTagRewriter(url_rewriter);
cfg.addParenRewriter(username_rewriter);
cfg.configureNormalTagSet();
cfg.disallowTagSet(HTMLTagSets.FONT_FORMAT);
html_configs[HTMLC_POST_BODY_EMAIL] = cfg;
if (logger.isDebugEnabled())
logger.debug("initialize() complete :-)");
@ -833,7 +692,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // look for a user name matching this user record
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT c.email FROM users u, contacts c WHERE u.contactid = "
+ "c.contactid AND u.username = '" + SQLUtil.encodeString(username)
@ -875,7 +734,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // look for a user name matching this user record
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT c.email, u.uid, u.passreminder FROM users u, contacts c "
+ "WHERE u.contactid = c.contactid AND u.username = '");
@ -974,7 +833,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
Statement stmt = null;
try
{ // perform the database update
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '");
sql.append(hash_value).append("' WHERE uid = ").append(uid).append(';');
@ -1059,7 +918,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // do a SELECT on the sigs table
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT sigid FROM sigs WHERE alias = '");
sql.append(alias).append("'");
@ -1098,7 +957,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // do a SELECT on the category table
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE catid = ");
sql.append(catid).append(';');
@ -1134,7 +993,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // get a database connection
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, "
+ "c.family_name, c.locality, c.region, c.country FROM users u, "
@ -1227,7 +1086,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // get a database connection
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c WHERE u.contactid = "
+ "c.contactid AND ");
@ -1317,7 +1176,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // get a database connection
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
// create and execute the right SQL statement
@ -1351,7 +1210,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // do a SELECT on the confalias table
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '");
sql.append(alias).append("';");
@ -1377,7 +1236,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
public HTMLChecker getEscapingChecker()
{
return html_configs[HTMLC_ESCAPE_BODY_PSEUD].createHTMLChecker();
return (HTMLChecker)(globalsite.queryService(HTMLChecker.class,"escaper"));
} // end getEscapingChecker
@ -1600,14 +1459,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end registerNewConference
public HTMLChecker createCheckerObject(int type)
{
if ((type<0) || (type>=html_configs.length))
throw new IllegalArgumentException("invalid HTML checker type index");
return html_configs[type].createHTMLChecker();
} // end createCheckerObject
public int getParamInt(int selector)
{
return gp_ints[selector];
@ -1635,7 +1486,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
try
{ // get a connection and use it to reload
conn = env.getConnection();
conn = globalsite.getConnection(null);
stmt = conn.createStatement();
loadDefaults(stmt);

View File

@ -19,7 +19,6 @@ package com.silverwrist.venice.core.internals;
import java.util.BitSet;
import java.util.List;
import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.security.SecurityMonitor;
import com.silverwrist.venice.htmlcheck.HTMLChecker;
@ -31,14 +30,6 @@ import com.silverwrist.venice.except.DataException;
public interface EngineBackend
{
// HTML checker types
public static final int HTMLC_POST_BODY = 0;
public static final int HTMLC_POST_PSEUD = 1;
public static final int HTMLC_PREVIEW_BODY = 2;
public static final int HTMLC_ESCAPE_BODY_PSEUD = 3;
public static final int HTMLC_MAIL_POST = 4;
public static final int HTMLC_POST_BODY_EMAIL = 5;
// Integer parameter indexes
public static final int IP_POSTSPERPAGE = 0;
public static final int IP_POSTSATTOP = 1;
@ -76,8 +67,6 @@ public interface EngineBackend
public abstract void registerNewConference(ConferenceData conf);
public abstract HTMLChecker createCheckerObject(int type);
public abstract int getParamInt(int selector);
public abstract boolean getParamBoolean(int selector);

View File

@ -24,6 +24,7 @@ import org.apache.log4j.*;
import com.silverwrist.venice.core.SecurityInfo;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.htmlcheck.HTMLChecker;
import com.silverwrist.venice.security.*;
import com.silverwrist.venice.svc.ServiceControl;
import com.silverwrist.venice.svc.internal.GlobalSite;
@ -144,32 +145,6 @@ public class EnvEngine
} // end getSecurityInfo
public final void saveAuditRecord(AuditRecord ar)
{
Connection conn = null;
if (ar==null)
return; // don't store a null record
try
{ // get a connection and use it to store the audit record
conn = globalsite.getConnection(null);
ar.store(conn);
} // end try
catch (SQLException e)
{ // just log an error if we screwed up
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
SQLUtil.shutdown(conn);
} // end finally
} // end saveAuditRecord
public final String getStockMessage(String key)
{
return globalsite.getStockMessage(key);
@ -182,4 +157,10 @@ public class EnvEngine
} // end getMailSender
public final HTMLChecker getHTMLChecker(String id)
{
return (HTMLChecker)(globalsite.queryService(HTMLChecker.class,id));
} // end getHTMLChecker
} // end class EnvEngine

View File

@ -24,6 +24,9 @@ import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.htmlcheck.*;
import com.silverwrist.venice.htmlcheck.dict.*;
import com.silverwrist.venice.htmlcheck.filters.*;
import com.silverwrist.venice.svc.internal.GlobalSite;
import com.silverwrist.venice.util.ServiceProvider;
import com.silverwrist.venice.util.MailSend;
@ -48,13 +51,14 @@ public class GlobalSiteImpl implements GlobalSite
private Properties email_props = null; // email properties
private javax.mail.Session mailsession = null; // email session object
private StockMessages stock_messages = null; // stock messages holder
private HashMap html_checkers = new HashMap(); // HTML checkers
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public GlobalSiteImpl(EngineBackend engine, Element config) throws ConfigException
public GlobalSiteImpl(EngineBackend engine, Element config, String application_root) throws ConfigException
{
this.engine = engine;
XMLLoader loader = XMLLoader.get();
@ -93,8 +97,262 @@ public class GlobalSiteImpl implements GlobalSite
// Initialize the stock messages list.
stock_messages = new StockMessages(sect);
// Get the <dictionary/> section.
sect = loader.configGetSubSection(config_h,"dictionary");
// Retrieve the list of dictionary files.
Collection dictionary_tmp = getDictionaryNames(sect,application_root);
// Create the intermediate object map for HTML checker creation, and "seed" it.
HashMap intermediate_map = new HashMap();
SpellingRewriter spell_rewriter = new SpellingRewriter();
LazyTreeLexicon lex = new LazyTreeLexicon((String[])(dictionary_tmp.toArray(new String[0])));
spell_rewriter.addDictionary(lex);
intermediate_map.put(spell_rewriter.getClass().getName(),spell_rewriter);
PostLinkRewriter postlink_rewriter = new PostLinkRewriter(this);
intermediate_map.put(postlink_rewriter.getClass().getName(),postlink_rewriter);
UserNameRewriter username_rewriter = new UserNameRewriter(this);
intermediate_map.put(username_rewriter.getClass().getName(),username_rewriter);
// Get the <html-checker/> section.
sect = loader.configGetSubSection(config_h,"html-checker");
NodeList nl = sect.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // get each node in turn and test to see if it's an element
Node n = nl.item(i);
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // process based on node name
if (n.getNodeName().equals("config"))
createHTMLChecker((Element)n,intermediate_map);
else // this is an error
throw new ConfigException("unknown node type found in <html-checker/> section",(Element)n);
} // end if
// else ignore this node
} // end for
intermediate_map.clear(); // cut all extra references
} // end class GlobalSiteImpl
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private static final Collection getDictionaryNames(Element sect, String app_root)
{
ArrayList rc = new ArrayList();
NodeList nl = sect.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // scan the element looking for <file/> elements
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("file")))
{ // extract the name of the file, possibly prefixing the application root directory
DOMElementHelper h = new DOMElementHelper((Element)n);
String fname = h.getElementText();
if (fname==null)
continue; // no file name???
if (!(fname.startsWith("/")))
fname = app_root + fname;
rc.add(fname);
} // end if
} // end for
return rc;
} // end getDictionaryNames
private static final OutputFilter createOutputFilter(Element elt, HashMap intermediate)
throws ConfigException
{
XMLLoader loader = XMLLoader.get();
String classname = loader.configGetAttribute(elt,"class");
try
{ // see if there's an existing OutputFilter
OutputFilter of = (OutputFilter)(intermediate.get(classname));
if (of!=null)
return of;
// create a new OutputFilter, save it, and return it
Class klass = Class.forName(classname);
of = (OutputFilter)(klass.newInstance());
intermediate.put(classname,of);
return of;
} // end try
catch (ClassCastException cce)
{ // class name specified in wrong context - bail out!
throw new ConfigException("improper classname: \"" + classname + "\" is not an OutputFilter",elt);
} // end catch
catch (ClassNotFoundException cnfe)
{ // unable to load the class
throw new ConfigException("improper classname: \"" + classname + "\" does not exist",elt);
} // end catch
catch (IllegalAccessException iae)
{ // class is abstract, or constructor not found, or something
throw new ConfigException("improper classname: \"" + classname + "\" cannot be created",elt);
} // end catch
catch (InstantiationException ie)
{ // class could not be instantiated
throw new ConfigException("improper classname: \"" + classname + "\" cannot be created",elt);
} // end catch
} // end createOutputFilter
private static final Rewriter createRewriter(Element elt, HashMap intermediate) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
String classname = loader.configGetAttribute(elt,"class");
try
{ // see if there's an existing Rewriter
Rewriter r = (Rewriter)(intermediate.get(classname));
if (r!=null)
return r;
// create a new Rewriter, save it, and return it
Class klass = Class.forName(classname);
r = (Rewriter)(klass.newInstance());
intermediate.put(classname,r);
return r;
} // end try
catch (ClassCastException cce)
{ // class name specified in wrong context - bail out!
throw new ConfigException("improper classname: \"" + classname + "\" is not a Rewriter",elt);
} // end catch
catch (ClassNotFoundException cnfe)
{ // unable to load the class
throw new ConfigException("improper classname: \"" + classname + "\" does not exist",elt);
} // end catch
catch (IllegalAccessException iae)
{ // class is abstract, or constructor not found, or something
throw new ConfigException("improper classname: \"" + classname + "\" cannot be created",elt);
} // end catch
catch (InstantiationException ie)
{ // class could not be instantiated
throw new ConfigException("improper classname: \"" + classname + "\" cannot be created",elt);
} // end catch
} // end createRewriter
private final void createHTMLChecker(Element elt, HashMap intermediate) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
String checker_name = loader.configGetAttribute(elt,"name");
if (html_checkers.containsKey(checker_name))
throw new ConfigException("config name \"" + checker_name + "\" defined twice",elt);
HTMLCheckerConfig cfg = HTMLCheckerCreator.create();
NodeList nl = elt.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // get each node in the list in turn and figure out what it means
Node n = nl.item(i);
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // now select based on node name
if (n.getNodeName().equals("options"))
{ // process the various "options" for the HTML checker
Element opt_elt = (Element)n;
cfg.setWordWrapLength((short)(loader.configGetAttributeInt(opt_elt,"wordwrap",
cfg.getWordWrapLength())));
cfg.setRewrapLines(loader.configGetAttributeBoolean(opt_elt,"rewrap",cfg.getRewrapLines()));
cfg.setProcessAngles(loader.configGetAttributeBoolean(opt_elt,"angles",cfg.getProcessAngles()));
cfg.setProcessParens(loader.configGetAttributeBoolean(opt_elt,"parens",cfg.getProcessParens()));
cfg.setDiscardHTMLTags(loader.configGetAttributeBoolean(opt_elt,"discardHTML",
cfg.getDiscardHTMLTags()));
cfg.setDiscardRejectedHTML(loader.configGetAttributeBoolean(opt_elt,"discardRejected",
cfg.getDiscardRejectedHTML()));
cfg.setDiscardHTMLComments(loader.configGetAttributeBoolean(opt_elt,"discardComments",
cfg.getDiscardHTMLComments()));
cfg.setDiscardXMLConstructs(loader.configGetAttributeBoolean(opt_elt,"discardXML",
cfg.getDiscardXMLConstructs()));
cfg.setAnchorTail(loader.configGetAttribute(opt_elt,"anchorTail",cfg.getAnchorTail()));
} // end if ("options" element seen)
else if (n.getNodeName().equals("output-filter"))
{ // specify an output filter - we need to create it here
Element of_elt = (Element)n;
String of_type = loader.configGetAttribute(of_elt,"type");
if (of_type.equals("normal"))
cfg.addOutputFilter(createOutputFilter(of_elt,intermediate));
else if (of_type.equals("raw"))
cfg.addRawOutputFilter(createOutputFilter(of_elt,intermediate));
else
throw new ConfigException("invalid type= attribute for <output-filter/> element",of_elt);
} // end else if ("output-filter" element seen)
else if (n.getNodeName().equals("rewriter"))
{ // specify a rewriter - we need to create it here
Element rw_elt = (Element)n;
String rw_type = loader.configGetAttribute(rw_elt,"type");
if (rw_type.equals("string"))
cfg.addStringRewriter(createRewriter(rw_elt,intermediate));
else if (rw_type.equals("word"))
cfg.addWordRewriter(createRewriter(rw_elt,intermediate));
else if (rw_type.equals("tag"))
cfg.addTagRewriter(createRewriter(rw_elt,intermediate));
else if (rw_type.equals("paren"))
cfg.addParenRewriter(createRewriter(rw_elt,intermediate));
else
throw new ConfigException("invalid type= attribute for <rewriter/> element",rw_elt);
} // end else if ("rewriter" element seen)
else if (n.getNodeName().equals("tag-set"))
{ // specify a tag set to deal with
Element ts_elt = (Element)n;
DOMElementHelper ts_elt_h = new DOMElementHelper(ts_elt);
if (ts_elt_h.hasAttribute("id"))
{ // we're an "id" element - use that to configure "normal" or "restricted"
String id = ts_elt.getAttribute("id");
if (id.equals("normal"))
cfg.configureNormalTagSet();
else if (id.equals("restricted"))
cfg.configureRestrictedTagSet();
else
throw new ConfigException("invalid id= attribute on <tag-set/> element",ts_elt);
} // end if ("id" attribute found)
else if (ts_elt_h.hasAttribute("allow"))
{ // allow a specified tag set
int set = HTMLCheckerCreator.convertTagSetLabel(ts_elt.getAttribute("allow"));
if (set<0)
throw new ConfigException("invalid allow= set identifier on <tag-set/> element",ts_elt);
cfg.allowTagSet(set);
} // end else if ("allow" attribute found)
else if (ts_elt_h.hasAttribute("disallow"))
{ // disallow a specified tag set
int set = HTMLCheckerCreator.convertTagSetLabel(ts_elt.getAttribute("disallow"));
if (set<0)
throw new ConfigException("invalid disallow= set identifier on <tag-set/> element",ts_elt);
cfg.disallowTagSet(set);
} // end else if ("disallow" attribute found)
} // end else if ("tag-set" element seen)
else // this is an error
throw new ConfigException("unknown node type found in <config/> section",(Element)n);
} // end if
// else ignore this node
} // end for
html_checkers.put(checker_name,cfg);
} // end createHTMLChecker
/*--------------------------------------------------------------------------------
* Implementations from interface ServiceProvider
*--------------------------------------------------------------------------------
@ -112,6 +370,38 @@ public class GlobalSiteImpl implements GlobalSite
public Object queryService(Class klass, String serviceid)
{
if (klass==Connection.class)
{ // want to get a database connection
try
{ // call through
return this.getConnection(serviceid);
} // end try
catch (SQLException e)
{ // unable to get the connection
throw new NoSuchServiceException("GlobalSite",klass,serviceid);
} // end catch
} // end if
if (klass==HTMLCheckerConfig.class)
{ // get the HTML Checker config
Object rc = html_checkers.get(serviceid);
if (rc==null)
throw new NoSuchServiceException("GlobalSite",klass,serviceid);
return rc;
} // end if
if (klass==HTMLChecker.class)
{ // create an HTML Checker using the specified HTML Checker config
HTMLCheckerConfig fact = (HTMLCheckerConfig)(html_checkers.get(serviceid));
if (fact==null)
throw new NoSuchServiceException("GlobalSite",klass,serviceid);
return fact.createHTMLChecker();
} // end if
return this.queryService(klass);
} // end queryService

View File

@ -7,24 +7,168 @@
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Community System.
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.htmlcheck;
import java.util.*;
import com.silverwrist.venice.htmlcheck.impl.HTMLCheckerConfigImpl;
public class HTMLCheckerCreator
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static final Map LABELS;
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------
*/
public static HTMLCheckerConfig create()
{
return HTMLCheckerConfigImpl.createHTMLCheckerConfig();
} // end create
public static int convertTagSetLabel(String label)
{
if (label==null)
return -1;
Integer foo = (Integer)(LABELS.get(label.trim().toLowerCase()));
return ((foo==null) ? -1 : foo.intValue());
} // end convertTagSetLabel
/*--------------------------------------------------------------------------------
* Static initializer
*--------------------------------------------------------------------------------
*/
static
{ // build up the Labels map
HashMap tmp = new HashMap();
Integer val = new Integer(HTMLTagSets.INLINE_FORMAT);
tmp.put("inline",val);
tmp.put("inline-format",val);
val = new Integer(HTMLTagSets.ANCHOR);
tmp.put("anchor",val);
tmp.put("a",val);
val = new Integer(HTMLTagSets.BLOCK_FORMAT);
tmp.put("block",val);
tmp.put("block-format",val);
val = new Integer(HTMLTagSets.ACTIVE_CONTENT);
tmp.put("active",val);
tmp.put("active-content",val);
tmp.put("object",val);
tmp.put("embed",val);
tmp.put("applet",val);
tmp.put("script",val);
val = new Integer(HTMLTagSets.IMAGE_MAPS);
tmp.put("imagemap",val);
tmp.put("map",val);
val = new Integer(HTMLTagSets.DOC_FORMAT);
tmp.put("doc",val);
tmp.put("doc-format",val);
tmp.put("document",val);
tmp.put("document-format",val);
val = new Integer(HTMLTagSets.FONT_FORMAT);
tmp.put("font",val);
tmp.put("font-format",val);
val = new Integer(HTMLTagSets.FORMS);
tmp.put("form",val);
tmp.put("forms",val);
val = new Integer(HTMLTagSets.TABLES);
tmp.put("table",val);
tmp.put("tables",val);
val = new Integer(HTMLTagSets.CHANGE_MARKUP);
tmp.put("change",val);
tmp.put("change-markup",val);
tmp.put("delta",val);
val = new Integer(HTMLTagSets.FRAMES);
tmp.put("frame",val);
tmp.put("frames",val);
val = new Integer(HTMLTagSets.IMAGES);
tmp.put("image",val);
tmp.put("images",val);
tmp.put("img",val);
val = new Integer(HTMLTagSets.PREFORMAT);
tmp.put("preformat",val);
tmp.put("pre",val);
val = new Integer(HTMLTagSets.NSCP_INLINE_FORMAT);
tmp.put("inline.nscp",val);
tmp.put("inline-format.nscp",val);
val = new Integer(HTMLTagSets.NSCP_LAYERS);
tmp.put("layer.nscp",val);
tmp.put("layers.nscp",val);
val = new Integer(HTMLTagSets.NSCP_FORMS);
tmp.put("form.nscp",val);
tmp.put("forms.nscp",val);
val = new Integer(HTMLTagSets.NSCP_BLOCK_FORMAT);
tmp.put("block.nscp",val);
tmp.put("block-format.nscp",val);
val = new Integer(HTMLTagSets.NSCP_SERVER);
tmp.put("server.nscp",val);
val = new Integer(HTMLTagSets.MSFT_DOC_FORMAT);
tmp.put("doc.msft",val);
tmp.put("doc-format.msft",val);
tmp.put("document.msft",val);
tmp.put("document-format.msft",val);
val = new Integer(HTMLTagSets.MSFT_INLINE_FORMAT);
tmp.put("inline.msft",val);
tmp.put("inline-format.msft",val);
val = new Integer(HTMLTagSets.MSFT_BLOCK_FORMAT);
tmp.put("block.msft",val);
tmp.put("block-format.msft",val);
val = new Integer(HTMLTagSets.MSFT_ACTIVE_CONTENT);
tmp.put("active.msft",val);
tmp.put("active-content.msft",val);
val = new Integer(HTMLTagSets.SERVER_PAGE);
tmp.put("server",val);
tmp.put("asp",val);
tmp.put("jsp",val);
val = new Integer(HTMLTagSets.JAVA_SERVER);
tmp.put("server.java",val);
tmp.put("jsp.component",val);
val = new Integer(HTMLTagSets.COMMENT);
tmp.put("comment",val);
LABELS = Collections.unmodifiableMap(tmp);
} // end static initializer
} // end HTMLCheckerCreator

View File

@ -24,6 +24,7 @@ import com.silverwrist.venice.db.SQLUtil;
import com.silverwrist.venice.core.AuditData;
import com.silverwrist.venice.except.DataException;
import com.silverwrist.venice.except.InternalStateError;
import com.silverwrist.venice.svc.internal.GlobalSite;
public class AuditRecord implements AuditData
{
@ -385,6 +386,29 @@ public class AuditRecord implements AuditData
} // end store
public void store(GlobalSite globalsite)
{
Connection conn = null;
try
{ // get a connection and use it to store the audit record
conn = globalsite.getConnection(null);
this.store(conn);
} // end try
catch (SQLException e)
{ // just log an error if we screwed up
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
SQLUtil.shutdown(conn);
} // end finally
} // end store
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------

View File

@ -312,6 +312,13 @@ public class XMLLoader
} // end configGetAttribute
public final String configGetAttribute(Element elt, String attr_name, String default_val)
{
String rc = elt.getAttribute(attr_name);
return (StringUtil.isStringEmpty(rc) ? default_val : rc);
} // end configGetAttribute
public final int configGetAttributeInt(Element elt, String attr_name) throws ConfigException
{
String tmp = elt.getAttribute(attr_name);
@ -338,6 +345,43 @@ public class XMLLoader
} // end configGetAttributeInt
public final int configGetAttributeInt(Element elt, String attr_name, int default_val) throws ConfigException
{
String tmp = elt.getAttribute(attr_name);
if (StringUtil.isStringEmpty(tmp))
return default_val; // the attribute is not present
try
{ // parse out the integer value
return Integer.parseInt(tmp.trim());
} // end try
catch (NumberFormatException nfe)
{ // but it's not a valid integer - throw something else!
logger.fatal(attr_name + "= attribute in <" + elt.getTagName() + "/> element is not a valid integer");
throw new ConfigException(attr_name + "= attribute in <" + elt.getTagName()
+ "/> element is not a valid integer",elt);
} // end catch
} // end configGetAttributeInt
public final boolean configGetAttributeBoolean(Element elt, String attr_name, boolean default_val)
throws ConfigException
{
String tmp = elt.getAttribute(attr_name);
if (StringUtil.isStringEmpty(tmp))
return default_val; // the attribute is not present
if (StringUtil.isBooleanTrue(tmp))
return true;
if (StringUtil.isBooleanFalse(tmp))
return false;
logger.fatal(attr_name + "= attribute in <" + elt.getTagName() + "/> element is not a valid Boolean");
throw new ConfigException(attr_name + "= attribute in <" + elt.getTagName()
+ "/> element is not a valid Boolean",elt);
} // end configGetAttributeBoolean
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------