001: package org.gridsphere.provider.portletui.beans;
002:
003: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
004: import org.gridsphere.services.core.portal.PortalConfigService;
005:
006: /**
007: * The <code>TextEditorBean</code> represents a text editor provided
008: * by Cezary Tomczak at http://gosu.pl/dhtml/SimpleTextEditor.html
009: */
010: public class TextEditorBean extends BaseComponentBean implements
011: TagBean {
012:
013: private int cols = 0;
014: private int rows = 0;
015: private String value = null;
016: private String action = null;
017: private boolean viewsource = true;
018:
019: /**
020: * Constructs a default text area bean
021: */
022: public TextEditorBean() {
023: super (TagBean.TEXTEDITOR_NAME);
024: }
025:
026: /**
027: * Constructs a text area bean from a supplied portlet request and bean identifier
028: *
029: * @param beanId the bean identifier
030: */
031: public TextEditorBean(String beanId) {
032: super (TagBean.TEXTEDITOR_NAME);
033: this .beanId = beanId;
034: }
035:
036: /**
037: * Returns true if text editor should allow users to edit/view HTML source
038: *
039: * @return true if text editor should allow users to edit/view HTML source
040: */
041: public boolean getViewsource() {
042: return viewsource;
043: }
044:
045: /**
046: * Set to true if text editor should allow users to edit/view HTML source
047: *
048: * @param viewsource is true if text editor should allow users to edit/view HTML source
049: */
050: public void setViewsource(boolean viewsource) {
051: this .viewsource = viewsource;
052: }
053:
054: public String getAction() {
055: return action;
056: }
057:
058: public void setAction(String action) {
059: this .action = action;
060: }
061:
062: /**
063: * Gets the number of columns of the TextArea.
064: *
065: * @return number of columns
066: */
067: public int getCols() {
068: return cols;
069: }
070:
071: /**
072: * Sets the number of columns of the TextArea.
073: *
074: * @param cols number of cols
075: */
076: public void setCols(int cols) {
077: this .cols = cols;
078: }
079:
080: /**
081: * Return the number of rows of the textarea.
082: *
083: * @return number of rows
084: */
085: public int getRows() {
086: return rows;
087: }
088:
089: /**
090: * Sets the number of rows of the textarea.
091: *
092: * @param rows number of rows
093: */
094: public void setRows(int rows) {
095: this .rows = rows;
096: }
097:
098: /**
099: * Sets the bean value
100: *
101: * @param value the bean value
102: */
103: public void setValue(String value) {
104: this .value = value;
105: }
106:
107: /**
108: * Returns the bean value
109: *
110: * @return the bean value
111: */
112: public String getValue() {
113: return value;
114: }
115:
116: public String toStartString() {
117: PortalConfigService configService = (PortalConfigService) PortletServiceFactory
118: .createPortletService(PortalConfigService.class, true);
119: // deal with ROOT context case
120: String contextPath = configService
121: .getProperty("gridsphere.deploy");
122: if (!contextPath.equals(""))
123: contextPath = "/" + contextPath;
124: renderResponse.setProperty("CSS_HREF", contextPath
125: + "/css/SimpleTextEditor.css");
126: renderResponse.addProperty("JAVASCRIPT_SRC", contextPath
127: + "/javascript/SimpleTextEditor.js");
128: StringBuffer sb = new StringBuffer();
129: sb.append("<form action=\"" + action + "\" method=\"post\">");
130: String sname = createTagName(name);
131: sb.append("<textarea id=\"body\" name=\"" + sname
132: + "\" cols=\"" + cols + "\" rows=\"" + rows + "\">");
133: return sb.toString();
134: }
135:
136: public String toEndString() {
137: StringBuffer sb = new StringBuffer();
138: String result = (value != null) ? value : "";
139: sb.append(result + "</textarea>");
140: sb.append("<script type=\"text/javascript\">");
141: String sname = createTagName(name);
142: sb.append("var ste = new SimpleTextEditor(\"body\", \"" + sname
143: + "\", " + viewsource + ", \"ste\");");
144: sb.append("ste.init();");
145: sb.append("</script>");
146: sb
147: .append("<input type=\"submit\" value=\"Submit\" onclick=\"ste.submit();\">");
148: sb.append("</form>");
149: return sb.toString();
150: }
151:
152: }
|