01: package com.technoetic.xplanner.tags;
02:
03: import org.apache.struts.Globals;
04: import org.apache.struts.util.MessageResources;
05:
06: import javax.servlet.jsp.JspException;
07: import javax.servlet.jsp.tagext.BodyTagSupport;
08: import java.text.MessageFormat;
09: import java.util.ArrayList;
10:
11: public class ContentTitleTag extends BodyTagSupport {
12: private ArrayList titleArguments;
13: private String title;
14: private String titleKey;
15:
16: public int doStartTag() throws JspException {
17: titleArguments = new ArrayList();
18: return super .doStartTag();
19: }
20:
21: public int doEndTag() throws JspException {
22: String formattedTitle = null;
23: if (title == null) {
24: if (titleKey != null) {
25: MessageResources resources = (MessageResources) pageContext
26: .findAttribute(Globals.MESSAGES_KEY);
27: if (resources == null) {
28: throw new JspException(
29: "no resource bundle in request");
30: }
31: formattedTitle = resources.getMessage(titleKey,
32: titleArguments.toArray());
33: } else {
34: formattedTitle = getBodyContent().getString().trim();
35: }
36: } else {
37: formattedTitle = MessageFormat.format(title, titleArguments
38: .toArray());
39: }
40: ContentTag tag = (ContentTag) findAncestorWithClass(this ,
41: ContentTag.class);
42: tag.putAttribute("title", formattedTitle);
43: return super .doEndTag();
44: }
45:
46: public void setTitle(String title) {
47: this .title = title;
48: }
49:
50: public void setTitleKey(String titleKey) {
51: this .titleKey = titleKey;
52: }
53:
54: public void addTitleArgument(Object value) {
55: titleArguments.add(value);
56: }
57:
58: public void release() {
59: title = null;
60: titleKey = null;
61: titleArguments = null;
62: super.release();
63: }
64: }
|