001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: ActionLinkTag.java 6423 2008-02-28 13:26:21Z wehrens $
004: */package org.gridsphere.provider.portletui.tags;
005:
006: import org.gridsphere.portlet.impl.SportletProperties;
007: import org.gridsphere.provider.portletui.beans.ActionLinkBean;
008: import org.gridsphere.provider.portletui.beans.ImageBean;
009: import org.gridsphere.provider.portletui.beans.MessageStyle;
010:
011: import javax.servlet.jsp.JspException;
012: import javax.servlet.jsp.JspWriter;
013: import javax.servlet.jsp.PageContext;
014: import javax.servlet.jsp.tagext.Tag;
015:
016: /**
017: * The <code>ActionLinkTag</code> provides a hyperlink element that includes a <code>DefaultPortletAction</code>
018: * and can contain nested <code>ActionParamTag</code>s
019: */
020: public class ActionLinkTag extends ActionTag {
021:
022: protected ActionLinkBean actionlink = null;
023:
024: protected String style = MessageStyle.MSG_INFO;
025: protected ImageBean imageBean = null;
026:
027: /**
028: * Sets the style of the text: Available styles are
029: * <ul>
030: * <li>nostyle</li>
031: * <li>error</li>
032: * <li>info</li>
033: * <li>status</li>
034: * <li>alert</li>
035: * <li>success</li>
036: *
037: * @param style the text style
038: */
039: public void setStyle(String style) {
040: this .style = style;
041: }
042:
043: /**
044: * Returns the style of the text: Available styles are
045: * <ul>
046: * <li>nostyle</li>
047: * <li>error</li>
048: * <li>info</li>
049: * <li>status</li>
050: * <li>alert</li>
051: * <li>success</li>
052: *
053: * @return the text style
054: */
055: public String getStyle() {
056: return style;
057: }
058:
059: /**
060: * Sets the image bean
061: *
062: * @param imageBean the image bean
063: */
064: public void setImageBean(ImageBean imageBean) {
065: this .imageBean = imageBean;
066: }
067:
068: /**
069: * Returns the image bean
070: *
071: * @return the image bean
072: */
073: public ImageBean getImageBean() {
074: return imageBean;
075: }
076:
077: public int doStartTag() throws JspException {
078: if (!beanId.equals("")) {
079: actionlink = (ActionLinkBean) getTagBean();
080: if (actionlink == null) {
081: actionlink = new ActionLinkBean(beanId);
082: actionlink.setStyle(style);
083: this .setBaseComponentBean(actionlink);
084: } else {
085: if (actionlink.getParamBeanList() != null) {
086: paramBeans = actionlink.getParamBeanList();
087: }
088: if (actionlink.getAction() != null) {
089: action = actionlink.getAction();
090: }
091: if (actionlink.getValue() != null) {
092: value = actionlink.getValue();
093: }
094: if (actionlink.getKey() != null) {
095: key = actionlink.getKey();
096: }
097: if (actionlink.getOnClick() != null) {
098: onClick = actionlink.getOnClick();
099: }
100: }
101: } else {
102: actionlink = new ActionLinkBean();
103: this .setBaseComponentBean(actionlink);
104: actionlink.setStyle(style);
105: }
106:
107: actionlink.setUseAjax(useAjax);
108: if (name != null)
109: actionlink.setName(name);
110: if (anchor != null)
111: actionlink.setAnchor(anchor);
112: if (action != null)
113: actionlink.setAction(action);
114: if (value != null)
115: actionlink.setValue(value);
116: if (onClick != null)
117: actionlink.setOnClick(onClick);
118: if (style != null)
119: actionlink.setStyle(style);
120: if (cssStyle != null)
121: actionlink.setCssStyle(cssStyle);
122: if (cssClass != null)
123: actionlink.setCssClass(cssClass);
124: if (layout != null)
125: actionlink.setLayout(layout);
126: if (label != null)
127: actionlink.setLabel(label);
128: if (onMouseOut != null)
129: actionlink.setOnMouseOut(onMouseOut);
130: if (onMouseOver != null)
131: actionlink.setOnMouseOver(onMouseOver);
132:
133: Tag parent = getParent();
134: if (parent instanceof ActionMenuTag) {
135: ActionMenuTag actionMenuTag = (ActionMenuTag) parent;
136: if (!actionMenuTag.getLayout().equals("horizontal")) {
137: actionlink.setCssStyle("display: block");
138: }
139: }
140:
141: if (key != null) {
142: actionlink.setKey(key);
143: actionlink.setValue(getLocalizedText(key));
144: value = actionlink.getValue();
145: }
146:
147: return EVAL_BODY_BUFFERED;
148: }
149:
150: public int doEndTag() throws JspException {
151: if (!beanId.equals("")) {
152: paramBeans = actionlink.getParamBeanList();
153: action = actionlink.getAction();
154: }
155:
156: if (action != null) {
157: actionlink.setPortletURI(createActionURI());
158: } else {
159: actionlink.setPortletURI(createRenderURI());
160: }
161: if ((bodyContent != null) && (value == null)) {
162: actionlink.setValue(bodyContent.getString());
163: }
164:
165: if (pageContext.getRequest().getAttribute(
166: SportletProperties.USE_AJAX) != null) {
167: String paction = ((!action.equals("")) ? "&"
168: + portletPhase.toString() : "");
169: String portlet = (String) pageContext.getRequest()
170: .getAttribute(SportletProperties.PORTLET_NAME);
171: String compname = (String) pageContext.getRequest()
172: .getAttribute(SportletProperties.COMPONENT_NAME);
173: actionlink.setUseAjax(true);
174: actionlink
175: .setOnClick("GridSphereAjaxHandler2.startRequest('"
176: + portlet + "', '" + compname + "', '"
177: + paction + "');");
178: }
179:
180: if (useAjax) {
181: String cid = (String) pageContext.getRequest()
182: .getAttribute(SportletProperties.COMPONENT_ID);
183: String paction = ((!action.equals("")) ? "&"
184: + portletPhase.toString() : "");
185: actionlink.setOnClick("GridSphereAjaxHandler.startRequest("
186: + cid + ", '" + paction + "');");
187: }
188:
189: if (imageBean != null) {
190: String val = actionlink.getValue();
191: if (val == null)
192: val = "";
193: actionlink.setValue(imageBean.toStartString() + val);
194: }
195:
196: if (var == null) {
197: try {
198: JspWriter out = pageContext.getOut();
199: out.print(actionlink.toEndString());
200: } catch (Exception e) {
201: throw new JspException(e);
202: }
203: } else {
204: pageContext.setAttribute(var, actionlink.toEndString(),
205: PageContext.PAGE_SCOPE);
206: }
207: release();
208: return EVAL_PAGE;
209: }
210: }
|