the first real phase of service integration - mostly it's the configuration

file, the bare beginnings of the Service Control Manager on the server side,
and the new "community left menu" on the client side (still controlled by the
existing feature mechanism, for now).  The engine still needs to incorporate
the SCM in place of the old feature definitions.  Also added some utility
classes (StockMessage, XMLLoader) to aid with loading XML data from the
config files (big help in the RenderConfig constructor and
VeniceEngineImpl.initialize!)
This commit is contained in:
Eric J. Bowersox
2001-11-21 09:47:27 +00:00
parent 41299f6d85
commit 3752e73c2d
20 changed files with 1416 additions and 732 deletions

View File

@@ -26,7 +26,7 @@ import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.*;
import com.silverwrist.venice.servlets.format.menus.LeftMenu;
import com.silverwrist.venice.servlets.format.menus.*;
public class Variables
{
@@ -206,23 +206,34 @@ public class Variables
} // end setMenuTop
public static void setMenuCommunity(HttpSession session, CommunityContext comm)
public static void setMenuCommunity(ServletContext ctxt, HttpSession session, CommunityContext comm)
{
Object obj = session.getAttribute(MENU_ATTRIBUTE);
boolean do_change;
if ((obj==null) || !(obj instanceof MenuCommunity))
if ((obj==null) || !(obj instanceof CommunityLeftMenu))
do_change = true;
else
{ // look at the actual community IDs underlying the MenuCommunity
MenuCommunity tmp = (MenuCommunity)obj;
CommunityLeftMenu tmp = (CommunityLeftMenu)obj;
do_change = (tmp.getID()!=comm.getCommunityID());
} // end else
if (do_change)
{ // switch to the appropriate MenuCommunity
MenuCommunity mc = new MenuCommunity(comm);
session.setAttribute(MENU_ATTRIBUTE,mc);
{ // switch to the appropriate CommunityLeftMenu
try
{ // but note that getting the rendering configuration can throw a ServletException
RenderConfig cfg = RenderConfig.getRenderConfig(ctxt);
CommunityLeftMenu menu = cfg.createCommunityMenu(comm);
session.setAttribute(MENU_ATTRIBUTE,menu);
} // end try
catch (ServletException e)
{ // if we fail, just clear it out
logger.warn("caught ServletException in setMenuCommunity",e);
session.removeAttribute(MENU_ATTRIBUTE);
} // end catch
} // end if

View File

@@ -321,7 +321,7 @@ public abstract class VeniceServlet extends HttpServlet
protected final void changeMenuCommunity(HttpServletRequest request, CommunityContext comm)
{
Variables.setMenuCommunity(request.getSession(true),comm);
Variables.setMenuCommunity(getServletContext(),request.getSession(true),comm);
} // end changeMenuCommunity

View File

@@ -21,22 +21,17 @@ import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.silverwrist.util.DOMElementHelper;
import com.silverwrist.util.IOUtil;
import com.silverwrist.util.StringUtil;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.CommunityContext;
import com.silverwrist.venice.core.UserContext;
import com.silverwrist.venice.core.VeniceEngine;
import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.except.ConfigException;
import com.silverwrist.venice.except.DataException;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.Variables;
import com.silverwrist.venice.servlets.format.menus.LeftMenu;
import com.silverwrist.venice.servlets.format.menus.*;
import com.silverwrist.venice.servlets.format.sideboxes.SideBoxFactory;
import com.silverwrist.venice.util.XMLLoader;
public class RenderConfig implements ColorSelectors
{
@@ -57,7 +52,6 @@ public class RenderConfig implements ColorSelectors
*--------------------------------------------------------------------------------
*/
private Document config;
private String site_title;
private boolean want_comments;
private boolean allow_gzip;
@@ -71,13 +65,14 @@ public class RenderConfig implements ColorSelectors
private int site_logo_width = 140;
private int site_logo_height = 80;
private String site_logo_linkURL = null;
private HashMap stock_messages;
private HashMap menus;
private StockMessages stock_messages;
private Map menus;
private String[] colors_array;
private int footer_logo_scale;
private Map sidebox_factories;
private String photo_not_avail;
private boolean photo_not_avail_fixup;
private CommunityLeftMenuFactory comm_menu_fact;
/*--------------------------------------------------------------------------------
* Constructor
@@ -86,104 +81,76 @@ public class RenderConfig implements ColorSelectors
protected RenderConfig(String config_file, String root_file_path) throws ConfigException
{
config = loadConfiguration(config_file);
XMLLoader loader = XMLLoader.get();
Document doc = loader.loadConfigDocument(config_file);
// Make sure the configuration is valid...
Element root = config.getDocumentElement();
if (!(root.getTagName().equals("render-config")))
{ // not the correct root tag name
logger.fatal("config document is not a <render-config/> document (root tag: <"
+ root.getTagName() + "/>)");
throw new ConfigException("document is not a <render-config/> document",root);
} // end if
// Get the site name.
// Make sure the document is valid.
Element root = loader.configGetRootElement(doc,"render-config");
DOMElementHelper root_h = new DOMElementHelper(root);
site_title = root_h.getSubElementText("site-name");
if (site_title==null)
{ // no <site-name/> section - bail out now!
logger.fatal("config document has no <site-title/> element");
throw new ConfigException("no <site-title/> section found in config file",root);
} // end if
// Get the site title.
site_title = loader.configGetSubElementText(root_h,"site-name");
if (logger.isDebugEnabled())
logger.debug("Site title: " + site_title);
Element render_sect = root_h.getSubElement("rendering");
if (render_sect==null)
{ // no <rendering/> section - bail out now!
logger.fatal("config document has no <rendering/> section");
throw new ConfigException("no <rendering/> section found in config file",root);
// Get the <rendering/> section.
Element sect = loader.configGetSubSection(root_h,"rendering");
} // end if
DOMElementHelper render_sect_h = new DOMElementHelper(render_sect);
want_comments = render_sect_h.hasChildElement("html-comments");
allow_gzip = render_sect_h.hasChildElement("gzip-output");
no_smart_tags = !(render_sect_h.hasChildElement("ms-copyright-violations"));
// Load the quick Boolean values indicated by the presence or absence of a tag.
DOMElementHelper sect_h = new DOMElementHelper(sect);
want_comments = sect_h.hasChildElement("html-comments");
allow_gzip = sect_h.hasChildElement("gzip-output");
no_smart_tags = !(sect_h.hasChildElement("ms-copyright-violations"));
if (logger.isDebugEnabled())
{ // log the read values
logger.debug("Use HTML comments: " + String.valueOf(want_comments));
logger.debug("Use GZIP encoding: " + String.valueOf(allow_gzip));
logger.debug("Disable IE Smart Tags: " + String.valueOf(no_smart_tags));
} // end if
font_face = render_sect_h.getSubElementText("font");
if (font_face==null)
{ // no <font/> tag - bail out now!
logger.fatal("<rendering/> section has no <font/> element");
throw new ConfigException("no <font/> found in <rendering/> section",render_sect);
logger.debug("Use HTML comments: " + want_comments);
logger.debug("Use GZIP encoding: " + allow_gzip);
logger.debug("Disable IE Smart Tags: " + no_smart_tags);
} // end if
// Load the default font face.
font_face = loader.configGetSubElementText(sect_h,"font");
if (logger.isDebugEnabled())
logger.debug("Font face: " + font_face);
String stylesheet_loc = render_sect_h.getSubElementText("stylesheet");
if (stylesheet_loc!=null)
// Load the default stylesheet file reference.
String tmp = sect_h.getSubElementText("stylesheet");
if (tmp!=null)
{ // we're using Cascading Stylesheets - load it and test for existence
if (!(stylesheet_loc.startsWith("/")))
stylesheet_loc = root_file_path + stylesheet_loc;
if (!(tmp.startsWith("/"))) // prepend app root
tmp = root_file_path + tmp;
if (logger.isDebugEnabled())
logger.debug("Stylesheet location: " + stylesheet_loc);
logger.debug("Stylesheet location: " + tmp);
// Test to make sure the stylesheet is actually present.
stylesheet = new File(stylesheet_loc);
stylesheet = new File(tmp);
if (!(stylesheet.exists() && stylesheet.canRead()))
{ // it's not there - bail out!
logger.fatal("unable to read stylesheet file: " + stylesheet_loc);
throw new ConfigException("stylesheet " + stylesheet_loc + " cannot be read",render_sect);
logger.fatal("unable to read stylesheet file: " + tmp);
throw new ConfigException("stylesheet " + tmp + " cannot be read",sect);
} // end if
} // end if
else // no stylesheet
else // no stylesheet
stylesheet = null;
Element colors_sect = render_sect_h.getSubElement("colors");
if (colors_sect==null)
{ // no <colors/> tag - bail out now!
logger.fatal("<rendering/> section has no <colors/> element");
throw new ConfigException("no <colors/> found in <rendering/> section",render_sect);
} // end if
// Get the <colors/> section and load the colors out of it..
Element sect1 = loader.configGetSubSection(sect_h,"colors");
colors_array = new String[colornames_map.size()];
int i;
NodeList colors_nlist = colors_sect.getChildNodes();
for (i=0; i<colors_nlist.getLength(); i++)
NodeList nl = sect1.getChildNodes();
for (i=0; i<nl.getLength(); i++)
{ // look at all subelements and map their names to color selectors
Node foo = colors_nlist.item(i);
if (foo.getNodeType()==Node.ELEMENT_NODE)
{ // map the element name to a color selector
Integer csel = (Integer)(colornames_map.get(foo.getNodeName()));
if (csel!=null)
{ // load the specified color into the colors array
DOMElementHelper foo_h = new DOMElementHelper((Element)foo);
colors_array[csel.intValue()] = foo_h.getElementText();
Node n = nl.item(i);
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // map the name of the node to a color selector
Integer cs = (Integer)(colornames_map.get(n.getNodeName()));
if (cs!=null)
{ // get the color value and load it into the array
DOMElementHelper h = new DOMElementHelper((Element)n);
colors_array[cs.intValue()] = h.getElementText();
} // end if
@@ -191,186 +158,57 @@ public class RenderConfig implements ColorSelectors
} // end for
try
{ // load in the footer logo scale
String tmp = render_sect_h.getSubElementText("footer-logo-scale");
if (tmp==null)
footer_logo_scale = 100;
else
footer_logo_scale = Integer.parseInt(tmp.trim());
// Load in the footer logo scale.
Integer itmp = sect_h.getSubElementInt("footer-logo-scale");
footer_logo_scale = ((itmp==null) ? 100 : itmp.intValue());
} // end try
catch (NumberFormatException nfe)
{ // just default on serious error
footer_logo_scale = 100;
} // end catch
Element paths_sect = root_h.getSubElement("paths");
if (paths_sect==null)
{ // no <paths/> section - bail out now!
logger.fatal("config document has no <paths/> section");
throw new ConfigException("no <paths/> section found in config file",root);
} // end if
DOMElementHelper paths_sect_h = new DOMElementHelper(paths_sect);
image_url = paths_sect_h.getSubElementText("image");
if (image_url==null)
{ // no <image/> tag - bail out now!
logger.fatal("<paths/> section has no <image/> element");
throw new ConfigException("no <image/> found in <paths/> section",paths_sect);
} // end if
// Get the <paths/> section.
sect = loader.configGetSubSection(root_h,"paths");
sect_h = new DOMElementHelper(sect);
// Load the image path.
image_url = loader.configGetSubElementText(sect_h,"image");
if (logger.isDebugEnabled())
logger.debug("Image path: " + image_url);
static_url = paths_sect_h.getSubElementText("static");
if (static_url==null)
{ // no <static/> tag - bail out now!
logger.fatal("<paths/> section has no <static/> element");
throw new ConfigException("no <static/> found in <paths/> section",paths_sect);
} // end if
// Load the static path.
static_url = loader.configGetSubElementText(sect_h,"static");
if (logger.isDebugEnabled())
logger.debug("Static files path: " + static_url);
Element site_logo_elt = paths_sect_h.getSubElement("site-logo");
if (site_logo_elt==null)
{ // no <site-logo/> tag - bail out now!
logger.fatal("<paths/> section has no <site-logo/> element");
throw new ConfigException("no <site-logo/> found in <paths/> section",paths_sect);
// Get the site logo element.
sect1 = loader.configGetSubSection(sect_h,"site-logo");
DOMElementHelper sect1_h = new DOMElementHelper(sect1);
site_logo = loader.configGetText(sect1_h);
} // end if
// Get the width and height of the logo.
itmp = sect1_h.getAttributeInt("width");
if (itmp!=null)
site_logo_width = itmp.intValue();
itmp = sect1_h.getAttributeInt("height");
if (itmp!=null)
site_logo_height = itmp.intValue();
DOMElementHelper site_logo_h = new DOMElementHelper(site_logo_elt);
site_logo = site_logo_h.getElementText();
if (site_logo==null)
{ // no site logo specified - bail out now!
logger.fatal("<paths/> section has no site logo element");
throw new ConfigException("no site logo found in <paths/> section",paths_sect);
} // end if
// get logo width and height
Integer fooint = site_logo_h.getAttributeInt("width");
if (fooint!=null)
site_logo_width = fooint.intValue();
fooint = site_logo_h.getAttributeInt("height");
if (fooint!=null)
site_logo_height = fooint.intValue();
// get logo link URL
String tmp = site_logo_elt.getAttribute("href");
// Get the link URL of the logo.
tmp = sect1.getAttribute("href");
if (!(StringUtil.isStringEmpty(tmp)))
site_logo_linkURL = tmp;
if (logger.isDebugEnabled())
logger.debug("Site logo: " + site_logo);
// Load the sidebox configuration information.
String sidebox_config = paths_sect_h.getSubElementText("sidebox-config");
if (sidebox_config==null)
{ // the sidebox config was not present
logger.fatal("<paths/> section has no <sidebox-config/> element");
throw new ConfigException("no <sidebox-config/> found in <paths/> section",paths_sect);
} // end if
// Get the name of the sidebox configuration file.
String sidebox_config = loader.configGetSubElementText(sect_h,"sidebox-config");
if (!(sidebox_config.startsWith("/")))
sidebox_config = root_file_path + sidebox_config;
Document sb_doc = loadConfiguration(sidebox_config);
Element sb_root = sb_doc.getDocumentElement();
if (!(sb_root.getTagName().equals("sidebox-config")))
{ // the sidebox configuration file isn't the right type
logger.fatal("config document is not a <sidebox-config/> document (root tag: <"
+ sb_root.getTagName() + "/>)");
throw new ConfigException("document is not a <sidebox-config/> document",sb_root);
} // end if
NodeList sb_nodes = sb_root.getChildNodes();
HashMap tmp_factories = new HashMap();
for (i=0; i<sb_nodes.getLength(); i++)
{ // extract each sidebox section from the list and build a new master sidebox object
Node s = sb_nodes.item(i);
if ((s.getNodeType()==Node.ELEMENT_NODE) && (s.getNodeName().equals("sidebox")))
{ // get the various attributes of the sidebox
Element sb = (Element)s;
try
{ // get the ID of the sidebox first
tmp = sb.getAttribute("id");
if (StringUtil.isStringEmpty(tmp))
{ // there was no ID specified for the sidebox
logger.fatal("<sidebox/> specified with no ID!");
throw new ConfigException("no ID specified in <sidebox/>",sb);
} // end if
// convert to an integer which we'll be using later in the HashMap
Integer id = new Integer(tmp);
// get the name of the factory class
DOMElementHelper sb_h = new DOMElementHelper(sb);
tmp = sb_h.getSubElementText("factory-class");
if (StringUtil.isStringEmpty(tmp))
{ // the factory class was not specified!
logger.fatal("<sidebox/> config incomplete (missing <factory-class/>)!");
throw new ConfigException("configuration of <sidebox/> is not complete!",sb);
} // end if
Class factory_class = Class.forName(tmp);
SideBoxFactory factory = (SideBoxFactory)(factory_class.newInstance());
factory.setConfiguration(sb);
tmp_factories.put(id,factory);
} // end if
catch (NumberFormatException e1)
{ // ID value was not an integer
logger.fatal("<sidebox/> ID not numeric!");
throw new ConfigException("non-numeric ID specified in <sidebox/>",sb);
} // end catch
catch (ClassNotFoundException e2)
{ // sidebox could not be configured
logger.fatal("<sidebox/> config <factory-class/> not valid!",e2);
throw new ConfigException("<factory-class/> in <sidebox/> is not a valid class!",sb);
} // end catch
catch (IllegalAccessException e3)
{ // could not access class and/or constructor
logger.fatal("<sidebox/> <factory-class/> is not accessible!",e3);
throw new ConfigException("<factory-class/> in <sidebox/> is not accessible!",sb);
} // end catch
catch (InstantiationException e4)
{ // unable to create the class
logger.fatal("<sidebox/> <factory-class/> could not be instantiated!",e4);
throw new ConfigException("<factory-class/> in <sidebox/> could not be created!",sb);
} // end catch
catch (ClassCastException e5)
{ // the class is not a SideBoxFactory implementor - cannot create
logger.fatal("<sidebox/> <factory-class/> is not a SideBoxFactory!",e5);
throw new ConfigException("<factory-class/> in <sidebox/> is not the correct type!",sb);
} // end catch
} // end if
} // end for
sidebox_factories = Collections.unmodifiableMap(tmp_factories);
Element pna = paths_sect_h.getSubElement("photo-not-avail");
if (pna!=null)
{ // copy element text and fixup information
DOMElementHelper pna_h = new DOMElementHelper(pna);
photo_not_avail = pna_h.getElementText();
photo_not_avail_fixup = pna_h.hasAttribute("fixup");
// Get the name of the "photo not available" image.
sect1 = sect_h.getSubElement("photo-not-avail");
if (sect1!=null)
{ // load the element text and fixup information
sect1_h = new DOMElementHelper(sect1);
photo_not_avail = sect1_h.getElementText();
photo_not_avail_fixup = sect1_h.hasAttribute("fixup");
} // end if
else
@@ -380,84 +218,97 @@ public class RenderConfig implements ColorSelectors
} // end else
Element msg_sect = root_h.getSubElement("messages");
if (msg_sect==null)
{ // no <messages/> section - bail out now!
logger.fatal("config document has no <messages/> section");
throw new ConfigException("no <messages/> section found in config file",root);
// Get the name of the services configuration file.
String services_config = loader.configGetSubElementText(sect_h,"services-config");
if (!(services_config.startsWith("/")))
services_config = root_file_path + services_config;
} // end if
// Load the <messages/> section.
sect = loader.configGetSubSection(root_h,"messages");
// Initialize the stock messages list.
stock_messages = new HashMap();
NodeList msg_nodes = msg_sect.getChildNodes();
for (i=0; i<msg_nodes.getLength(); i++)
{ // examine all subnodes to add them to the message text
Node msgn = msg_nodes.item(i);
if (msgn.getNodeType()==Node.ELEMENT_NODE)
{ // add it to the hash table by its tag name
Element msgel = (Element)msgn;
DOMElementHelper h = new DOMElementHelper(msgel);
String txt = h.getElementText();
if (txt!=null)
stock_messages.put(msgel.getTagName(),txt.trim());
stock_messages = new StockMessages(sect);
} // end if
} // end for
if (logger.isDebugEnabled())
logger.debug(stock_messages.size() + " stock messages loaded from config");
Element menu_sect = root_h.getSubElement("menu-definitions");
if (menu_sect==null)
{ // no <menu-definitions/> section - bail out now!
logger.fatal("config document has no <menu-definitions/> section");
throw new ConfigException("no <menu-definitions/> section found in config file",root);
} // end if
// Load the <menu-definitions/> section.
sect = loader.configGetSubSection(root_h,"menu-definitions");
// Initialize the menus list.
menus = new HashMap();
NodeList menu_nodes = menu_sect.getChildNodes();
for (i=0; i<menu_nodes.getLength(); i++)
HashMap tmp_menus = new HashMap();
nl = sect.getChildNodes();
for (i=0; i<nl.getLength(); i++)
{ // look for <menudef> subnodes and use them to initialize menus
Node mn = menu_nodes.item(i);
if (mn.getNodeType()==Node.ELEMENT_NODE)
{ // found an element - now check it's name
if (mn.getNodeName().equals("menudef"))
{ // root of a menu definition - get its ID, build it, and save it
Element mel = (Element)mn;
String menuid = mel.getAttribute("id");
if (menuid==null)
{ // no menu ID attribute
logger.fatal("<menudef/> seen with no \"id\" attribute");
throw new ConfigException("<menudef/> seen with no \"id\" attribute",mel);
Node n = nl.item(i);
if (n.getNodeType()==Node.ELEMENT_NODE)
{ // verify that it's a menu definition, then get its ID and build a menu
loader.configVerifyNodeName(n,"menudef",sect);
String menuid = loader.configGetAttribute((Element)n,"id");
} // end if
// create the menu and add it to the mapping
LeftMenu menu = new LeftMenu(mel,menuid);
menus.put(menuid,menu);
if (logger.isDebugEnabled())
logger.debug("menu \"" + menuid + "\" defined");
} // end if (found the root of a menu definition)
else
{ // unknown element - bail out!
logger.fatal("config document has unknown node <" + mn.getNodeName() +
"/> inside <menu-definitions/>");
throw new ConfigException("unknown node name <" + mn.getNodeName() + "/> in <menu-definitions/>",
menu_sect);
} // end else
// create the menu and add it to the mapping
LeftMenu menu = new LeftMenu((Element)n,menuid);
tmp_menus.put(menuid,menu);
if (logger.isDebugEnabled())
logger.debug("menu \"" + menuid + "\" defined");
} // end if
// else just ignore it
} // end for
// save off the menus as an unmodifiable map
if (tmp_menus.isEmpty())
menus = Collections.EMPTY_MAP;
else
menus = Collections.unmodifiableMap(tmp_menus);
if (logger.isDebugEnabled())
logger.debug(menus.size() + " menu definitions loaded from config");
// done with the render-config.xml file
// Load up the sidebox-config.xml file.
doc = loader.loadConfigDocument(sidebox_config);
root = loader.configGetRootElement(doc,"sidebox-config");
// Examine the child nodes for sidebox configuration data.
nl = root.getChildNodes();
HashMap tmp_factories = new HashMap();
for (i=0; i<nl.getLength(); i++)
{ // extract each sidebox section from the list and build a new master sidebox object
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("sidebox")))
{ // get the ID for this sidebox
try
{ // get the ID and convert it to integer
tmp = loader.configGetAttribute((Element)n,"id");
itmp = new Integer(tmp);
} // end try
catch (NumberFormatException nfe)
{ // sidebox ID was not an integer!
logger.fatal("<sidebox/> ID not numeric!");
throw new ConfigException("non-numeric ID specified in <sidebox/>",(Element)n);
} // end catch
SideBoxFactory factory = createSideBoxFactory((Element)n);
tmp_factories.put(itmp,factory);
} // end if
// else ignore this node
} // end for
if (logger.isDebugEnabled())
logger.debug(menus.size() + " menu definitions loaded from config");
if (tmp_factories.isEmpty())
sidebox_factories = Collections.EMPTY_MAP;
else
sidebox_factories = Collections.unmodifiableMap(tmp_factories);
// done with the sidebox-config.xml file
// Load up the services-config.xml file.
doc = loader.loadConfigDocument(services_config);
root = loader.configGetRootElement(doc,"services-config");
root_h = new DOMElementHelper(root);
// Get the community section and pass it to the CommunityLeftMenuFactory.
comm_menu_fact = new CommunityLeftMenuFactory(root_h.getSubElement("community"));
} // end constructor
@@ -466,62 +317,44 @@ public class RenderConfig implements ColorSelectors
*--------------------------------------------------------------------------------
*/
private static Document loadConfiguration(String configname) throws ConfigException
private static SideBoxFactory createSideBoxFactory(Element cfg) throws ConfigException
{
try
{ // create a simple DOM parser by using the Java XML parsing API
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setNamespaceAware(false);
fac.setValidating(false);
DocumentBuilder parser = fac.newDocumentBuilder();
XMLLoader loader = XMLLoader.get();
String cname = loader.configGetSubElementText(cfg,"factory-class");
// access the config file and parse it into our config data tree
File configfile = new File(configname);
Document rc = parser.parse(configfile);
if (logger.isDebugEnabled())
logger.debug("configuration loaded successfully");
return rc;
try
{ // load the factory class and create an instance of the factory
SideBoxFactory factory = (SideBoxFactory)(Class.forName(cname).newInstance());
factory.setConfiguration(cfg);
return factory;
} // end try
catch (FactoryConfigurationError e1)
{ // if the document builder factory could not be created
logger.fatal("Parser factory configuration error: " + e1.getMessage(),e1);
throw new ConfigException("XML parser factory could not be created - " + e1.getMessage());
catch (ClassNotFoundException cnfe)
{ // sidebox could not be configured
logger.fatal("<sidebox/> config <factory-class/> not valid!",cnfe);
throw new ConfigException("<factory-class/> in <sidebox/> is not a valid class!",cfg);
} // end catch
catch (ParserConfigurationException e2)
{ // if the XML parser itself could not be created
logger.fatal("Parser configuration error: " + e2.getMessage(),e2);
throw new ConfigException("XML parser could not be created - " + e2.getMessage(),e2);
catch (IllegalAccessException iae)
{ // could not access class and/or constructor
logger.fatal("<sidebox/> <factory-class/> is not accessible!",iae);
throw new ConfigException("<factory-class/> in <sidebox/> is not accessible!",cfg);
} // end catch
catch (SAXException e3)
{ // if the XML parser choked on our document
if (e3 instanceof SAXParseException)
{ // we have a detailed message - make a proper exception
SAXParseException e3a = (SAXParseException)e3;
logger.fatal("Config file error [" + configname + ":" + e3a.getLineNumber() + ","
+ e3a.getColumnNumber() + "]: " + e3a.getMessage(),e3a);
throw new ConfigException("Configuration file error: " + e3a.getMessage() + " at line "
+ e3a.getLineNumber() + ", column " + e3a.getColumnNumber(),e3a);
} // end if
else
{ // generic exception - just send up a simple error message
logger.fatal("Config file error [" + configname + "]: " + e3.getMessage(),e3);
throw new ConfigException("Configuration file error - " + e3.getMessage(),e3);
} // end else
catch (InstantiationException ie)
{ // unable to create the class
logger.fatal("<sidebox/> <factory-class/> could not be instantiated!",ie);
throw new ConfigException("<factory-class/> in <sidebox/> could not be created!",cfg);
} // end catch
catch (IOException e4)
{ // error reading the config file itself off the disk
logger.fatal("IO error reading config: " + e4.getMessage(),e4);
throw new ConfigException("unable to read config file \"" + configname + "\" - " + e4.getMessage(),e4);
catch (ClassCastException cce)
{ // the class is not a SideBoxFactory implementor - cannot create
logger.fatal("<sidebox/> <factory-class/> is not a SideBoxFactory!",cce);
throw new ConfigException("<factory-class/> in <sidebox/> is not the correct type!",cfg);
} // end catch
} // end loadConfiguration
} // end createSideBoxFactory
/*--------------------------------------------------------------------------------
* External operations usable only by RenderData
@@ -740,6 +573,12 @@ public class RenderConfig implements ColorSelectors
} // end getPhotoNotAvailFixup
public CommunityLeftMenu createCommunityMenu(CommunityContext comm)
{
return comm_menu_fact.createMenu(comm);
} // end createCommunityMenu
/*--------------------------------------------------------------------------------
* Static operations for use by VeniceServlet
*--------------------------------------------------------------------------------

View File

@@ -15,16 +15,17 @@
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
package com.silverwrist.venice.servlets.format.menus;
import java.io.Writer;
import java.io.IOException;
import java.util.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.*;
public class MenuCommunity implements ComponentRender, ColorSelectors
public class CommunityLeftMenu implements ComponentRender, ColorSelectors
{
/*--------------------------------------------------------------------------------
* Attributes
@@ -43,7 +44,7 @@ public class MenuCommunity implements ComponentRender, ColorSelectors
*--------------------------------------------------------------------------------
*/
public MenuCommunity(CommunityContext ctxt)
CommunityLeftMenu(CommunityContext ctxt, List items)
{
try
{ // retrieve the contact info for this puppy
@@ -64,7 +65,7 @@ public class MenuCommunity implements ComponentRender, ColorSelectors
} // end catch
title = ctxt.getName();
items_list = ctxt.getCommunityFeaturesList();
items_list = items;
cid = ctxt.getCommunityID();
show_unjoin = ctxt.canUnjoin();
@@ -92,24 +93,21 @@ public class MenuCommunity implements ComponentRender, ColorSelectors
} // end if
// display the title
out.write("<B>" + StringUtil.encodeHTML(title) + "</B>");
out.write("<B>" + StringUtil.encodeHTML(title) + "</B><BR>");
// display the menu items
Iterator it = items_list.iterator();
String cparm = "sig=" + cid;
while (it.hasNext())
{ // display each menu item in turn
CommunityFeature ftr = (CommunityFeature)(it.next());
out.write("<BR>\n<A CLASS=\"lbar\" HREF=\""
+ rdat.getEncodedServletPath(ftr.getApplet() + "?" + cparm) + "\">" + hilite
+ StringUtil.encodeHTML(ftr.getName()) + "</FONT></A>\n");
ComponentRender cr = (ComponentRender)(it.next());
cr.renderHere(out,rdat);
} // end while
if (show_unjoin)
out.write("<P>\n<A CLASS=\"lbar\" HREF=\""
+ rdat.getEncodedServletPath("sigops?cmd=U&" + cparm) + "\">"
+ hilite + "Unjoin</FONT></A>\n");
out.write("<BR>\n<A CLASS=\"lbar\" HREF=\""
+ rdat.getEncodedServletPath("sigops?cmd=U&sig=" + cid) + "\">" + hilite
+ "Unjoin</FONT></A>\n");
out.write("\n"); // all done...
@@ -126,4 +124,4 @@ public class MenuCommunity implements ComponentRender, ColorSelectors
} // end getID
} // end class MenuCommunity
} // end class CommunityLeftMenu

View File

@@ -0,0 +1,117 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format.menus;
import java.util.Map;
import org.w3c.dom.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.util.XMLLoader;
class CommunityLeftMenuEntry implements Comparable
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private String symbol;
private int index;
private int sequence;
private LinkItem item;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
CommunityLeftMenuEntry(Element svc) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
symbol = loader.configGetAttribute(svc,"id");
index = loader.configGetAttributeInt(svc,"index");
Element link_elt = loader.configGetSubSection(svc,"link");
sequence = loader.configGetAttributeInt(link_elt,"sequence");
item = new LinkItem(link_elt);
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class Object
*--------------------------------------------------------------------------------
*/
public boolean equals(Object o)
{
if ((o==null) || !(o instanceof CommunityLeftMenuEntry))
return false;
CommunityLeftMenuEntry other = (CommunityLeftMenuEntry)o;
return (sequence==other.sequence);
} // end equals
public int hashCode()
{
return sequence;
} // end hashCode
/*--------------------------------------------------------------------------------
* Implementations from interface Comparable
*--------------------------------------------------------------------------------
*/
public int compareTo(Object o)
{
if (o==null)
throw new NullPointerException("compareTo null object!");
CommunityLeftMenuEntry other = (CommunityLeftMenuEntry)o; // may throw ClassCastException
return sequence - other.sequence;
} // end compareTo
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
final String getSymbol()
{
return symbol;
} // end getSymbol
final int getIndex()
{
return index;
} // end getIndex
final int getSequence()
{
return sequence;
} // end getSequence
final LinkItem resolveItem(Map vars)
{
return new LinkItem(item,vars);
} // end resolveItem
} // end class CommunityLeftMenuEntry

View File

@@ -0,0 +1,130 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format.menus;
import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
public class CommunityLeftMenuFactory
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private List entries;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public CommunityLeftMenuFactory(Element comm_sect) throws ConfigException
{
if (comm_sect!=null)
{ // look for community services
NodeList nl = comm_sect.getChildNodes();
ArrayList tmp_entries = new ArrayList(nl.getLength());
for (int i=0; i<nl.getLength(); i++)
{ // get each node and see if it's a service node
Node n = nl.item(i);
if ((n.getNodeType()==Node.ELEMENT_NODE) && (n.getNodeName().equals("service")))
{ // create a template LeftMenuEntry and add it
CommunityLeftMenuEntry ent = new CommunityLeftMenuEntry((Element)n);
tmp_entries.add(ent);
} // end if
} // end for
if (tmp_entries.isEmpty())
entries = Collections.EMPTY_LIST;
else
{ // sort the list by sequence before we save it
if (tmp_entries.size()>1)
Collections.sort(tmp_entries);
tmp_entries.trimToSize();
entries = Collections.unmodifiableList(tmp_entries);
} // end else
} // end if
else // no communty services - initialize to null
entries = Collections.EMPTY_LIST;
} // end constructor
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public CommunityLeftMenu createMenu(CommunityContext comm)
{
// N.B. This implementation will change once the engine uses the SCM to return the defined
// community services.
List items;
if (entries.size()>0)
{ // Get the community features list and stash the indexes in a set.
HashSet defined = new HashSet();
List ftr_list = comm.getCommunityFeaturesList();
Iterator it = ftr_list.iterator();
while (it.hasNext())
{ // add each index to the set
CommunityFeature ftr = (CommunityFeature)(it.next());
defined.add(new Integer(ftr.getFeatureCode()));
} // end while
// Create the map used to replace the variables in the menu items.
HashMap vars = new HashMap();
vars.put("cid",String.valueOf(comm.getCommunityID()));
// Run through the list of entries (sorted by sequence) and add them.
ArrayList tmp_items = new ArrayList(defined.size());
it = entries.iterator();
while (it.hasNext())
{ // get this entry and see if there's a match in the set
CommunityLeftMenuEntry ntry = (CommunityLeftMenuEntry)(it.next());
if (defined.contains(new Integer(ntry.getIndex())))
tmp_items.add(ntry.resolveItem(vars));
} // end while
if (tmp_items.isEmpty()) // dummy out the list
items = Collections.EMPTY_LIST;
else
{ // make the list unmodifiable
tmp_items.trimToSize();
items = Collections.unmodifiableList(tmp_items);
} // end else
} // end if
else // no defined services - short-circuit the whole business
items = Collections.EMPTY_LIST;
// the constructor will handle the rest of the initialization
return new CommunityLeftMenu(comm,items);
} // end createMenu
} // end class CommunityLeftMenuFactory

View File

@@ -19,6 +19,7 @@ package com.silverwrist.venice.servlets.format.menus;
import java.io.Writer;
import java.io.IOException;
import java.util.Map;
import org.apache.log4j.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
@@ -53,7 +54,7 @@ class LinkItem implements ComponentRender, ColorSelectors
private ComponentRender contents;
/*--------------------------------------------------------------------------------
* Constructor
* Constructors
*--------------------------------------------------------------------------------
*/
@@ -103,6 +104,16 @@ class LinkItem implements ComponentRender, ColorSelectors
} // end constructor
LinkItem(LinkItem other, Map vars)
{
this.href = StringUtil.replaceAllVariables(other.href,vars);
this.type = other.type;
this.enabled = other.enabled;
this.target = other.target;
this.contents = other.contents;
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface ComponentRender
*--------------------------------------------------------------------------------