001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: TextBean.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005:
006: package org.gridsphere.provider.portletui.beans;
007:
008: import java.awt.*;
009:
010: /**
011: * The <code>TextBean</code> represents text to be displayed
012: */
013: public class TextBean extends BaseComponentBean implements TagBean {
014:
015: public static final String NAME = "tb";
016:
017: protected String style = "info";
018:
019: /* @deprecated -- use MessageStyle instead */
020: // CSS definitions according to Portlet API spec. PLT.C
021: public static final String MSG_STATUS = "portlet-msg-status";
022: public static final String MSG_INFO = "portlet-msg-info";
023: public static final String MSG_ERROR = "portlet-msg-error";
024: public static final String MSG_ALERT = "portlet-msg-alert";
025: public static final String MSG_SUCCESS = "portlet-msg-success";
026: public static final String MSG_ITALIC = "italic";
027: public static final String MSG_BOLD = "bold";
028: public static final String MSG_UNDERLINE = "underline";
029:
030: /**
031: * Constructs a default text bean
032: */
033: public TextBean() {
034: super (NAME);
035: this .cssClass = MessageStyle.MSG_INFO;
036: }
037:
038: /**
039: * Constructs a text bean using a supplied bean identifier
040: *
041: * @param beanId the bean identifier
042: */
043: public TextBean(String beanId) {
044: super (NAME);
045: this .beanId = beanId;
046: this .cssClass = MessageStyle.MSG_INFO;
047: }
048:
049: /**
050: * Returns the style of the text: Available styles are
051: * <ul>
052: * <li>nostyle - plain text</li>
053: * <li>error - error text</li>
054: * <li>info - default info text</li>
055: * <li>status - status text</li>
056: * <li>alert - alert text</li>
057: * <li>success - success text</li>
058: *
059: * @return the text style
060: */
061: public String getStyle() {
062: return style;
063: }
064:
065: /**
066: * Sets the style of the text: Available styles are
067: * <ul>
068: * <li>error</li>
069: * <li>info</li>
070: * <li>status</li>
071: * <li>alert</li>
072: * <li>success</li>
073: *
074: * @param style the text style
075: */
076: public void setStyle(String style) {
077: this .style = style;
078: }
079:
080: public String toStartString() {
081: return "";
082: }
083:
084: public String toEndString() {
085: String text = "";
086: String dir = "ltr";
087: if (locale != null) {
088: ComponentOrientation orientation = ComponentOrientation
089: .getOrientation(locale);
090: if (!orientation.isLeftToRight()) {
091: dir = "rtl";
092: }
093: }
094: if (value == null)
095: return "";
096: if (style.equalsIgnoreCase("error")
097: || (style.equalsIgnoreCase("err"))) {
098: this .cssClass = MessageStyle.MSG_ERROR;
099: } else if (style.equalsIgnoreCase("status")) {
100: this .cssClass = MessageStyle.MSG_STATUS;
101: } else if (style.equalsIgnoreCase("info")) {
102: this .cssClass = MessageStyle.MSG_INFO;
103: } else if (style.equalsIgnoreCase("alert")) {
104: this .cssClass = MessageStyle.MSG_ALERT;
105: } else if (style.equalsIgnoreCase("success")) {
106: this .cssClass = MessageStyle.MSG_SUCCESS;
107: } else if (style.equalsIgnoreCase("nostyle")) {
108: return value;
109: } else if (style.equalsIgnoreCase(MessageStyle.MSG_BOLD)) {
110: cssStyle = "font-weight: bold; ";
111: } else if (style.equalsIgnoreCase(MessageStyle.MSG_ITALIC)) {
112: cssStyle = "font-style: italic; ";
113: } else if (style.equalsIgnoreCase(MessageStyle.MSG_UNDERLINE)) {
114: cssStyle = "text-decoration: underline; ";
115: }
116: text = "<span ";
117: if (id != null)
118: text += "id=\"" + id + "\"";
119: text += " dir=\"" + dir + "\" " + getFormattedCss();
120: text += ">" + value + "</span>";
121: return text;
122: }
123: }
|