001: package org.gridsphere.provider.portletui.tags;
002:
003: import org.gridsphere.portlet.impl.SportletProperties;
004: import org.gridsphere.provider.portletui.beans.ActionMenuBean;
005:
006: import javax.portlet.*;
007: import javax.servlet.jsp.JspException;
008: import javax.servlet.jsp.JspWriter;
009: import javax.servlet.jsp.PageContext;
010: import javax.servlet.jsp.tagext.Tag;
011:
012: /*
013: * @author <a href="mailto:oliver.wehrens@aei.mpg.de">Oliver Wehrens</a>
014: * @version $Id: ActionMenuTag.java 6385 2007-10-25 14:02:26Z wehrens $
015: */
016:
017: public class ActionMenuTag extends ContainerTag {
018:
019: protected ActionMenuBean actionMenuBean = null;
020: protected String layout = null;
021: protected String title = null;
022: protected String menutype = null;
023: protected boolean collapsible = false;
024: protected boolean collapsed = false;
025: protected String key = null;
026:
027: public ActionMenuBean getActionMenuBean() {
028: return actionMenuBean;
029: }
030:
031: public String getMenutype() {
032: return menutype;
033: }
034:
035: public void setMenutype(String menutype) {
036: this .menutype = menutype;
037: }
038:
039: public boolean isCollapsed() {
040: return collapsed;
041: }
042:
043: public void setCollapsed(boolean collapsed) {
044: this .collapsed = collapsed;
045: }
046:
047: public boolean isCollapsible() {
048: return collapsible;
049: }
050:
051: public void setCollapsible(boolean collapsible) {
052: this .collapsible = collapsible;
053: }
054:
055: public String getTitle() {
056: return title;
057: }
058:
059: public void setTitle(String title) {
060: this .title = title;
061: }
062:
063: public String getLayout() {
064: return layout;
065: }
066:
067: public void setLayout(String layout) {
068: this .layout = layout;
069: }
070:
071: /**
072: * Returns the key used to identify localized text
073: *
074: * @return the key used to identify localized text
075: */
076: public String getKey() {
077: return key;
078: }
079:
080: /**
081: * Sets the key used to identify localized text
082: *
083: * @param key the key used to identify localized text
084: */
085: public void setKey(String key) {
086: this .key = key;
087: }
088:
089: public int doStartTag() throws JspException {
090:
091: // get the bean and the values
092: if (!beanId.equals("")) {
093: actionMenuBean = (ActionMenuBean) getTagBean();
094: }
095: if (actionMenuBean == null) {
096: actionMenuBean = new ActionMenuBean();
097: }
098:
099: Tag parent = getParent();
100: if (parent instanceof ActionMenuTag) {
101: actionMenuBean.setHasParentMenu(true);
102: if (menutype == null) {
103: ActionMenuTag actionMenu = (ActionMenuTag) parent;
104: menutype = actionMenu.getMenutype();
105: }
106: }
107:
108: if (layout == null) {
109: layout = actionMenuBean.getAlign();
110: } else {
111: actionMenuBean.setAlign(layout);
112: }
113: if (title == null) {
114: title = actionMenuBean.getTitle();
115: } else {
116: actionMenuBean.setTitle(title);
117: }
118: if (menutype == null) {
119: menutype = actionMenuBean.getMenutype();
120: } else {
121: actionMenuBean.setMenutype(menutype);
122: }
123:
124: // TODO not working so far
125: actionMenuBean.setCollapsible(this .collapsible);
126: actionMenuBean.setCollapsed(this .collapsed);
127: // if using JSR then create render link
128: RenderResponse res = (RenderResponse) pageContext.getAttribute(
129: SportletProperties.RENDER_RESPONSE,
130: PageContext.REQUEST_SCOPE);
131: PortletURL uri = null;
132:
133: uri = res.createActionURL();
134:
135: actionMenuBean.setPortletURL(uri);
136: // PortletResponse res = (PortletResponse) pageContext.getAttribute("portletResponse");
137: // PortletURI uri = res.createURI();
138: // locale stuff
139: if (key != null) {
140: actionMenuBean
141: .setTitle(getLocalizedText(key, "ActionMenu"));
142: }
143:
144: try {
145: JspWriter out = pageContext.getOut();
146: out.print(actionMenuBean.toStartString());
147: } catch (Exception e) {
148: throw new JspException(e.getMessage());
149: }
150: return EVAL_BODY_INCLUDE;
151:
152: }
153:
154: protected String createJSRActionURI(RenderResponse res)
155: throws JspException {
156: // action is a required attribute except for FormTag
157: RenderRequest req = (RenderRequest) pageContext.getAttribute(
158: SportletProperties.RENDER_REQUEST,
159: PageContext.REQUEST_SCOPE);
160: String windowState = req.getWindowState().toString();
161: String portletMode = req.getPortletMode().toString();
162: PortletURL actionURL = res.createRenderURL();
163: if (windowState != null) {
164: WindowState state = new WindowState(windowState);
165: try {
166: System.err.println("set state to:" + state);
167: actionURL.setWindowState(state);
168: } catch (WindowStateException e) {
169: throw new JspException(
170: "Unknown window state in renderURL tag: "
171: + windowState);
172: }
173: }
174: if (portletMode != null) {
175: PortletMode mode = new PortletMode(portletMode);
176: try {
177: actionURL.setPortletMode(mode);
178: System.err.println("set mode to:" + mode);
179: } catch (PortletModeException e) {
180: throw new JspException(
181: "Unknown portlet mode in renderURL tag: "
182: + portletMode);
183: }
184: }
185:
186: System.err.println("printing action URL = "
187: + actionURL.toString());
188:
189: return actionURL.toString();
190: }
191:
192: public int doEndTag() throws JspException {
193:
194: try {
195: JspWriter out = pageContext.getOut();
196: out.print(actionMenuBean.toEndString());
197: } catch (Exception e) {
198: throw new JspException(e.getMessage());
199: }
200:
201: return EVAL_PAGE;
202: }
203: }
|