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:
@@ -27,7 +27,7 @@ import org.w3c.dom.*;
|
||||
* @version X
|
||||
* @see org.w3c.dom.Element
|
||||
*/
|
||||
public class DOMElementHelper
|
||||
public final class DOMElementHelper
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
@@ -65,7 +65,7 @@ public class DOMElementHelper
|
||||
* @return The text content under this <CODE>Element</CODE> node. If the specified <CODE>Element</CODE>
|
||||
* has no text nodes underneath it, returns <CODE>null.</CODE>
|
||||
*/
|
||||
private static String getTextOfElement(Element e)
|
||||
private static final String getTextOfElement(Element e)
|
||||
{
|
||||
NodeList kids = e.getChildNodes();
|
||||
if (kids==null)
|
||||
@@ -94,6 +94,30 @@ public class DOMElementHelper
|
||||
|
||||
} // end getTextOfElement
|
||||
|
||||
/**
|
||||
* Returns the value of the text of the specified <CODE>Element</CODE>, expressed as an integer.
|
||||
*
|
||||
* @param e The <CODE>Element</CODE> to extract text from.
|
||||
* @return An <CODE>Integer</CODE> object containing the value of the specified element. If
|
||||
* the <CODE>Element</CODE> has no text, or if the text cannot be expressed as an integer,
|
||||
* returns <CODE>null</CODE>.
|
||||
*/
|
||||
private static final Integer getIntegerFromElement(Element e)
|
||||
{
|
||||
try
|
||||
{ // extract the text and create an Integer around it
|
||||
String s = getTextOfElement(e);
|
||||
return ((s==null) ? null : new Integer(s.trim()));
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException nfe)
|
||||
{ // value cannot be parsed as an integer
|
||||
return null;
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end getIntegerFromElement
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -104,7 +128,7 @@ public class DOMElementHelper
|
||||
*
|
||||
* @return See above.
|
||||
*/
|
||||
public Element getElement()
|
||||
public final Element getElement()
|
||||
{
|
||||
return elt;
|
||||
|
||||
@@ -118,7 +142,7 @@ public class DOMElementHelper
|
||||
* If the <CODE>Element</CODE> has no child <CODE>Elements</CODE> with the given name,
|
||||
* the method returns <CODE>null</CODE>.
|
||||
*/
|
||||
public Element getSubElement(String name)
|
||||
public final Element getSubElement(String name)
|
||||
{
|
||||
NodeList kids = elt.getChildNodes();
|
||||
if (kids==null)
|
||||
@@ -142,12 +166,25 @@ public class DOMElementHelper
|
||||
* @return The text content under the wrapped <CODE>Element</CODE> node. If the wrapped <CODE>Element</CODE>
|
||||
* has not text nodes underneath it, returns <CODE>null.</CODE>
|
||||
*/
|
||||
public String getElementText()
|
||||
public final String getElementText()
|
||||
{
|
||||
return getTextOfElement(elt);
|
||||
|
||||
} // end getElementText
|
||||
|
||||
/**
|
||||
* Returns the value of the text of the wrapped <CODE>Element</CODE>, expressed as an integer.
|
||||
*
|
||||
* @return An <CODE>Integer</CODE> object containing the value of the wrapped element. If
|
||||
* the <CODE>Element</CODE> has no text, or if the text cannot be expressed as an integer,
|
||||
* returns <CODE>null</CODE>.
|
||||
*/
|
||||
public final Integer getElementInt()
|
||||
{
|
||||
return getIntegerFromElement(elt);
|
||||
|
||||
} // end getElementInt
|
||||
|
||||
/**
|
||||
* Returns the content of all text nodes underneath the first sub-element of the wrapped
|
||||
* <CODE>Element</CODE>, with the given name, concatenated together into a single string.
|
||||
@@ -157,16 +194,30 @@ public class DOMElementHelper
|
||||
* If the wrapped <CODE>Element</CODE> does not have a sub-element with the given name, or
|
||||
* that sub-element has no text nodes underneath it, returns <CODE>null.</CODE>
|
||||
*/
|
||||
public String getSubElementText(String name)
|
||||
public final String getSubElementText(String name)
|
||||
{
|
||||
Element se = getSubElement(name);
|
||||
if (se==null)
|
||||
return null;
|
||||
else
|
||||
return getTextOfElement(se);
|
||||
return ((se==null) ? null : getTextOfElement(se));
|
||||
|
||||
} // end getSubElementText
|
||||
|
||||
/**
|
||||
* Returns the value of the text underneath the first sub-element of the wrapped
|
||||
* <CODE>Element</CODE>, with the given name, expressed as an integer.
|
||||
*
|
||||
* @param name The name of the sub-element to search for.
|
||||
* @return An <CODE>Integer</CODE> object containing the value of the specified element. If
|
||||
* the wrapped <CODE>Element</CODE> does not have a sub-element with the given name, or that
|
||||
* sub-element has no text, or if the text cannot be expressed as an integer, returns
|
||||
* <CODE>null</CODE>.
|
||||
*/
|
||||
public final Integer getSubElementInt(String name)
|
||||
{
|
||||
Element se = getSubElement(name);
|
||||
return ((se==null) ? null : getIntegerFromElement(se));
|
||||
|
||||
} // end getSubElementInt
|
||||
|
||||
/**
|
||||
* Determines whether the wrapped <CODE>Element</CODE> has a sub-element with the given name.
|
||||
*
|
||||
@@ -174,10 +225,9 @@ public class DOMElementHelper
|
||||
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has a sub-element with the
|
||||
* specified name, <CODE>false</CODE> if not.
|
||||
*/
|
||||
public boolean hasChildElement(String name)
|
||||
public final boolean hasChildElement(String name)
|
||||
{
|
||||
Element tmp = getSubElement(name);
|
||||
return (tmp==null) ? false : true;
|
||||
return (getSubElement(name)!=null);
|
||||
|
||||
} // end hasChildElement
|
||||
|
||||
@@ -188,7 +238,7 @@ public class DOMElementHelper
|
||||
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has an attribute with the
|
||||
* specified name, <CODE>false</CODE> if not.
|
||||
*/
|
||||
public boolean hasAttribute(String name)
|
||||
public final boolean hasAttribute(String name)
|
||||
{
|
||||
return !(StringUtil.isStringEmpty(elt.getAttribute(name)));
|
||||
|
||||
@@ -203,14 +253,14 @@ public class DOMElementHelper
|
||||
* the wrapped <CODE>Element</CODE> has no such attribute, or if the attribute's value
|
||||
* cannot be expressed as an integer, returns <CODE>null</CODE>.
|
||||
*/
|
||||
public Integer getAttributeInt(String name)
|
||||
public final Integer getAttributeInt(String name)
|
||||
{
|
||||
String tmp = elt.getAttribute(name);
|
||||
if (StringUtil.isStringEmpty(tmp))
|
||||
return null;
|
||||
try
|
||||
{ // convert to an Integer
|
||||
return new Integer(tmp);
|
||||
return new Integer(tmp.trim());
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException nfe)
|
||||
|
||||
85
src/com/silverwrist/util/StockMessages.java
Normal file
85
src/com/silverwrist/util/StockMessages.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.log4j.*;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
public final class StockMessages
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Category logger = Category.getInstance(StockMessages.class);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private Map msgmap;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public StockMessages(Element elt)
|
||||
{
|
||||
HashMap tmp_msgmap = new HashMap();
|
||||
NodeList msgs = elt.getChildNodes();
|
||||
for (int i=0; i<msgs.getLength(); i++)
|
||||
{ // check each sub-element, get its message, and load it
|
||||
Node n = msgs.item(i);
|
||||
if (n.getNodeType()==Node.ELEMENT_NODE)
|
||||
{ // add this node to the hashmap by its tag name
|
||||
DOMElementHelper h = new DOMElementHelper((Element)n);
|
||||
String txt = h.getElementText();
|
||||
if (txt!=null)
|
||||
tmp_msgmap.put(n.getNodeName(),txt.trim());
|
||||
|
||||
} // end if
|
||||
|
||||
} // end for
|
||||
|
||||
if (tmp_msgmap.size()>0)
|
||||
msgmap = Collections.unmodifiableMap(tmp_msgmap);
|
||||
else
|
||||
msgmap = Collections.EMPTY_MAP;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug(msgmap.size() + " stock message(s) loaded from <" + elt.getTagName() + "/> section");
|
||||
|
||||
} // end constructor
|
||||
|
||||
public final String get(String name)
|
||||
{
|
||||
return (String)(msgmap.get(name));
|
||||
|
||||
} // end get
|
||||
|
||||
public final String getReplace(String name, Map vars)
|
||||
{
|
||||
return StringUtil.replaceAllVariables((String)(msgmap.get(name)),vars);
|
||||
|
||||
} // end getReplace
|
||||
|
||||
} // end class StockMessages
|
||||
Reference in New Issue
Block a user