diff --git a/etc/venice-config.xml b/etc/venice-config.xml index 1289d58..8a298e2 100644 --- a/etc/venice-config.xml +++ b/etc/venice-config.xml @@ -12,7 +12,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) 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 @@ WEB-INF/erbo.dict + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/silverwrist/util/StringUtil.java b/src/com/silverwrist/util/StringUtil.java index 31381ad..447c5d3 100644 --- a/src/com/silverwrist/util/StringUtil.java +++ b/src/com/silverwrist/util/StringUtil.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) 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 diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java index f5db0e6..124b459 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java @@ -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)); diff --git a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java index bd57b6c..7f7a650 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java @@ -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; diff --git a/src/com/silverwrist/venice/core/impl/PostDeliveryAgent.java b/src/com/silverwrist/venice/core/impl/PostDeliveryAgent.java index 6b32057..e4df115 100644 --- a/src/com/silverwrist/venice/core/impl/PostDeliveryAgent.java +++ b/src/com/silverwrist/venice/core/impl/PostDeliveryAgent.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) 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(); diff --git a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java index 81a72af..7058f9c 100644 --- a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java @@ -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; diff --git a/src/com/silverwrist/venice/core/impl/UserContextImpl.java b/src/com/silverwrist/venice/core/impl/UserContextImpl.java index e47ffe3..33e8463 100644 --- a/src/com/silverwrist/venice/core/impl/UserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/UserContextImpl.java @@ -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 diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java index 431ad84..134fdf7 100644 --- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java +++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java @@ -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 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 section. sect = loader.configGetSubSection(root_h,"security"); @@ -584,12 +557,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end for - // Get the section. - sect = loader.configGetSubSection(root_h,"dictionary"); - - // Retrieve the list of dictionary files. - dictionary_tmp = getDictionaryNames(sect,app_root); - // Get the 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); diff --git a/src/com/silverwrist/venice/core/internals/EngineBackend.java b/src/com/silverwrist/venice/core/internals/EngineBackend.java index 51f789f..48d0971 100644 --- a/src/com/silverwrist/venice/core/internals/EngineBackend.java +++ b/src/com/silverwrist/venice/core/internals/EngineBackend.java @@ -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); diff --git a/src/com/silverwrist/venice/core/internals/EnvEngine.java b/src/com/silverwrist/venice/core/internals/EnvEngine.java index bc4a380..b8d8b4e 100644 --- a/src/com/silverwrist/venice/core/internals/EnvEngine.java +++ b/src/com/silverwrist/venice/core/internals/EnvEngine.java @@ -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 diff --git a/src/com/silverwrist/venice/core/internals/GlobalSiteImpl.java b/src/com/silverwrist/venice/core/internals/GlobalSiteImpl.java index 14d79a0..a3e2e1d 100644 --- a/src/com/silverwrist/venice/core/internals/GlobalSiteImpl.java +++ b/src/com/silverwrist/venice/core/internals/GlobalSiteImpl.java @@ -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 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 section. + sect = loader.configGetSubSection(config_h,"html-checker"); + NodeList nl = sect.getChildNodes(); + for (int i=0; i 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 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 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 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 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 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 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 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 diff --git a/src/com/silverwrist/venice/htmlcheck/HTMLCheckerCreator.java b/src/com/silverwrist/venice/htmlcheck/HTMLCheckerCreator.java index 8e7524f..d30fb06 100644 --- a/src/com/silverwrist/venice/htmlcheck/HTMLCheckerCreator.java +++ b/src/com/silverwrist/venice/htmlcheck/HTMLCheckerCreator.java @@ -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 , * 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 diff --git a/src/com/silverwrist/venice/security/AuditRecord.java b/src/com/silverwrist/venice/security/AuditRecord.java index 463fc49..273e356 100644 --- a/src/com/silverwrist/venice/security/AuditRecord.java +++ b/src/com/silverwrist/venice/security/AuditRecord.java @@ -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 *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/util/XMLLoader.java b/src/com/silverwrist/venice/util/XMLLoader.java index b05c0ed..32175a1 100644 --- a/src/com/silverwrist/venice/util/XMLLoader.java +++ b/src/com/silverwrist/venice/util/XMLLoader.java @@ -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 *--------------------------------------------------------------------------------