001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @author <a href="mailto:oliver.wehrens@aei.mpg.de">Oliver Wehrens</a>
004: * @version $Id: TextTag.java 6385 2007-10-25 14:02:26Z wehrens $
005: */
006:
007: package org.gridsphere.provider.portletui.tags;
008:
009: import org.gridsphere.provider.portletui.beans.BaseComponentBean;
010: import org.gridsphere.provider.portletui.beans.MessageStyle;
011: import org.gridsphere.provider.portletui.beans.TextBean;
012:
013: import javax.servlet.jsp.JspException;
014: import javax.servlet.jsp.JspWriter;
015: import javax.servlet.jsp.PageContext;
016: import java.util.Locale;
017:
018: /**
019: * A <code>TextTag</code> represents text to be displayed
020: */
021: public class TextTag extends BaseComponentTag {
022:
023: protected TextBean textBean = null;
024: protected String style = MessageStyle.MSG_INFO;
025: protected String var = null;
026:
027: /**
028: * Sets the name of the variable to export as a RenderURL object
029: *
030: * @param var the name of the variable to export as a RenderURL object
031: */
032: public void setVar(String var) {
033: this .var = var;
034: }
035:
036: /**
037: * Returns the name of the exported RenderURL object
038: *
039: * @return the exported variable
040: */
041: public String getVar() {
042: return var;
043: }
044:
045: /**
046: * Sets the style of the text: Available styles are
047: * <ul>
048: * <li>nostyle</li>
049: * <li>error</li>
050: * <li>info</li>
051: * <li>status</li>
052: * <li>alert</li>
053: * <li>success</li>
054: *
055: * @param style the text style
056: */
057: public void setStyle(String style) {
058: this .style = style;
059: }
060:
061: /**
062: * Returns the style of the text: Available styles are
063: * <ul>
064: * <li>nostyle</li>
065: * <li>error</li>
066: * <li>info</li>
067: * <li>status</li>
068: * <li>alert</li>
069: * <li>success</li>
070: * <li>bold</li>
071: * <li>italic</li>
072: * <li>underline</li>
073: *
074: * @return the text style
075: */
076: public String getStyle() {
077: return style;
078: }
079:
080: protected void setBaseComponentBean(BaseComponentBean componentBean) {
081: super .setBaseComponentBean(componentBean);
082: if (style != null)
083: ((TextBean) componentBean).setStyle(style);
084: }
085:
086: protected void updateBaseComponentBean(
087: BaseComponentBean componentBean) {
088: super .setBaseComponentBean(componentBean);
089: if (style != null
090: && ((TextBean) componentBean).getStyle() == null) {
091: ((TextBean) componentBean).setStyle(style);
092: }
093: }
094:
095: protected void overrideBaseComponentBean(
096: BaseComponentBean componentBean) {
097: super .setBaseComponentBean(componentBean);
098: // 1st of property defined in tag put it in bean
099: //if (style != null) ((TextBean)componentBean).setStyle(style);
100: // 2nd if property exists in bean then use it
101: if (((TextBean) componentBean).getStyle() != null) {
102: style = ((TextBean) componentBean).getStyle();
103: } else {
104: ((TextBean) componentBean).setStyle(style);
105: }
106: }
107:
108: public int doStartTag() throws JspException {
109: return EVAL_BODY_BUFFERED;
110: }
111:
112: public int doEndTag() throws JspException {
113: if (!beanId.equals("")) {
114: textBean = (TextBean) getTagBean();
115: if (textBean == null) {
116: textBean = new TextBean();
117: this .setBaseComponentBean(textBean);
118: } else {
119: //this.overrideBaseComponentBean(textBean);
120: this .setBaseComponentBean(textBean);
121: textBean.setStyle(style);
122: key = textBean.getKey();
123: }
124: } else {
125: textBean = new TextBean();
126: this .setBaseComponentBean(textBean);
127: textBean.setStyle(style);
128: textBean.setCssClass(this .cssClass);
129: textBean.setCssStyle(this .cssStyle);
130: }
131:
132: Locale locale = getLocale();
133: textBean.setLocale(locale);
134:
135: if (key != null) {
136: textBean.setValue(getLocalizedText(key));
137: }
138:
139: if ((this .getBodyContent() != null) && (value == null)) {
140: textBean.setValue(this .getBodyContent().getString());
141: }
142:
143: if (var == null) {
144: try {
145: JspWriter out = pageContext.getOut();
146: out.print(textBean.toEndString());
147: } catch (Exception e) {
148: throw new JspException(e.getMessage());
149: }
150: } else {
151: if (key != null)
152: value = getLocalizedText(key);
153: pageContext
154: .setAttribute(var, value, PageContext.PAGE_SCOPE);
155: }
156: super.release();
157: return EVAL_PAGE;
158: }
159:
160: }
|