initial support for the "emoticons" or "smileys" - defined the config file

here so we can change over all the custom venice-config.xml and ui-config.xml
files before going any further
This commit is contained in:
Eric J. Bowersox
2004-07-27 04:53:30 +00:00
parent 7060b5ff76
commit 8a745717e1
19 changed files with 333 additions and 3 deletions
@@ -293,5 +293,3 @@ public final class DOMElementHelper
} // end getAttributeBoolean
} // end DOMElementHelper
@@ -143,9 +143,14 @@ public class GlobalSiteImpl implements GlobalSite
// Get the <engine/> section.
DOMElementHelper config_h = new DOMElementHelper(config);
Element sect = loader.configGetSubSection(config_h,"database");
Element sect = loader.configGetSubSection(config_h,"engine");
DOMElementHelper sect_h = new DOMElementHelper(sect);
// Get the name of the emoticons configuration file.
String emoticon_config = loader.configGetSubElementText(sect_h,"emoticon-config");
if (!(emoticon_config.startsWith("/")))
emoticon_config = application_root + emoticon_config;
// Get the <privileged-addresses/> value.
String s = sect_h.getSubElementText("privileged-addresses");
if (!(StringUtil.isStringEmpty(s)))
@@ -225,6 +230,8 @@ public class GlobalSiteImpl implements GlobalSite
intermediate_map.put(postlink_rewriter.getClass().getName(),postlink_rewriter);
UserNameRewriter username_rewriter = new UserNameRewriter(this);
intermediate_map.put(username_rewriter.getClass().getName(),username_rewriter);
EmoticonRewriter emoticon_rewriter = new EmoticonRewriter(emoticon_config);
intermediate_map.put(emoticon_rewriter.getClass().getName(),emoticon_rewriter);
// Get the <html-checker/> section.
sect = loader.configGetSubSection(config_h,"html-checker");
@@ -0,0 +1,111 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Community System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.htmlcheck.filters;
import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.htmlcheck.Rewriter;
import com.silverwrist.venice.htmlcheck.RewriterServices;
import com.silverwrist.venice.htmlcheck.MarkupData;
import com.silverwrist.venice.util.XMLLoader;
public class EmoticonRewriter implements Rewriter
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private String m_prefixchars;
private Map m_patmap;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public EmoticonRewriter(String config_file) throws ConfigException
{
// Load the configuration file.
XMLLoader loader = XMLLoader.get();
Document config = loader.loadConfigDocument(config_file);
Element root = loader.configGetRootElement(config,"emoticon-config");
// Get the set of prefix characters.
m_prefixchars = loader.configGetSubElementText(root,"prefix-chars");
HashMap tmp = new HashMap();
// Look for all associated icons.
NodeList nl = root.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // look through all the child nodes...
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && n.getNodeName().equals("icon"))
{ // load the icon name
String icon_name = loader.configGetAttribute((Element)n,"name").intern();
// get the associated patterns
NodeList nl2 = n.getChildNodes();
for (int j=0; j<nl2.getLength(); j++)
{ // look for <pattern/> elements
Node n2 = nl2.item(i);
if ((n2.getNodeType()==Node.ELEMENT_NODE) && n2.getNodeName().equals("pattern"))
{ // get the element text
DOMElementHelper h = new DOMElementHelper((Element)n2);
String pattern = h.getElementText();
if (m_prefixchars.indexOf(pattern.charAt(0))>=0)
tmp.put(pattern,icon_name);
} // end if
// else skip this element
} // end for
} // end if
// else skip this element
} // end for
if (tmp.isEmpty())
m_patmap = Collections.EMPTY_MAP;
else
m_patmap = Collections.unmodifiableMap(tmp);
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface Rewriter
*--------------------------------------------------------------------------------
*/
public String getName()
{
return "emoticon";
} // end getName
public MarkupData rewrite(String data, RewriterServices svc)
{
return null;
} // end rewrite
} // end class EmoticonRewriter
@@ -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 <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.ui.config;
import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.util.XMLLoader;
public class EmoticonManager
{
/*--------------------------------------------------------------------------------
* Internal class that contains the icon data.
*--------------------------------------------------------------------------------
*/
private static class IconDefinition
{
/*====================================================================
* Attributes
*====================================================================
*/
private int m_width;
private int m_height;
private boolean m_fixup;
private String m_path;
private String m_text;
/*====================================================================
* Constructor
*====================================================================
*/
IconDefinition(Element icon_elt) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
DOMElementHelper h = new DOMElementHelper(icon_elt);
// Get the icon image data.
Element img_elt = loader.configGetSubSection(h,"image");
m_width = loader.configGetAttributeInt(img_elt,"width");
m_height = loader.configGetAttributeInt(img_elt,"height");
DOMElementHelper h2 = new DOMElementHelper(img_elt);
m_fixup = h2.getAttributeBoolean("fixup",false).booleanValue();
m_path = h2.getElementText();
// Get the text data.
m_text = h.getSubElementText("text");
} // end constructor
} // end class IconDefinition
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private Map m_iconmap;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
EmoticonManager(Element config) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
HashMap tmp = new HashMap();
NodeList nl = config.getChildNodes();
for (int i=0; i<nl.getLength(); i++)
{ // get the element
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && n.getNodeName().equals("icon"))
{ // load the emoticon
Element elt = (Element)n;
String icon_name = loader.configGetAttribute(elt,"name").intern();
IconDefinition defn = new IconDefinition(elt);
tmp.put(icon_name,defn);
} // end if
} // end for
if (tmp.isEmpty())
m_iconmap = Collections.EMPTY_MAP;
else
m_iconmap = Collections.unmodifiableMap(tmp);
} // end constructor
} // end class EmoticonManager
@@ -92,6 +92,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
private DialogManager m_dialogs; // the dialog manager
private SideBoxManager m_sideboxes; // the sidebox manager
private CommunityMenuFactory m_comm_menu_fact; // the community menu factory
private EmoticonManager m_emoticons; // the emoticon manager
/*--------------------------------------------------------------------------------
* Constructor
@@ -120,6 +121,11 @@ public class RootConfig implements LinkTypes, ColorSelectors
if (!(services_config.startsWith("/")))
services_config = root_file_path + services_config;
// Get the full pathname of the emoticon configuration file.
String emoticon_config = loader.configGetSubElementText(sect_h,"emoticon-config");
if (!(emoticon_config.startsWith("/")))
emoticon_config = root_file_path + emoticon_config;
// Get the full pathname of the script directory.
m_script_directory = getRelativeDirectory(sect_h,"script-dir",root_file_path,true);
@@ -511,6 +517,14 @@ public class RootConfig implements LinkTypes, ColorSelectors
// Get the community section and pass it to the CommunityMenuFactory.
m_comm_menu_fact = new CommunityMenuFactory(root_h.getSubElement("community"),this);
// done with the services-config.xml file
// Load up the emoticon.xml file.
doc = loader.loadConfigDocument(emoticon_config);
root = loader.configGetRootElement(doc,"emoticon-config");
// Load the emoticon manager.
m_emoticons = new EmoticonManager(root);
} // end constructor
/*--------------------------------------------------------------------------------
@@ -892,6 +906,12 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end addFormatParams
public final EmoticonManager getEmoticonManager()
{
return m_emoticons;
} // end getEmoticonManager
/*--------------------------------------------------------------------------------
* Static initializer
*--------------------------------------------------------------------------------