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