001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portlet.inline;
021:
022: import java.io.IOException;
023: import java.io.Writer;
024:
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.GenericPortlet;
028: import javax.portlet.PortletException;
029: import javax.portlet.ReadOnlyException;
030: import javax.portlet.RenderRequest;
031: import javax.portlet.RenderResponse;
032: import javax.portlet.ValidatorException;
033:
034: import com.nabhinc.util.StringUtil;
035:
036: /**
037: *
038: *
039: * @author Padmanabh Dabke
040: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
041: */
042: public class InlinePortlet extends GenericPortlet {
043: /**
044: * Displays portlet content configured via "content" parameter.
045: * The default implementation throws an exception.
046: * @param request The portlet request.
047: * @param response The render response.
048: * @exception PortletException If the portlet cannot fulfilling the request.
049: * @exception IOException If the streaming causes an I/O problem
050: */
051: protected void doView(RenderRequest request, RenderResponse response)
052: throws PortletException, java.io.IOException {
053: Writer w = response.getWriter();
054: w.write("<script type=\"text/javascript\">/*<![CDATA[*/");
055: w.write("sb_register_unload_callback(null, '");
056: w.write(response.getNamespace());
057: w.write("');");
058: w.write("sb_register_load_callback(null, '");
059: w.write(response.getNamespace());
060: w.write("');");
061: w.write("/*]]>*/</script>");
062: w.write(request.getPreferences().getValue("content",
063: "No Content"));
064: w.flush();
065: }
066:
067: /**
068: * Helper method to serve up the <code>edit</code> mode.
069: * The default implementation throws an exception.
070: * @param request The portlet request
071: * @param response The render response
072: * @exception PortletException If the portlet cannot fulfilling the request
073: * @exception IOException If the streaming causes an I/O problem
074: */
075: protected void doEdit(RenderRequest request, RenderResponse response)
076: throws PortletException, java.io.IOException {
077: Writer w = response.getWriter();
078: String textAreaId = response.getNamespace() + "_textarea";
079: w.write("<form method=\"POST\" action=\"");
080: w.write(response.createActionURL().toString());
081: // w.write("\"><center><div style=\"padding: 5px;\">");
082: w.write("\">");
083: w.write("<textarea id=\"");
084: w.write(textAreaId);
085: w.write("\" name=\"content\">");
086: w.write(request.getPreferences().getValue("content", ""));
087: w.write("</textarea>");
088: // w.write("</div></center></form>");
089: w.write("</center></form>");
090: // if (request.getProperty(PortalConstants.AJAX_HEADER) != null) {
091: w.write("<script type=\"text/javascript\">");
092: w
093: .write("sb_register_unload_callback(sb_remove_tiny_mce_control, '");
094: w.write(response.getNamespace());
095: w.write("');");
096: /*
097: w.write("sb_register_load_callback(sb_tiny_mce_content_saved, '");
098: w.write(response.getNamespace());
099: w.write("');");
100:
101: w.write("tinyMCE.execCommand('mceRemoveControl', true, '");
102: w.write(textAreaId);
103: w.write("');");
104: */
105: w.write("tinyMCE.execCommand('mceAddControl', true, '");
106: w.write(textAreaId);
107: w.write("');");
108:
109: /*
110: w.write("sb_add_tiny_mce_control('");
111: w.write(textAreaId);
112: w.write("');");
113: */
114: w.write("</script>");
115:
116: // }
117: }
118:
119: /**
120: * Helper method to serve up the <code>help</code> mode.
121: * The default implementation throws an exception.
122: * @param request The portlet request
123: * @param response The render response
124: * @exception PortletException If the portlet cannot fulfilling the request
125: * @exception IOException If the streaming causes an I/O problem
126: */
127: protected void doHelp(RenderRequest request, RenderResponse response)
128: throws PortletException, java.io.IOException {
129: Writer w = response.getWriter();
130: w.write(request.getPreferences().getValue("help",
131: "Help is not available."));
132: w.flush();
133: }
134:
135: public void processAction(ActionRequest request,
136: ActionResponse response) throws ReadOnlyException,
137: ValidatorException, IOException {
138: String content = request.getParameter("content");
139: if (StringUtil.isNotNullOrEmpty(content)) {
140: request.getPreferences().setValue("content", content);
141: request.getPreferences().store();
142: }
143: }
144:
145: }
|