AbstractDirectivepublic abstract class AbstractDirective extends org.apache.velocity.runtime.directive.Directive
Methods Summary |
---|
protected java.util.Map | createPropertyMap(org.apache.velocity.context.InternalContextAdapter contextAdapter, org.apache.velocity.runtime.parser.node.Node node)create a Map of properties that the user has passed in. for example,
#xxx("name=hello" "value=world" "template=foo")
would yield a params that contains {["name", "hello"], ["value", "world"], ["template", "foo"]}
Map propertyMap = new HashMap();
int children = node.jjtGetNumChildren();
if (getType() == BLOCK) {
children--;
}
for (int index = 0, length = children; index < length; index++) {
this.putProperty(propertyMap, contextAdapter, node.jjtGetChild(index));
}
return propertyMap;
| protected abstract org.apache.struts2.components.Component | getBean(com.opensymphony.xwork2.util.ValueStack stack, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
| public abstract java.lang.String | getBeanName()
| public java.lang.String | getName()
return "s" + getBeanName();
| public int | getType()All components, unless otherwise stated, are LINE-level directives.
return LINE;
| protected void | putProperty(java.util.Map propertyMap, org.apache.velocity.context.InternalContextAdapter contextAdapter, org.apache.velocity.runtime.parser.node.Node node)adds a given Node's key/value pair to the propertyMap. For example, if this Node contained the value "rows=20",
then the key, rows, would be added to the propertyMap with the String value, 20.
// node.value uses the StrutsValueStack to evaluate the directive's value parameter
String param = node.value(contextAdapter).toString();
int idx = param.indexOf("=");
if (idx != -1) {
String property = param.substring(0, idx);
String value = param.substring(idx + 1);
propertyMap.put(property, value);
} else {
throw new ParseErrorException("#" + this.getName() + " arguments must include an assignment operator! For example #tag( Component \"template=mytemplate\" ). #tag( TextField \"mytemplate\" ) is illegal!");
}
| public boolean | render(org.apache.velocity.context.InternalContextAdapter ctx, java.io.Writer writer, org.apache.velocity.runtime.parser.node.Node node)
// get the bean
ValueStack stack = (ValueStack) ctx.get("stack");
HttpServletRequest req = (HttpServletRequest) stack.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse res = (HttpServletResponse) stack.getContext().get(ServletActionContext.HTTP_RESPONSE);
Component bean = getBean(stack, req, res);
Container container = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getContainer();
container.inject(bean);
// get the parameters
Map params = createPropertyMap(ctx, node);
bean.copyParams(params);
//bean.addAllParameters(params);
bean.start(writer);
if (getType() == BLOCK) {
Node body = node.jjtGetChild(node.jjtGetNumChildren() - 1);
body.render(ctx, writer);
}
bean.end(writer, "");
return true;
|
|