001: package org.gridsphere.provider.portletui.tags;
002:
003: import org.gridsphere.provider.portletui.beans.TextEditorBean;
004:
005: import javax.servlet.jsp.JspException;
006: import javax.servlet.jsp.JspWriter;
007:
008: /**
009: * The <code>TextEditorTag</code> uses the SimpleTextEditor javscript provided
010: * by Cezary Tomczak at http://gosu.pl/dhtml/SimpleTextEditor.html
011: */
012: public class TextEditorTag extends ActionTag {
013:
014: protected TextEditorBean textEditorBean = null;
015: private int cols = 0;
016: private int rows = 0;
017: private boolean viewsource = true;
018:
019: /**
020: * Returns true if text editor should allow users to edit/view HTML source
021: *
022: * @return true if text editor should allow users to edit/view HTML source
023: */
024: public boolean getViewsource() {
025: return viewsource;
026: }
027:
028: /**
029: * Set to true if text editor should allow users to edit/view HTML source
030: *
031: * @param viewsource is true if text editor should allow users to edit/view HTML source
032: */
033: public void setViewsource(boolean viewsource) {
034: this .viewsource = viewsource;
035: }
036:
037: /**
038: * Returns the number of columns of the text area
039: *
040: * @return number of columns
041: */
042: public int getCols() {
043: return cols;
044: }
045:
046: /**
047: * Sets the number of columns of the text area
048: *
049: * @param cols number of cols
050: */
051: public void setCols(int cols) {
052: this .cols = cols;
053: }
054:
055: /**
056: * Return the number of rows of the text area
057: *
058: * @return number of rows
059: */
060: public int getRows() {
061: return rows;
062: }
063:
064: /**
065: * Sets the number of rows of the text area
066: *
067: * @param rows number of rows
068: */
069: public void setRows(int rows) {
070: this .rows = rows;
071: }
072:
073: public int doStartTag() throws JspException {
074: if (!beanId.equals("")) {
075: textEditorBean = (TextEditorBean) getTagBean();
076: if (textEditorBean == null) {
077: textEditorBean = new TextEditorBean();
078: textEditorBean.setRows(rows);
079: textEditorBean.setCols(cols);
080: textEditorBean.setViewsource(viewsource);
081: this .setBaseComponentBean(textEditorBean);
082: } else {
083: if ((textEditorBean.getCols() == 0) && (cols != 0)) {
084: textEditorBean.setCols(cols);
085: }
086: if ((textEditorBean.getRows() == 0) && (rows != 0)) {
087: textEditorBean.setRows(rows);
088: }
089: this .updateBaseComponentBean(textEditorBean);
090: this .viewsource = textEditorBean.getViewsource();
091: }
092: } else {
093: textEditorBean = new TextEditorBean();
094: textEditorBean.setRows(rows);
095: textEditorBean.setCols(cols);
096: textEditorBean.setViewsource(viewsource);
097: this .setBaseComponentBean(textEditorBean);
098: }
099:
100: textEditorBean.setAction(createActionURI());
101:
102: //debug();
103:
104: try {
105: JspWriter out = pageContext.getOut();
106: out.print(textEditorBean.toStartString());
107: } catch (Exception e) {
108: throw new JspException(e.getMessage());
109: }
110:
111: return EVAL_BODY_INCLUDE;
112: }
113:
114: public int doEndTag() throws JspException {
115:
116: if ((bodyContent != null) && (value == null)) {
117: textEditorBean.setValue(bodyContent.getString());
118: }
119:
120: try {
121: JspWriter out = pageContext.getOut();
122: out.print(textEditorBean.toEndString());
123: } catch (Exception e) {
124: throw new JspException(e.getMessage());
125: }
126: super.release();
127: return EVAL_PAGE;
128: }
129:
130: }
|