001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: ActionLinkBean.java 6424 2008-02-29 09:20:31Z wehrens $
004: */package org.gridsphere.provider.portletui.beans;
005:
006: import java.util.ArrayList;
007: import java.util.List;
008:
009: /**
010: * An <code>ActionLinkBean</code> is a visual bean that represents a hyperlink containing a portlet action
011: */
012: public class ActionLinkBean extends ActionBean implements TagBean {
013:
014: protected String style = "none";
015: protected List<TagBean> beans = new ArrayList<TagBean>();
016:
017: /**
018: * Constructs a default action link bean
019: */
020: public ActionLinkBean() {
021: }
022:
023: /**
024: * Constructs an action link bean from a portlet request and supplied bean identifier
025: *
026: * @param beanId the bean id used to reference this ActionLinkBean
027: */
028: public ActionLinkBean(String beanId) {
029: this .beanId = beanId;
030: }
031:
032: /**
033: * Returns the style of the text: Available styles are
034: * <ul>
035: * <li>nostyle - plain text</li>
036: * <li>error - error text</li>
037: * <li>info - default info text</li>
038: * <li>status - status text</li>
039: * <li>alert - alert text</li>
040: * <li>success - success text</li>
041: *
042: * @return the text style
043: */
044: public String getStyle() {
045: return style;
046: }
047:
048: /**
049: * Sets the style of the text: Available styles are
050: * <ul>
051: * <li>error</li>
052: * <li>info</li>
053: * <li>status</li>
054: * <li>alert</li>
055: * <li>success</li>
056: *
057: * @param style the text style
058: */
059: public void setStyle(String style) {
060: this .style = style;
061: }
062:
063: /**
064: * Gets the beans to be rendered before the text in the ActionLink.
065: *
066: * @return TagBean
067: */
068:
069: public List<TagBean> getTagBeans() {
070: return beans;
071: }
072:
073: /**
074: * Sets beans to be rendered before the text in the ActionLink.
075: *
076: * @param beans Bean to be rendered
077: */
078: public void setTagBeans(List<TagBean> beans) {
079: this .beans = beans;
080: }
081:
082: public String toStartString() {
083: return "";
084: }
085:
086: public String toEndString() {
087: // now do the string rendering
088: action = this .portletURI.toString();
089:
090: if (anchor != null)
091: action += "#" + anchor;
092:
093: //String hlink = "<a href=\"" + action + "\"" + " onClick=\"this.href='" + action + "&JavaScript=enabled'\"/>" + value + "</a>";
094: if (style.equalsIgnoreCase("error")
095: || (style.equalsIgnoreCase("err"))) {
096: this .cssClass = MessageStyle.MSG_ERROR;
097: } else if (style.equalsIgnoreCase("status")) {
098: this .cssClass = MessageStyle.MSG_STATUS;
099: } else if (style.equalsIgnoreCase("info")) {
100: this .cssClass = MessageStyle.MSG_INFO;
101: } else if (style.equalsIgnoreCase("alert")) {
102: this .cssClass = MessageStyle.MSG_ALERT;
103: } else if (style.equalsIgnoreCase("success")) {
104: this .cssClass = MessageStyle.MSG_SUCCESS;
105: } else if (style.equalsIgnoreCase(MessageStyle.MSG_BOLD)) {
106: this .addCssStyle("font-weight: bold;");
107: } else if (style.equalsIgnoreCase(MessageStyle.MSG_ITALIC)) {
108: this .addCssStyle("font-style: italic;");
109: } else if (style.equalsIgnoreCase(MessageStyle.MSG_UNDERLINE)) {
110: this .addCssStyle("text-decoration: underline;");
111: }
112: StringBuffer sb = new StringBuffer();
113: sb.append("<a");
114: if (name != null)
115: sb.append(" name=\"").append(name).append("\"");
116: if (id != null)
117: sb.append(" id=\"").append(id).append("\" ");
118: if (useAjax)
119: action = "#";
120: sb.append(" href=\"").append(action).append("\"");
121:
122: sb.append(getFormattedCss());
123: if (onClick != null)
124: sb.append(" onclick=\"").append(onClick).append("\"");
125: if (onMouseOut != null)
126: sb.append(" onMouseOut=\"").append(onMouseOut).append("\"");
127: if (onMouseOver != null)
128: sb.append(" onMouseOver=\"").append(onMouseOver).append(
129: "\"");
130: sb.append(">");
131:
132: for (TagBean bean : beans) {
133: sb.append(bean.toStartString());
134: sb.append(bean.toEndString());
135: }
136:
137: sb.append(value).append("</a>");
138: return sb.toString();
139: }
140:
141: }
|