revamped the post box tag to use a Velocity template to render with
This commit is contained in:
parent
7d3c167733
commit
7060b5ff76
|
@ -19,11 +19,13 @@ package com.silverwrist.venice.ui.conf.jsp;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.jsp.*;
|
||||
import javax.servlet.jsp.tagext.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.venice.ui.*;
|
||||
import com.silverwrist.venice.ui.helpers.HTMLRendering;
|
||||
import com.silverwrist.venice.ui.velocity.*;
|
||||
|
||||
public class PostBoxTag extends VeniceConfBodyTagSupport
|
||||
{
|
||||
|
@ -41,17 +43,9 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
|
||||
private String m_action = null;
|
||||
private String m_type = "servlet";
|
||||
private int m_real_type = -1;
|
||||
private HashMap m_params = new HashMap();
|
||||
private String m_newtopic_name = null;
|
||||
private String m_newtopic_value = null;
|
||||
private String m_pseud_name = null;
|
||||
private String m_pseud_value = null;
|
||||
private String m_attach_name = null;
|
||||
private boolean m_attach_value = false;
|
||||
private String m_text_name = null;
|
||||
private String m_text_value = null;
|
||||
private ArrayList m_buttons = new ArrayList();
|
||||
private HashMap m_params = null;
|
||||
private ArrayList m_buttons = null;
|
||||
private HashMap m_render_data = null;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class BodyTagSupport
|
||||
|
@ -65,9 +59,15 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
if (m_action==null)
|
||||
throw new JspTagException("<post:box/> action= attribute not specified!");
|
||||
HTMLRendering html = (HTMLRendering)(getRequestInput().queryService(HTMLRendering.class));
|
||||
m_real_type = html.convertLinkType(m_type);
|
||||
if (m_real_type<0)
|
||||
if (html.convertLinkType(m_type)<0)
|
||||
throw new JspTagException("<post:box/> type= attribute not a valid link type");
|
||||
m_render_data = new HashMap();
|
||||
m_params = new HashMap();
|
||||
m_buttons = new ArrayList();
|
||||
m_render_data.put("action",m_action);
|
||||
m_render_data.put("action_type",m_type);
|
||||
m_render_data.put("params",m_params);
|
||||
m_render_data.put("buttons",m_buttons);
|
||||
return EVAL_BODY_BUFFERED;
|
||||
|
||||
} // end doStartTag
|
||||
|
@ -84,97 +84,37 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("PostBoxTag.doEndTag(): entry");
|
||||
if (m_pseud_name==null)
|
||||
if (!(m_render_data.containsKey("pseud_name")))
|
||||
throw new JspTagException("<post:box/> tag has no <post:pseud/> tag inside it!");
|
||||
if (m_attach_name==null)
|
||||
if (!(m_render_data.containsKey("attach_name")))
|
||||
throw new JspTagException("<post:box/> tag has no <post:attach/> tag inside it!");
|
||||
if (m_text_name==null)
|
||||
if (!(m_render_data.containsKey("text_name")))
|
||||
throw new JspTagException("<post:box/> tag has no <post:text/> tag inside it!");
|
||||
if (m_buttons.isEmpty())
|
||||
throw new JspTagException("<post:box/> tag has no <post:button/> tags inside it!");
|
||||
|
||||
HTMLRendering html = (HTMLRendering)(getRequestOutput().queryService(HTMLRendering.class));
|
||||
|
||||
try
|
||||
{ // write out what we came here to accomplish
|
||||
{ // render this as a template
|
||||
JspWriter out = pageContext.getOut();
|
||||
out.write("<form method=\"POST\" action=\"" + html.formatURL(m_action,m_real_type)
|
||||
+ "\"><div class=\"content\">\n");
|
||||
Iterator it = m_params.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{ // write the hidden parameters
|
||||
Map.Entry ntry = (Map.Entry)(it.next());
|
||||
out.write("<input type=\"hidden\" name=\"" + ntry.getKey() + "\" value=\"" + ntry.getValue()
|
||||
+ "\" />\n");
|
||||
|
||||
} // end while
|
||||
|
||||
String my_font = html.getFontTag(html.CONTENT_FOREGROUND,"content");
|
||||
out.write("<table border=\"0\" cellpadding=\"0\">\n");
|
||||
if (m_newtopic_name!=null)
|
||||
{ // write the "new topic name" field
|
||||
out.write("<tr><td align=\"left\" colspan=\"2\" class=\"content\">\n"
|
||||
+ my_font + "New topic name:</font><br />\n<span class=\"cinput\">"
|
||||
+ "<input type=\"text\" class=\"cinput\" name=\"" + m_newtopic_name
|
||||
+ "\" size=\"37\" maxlength=\"128\" VALUE=\"");
|
||||
if (m_newtopic_value!=null)
|
||||
out.write(m_newtopic_value);
|
||||
out.write("\" /></span>\n</td></tr>\n");
|
||||
|
||||
} // end if
|
||||
|
||||
out.write("<tr><td align=\"left\" colspan=\"2\" class=\"content\">\n"
|
||||
+ my_font + "Your name/header:</font><br/>\n<span class=\"cinput\">"
|
||||
+ "<input type=\"text\" class=\"cinput\" name=\"" + m_pseud_name
|
||||
+ "\" size=\"37\" maxlength=\"255\" value=\"");
|
||||
if (m_pseud_value!=null)
|
||||
out.write(m_pseud_value);
|
||||
out.write("\" /></span>\n" + my_font + "<input type=\"checkbox\" name=\"" + m_attach_name
|
||||
+ "\" value=\"Y\"");
|
||||
if (m_attach_value)
|
||||
out.write(" checked=\"checked\"");
|
||||
out.write(" /> Attach a file</font>\n</td></tr>\n<tr>\n<td align=\"left\" class=\"content\">\n"
|
||||
+ my_font + "Message:</font>\n</td>\n<td align=\"right\" class=\"content\">" + my_font
|
||||
+ "\n<a href=\"" + html.getExternalStaticPath("html-reference.html")
|
||||
+ "\" target=\"_blank\">HTML Guide</a>\n</font></td>\n</tr>\n<tr>"
|
||||
+ "<td align=\"left\" colspan=\"2\" class=\"cinput\">\n<textarea name=\"" + m_text_name
|
||||
+ "\" wrap=\"soft\" rows=\"7\" cols=\"51\">");
|
||||
if (m_text_value!=null)
|
||||
out.write(m_text_value);
|
||||
out.write("</textarea>\n</td></tr>\n<tr><td align=\"center\" colspan=\"2\" class=\"content\">\n");
|
||||
boolean first = true;
|
||||
it = m_buttons.iterator();
|
||||
while (it.hasNext())
|
||||
{ // write out all the buttons
|
||||
String id = (String)(it.next());
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
out.write(" ");
|
||||
out.write(html.getButtonInput(id) + "\n");
|
||||
|
||||
} // end while
|
||||
|
||||
out.write("</td></tr>\n</table>\n</div></form>\n");
|
||||
VelocityRenderer vr = VelocityRenderer.get(pageContext.getServletContext());
|
||||
vr.formatTemplate("conf/post_box.vm",new ParamMapWrapper(m_render_data),getRequestOutput(),out);
|
||||
|
||||
} // end try
|
||||
catch (IOException e)
|
||||
{ // convert the I/O error into something the servlet engine can deal with
|
||||
throw new JspTagException("error writing post box - " + e.getMessage());
|
||||
|
||||
} // end catch
|
||||
catch (ServletException e)
|
||||
{ // convert the I/O error into something the servlet engine can deal with
|
||||
throw new JspTagException("error writing post box - " + e.getMessage());
|
||||
|
||||
} // end catch
|
||||
|
||||
// anything set by subtags must be cleared in doEndTag, not release
|
||||
m_params.clear();
|
||||
m_newtopic_name = null;
|
||||
m_newtopic_value = null;
|
||||
m_pseud_name = null;
|
||||
m_pseud_value = null;
|
||||
m_attach_name = null;
|
||||
m_attach_value = false;
|
||||
m_text_name = null;
|
||||
m_text_value = null;
|
||||
m_buttons.clear();
|
||||
m_render_data = null;
|
||||
m_params = null;
|
||||
m_buttons = null;
|
||||
return EVAL_PAGE;
|
||||
|
||||
} // end doEndTag
|
||||
|
@ -186,7 +126,6 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
super.release();
|
||||
m_action = null;
|
||||
m_type = "servlet";
|
||||
m_real_type = -1;
|
||||
|
||||
} // end release
|
||||
|
||||
|
@ -204,7 +143,6 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
public void setType(String v)
|
||||
{
|
||||
m_type = v;
|
||||
m_real_type = -1;
|
||||
|
||||
} // end setType
|
||||
|
||||
|
@ -213,8 +151,10 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
final void addParam(String name, String value)
|
||||
final void addParam(String name, String value) throws JspException
|
||||
{
|
||||
if (m_params==null)
|
||||
throw new JspTagException("addParam() called at wrong time!");
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("PostBoxTag.addParam(\"" + name + "\",\"" + value + "\") entry");
|
||||
m_params.put(name,value);
|
||||
|
@ -223,54 +163,64 @@ public class PostBoxTag extends VeniceConfBodyTagSupport
|
|||
|
||||
final void setNewTopic(String param_name, String value) throws JspException
|
||||
{
|
||||
if (m_newtopic_name!=null)
|
||||
if (m_render_data==null)
|
||||
throw new JspTagException("setNewTopic() called at wrong time!");
|
||||
if (m_render_data.containsKey("newtopic_name"))
|
||||
throw new JspTagException("<post:newtopic/> may only appear once inside a <post:box/>!");
|
||||
if (param_name==null)
|
||||
throw new JspTagException("<post:newtopic/> parameter name not specified!");
|
||||
m_newtopic_name = param_name;
|
||||
m_newtopic_value = value;
|
||||
m_render_data.put("newtopic_name",param_name);
|
||||
m_render_data.put("newtopic_value",value);
|
||||
|
||||
} // end setNewTopic
|
||||
|
||||
final void setPseud(String param_name, String value) throws JspException
|
||||
{
|
||||
if (m_render_data==null)
|
||||
throw new JspTagException("setPseud() called at wrong time!");
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("PostBoxTag.setPseud(\"" + param_name + "\",\"" + value + "\") entry");
|
||||
if (m_pseud_name!=null)
|
||||
if (m_render_data.containsKey("pseud_name"))
|
||||
throw new JspTagException("<post:pseud/> may only appear once inside a <post:box/>!");
|
||||
if (param_name==null)
|
||||
throw new JspTagException("<post:pseud/> parameter name not specified!");
|
||||
m_pseud_name = param_name;
|
||||
m_pseud_value = value;
|
||||
m_render_data.put("pseud_name",param_name);
|
||||
m_render_data.put("pseud_value",value);
|
||||
|
||||
} // end setPseud
|
||||
|
||||
final void setAttach(String param_name, boolean value) throws JspException
|
||||
{
|
||||
if (m_attach_name!=null)
|
||||
if (m_render_data==null)
|
||||
throw new JspTagException("setAttach() called at wrong time!");
|
||||
if (m_render_data.containsKey("attach_name"))
|
||||
throw new JspTagException("<post:attach/> may only appear once inside a <post:box/>!");
|
||||
if (param_name==null)
|
||||
throw new JspTagException("<post:attach/> parameter name not specified!");
|
||||
m_attach_name = param_name;
|
||||
m_attach_value = value;
|
||||
m_render_data.put("attach_name",param_name);
|
||||
m_render_data.put("attach_value",(value ? Boolean.TRUE : Boolean.FALSE));
|
||||
|
||||
} // end setAttach
|
||||
|
||||
final void setText(String param_name, String value) throws JspException
|
||||
{
|
||||
if (m_render_data==null)
|
||||
throw new JspTagException("setText() called at wrong time!");
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("PostBoxTag.setText(\"" + param_name + "\",<value>) entry");
|
||||
if (m_text_name!=null)
|
||||
if (m_render_data.containsKey("text_name"))
|
||||
throw new JspTagException("<post:text/> may only appear once inside a <post:box/>!");
|
||||
if (param_name==null)
|
||||
throw new JspTagException("<post:text/> parameter name not specified!");
|
||||
m_text_name = param_name;
|
||||
m_text_value = value;
|
||||
m_render_data.put("text_name",param_name);
|
||||
m_render_data.put("text_value",value);
|
||||
|
||||
} // end setText
|
||||
|
||||
final void addButton(String id)
|
||||
final void addButton(String id) throws JspException
|
||||
{
|
||||
if (m_buttons==null)
|
||||
throw new JspTagException("addButton() called at wrong time!");
|
||||
m_buttons.add(id);
|
||||
|
||||
} // end addButton
|
||||
|
|
70
src/com/silverwrist/venice/ui/velocity/ParamMapWrapper.java
Normal file
70
src/com/silverwrist/venice/ui/velocity/ParamMapWrapper.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.ui.velocity;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class ParamMapWrapper implements VelocitySupplyParams
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private Map m_map;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public ParamMapWrapper(Map map)
|
||||
{
|
||||
m_map = map;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from 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 <code>null</code> if the parameter was not set.
|
||||
*/
|
||||
public Object getParameter(String key)
|
||||
{
|
||||
return m_map.get(key);
|
||||
|
||||
} // end getParameter
|
||||
|
||||
/**
|
||||
* Returns a <code>java.util.Collection</code> of all parameter names currently defined on this object.
|
||||
*
|
||||
* @return A collection of all parameter names currently defined.
|
||||
*/
|
||||
public Collection getParameterNames()
|
||||
{
|
||||
return m_map.keySet();
|
||||
|
||||
} // end getParameterNames
|
||||
|
||||
} // end class ParamMapWrapper
|
|
@ -54,4 +54,46 @@ public class StdObject
|
|||
|
||||
} // end formatURL
|
||||
|
||||
public String fontTag(String color, String size)
|
||||
{
|
||||
if (m_html==null)
|
||||
m_html = (HTMLRendering)(m_rout.queryService(HTMLRendering.class));
|
||||
return m_html.getFontTag(color.trim(),size.trim());
|
||||
|
||||
} // end fontTag
|
||||
|
||||
public String externalStatic(String path)
|
||||
{
|
||||
if (m_html==null)
|
||||
m_html = (HTMLRendering)(m_rout.queryService(HTMLRendering.class));
|
||||
return m_html.getExternalStaticPath(path);
|
||||
|
||||
} // end externalStatic
|
||||
|
||||
public String button(String id, String type)
|
||||
{
|
||||
if (m_html==null)
|
||||
m_html = (HTMLRendering)(m_rout.queryService(HTMLRendering.class));
|
||||
id = id.trim().toLowerCase();
|
||||
type = type.trim().toLowerCase();
|
||||
if (type.equals("visual"))
|
||||
return m_html.getButtonVisual(id);
|
||||
else if (type.equals("input"))
|
||||
return m_html.getButtonInput(id);
|
||||
else
|
||||
return "";
|
||||
|
||||
} // end button
|
||||
|
||||
public String comment(String data)
|
||||
{
|
||||
if (m_html==null)
|
||||
m_html = (HTMLRendering)(m_rout.queryService(HTMLRendering.class));
|
||||
if (m_html.useHTMLComments())
|
||||
return "<!-- " + data + " -->";
|
||||
else
|
||||
return "";
|
||||
|
||||
} // end comment
|
||||
|
||||
} // end class StdObject
|
||||
|
|
|
@ -18,3 +18,11 @@
|
|||
|
||||
## Define macros around the "std" object.
|
||||
#macro( formatURL $type $url )$std.formatURL($type,$url)#end
|
||||
|
||||
#macro( font $color $size )$std.fontTag($color,$size)#end
|
||||
|
||||
#macro( externalStatic $p )$std.externalStatic($p)#end
|
||||
|
||||
#macro( button $id $typ )$std.button($id,$typ)#end
|
||||
|
||||
#macro( comment $d )$std.comment($d)#end
|
||||
|
|
65
templates/conf/post_box.vm
Normal file
65
templates/conf/post_box.vm
Normal file
|
@ -0,0 +1,65 @@
|
|||
#*
|
||||
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
(the "License"); you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing rights and limitations under the License.
|
||||
|
||||
The Original Code is the Venice Web Communities System.
|
||||
|
||||
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
|
||||
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
*#
|
||||
## Render the post box.
|
||||
#set( $html_reference = "html-reference.html" )
|
||||
#comment( "BEGIN POST BOX" )
|
||||
<form method="POST" action="#formatURL( $action $action_type )"><div class="content">
|
||||
#foreach( $pn in $params.keySet() )
|
||||
<input type="hidden" name="$pn" value="$!{params.get($pn)}" />
|
||||
#end
|
||||
<table border="0" cellpadding="0">
|
||||
#if( $newtopic_name )
|
||||
<tr><td align="left" colspan="2" class="content">
|
||||
#font( "content.fg" "content" )New topic name:</font><br />
|
||||
<span class="cinput"><input type="text" class="cinput" name="$newtopic_name"
|
||||
size="37" maxlength="128" value="$!newtopic_value" /></span>
|
||||
</td></tr>
|
||||
#end
|
||||
<tr><td align="left" colspan="2" class="content">
|
||||
#font( "content.fg" "content" )Your name/header:</font><br />
|
||||
<span class="cinput"><input type="text" class="cinput" name="$pseud_name"
|
||||
size="37" maxlength="255" value="$!pseud_value" /></span>
|
||||
#font( "content.fg" "content" )<input type="checkbox"
|
||||
name="$attach_name"
|
||||
#if( $attach_value )checked="checked"#end
|
||||
value="Y" /> Attach a file</font>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="left" class="content">#font( "content.fg" "content" )Message:</font></td>
|
||||
<td align="right" class="content">#font( "content.fg" "content" )
|
||||
<a href="#externStatic( $html_reference )" target="_blank">HTML Guide</a>
|
||||
</font></td>
|
||||
</tr>
|
||||
<tr><td align="left" colspan="2" class="cinput">
|
||||
<textarea name="$text_name" wrap="soft" rows="7" cols="51">$!text_value</textarea>
|
||||
</td></tr>
|
||||
<tr><td align="center" colspan="2" class="content">
|
||||
#set( $first = 1 )
|
||||
#foreach( $bn in $buttons )
|
||||
#if( $first == 1 )
|
||||
#set( $first = 0 )
|
||||
#else
|
||||
|
||||
#end
|
||||
#button( $bn "input" )
|
||||
#end
|
||||
</td></tr>
|
||||
</table>
|
||||
</div></form>
|
||||
#comment( "END POST BOX" )
|
||||
## -- EOF --
|
Loading…
Reference in New Issue
Block a user