001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: FrameTag.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.provider.portletui.tags;
005:
006: import org.gridsphere.provider.portletui.beans.FrameBean;
007: import org.gridsphere.provider.portletui.beans.TableBean;
008:
009: import javax.servlet.jsp.JspException;
010: import javax.servlet.jsp.JspWriter;
011: import java.util.Locale;
012: import java.util.ResourceBundle;
013:
014: /**
015: * A <code>FrameTag</code> is a stylized <code>TableTag</code> that can also be used to set text messages
016: */
017: public class FrameTag extends TableTag {
018:
019: protected String style = null;
020: protected String key = null;
021: protected String value = null;
022:
023: public FrameTag() {
024: cssClass = FrameBean.FRAME_TABLE;
025: }
026:
027: /**
028: * Sets the key used to locate localized text
029: *
030: * @param key the key
031: */
032: public void setKey(String key) {
033: this .key = key;
034: }
035:
036: /**
037: * Returns the key used to locate localized text
038: *
039: * @return the key
040: */
041: public String getKey() {
042: return key;
043: }
044:
045: /**
046: * Sets the style of the text: Available styles are
047: * <ul>
048: * <li>error</li>
049: * <li>info</li>
050: * <li>status</li>
051: * <li>alert</li>
052: * <li>success</li>
053: *
054: * @param style the text style
055: */
056: public void setStyle(String style) {
057: this .style = style;
058: }
059:
060: /**
061: * Returns the style of the text: Available styles are
062: * <ul>
063: * <li>error</li>
064: * <li>info</li>
065: * <li>status</li>
066: * <li>alert</li>
067: * <li>success</li>
068: *
069: * @return the text style
070: */
071: public String getStyle() {
072: return style;
073: }
074:
075: public int doStartTag() throws JspException {
076: if (style != null) {
077: if (style.equalsIgnoreCase("error")
078: || (style.equalsIgnoreCase("err"))) {
079: this .cssClass = FrameBean.FRAME_ERROR_MESSAGE;
080: //this.cssClass = TextBean.MSG_ERROR;
081: } else if (style.equalsIgnoreCase("status")) {
082: this .cssClass = FrameBean.FRAME_ERROR_MESSAGE;
083: //this.cssClass = TextBean.MSG_STATUS;
084: } else if (style.equalsIgnoreCase("info")) {
085: this .cssClass = FrameBean.FRAME_INFO_MESSAGE;
086: //this.cssClass = TextBean.MSG_INFO;
087: } else if (style.equalsIgnoreCase("alert")) {
088: this .cssClass = FrameBean.FRAME_ALERT_MESSAGE;
089: //this.cssClass = TextBean.MSG_ALERT;
090: } else if (style.equalsIgnoreCase("success")) {
091: this .cssClass = FrameBean.FRAME_INFO_MESSAGE;
092: //this.cssClass = TextBean.MSG_SUCCESS;
093: }
094: }
095: // get any parameter values if data is divided
096: if (maxRows > 0) {
097: String curPage = pageContext.getRequest().getParameter(
098: TableBean.CURRENT_PAGE);
099: if (curPage != null) {
100: currentPage = Integer.valueOf(curPage).intValue();
101: }
102: }
103: if (!beanId.equals("")) {
104: tableBean = (FrameBean) getTagBean();
105: if (tableBean == null) {
106: tableBean = new FrameBean(beanId);
107: this .setBaseComponentBean(tableBean);
108:
109: return SKIP_BODY;
110: } else {
111: String key = tableBean.getKey();
112: if (key != null) {
113: tableBean.setValue(getLocalizedText(key));
114: }
115: tableBean.setCssClass(cssClass);
116: tableBean.setCssStyle(cssStyle);
117: }
118: } else {
119: tableBean = new FrameBean();
120: tableBean.setWidth(width);
121: if (cellSpacing != null)
122: tableBean.setCellSpacing(cellSpacing);
123: if (cellPadding != null)
124: tableBean.setCellPadding(cellPadding);
125: if (border != null)
126: tableBean.setBorder(border);
127: if (align != null)
128: tableBean.setAlign(align);
129: if (align != null)
130: tableBean.setValign(valign);
131: tableBean.setCssClass(cssClass);
132: tableBean.setCssStyle(cssStyle);
133: if (sortable) {
134: tableBean.setSortable(sortable);
135: tableBean.setSortableID("td"
136: + this .getUniqueId("gs_tableNum"));
137: }
138: this .setBaseComponentBean(tableBean);
139: if (key != null) {
140: tableBean.setKey(key);
141: Locale locale = pageContext.getRequest().getLocale();
142: ResourceBundle bundle = ResourceBundle.getBundle(
143: "Portlet", locale);
144: tableBean
145: .setValue(bundle.getString(tableBean.getKey()));
146: }
147: tableBean.setMaxRows(maxRows);
148: }
149:
150: tableBean.setCurrentPage(currentPage);
151: tableBean.setRowCount(rowCount);
152: tableBean.setZebra(isZebra);
153: PanelTag panelTag = (PanelTag) findAncestorWithClass(this ,
154: PanelTag.class);
155: if (panelTag != null) {
156: int numCols = panelTag.getNumCols();
157: int this col = panelTag.getColumnCounter();
158: try {
159: JspWriter out = pageContext.getOut();
160: if ((this col % numCols) == 0) {
161: out.println("<tr valign=\"top\">");
162: }
163: // Attribute 'width' replaced by 'style="width:"' for XHTML 1.0 Strict compliance
164: out.println("<td style=\"width:" + "100%" + "\">");
165: } catch (Exception e) {
166: throw new JspException(e.getMessage());
167: }
168: }
169:
170: try {
171: JspWriter out = pageContext.getOut();
172: out.print(tableBean.toStartString());
173: } catch (Exception e) {
174: throw new JspException(e.getMessage());
175: }
176:
177: return EVAL_BODY_INCLUDE;
178: }
179:
180: public int doEndTag() throws JspException {
181: tableBean.setRowCount(rowCount);
182: if (!beanId.equals("")) {
183: tableBean = (FrameBean) getTagBean();
184: if (tableBean == null) {
185: return EVAL_PAGE;
186: }
187: }
188: rowCount = 0;
189: try {
190: JspWriter out = pageContext.getOut();
191: out.print(tableBean.toEndString());
192: } catch (Exception e) {
193: throw new JspException(e.getMessage());
194: }
195:
196: PanelTag panelTag = (PanelTag) findAncestorWithClass(this ,
197: PanelTag.class);
198: if (panelTag != null) {
199: int numCols = panelTag.getNumCols();
200: int this col = panelTag.getColumnCounter();
201: this col++;
202: panelTag.setColumnCounter(this col);
203: try {
204: JspWriter out = pageContext.getOut();
205: out.println("</td>");
206: if ((this col % numCols) == 0) {
207: out.println("</tr>");
208: }
209: } catch (Exception e) {
210: throw new JspException(e.getMessage());
211: }
212: }
213:
214: return EVAL_PAGE;
215: }
216: }
|