diff --git a/build.properties.sample b/build.properties.sample
index 6fb7ae3..6d9b567 100644
--- a/build.properties.sample
+++ b/build.properties.sample
@@ -65,3 +65,8 @@ jacl.base=/usr/local/java/jacl1.3.1
rhino.base=/usr/local/java/rhino1_5R4_1
# rhino.lib=${rhino.base}
# rhino.jarfile=js.jar
+
+# [Location of Velocity 1.4]
+velocity.base=/usr/local/java/velocity-1.4
+# velocity.lib=${velocity.base}
+# velocity.jarfile=velocity-1.4.jar
diff --git a/build.xml b/build.xml
index 3ddcba5..e8f2228 100644
--- a/build.xml
+++ b/build.xml
@@ -79,6 +79,11 @@
+
+
+
+
+
@@ -90,6 +95,7 @@
+
+
+
+
diff --git a/etc/ui-config.xml b/etc/ui-config.xml
index 4a39799..28357d3 100644
--- a/etc/ui-config.xml
+++ b/etc/ui-config.xml
@@ -34,6 +34,9 @@
WEB-INF/temp
+
+ WEB-INF/templates
+
diff --git a/src/com/silverwrist/venice/ui/config/RootConfig.java b/src/com/silverwrist/venice/ui/config/RootConfig.java
index 81cd7a0..284babb 100644
--- a/src/com/silverwrist/venice/ui/config/RootConfig.java
+++ b/src/com/silverwrist/venice/ui/config/RootConfig.java
@@ -49,24 +49,25 @@ public class RootConfig implements LinkTypes, ColorSelectors
private static Logger logger = Logger.getLogger(RootConfig.class);
- private static final Map link_types;
+ private static final Map s_link_types;
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
- private String script_directory; // the scripts directory
- private String rpc_script_directory; // the RPC scripts directory
- private String temp_directory; // the temporary directory
- private String image_path; // the images path
- private String static_path; // the static files path
- private String external_static_path; // the external static files path
- private String format_path; // the JSP formatter path
- private String blank_photo_path; // the "photo not available" path
- private Properties properties; // the property list
- private String frame_jsp_name; // the name of the frame JSP
- private String site_title; // the title for the site
+ private String m_script_directory; // the scripts directory
+ private String m_rpc_script_directory; // the RPC scripts directory
+ private String m_temp_directory; // the temporary directory
+ private String m_template_directory; // the Velocity templates directory
+ private String m_image_path; // the images path
+ private String m_static_path; // the static files path
+ private String m_external_static_path; // the external static files path
+ private String m_format_path; // the JSP formatter path
+ private String m_blank_photo_path; // the "photo not available" path
+ private Properties m_properties; // the property list
+ private String m_frame_jsp_name; // the name of the frame JSP
+ private String m_site_title; // the title for the site
private File stylesheet; // the stylesheet file reference
private long stylesheet_lastchange; // when was the stylesheet last changed?
private boolean smart_tags; // do we want to allow M$ IE6 Smart Tags?
@@ -74,23 +75,23 @@ public class RootConfig implements LinkTypes, ColorSelectors
private String site_logo_href = null; // the HREF to surround the site logo with
private int site_logo_href_type = -1; // the type of the above href
private String venice_logo_tag; // the HTML snippet containing the Venice logo
- private String page_icon_tags = null; // the HTML snippet containing the page icons
- private String font_face; // the default font face name
- private String base_font; // the default tag
+ private String m_page_icon_tags = null; // the HTML snippet containing the page icons
+ private String m_font_face; // the default font face name
+ private String m_base_font; // the default tag
private Map m_font_sizes; // the stock font sizes
- private ColorPalette colors; // all the colors
+ private ColorPalette m_colors; // all the colors
private boolean html_comments; // do we want to embed HTML comments?
private ButtonHolder buttons; // the button definitions
private String[] content_hdr; // the content header parts
private Remapper remapper; // the URL remapper
- private int rpc_timeout = 60; // RPC session timeout
- private List xmlrpc_methods; // the list of XML-RPC methods
- private StockMessages stock_messages; // the stock messages
- private Map menus; // the menus
+ private int m_rpc_timeout = 60; // RPC session timeout
+ private List m_xmlrpc_methods; // the list of XML-RPC methods
+ private StockMessages m_stock_messages; // the stock messages
+ private Map m_menus; // the menus
private Map m_menu_templates; // the menu templates
- private DialogManager dialogs; // the dialog manager
- private SideBoxManager sideboxes; // the sidebox manager
- private CommunityMenuFactory comm_menu_fact; // the community menu factory
+ private DialogManager m_dialogs; // the dialog manager
+ private SideBoxManager m_sideboxes; // the sidebox manager
+ private CommunityMenuFactory m_comm_menu_fact; // the community menu factory
/*--------------------------------------------------------------------------------
* Constructor
@@ -120,84 +121,47 @@ public class RootConfig implements LinkTypes, ColorSelectors
services_config = root_file_path + services_config;
// Get the full pathname of the script directory.
- script_directory = loader.configGetSubElementText(sect_h,"script-dir");
- if (!(script_directory.startsWith("/")))
- script_directory = root_file_path + script_directory;
- if (!(script_directory.endsWith("/")))
- script_directory = script_directory + "/";
-
- // Test to make sure the script directory exists.
- File t_file = new File(script_directory);
- if (!(t_file.isDirectory()))
- { // script directory does not exist - throw exception
- logger.fatal(" directory \"" + script_directory + "\" is not a directory");
- throw new ConfigException("specified is not a directory",
- sect_h.getSubElement("script-dir"));
-
- } // end if
+ m_script_directory = getRelativeDirectory(sect_h,"script-dir",root_file_path,true);
// Get the full pathname of the RPC script directory.
- rpc_script_directory = loader.configGetSubElementText(sect_h,"rpc-script-dir");
- if (!(rpc_script_directory.startsWith("/")))
- rpc_script_directory = root_file_path + rpc_script_directory;
- if (!(rpc_script_directory.endsWith("/")))
- rpc_script_directory = rpc_script_directory + "/";
-
- // Test to make sure the RPC script directory exists.
- t_file = new File(rpc_script_directory);
- if (!(t_file.isDirectory()))
- { // script directory does not exist - throw exception
- logger.fatal(" directory \"" + rpc_script_directory + "\" is not a directory");
- throw new ConfigException("specified is not a directory",
- sect_h.getSubElement("rpc-script-dir"));
-
- } // end if
+ m_rpc_script_directory = getRelativeDirectory(sect_h,"rpc-script-dir",root_file_path,true);
// Get the full pathname of the temporary directory.
- temp_directory = loader.configGetSubElementText(sect_h,"temp-dir");
- if (!(temp_directory.startsWith("/")))
- temp_directory = root_file_path + temp_directory;
+ m_temp_directory = getRelativeDirectory(sect_h,"temp-dir",root_file_path,false);
- // Test to make sure the temporary directory exists.
- t_file = new File(temp_directory);
- if (!(t_file.isDirectory()))
- { // temporary directory does not exist - throw exception
- logger.fatal(" directory \"" + temp_directory + "\" is not a directory");
- throw new ConfigException("specified is not a directory",
- sect_h.getSubElement("temp-dir"));
-
- } // end if
+ // Get the full pathname of the Velocity template directory.
+ m_template_directory = getRelativeDirectory(sect_h,"template-dir",root_file_path,false);
// Get the section.
sect = loader.configGetSubSection(root_h,"uri-paths");
sect_h = new DOMElementHelper(sect);
// Get the images path.
- image_path = loader.configGetSubElementText(sect_h,"image");
- if (!(image_path.endsWith("/")))
- image_path = image_path + "/";
+ m_image_path = loader.configGetSubElementText(sect_h,"image");
+ if (!(m_image_path.endsWith("/")))
+ m_image_path = m_image_path + "/";
// Get the static path.
- static_path = loader.configGetSubElementText(sect_h,"static");
- if (!(static_path.endsWith("/")))
- static_path = static_path + "/";
+ m_static_path = loader.configGetSubElementText(sect_h,"static");
+ if (!(m_static_path.endsWith("/")))
+ m_static_path = m_static_path + "/";
// Get the external static path.
- external_static_path = loader.configGetSubElementText(sect_h,"external-static");
- if (!(external_static_path.endsWith("/")))
- external_static_path = external_static_path + "/";
+ m_external_static_path = loader.configGetSubElementText(sect_h,"external-static");
+ if (!(m_external_static_path.endsWith("/")))
+ m_external_static_path = m_external_static_path + "/";
// Get the format JSP path.
- format_path = loader.configGetSubElementText(sect_h,"format-jsp");
- if (!(format_path.endsWith("/")))
- format_path = format_path + "/";
+ m_format_path = loader.configGetSubElementText(sect_h,"format-jsp");
+ if (!(m_format_path.endsWith("/")))
+ m_format_path = m_format_path + "/";
// Get the pathname of the "photo not available" image.
- blank_photo_path = loader.configGetSubElementText(sect_h,"photo-not-avail");
+ m_blank_photo_path = loader.configGetSubElementText(sect_h,"photo-not-avail");
Element sect1 = sect_h.getSubElement("photo-not-avail");
DOMElementHelper sect1_h = new DOMElementHelper(sect1);
if (sect1_h.hasAttribute("fixup"))
- blank_photo_path = image_path + blank_photo_path;
+ m_blank_photo_path = m_image_path + m_blank_photo_path;
// Load the default properties from the resources.
Properties defprops = new Properties();
@@ -212,7 +176,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end catch
- properties = new Properties(defprops); // create the actual properties
+ m_properties = new Properties(defprops); // create the actual properties
// Get the section.
sect = loader.configGetSubSection(root_h,"properties");
@@ -229,7 +193,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
if ((n.getNodeType()==Node.ELEMENT_NODE) && n.getNodeName().equals("property"))
{ // add the property value to the map
sect1 = (Element)n;
- properties.setProperty(loader.configGetAttribute(sect1,"name"),loader.configGetText(sect1));
+ m_properties.setProperty(loader.configGetAttribute(sect1,"name"),loader.configGetText(sect1));
} // end if
@@ -243,10 +207,10 @@ public class RootConfig implements LinkTypes, ColorSelectors
// Get the name of the frame JSP.
String tmp = loader.configGetSubElementText(sect_h,"jsp-name");
- frame_jsp_name = format_path + tmp;
+ m_frame_jsp_name = m_format_path + tmp;
// Get the site title.
- site_title = sect_h.getSubElementText("site-title");
+ m_site_title = sect_h.getSubElementText("site-title");
// Get the base font size.
Integer bf_size = sect_h.getSubElementInt("basefont-size");
@@ -285,7 +249,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
sect1 = loader.configGetSubSection(sect_h,"site-logo");
sect1_h = new DOMElementHelper(sect1);
StringBuffer tmpbuf = new StringBuffer(" type=\"" + tmp + "\" is not a valid value");
@@ -336,7 +300,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
itmp = new Integer(100);
int tmp_width = (VENICE_IMAGE_WIDTH * itmp.intValue()) / 100;
int tmp_height = (VENICE_IMAGE_HEIGHT * itmp.intValue()) / 100;
- venice_logo_tag = "";
@@ -362,17 +326,17 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end if
if (page_icon_1==null)
- page_icon_tags = page_icon_2; // just use "shortcut icon"
+ m_page_icon_tags = page_icon_2; // just use "shortcut icon"
else
- page_icon_tags = page_icon_1 + page_icon_2; // use both tags
+ m_page_icon_tags = page_icon_1 + page_icon_2; // use both tags
// Get the section.
sect = loader.configGetSubSection(root_h,"rendering");
sect_h = new DOMElementHelper(sect);
// Get the default font face name.
- font_face = loader.configGetSubElementText(sect_h,"font");
- base_font = "";
+ m_font_face = loader.configGetSubElementText(sect_h,"font");
+ m_base_font = "";
// Load the stock font sizes.
sect1 = sect_h.getSubElement("font-sizes");
@@ -404,7 +368,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
m_font_sizes = Collections.EMPTY_MAP;
// Load all the colors.
- colors = new ColorPalette(loader.configGetSubSection(sect_h,"colors"));
+ m_colors = new ColorPalette(loader.configGetSubSection(sect_h,"colors"));
// Set up the content header array.
content_hdr = new String[5];
@@ -419,7 +383,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
// Get the "Buttons" section and initialize it.
sect1 = loader.configGetSubSection(sect_h,"buttons");
- buttons = new ButtonHolder(sect1,image_path);
+ buttons = new ButtonHolder(sect1,m_image_path);
// Get the section.
sect = loader.configGetSubSection(root_h,"remapper");
@@ -437,8 +401,8 @@ public class RootConfig implements LinkTypes, ColorSelectors
Integer xtmp = sect_h.getSubElementInt("session-timeout");
if (xtmp==null)
throw new ConfigException(" value is not an integer",sect);
- rpc_timeout = xtmp.intValue();
- if (rpc_timeout<=0)
+ m_rpc_timeout = xtmp.intValue();
+ if (m_rpc_timeout<=0)
throw new ConfigException(" value is invalid",sect);
} // end if
@@ -460,11 +424,11 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end for
if (tmp_alist.isEmpty())
- xmlrpc_methods = Collections.EMPTY_LIST;
+ m_xmlrpc_methods = Collections.EMPTY_LIST;
else
{ // save off the methods list
tmp_alist.trimToSize();
- xmlrpc_methods = Collections.unmodifiableList(tmp_alist);
+ m_xmlrpc_methods = Collections.unmodifiableList(tmp_alist);
} // end else
@@ -472,7 +436,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
sect = loader.configGetSubSection(root_h,"messages");
// Initialize the stock messages list.
- stock_messages = new StockMessages(sect);
+ m_stock_messages = new StockMessages(sect);
// Get the section.
sect = loader.configGetSubSection(root_h,"menu-definitions");
@@ -495,9 +459,9 @@ public class RootConfig implements LinkTypes, ColorSelectors
} // end for
if (tmap.isEmpty())
- menus = Collections.EMPTY_MAP;
+ m_menus = Collections.EMPTY_MAP;
else
- menus = Collections.unmodifiableMap(tmap);
+ m_menus = Collections.unmodifiableMap(tmap);
// Get the section.
sect = loader.configGetSubSection(root_h,"menu-template-definitions");
@@ -528,7 +492,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
sect = loader.configGetSubSection(root_h,"dialog-definitions");
// Initialize the dialog manager.
- dialogs = new DialogManager(this,sect);
+ m_dialogs = new DialogManager(this,sect);
// done with the ui-config.xml file
// Load up the sidebox-config.xml file.
@@ -536,7 +500,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
root = loader.configGetRootElement(doc,"sidebox-config");
// Create the sidebox manager.
- sideboxes = new SideBoxManager(root);
+ m_sideboxes = new SideBoxManager(root);
// done with the sidebox-config.xml file
// Load up the services-config.xml file.
@@ -545,7 +509,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
root_h = new DOMElementHelper(root);
// Get the community section and pass it to the CommunityMenuFactory.
- comm_menu_fact = new CommunityMenuFactory(root_h.getSubElement("community"),this);
+ m_comm_menu_fact = new CommunityMenuFactory(root_h.getSubElement("community"),this);
} // end constructor
@@ -554,6 +518,32 @@ public class RootConfig implements LinkTypes, ColorSelectors
*--------------------------------------------------------------------------------
*/
+ private static final String getRelativeDirectory(DOMElementHelper sect_h, String tagname, String root_file_path,
+ boolean addslash) throws ConfigException
+ {
+ XMLLoader loader = XMLLoader.get();
+
+ // Get the full pathname of the directory.
+ String rc = loader.configGetSubElementText(sect_h,tagname);
+ if (!(rc.startsWith("/")))
+ rc = root_file_path + rc;
+ if (addslash && !(rc.endsWith("/")))
+ rc += "/";
+
+ // Test to make sure the directory exists.
+ File tmp = new File(rc);
+ if (!(tmp.isDirectory()))
+ { // directory does not exist, throw exception
+ logger.fatal("<" + tagname + "/> directory \"" + rc + "\" is not a directory");
+ throw new ConfigException("specified <" + tagname + "/> is not a directory",
+ sect_h.getSubElement(tagname));
+
+ } // end if
+
+ return rc;
+
+ } // end getRelativeDirectory
+
private final String mapFontSize(String sz)
{
String rc = (String)(m_font_sizes.get(sz));
@@ -568,64 +558,70 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final String getTemporaryPath()
{
- return temp_directory;
+ return m_temp_directory;
} // end getTemporaryPath
+ public final String getVelocityTemplateDirectory()
+ {
+ return m_template_directory;
+
+ } // end getVelocityTemplateDirectory
+
public final String getImagePath(String img)
{
- return image_path + img;
+ return m_image_path + img;
} // end getImagePath
public final String getStaticPath(String s)
{
- return static_path + s;
+ return m_static_path + s;
} // end getImagePath
public final String getExternalStaticPath(String s)
{
- return external_static_path + s;
+ return m_external_static_path + s;
} // end getExternalStaticPath
public final String getFormatJSPPath(String jsp)
{
- return format_path + jsp;
+ return m_format_path + jsp;
} // end getFormatJSPPath
public final String getScriptPath(String sname)
{
- return script_directory + sname;
+ return m_script_directory + sname;
} // end getScriptPath
public final String getRPCScriptPath(String sname)
{
- return rpc_script_directory + sname;
+ return m_rpc_script_directory + sname;
} // end getRPCScriptPath
public final String getFrameJSPName()
{
- return frame_jsp_name;
+ return m_frame_jsp_name;
} // end getFrameJSPName
public final String getPageTitle(String t)
{
- if (site_title==null)
+ if (m_site_title==null)
return t;
else
- return t + " - " + site_title;
+ return t + " - " + m_site_title;
} // end getPageTitle
public final String getBaseFontTag()
{
- return base_font;
+ return m_base_font;
} // end getBaseFontTag
@@ -659,36 +655,36 @@ public class RootConfig implements LinkTypes, ColorSelectors
// Set up the replacements map to replace the various parameters.
HashMap vars = new HashMap();
- vars.put("font",font_face);
- colors.fillParameterMap("color.",vars);
+ vars.put("font",m_font_face);
+ m_colors.fillParameterMap("color.",vars);
return StringUtil.replaceAllVariables(raw_data.toString(),vars);
} // end loadStyleSheetData
public final String getColor(int selector)
{
- return colors.getColor(selector);
+ return m_colors.getColor(selector);
} // end getColor
public final String getColor(String name)
{
- return colors.getColor(name);
+ return m_colors.getColor(name);
} // end getColor
public final String getFontTag(int colorsel, int size)
{
- return "";
+ return "";
} // end getFontTag
public final String getFontTag(String color, int size)
{
StringBuffer rc = new StringBuffer("');
return rc.toString();
@@ -697,7 +693,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final String getFontTag(int colorsel, String size)
{
StringBuffer rc = new StringBuffer("');
@@ -708,9 +704,9 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final String getFontTag(String color, String size)
{
StringBuffer rc = new StringBuffer("');
@@ -750,20 +746,20 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final int convertLinkType(String str)
{
- Integer tmp = (Integer)(link_types.get(str.trim().toLowerCase()));
+ Integer tmp = (Integer)(s_link_types.get(str.trim().toLowerCase()));
return (tmp==null) ? -1 : tmp.intValue();
} // end convertLinkType
public final String getStockMessage(String key)
{
- return stock_messages.get(key);
+ return m_stock_messages.get(key);
} // end getStockMessage
public final String getStockMessage(String key, Map vars)
{
- return stock_messages.getReplace(key,vars);
+ return m_stock_messages.getReplace(key,vars);
} // end getStockMessage
@@ -781,7 +777,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final String getPageIconTags()
{
- return page_icon_tags;
+ return m_page_icon_tags;
} // end getPageIconTags
@@ -798,13 +794,13 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final MenuComponent getMenu(String name)
{
- return (MenuComponent)(menus.get(name));
+ return (MenuComponent)(m_menus.get(name));
} // end getMenu
public final MenuComponent getMenu(String name, Map vars)
{
- return new Menu((Menu)(menus.get(name)),vars);
+ return new Menu((Menu)(m_menus.get(name)),vars);
} // end getMenu
@@ -828,63 +824,63 @@ public class RootConfig implements LinkTypes, ColorSelectors
public final Dialog getDialog(String name)
{
- return dialogs.getDialog(name);
+ return m_dialogs.getDialog(name);
} // end getDialog
public final SideBoxManager getSideBoxManager()
{
- return sideboxes;
+ return m_sideboxes;
} // end getSideBoxManager
public final String getBlankPhoto()
{
- return blank_photo_path;
+ return m_blank_photo_path;
} // end getBlankPhoto
public final String getProperty(String name)
{
- return properties.getProperty(name);
+ return m_properties.getProperty(name);
} // end getProperty
public final String getProperty(String name, String default_val)
{
- return properties.getProperty(name,default_val);
+ return m_properties.getProperty(name,default_val);
} // end getProperty
public final CommunityMenu getCommunityMenu(CommunityContext comm)
{
- return comm_menu_fact.createMenu(comm);
+ return m_comm_menu_fact.createMenu(comm);
} // end getCommunityMenu
public final String getDefaultServletAddress(RequestInput inp, CommunityContext comm)
{
- return comm_menu_fact.getDefaultServletAddress(inp,comm);
+ return m_comm_menu_fact.getDefaultServletAddress(inp,comm);
} // end getDefaultServletAddress
public final int getRpcSessionTimeout()
{
- return rpc_timeout;
+ return m_rpc_timeout;
} // end getRpcSessionTimeout
public final List getXmlRpcMethods()
{
- return xmlrpc_methods;
+ return m_xmlrpc_methods;
} // end getXmlRpcMethods
public final void addFormatParams(Map map)
{
// add font and colors first
- map.put("font",font_face);
- colors.fillParameterMap("color.",map);
+ map.put("font",m_font_face);
+ m_colors.fillParameterMap("color.",map);
// now add font sizes
for (Iterator it=m_font_sizes.entrySet().iterator(); it.hasNext(); )
@@ -908,7 +904,7 @@ public class RootConfig implements LinkTypes, ColorSelectors
m.put("servlet",new Integer(SERVLET));
m.put("frame",new Integer(FRAME));
m.put("fullservlet",new Integer(FULLSERVLET));
- link_types = Collections.unmodifiableMap(m);
+ s_link_types = Collections.unmodifiableMap(m);
} // end static initializer
diff --git a/src/com/silverwrist/venice/ui/helpers/HTMLRendering.java b/src/com/silverwrist/venice/ui/helpers/HTMLRendering.java
index ebc95d3..59eea16 100644
--- a/src/com/silverwrist/venice/ui/helpers/HTMLRendering.java
+++ b/src/com/silverwrist/venice/ui/helpers/HTMLRendering.java
@@ -35,6 +35,8 @@ public interface HTMLRendering extends ColorSelectors, LinkTypes
public String formatURL(String url, int type);
+ public String formatURL(String url, String type);
+
public String formatDate(Date date);
public String getFontTag(int colorsel, int size);
diff --git a/src/com/silverwrist/venice/ui/servlet/BaseServlet.java b/src/com/silverwrist/venice/ui/servlet/BaseServlet.java
index b6fdbee..0e4a608 100644
--- a/src/com/silverwrist/venice/ui/servlet/BaseServlet.java
+++ b/src/com/silverwrist/venice/ui/servlet/BaseServlet.java
@@ -31,6 +31,7 @@ import com.silverwrist.venice.ui.helpers.ErrorBox;
import com.silverwrist.venice.ui.helpers.ThrowableContent;
import com.silverwrist.venice.ui.script.ScriptingException;
import com.silverwrist.venice.ui.script.ScriptManagerContainer;
+import com.silverwrist.venice.ui.velocity.VelocityRenderer;
public abstract class BaseServlet extends HttpServlet
{
@@ -415,6 +416,7 @@ public abstract class BaseServlet extends HttpServlet
} // end if
ScriptManagerContainer.initialize(rootconf,ctxt); // make sure container initialized
+ VelocityRenderer.init(ctxt,rootconf); // initialize Velocity renderer
BrowserDatabase.get(ctxt); // initialize browser database
} // end synchronized block
diff --git a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java
index 8a5b8a9..dd8c54a 100644
--- a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java
+++ b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java
@@ -40,6 +40,7 @@ import com.silverwrist.venice.ui.menus.Menu;
import com.silverwrist.venice.ui.menus.MenuComponent;
import com.silverwrist.venice.ui.menus.MenuTemplate;
import com.silverwrist.venice.ui.script.*;
+import com.silverwrist.venice.ui.velocity.*;
import com.silverwrist.venice.util.XMLLoader;
public class RequestImpl implements RequestInput
@@ -212,6 +213,22 @@ public class RequestImpl implements RequestInput
} // end if
+ if (c instanceof ContentVelocity)
+ { // render the object
+ VelocityRenderer vr = VelocityRenderer.get(ctxt);
+ vr.render((ContentVelocity)c,this,null);
+ return;
+
+ } // end if
+
+ if (c instanceof ContentVelocityOwnTemplate)
+ { // render the object
+ VelocityRenderer vr = VelocityRenderer.get(ctxt);
+ vr.render((ContentVelocityOwnTemplate)c,this,null);
+ return;
+
+ } // end if
+
// if nothing else...
this.write(c.toString());
@@ -254,6 +271,22 @@ public class RequestImpl implements RequestInput
} // end if
+ if (c instanceof ContentVelocity)
+ { // render the object
+ VelocityRenderer vr = VelocityRenderer.get(ctxt);
+ vr.render((ContentVelocity)c,this,out);
+ return;
+
+ } // end if
+
+ if (c instanceof ContentVelocityOwnTemplate)
+ { // render the object
+ VelocityRenderer vr = VelocityRenderer.get(ctxt);
+ vr.render((ContentVelocityOwnTemplate)c,this,out);
+ return;
+
+ } // end if
+
this.output(c); // fall back in ContentJSP case
} // end output
@@ -2046,10 +2079,10 @@ class HTMLRenderingImpl implements HTMLRendering
*--------------------------------------------------------------------------------
*/
- private RequestImpl req; // request we're attached to
- private RootConfig config; // configuration data
- private DateFormat display_date = null; // format to use for displaying dates
- private DateFormat activity_time = null; // format to use for activity string times
+ private RequestImpl m_req; // request we're attached to
+ private RootConfig m_config; // configuration data
+ private DateFormat m_display_date = null; // format to use for displaying dates
+ private DateFormat m_activity_time = null; // format to use for activity string times
/*--------------------------------------------------------------------------------
* Constructor
@@ -2058,8 +2091,8 @@ class HTMLRenderingImpl implements HTMLRendering
HTMLRenderingImpl(RequestImpl req, RootConfig config)
{
- this.req = req;
- this.config = config;
+ this.m_req = req;
+ this.m_config = config;
} // end constructor
@@ -2070,19 +2103,19 @@ class HTMLRenderingImpl implements HTMLRendering
public String getColor(int selector)
{
- return config.getColor(selector);
+ return m_config.getColor(selector);
} // end getColor
public String getColor(String name)
{
- return config.getColor(name);
+ return m_config.getColor(name);
} // end getColor
public boolean useHTMLComments()
{
- return config.useHTMLComments();
+ return m_config.useHTMLComments();
} // end useHTMLComments
@@ -2091,108 +2124,118 @@ class HTMLRenderingImpl implements HTMLRendering
if (type==ABSOLUTE)
return url;
else if (type==SERVLET)
- return req.encodeServletPath(url);
+ return m_req.encodeServletPath(url);
else if (type==FRAME)
- return req.encodeServletPath("frame/" + url);
+ return m_req.encodeServletPath("frame/" + url);
else if (type==FULLSERVLET)
- return req.expandServletPath(url,true);
+ return m_req.expandServletPath(url,true);
else
throw new IndexOutOfBoundsException("invalid format type index for formatURL");
} // end formatURL
+ public String formatURL(String url, String type)
+ {
+ int ityp = m_config.convertLinkType(type);
+ if (ityp<0)
+ return url;
+ else
+ return formatURL(url,ityp);
+
+ } // end formatURL
+
public String formatDate(Date date)
{
synchronized (this)
{ // create the display date formatter if we don't yet have it
- if (display_date==null)
+ if (m_display_date==null)
{ // create the display date formatter
- display_date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,req.getLocale());
- display_date.setTimeZone(req.getTimeZone());
+ m_display_date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,m_req.getLocale());
+ m_display_date.setTimeZone(m_req.getTimeZone());
} // end if
} // end synchronized block
- return display_date.format(date);
+ return m_display_date.format(date);
} // end formatDate
public String getFontTag(int colorsel, int size)
{
- return config.getFontTag(colorsel,size);
+ return m_config.getFontTag(colorsel,size);
} // end getFontTag
public String getFontTag(String color, int size)
{
- return config.getFontTag(color,size);
+ return m_config.getFontTag(color,size);
} // end getFontTag
public String getFontTag(int colorsel, String size)
{
- return config.getFontTag(colorsel,size);
+ return m_config.getFontTag(colorsel,size);
} // end getFontTag
public String getFontTag(String color, String size)
{
- return config.getFontTag(color,size);
+ return m_config.getFontTag(color,size);
} // end getFontTag
public int convertLinkType(String str)
{
- return config.convertLinkType(str);
+ return m_config.convertLinkType(str);
} // end convertLinkType
public String getStockMessage(String key)
{
- return config.getStockMessage(key);
+ return m_config.getStockMessage(key);
} // end getStockMessage
public String getStockMessage(String key, Map vars)
{
- return config.getStockMessage(key,vars);
+ return m_config.getStockMessage(key,vars);
} // end getStockMessage
public String getStaticPath(String s)
{
- return config.getStaticPath(s);
+ return m_config.getStaticPath(s);
} // end getStaticPath
public String getExternalStaticPath(String s)
{
- return config.getExternalStaticPath(s);
+ return m_config.getExternalStaticPath(s);
} // end getExternalStaticPath
public String getImagePath(String s)
{
- return config.getImagePath(s);
+ return m_config.getImagePath(s);
} // end getImagePath
public String getButtonVisual(String id)
{
- return config.getButtonVisual(id);
+ return m_config.getButtonVisual(id);
} // end getButtonVisual
public String getButtonInput(String id)
{
- return config.getButtonInput(id);
+ return m_config.getButtonInput(id);
} // end getButtonInput
public String getUserPhotoTag(String url)
{
- return getUserPhotoTag(url,req.getEngine().getUserPhotoSize());
+ return getUserPhotoTag(url,m_req.getEngine().getUserPhotoSize());
} // end getUserPhotoTag
@@ -2200,7 +2243,7 @@ class HTMLRenderingImpl implements HTMLRendering
{
StringBuffer buf = new StringBuffer("");
return buf.toString();
@@ -2270,19 +2313,19 @@ class HTMLRenderingImpl implements HTMLRendering
public String expandServletPath(String spath)
{
- return req.expandServletPath(spath,false);
+ return m_req.expandServletPath(spath,false);
} // end expandServletPath
public Calendar getCalendar()
{
- return new GregorianCalendar(req.getTimeZone(),req.getLocale());
+ return new GregorianCalendar(m_req.getTimeZone(),m_req.getLocale());
} // end getCalendar
public Locale getLocale()
{
- return req.getLocale();
+ return m_req.getLocale();
} // end getLocale
diff --git a/src/com/silverwrist/venice/ui/velocity/ContentVelocity.java b/src/com/silverwrist/venice/ui/velocity/ContentVelocity.java
new file mode 100644
index 0000000..b8532ec
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/ContentVelocity.java
@@ -0,0 +1,34 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import com.silverwrist.venice.ui.Content;
+
+public interface ContentVelocity extends Content, VelocitySupplyParams
+{
+ /**
+ * Returns the resource name of the Velocity template to be used in rendering this object. This pathname
+ * is interpreted relative to the "template path" specified in the configuration.
+ * The template engine loads it via the standard resource loader, and then applies the parameters
+ * contained in this object to it.
+ *
+ * @return The resource pathname of the Velocity template to use.
+ */
+ public String getTemplateName();
+
+} // end interface ContentVelocity
diff --git a/src/com/silverwrist/venice/ui/velocity/ContentVelocityOwnTemplate.java b/src/com/silverwrist/venice/ui/velocity/ContentVelocityOwnTemplate.java
new file mode 100644
index 0000000..660444b
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/ContentVelocityOwnTemplate.java
@@ -0,0 +1,39 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import com.silverwrist.venice.ui.Content;
+
+public interface ContentVelocityOwnTemplate extends Content, VelocitySupplyParams
+{
+ /**
+ * Returns the Velocity template data to be rendered.
+ *
+ * @return The Velocity template data.
+ */
+ public String getTemplate();
+
+ /**
+ * Returns an identifier for the Velocity template, to be used when generating error messages and
+ * the like.
+ *
+ * @return The Velocity template identifier.
+ */
+ public String getIdentifier();
+
+} // end interface ContentVelocityOwnTemplate
diff --git a/src/com/silverwrist/venice/ui/velocity/ContextWrapper.java b/src/com/silverwrist/venice/ui/velocity/ContextWrapper.java
new file mode 100644
index 0000000..c9c575f
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/ContextWrapper.java
@@ -0,0 +1,132 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import java.util.*;
+import org.apache.velocity.context.Context;
+
+/**
+ * An Adapter which allows a {@link com.silverwrist.venice.ui.velocity.VelocitySupplyParams VelocitySupplyParams}
+ * to supply rendering parameters to Velocity as a standard Context
object.
+ */
+class ContextWrapper implements Context
+{
+ /*--------------------------------------------------------------------------------
+ * Attributes
+ *--------------------------------------------------------------------------------
+ */
+
+ private VelocitySupplyParams m_vr; // the parameter supplier we're adapting
+ private Object[] m_arr = null; // cache of the parameter names array
+
+ /*--------------------------------------------------------------------------------
+ * Constructor
+ *--------------------------------------------------------------------------------
+ */
+
+ /**
+ * Creates a new ContextWrapper
.
+ *
+ * @param vr The {@link com.silverwrist.venice.ui.velocity.VelocitySupplyParams VelocitySupplyParams} to be
+ * wrapped by this object.
+ */
+ ContextWrapper(VelocitySupplyParams vr)
+ {
+ m_vr = vr;
+
+ } // end constructor
+
+ /*--------------------------------------------------------------------------------
+ * Implementations from interface Context
+ *--------------------------------------------------------------------------------
+ */
+
+ /**
+ * Adds a name/value pair to the context. For this class, this is a no-op.
+ *
+ * @param key The name to key the provided value with.
+ * @param value The corresponding value.
+ * @return The previous value set for that key, or null/code>.
+ */
+ public Object put(String key, Object value)
+ {
+ return null; // dummy method
+
+ } // end put
+
+ /**
+ * Gets the value corresponding to the provided key from the context.
+ *
+ * @param key The name of the desired value.
+ * @return The value corresponding to the provided key.
+ */
+ public Object get(String key)
+ {
+ if (m_vr==null)
+ return null;
+ return m_vr.getParameter(key);
+
+ } // end get
+
+ /**
+ * Indicates whether the specified key is in the context.
+ *
+ * @param key The key to look for.
+ * @return true
if the key is in the context, false
if not.
+ */
+ public boolean containsKey(Object key)
+ {
+ if (m_vr==null)
+ return false;
+ return (m_vr.getParameter(key.toString())!=null);
+
+ } // end containsKey
+
+ /**
+ * Get all the keys for the values in the context.
+ *
+ * @return An array containing all the keys from this context.
+ */
+ public Object[] getKeys()
+ {
+ if (m_arr==null)
+ { // fill in array
+ if (m_vr==null)
+ m_arr = new Object[0];
+ else
+ m_arr = m_vr.getParameterNames().toArray();
+
+ } // end if
+
+ return m_arr;
+
+ } // end getKeys
+
+ /**
+ * Removes the value associated with the specified key from the context. For this class, this is a no-op.
+ *
+ * @param key The name of the value to remove.
+ * @return The value that the key was mapped to, or null
if unmapped.
+ */
+ public Object remove(Object key)
+ {
+ return null; // dummy method
+
+ } // end remove
+
+} // end class ContextWrapper
diff --git a/src/com/silverwrist/venice/ui/velocity/StdObject.java b/src/com/silverwrist/venice/ui/velocity/StdObject.java
new file mode 100644
index 0000000..3ef72f8
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/StdObject.java
@@ -0,0 +1,57 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import com.silverwrist.venice.ui.*;
+import com.silverwrist.venice.ui.helpers.*;
+
+public class StdObject
+{
+ /*--------------------------------------------------------------------------------
+ * Attributes
+ *--------------------------------------------------------------------------------
+ */
+
+ private RequestOutput m_rout;
+ private HTMLRendering m_html = null;
+
+ /*--------------------------------------------------------------------------------
+ * Constructor
+ *--------------------------------------------------------------------------------
+ */
+
+ StdObject(RequestOutput out)
+ {
+ m_rout = out;
+
+ } // end constructor
+
+ /*--------------------------------------------------------------------------------
+ * External operations
+ *--------------------------------------------------------------------------------
+ */
+
+ public String formatURL(String url, String type)
+ {
+ if (m_html==null)
+ m_html = (HTMLRendering)(m_rout.queryService(HTMLRendering.class));
+ return m_html.formatURL(url,type);
+
+ } // end formatURL
+
+} // end class StdObject
diff --git a/src/com/silverwrist/venice/ui/velocity/VelocityRenderer.java b/src/com/silverwrist/venice/ui/velocity/VelocityRenderer.java
new file mode 100644
index 0000000..1f6d548
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/VelocityRenderer.java
@@ -0,0 +1,289 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import java.io.*;
+import java.util.*;
+import javax.servlet.*;
+import org.apache.log4j.*;
+import org.apache.velocity.*;
+import org.apache.velocity.app.*;
+import org.apache.velocity.context.AbstractContext;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.*;
+import org.apache.velocity.runtime.RuntimeConstants;
+import com.silverwrist.venice.ui.*;
+import com.silverwrist.venice.ui.config.RootConfig;
+
+public class VelocityRenderer
+{
+ /*--------------------------------------------------------------------------------
+ * Internal "tool" context.
+ *--------------------------------------------------------------------------------
+ */
+
+ private class ToolContext extends AbstractContext
+ {
+ /*====================================================================
+ * Attributes
+ *====================================================================
+ */
+
+ private StdObject m_std;
+
+ /*====================================================================
+ * Constructor
+ *====================================================================
+ */
+
+ ToolContext(Context inner, RequestOutput out)
+ {
+ super(inner);
+ m_std = new StdObject(out);
+
+ } // end constructor
+
+ /*====================================================================
+ * Abstract implementations from class AbstractContext
+ *====================================================================
+ */
+
+ public Object internalGet(String key)
+ {
+ if (key.equals("std"))
+ return m_std;
+ return null;
+
+ } // end internalGet
+
+ public Object internalPut(String key, Object value)
+ {
+ Context ctxt = getChainedContext();
+ if (ctxt==null)
+ return null;
+ else
+ return ctxt.put(key,value);
+
+ } // end internalPut
+
+ public boolean internalContainsKey(Object key)
+ {
+ String keystr = key.toString();
+ if (keystr.equals("std"))
+ return true;
+ return false;
+
+ } // end internalContainsKey
+
+ public Object[] internalGetKeys()
+ {
+ ArrayList rc = new ArrayList();
+ rc.add("std");
+ return rc.toArray();
+
+ } // end internalGetKeys
+
+ public Object internalRemove(Object key)
+ {
+ Context ctxt = getChainedContext();
+ if (ctxt==null)
+ return null;
+ else
+ return ctxt.remove(key);
+
+ } // end internalRemove
+
+ } // end class ToolContext
+
+ /*--------------------------------------------------------------------------------
+ * Static data members
+ *--------------------------------------------------------------------------------
+ */
+
+ private static final String CONTEXT_KEY = VelocityRenderer.class.getName();
+ private static final String LOGGING_CATEGORY_NAME = "velocity.engine";
+
+ private static Logger vel_logger = Logger.getLogger(LOGGING_CATEGORY_NAME);
+ private static Logger logger = Logger.getLogger(VelocityRenderer.class);
+
+ /*--------------------------------------------------------------------------------
+ * Attributes
+ *--------------------------------------------------------------------------------
+ */
+
+ private VelocityEngine m_ve; // our instance of the Velocity engine
+
+ /*--------------------------------------------------------------------------------
+ * Constructor
+ *--------------------------------------------------------------------------------
+ */
+
+ private VelocityRenderer(String template_dir) throws Exception
+ {
+ m_ve = new VelocityEngine();
+ m_ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
+ "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
+ m_ve.setProperty("runtime.log.logsystem.log4j.category",LOGGING_CATEGORY_NAME);
+ m_ve.setProperty("resource.loader","file");
+ m_ve.setProperty("file.loader.description","Velocity File Resource Loader");
+ m_ve.setProperty("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+ m_ve.setProperty("file.resource.loader.path",template_dir);
+ m_ve.setProperty("velocimacro.permissions.allow.inline","true");
+ m_ve.setProperty("velocimacro.permissions.allow.inline.to.replace.global","false");
+ m_ve.setProperty("velocimacro.permissions.allow.inline.local.scope","true");
+ m_ve.init();
+
+ } // end constructor
+
+ /*--------------------------------------------------------------------------------
+ * External operations
+ *--------------------------------------------------------------------------------
+ */
+
+ public void formatTemplate(String template_name, VelocitySupplyParams params, RequestOutput out, Writer wr)
+ throws IOException, ServletException
+ {
+ if (wr==null)
+ wr = out.getWriter();
+ try
+ { // Load the template.
+ Template templ = m_ve.getTemplate(template_name);
+
+ // Create a context containing the arguments.
+ VelocityContext ctxt = new VelocityContext(new ContextWrapper(params));
+
+ // Merge the template onto the output.
+ templ.merge(new ToolContext(ctxt,out),wr);
+ wr.flush();
+
+ } // end try
+ catch (ResourceNotFoundException e)
+ { // this is not good
+ throw new ServletException("unable to load Velocity resource: " + e.getMessage(),e);
+
+ } // end catch
+ catch (ParseErrorException e)
+ { // parse error
+ throw new ServletException("Velocity parse error: " + e.getMessage(),e);
+
+ } // end catch
+ catch (MethodInvocationException e)
+ { // some method failed
+ throw new ServletException("Velocity method invocation error: " + e.getMessage(),e);
+
+ } // end catch
+ catch (IOException e)
+ { // pass IOExceptions straight through
+ throw e;
+
+ } // end catch
+ catch (Exception e)
+ { // all other garbage goes here
+ throw new ServletException("Velocity rendering failure: " + e.getMessage(),e);
+
+ } // end catch
+
+ } // end formatTemplate
+
+ public void render(ContentVelocity content, RequestOutput out, Writer wr) throws IOException, ServletException
+ {
+ formatTemplate(content.getTemplateName(),content,out,wr);
+
+ } // end render
+
+ public void render(ContentVelocityOwnTemplate content, RequestOutput out, Writer wr)
+ throws IOException, ServletException
+ {
+ if (wr==null)
+ wr = out.getWriter();
+ try
+ { // Get the identifier.
+ String ident = content.getIdentifier();
+ if (ident==null)
+ ident = "ContentVelocityOwnTemplate";
+
+ // Create a context containing the arguments.
+ VelocityContext ctxt = new VelocityContext(new ContextWrapper(content));
+
+ if (!(m_ve.evaluate(new ToolContext(ctxt,out),wr,ident,content.getTemplate())))
+ throw new ServletException("Velocity template rendering failure");
+ wr.flush();
+
+ } // end try
+ catch (ResourceNotFoundException e)
+ { // this is not good
+ throw new ServletException("unable to load Velocity resource: " + e.getMessage(),e);
+
+ } // end catch
+ catch (ParseErrorException e)
+ { // parse error
+ throw new ServletException("Velocity parse error: " + e.getMessage(),e);
+
+ } // end catch
+ catch (MethodInvocationException e)
+ { // some method failed
+ throw new ServletException("Velocity method invocation error: " + e.getMessage(),e);
+
+ } // end catch
+ catch (IOException e)
+ { // pass IOExceptions straight through
+ throw e;
+
+ } // end catch
+ catch (Exception e)
+ { // all other garbage goes here
+ throw new ServletException("Velocity rendering failure: " + e.getMessage(),e);
+
+ } // end catch
+
+ } // end render
+
+ /*--------------------------------------------------------------------------------
+ * External static operations
+ *--------------------------------------------------------------------------------
+ */
+
+ public static void init(ServletContext ctxt, RootConfig config)
+ {
+ if (ctxt.getAttribute(CONTEXT_KEY)!=null)
+ return; // already initialized
+
+ try
+ { // initialize the renderer object
+ VelocityRenderer tmp = new VelocityRenderer(config.getVelocityTemplateDirectory());
+ ctxt.setAttribute(CONTEXT_KEY,tmp);
+
+ } // end try
+ catch (Exception e)
+ { // the initialization failed!
+ logger.fatal("VelocityRenderer initialization failed!",e);
+
+ } // end catch
+
+ } // end init
+
+ public static VelocityRenderer get(ServletContext ctxt) throws ServletException
+ {
+ VelocityRenderer rc = (VelocityRenderer)(ctxt.getAttribute(CONTEXT_KEY));
+ if (rc==null)
+ throw new ServletException("VelocityRenderer not initialized");
+ return rc;
+
+ } // end get
+
+} // end class VelocityRenderer
diff --git a/src/com/silverwrist/venice/ui/velocity/VelocitySupplyParams.java b/src/com/silverwrist/venice/ui/velocity/VelocitySupplyParams.java
new file mode 100644
index 0000000..1b7b9fc
--- /dev/null
+++ b/src/com/silverwrist/venice/ui/velocity/VelocitySupplyParams.java
@@ -0,0 +1,45 @@
+/*
+ * 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 .
+ *
+ * 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 ,
+ * 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.velocity;
+
+import java.util.Collection;
+
+/**
+ * Common interface for all output objects that supply parameters to Velocity.
+ *
+ * @author Eric J. Bowersox <erbo@ricochet.com>
+ * @version X
+ */
+public interface VelocitySupplyParams
+{
+ /**
+ * Returns the value of a parameter set on the object.
+ *
+ * @param key The name of the parameter to look up.
+ * @return The parameter's value, or null
if the parameter was not set.
+ */
+ public Object getParameter(String key);
+
+ /**
+ * Returns a java.util.Collection
of all parameter names currently defined on this object.
+ *
+ * @return A collection of all parameter names currently defined.
+ */
+ public Collection getParameterNames();
+
+} // end interface VelocitySupplyParams
diff --git a/templates/VM_global_library.vm b/templates/VM_global_library.vm
new file mode 100644
index 0000000..e0db93b
--- /dev/null
+++ b/templates/VM_global_library.vm
@@ -0,0 +1,20 @@
+#*
+ 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 .
+
+ 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 ,
+ 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):
+*#
+
+## Define macros around the "std" object.
+#macro( formatURL $type $url )$std.formatURL($type,$url)#end