001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PanelTag.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.provider.portletui.tags;
005:
006: import org.gridsphere.provider.portletui.beans.PanelBean;
007:
008: import javax.servlet.jsp.JspException;
009: import javax.servlet.jsp.JspWriter;
010: import java.util.StringTokenizer;
011:
012: /**
013: * A <code>PanelTag</code> represents a stylized table that generally conatins other <code>TableTag</code> or
014: * <code>FrameTag</code> nested tags
015: */
016: public class PanelTag extends BaseComponentTag {
017:
018: protected String width = PanelBean.PANEL_WIDTH;
019: protected String cellSpacing = PanelBean.PANEL_SPACING;
020: protected String cellPadding = PanelBean.PANEL_PADDING;
021: protected String align = null;
022: protected String border = PanelBean.PANEL_BORDER;
023: protected String cols = "100%";
024: protected String[] colArray;
025: protected int numCols = 1;
026: protected PanelBean panelBean = null;
027: protected int counter = 0;
028:
029: /**
030: * Sets the panel (table) cell spacing
031: *
032: * @param cellPadding the panel cell padding
033: */
034: public void setCellpadding(String cellPadding) {
035: this .cellPadding = cellPadding;
036: }
037:
038: /**
039: * Returns the panel (table) cell padding
040: *
041: * @return the panel cell padding
042: */
043: public String getCellpadding() {
044: return cellPadding;
045: }
046:
047: /**
048: * Sets the table alignment e.g. "left", "center" or "right"
049: *
050: * @param align the table alignment
051: */
052: public void setAlign(String align) {
053: this .align = align;
054: }
055:
056: /**
057: * Returns the table alignment e.g. "left", "center" or "right"
058: *
059: * @return the table alignment
060: */
061: public String getAlign() {
062: return align;
063: }
064:
065: /**
066: * Sets the table border
067: *
068: * @param border the panel border
069: */
070: public void setBorder(String border) {
071: this .border = border;
072: }
073:
074: /**
075: * Returns the panel border
076: *
077: * @return the panel border
078: */
079: public String getBorder() {
080: return border;
081: }
082:
083: /**
084: * Sets the panel width
085: *
086: * @param width the panel width
087: */
088: public void setWidth(String width) {
089: this .width = width;
090: }
091:
092: /**
093: * Returns the panel width
094: *
095: * @return the panel width
096: */
097: public String getWidth() {
098: return width;
099: }
100:
101: /**
102: * Sets the number of columns in the panel
103: *
104: * @param cols the number of columns
105: */
106: public void setCols(String cols) {
107: this .cols = cols;
108: }
109:
110: /**
111: * Returns the number of columns in the panel
112: *
113: * @return the number of columns in the panel
114: */
115: public String getCols() {
116: return cols;
117: }
118:
119: /**
120: * Returns the number of columns in the panel
121: *
122: * @return the number of columns in the panel
123: */
124: public int getNumCols() {
125: return numCols;
126: }
127:
128: /**
129: * Returns the number of columns in the panel
130: *
131: * @return the number of columns in the panel
132: */
133: public String[] getColArray() {
134: return colArray;
135: }
136:
137: public void setColumnCounter(int counter) {
138: this .counter = counter;
139: }
140:
141: public int getColumnCounter() {
142: return counter;
143: }
144:
145: /**
146: * Sets the panel cell spacing
147: *
148: * @param cellSpacing the panel cell spacing
149: */
150: public void setCellSpacing(String cellSpacing) {
151: this .cellSpacing = cellSpacing;
152: }
153:
154: /**
155: * Returns the panel cell spacing
156: *
157: * @return the panel cell spacing
158: */
159: public String getCellSpacing() {
160: return cellSpacing;
161: }
162:
163: public int doStartTag() throws JspException {
164: boolean includeBody = true;
165:
166: counter = 0;
167: if (!beanId.equals("")) {
168: panelBean = (PanelBean) getTagBean();
169: if (panelBean == null) {
170: panelBean = new PanelBean();
171: this .setBaseComponentBean(panelBean);
172: } else {
173: includeBody = false;
174: }
175: } else {
176: panelBean = new PanelBean();
177: this .setBaseComponentBean(panelBean);
178: panelBean.setWidth(width);
179:
180: StringTokenizer st = new StringTokenizer(cols, ",");
181: numCols = st.countTokens();
182: colArray = new String[numCols];
183: int i = 0;
184: String colStr;
185: while (st.hasMoreElements()) {
186: colStr = (String) st.nextElement();
187: colArray[i++] = colStr.trim();
188: }
189:
190: panelBean.setCols(cols);
191: panelBean.setColArray(colArray);
192: panelBean.setNumCols(numCols);
193: panelBean.setCellSpacing(cellSpacing);
194: panelBean.setCellPadding(cellPadding);
195: panelBean.setBorder(border);
196: panelBean.setCssClass(cssClass);
197: panelBean.setCssStyle(cssStyle);
198: if (align != null)
199: panelBean.setAlign(align);
200: }
201:
202: try {
203: JspWriter out = pageContext.getOut();
204:
205: out.print(panelBean.toStartString());
206: } catch (Exception e) {
207: throw new JspException(e.getMessage());
208: }
209: if (includeBody) {
210: return EVAL_BODY_INCLUDE;
211: } else {
212: return SKIP_BODY;
213: }
214: }
215:
216: public int doEndTag() throws JspException {
217: try {
218: JspWriter out = pageContext.getOut();
219: out.print(panelBean.toEndString());
220: } catch (Exception e) {
221: throw new JspException(e.getMessage());
222: }
223:
224: return EVAL_PAGE;
225: }
226: }
|