001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.widget.google;
023:
024: import org.jboss.portal.widget.AbstractWidgetPortlet;
025: import org.jboss.portal.widget.Widget;
026: import org.jboss.portal.widget.WidgetProvider;
027: import org.jboss.portal.widget.google.provider.GGProvider;
028:
029: import javax.portlet.ActionRequest;
030: import javax.portlet.ActionResponse;
031: import javax.portlet.PortletConfig;
032: import javax.portlet.PortletException;
033: import javax.portlet.PortletRequestDispatcher;
034: import javax.portlet.PortletSecurityException;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037: import java.io.IOException;
038: import java.io.PrintWriter;
039: import java.util.HashMap;
040: import java.util.Iterator;
041: import java.util.Map;
042:
043: /**
044: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
045: * @author <a href="mailto:boleslaw dot dawidowicz at jboss dot com">Boleslaw Dawidowicz</a>
046: * @version $Revision: 8784 $
047: */
048: public class GGWidgetPortlet extends AbstractWidgetPortlet {
049: /** . */
050: private static final org.jboss.logging.Logger log = org.jboss.logging.Logger
051: .getLogger(GGWidgetPortlet.class);
052:
053: /** . */
054: private GGProvider provider = new GGProvider();
055:
056: @Override
057: protected WidgetProvider getProvider() {
058: return provider;
059: }
060:
061: public void processAction(ActionRequest req, ActionResponse resp)
062: throws PortletException, PortletSecurityException,
063: IOException {
064: if (req.getParameter("content.action.select") != null) {
065: PortletConfig conf = getPortletConfig();
066:
067: String contentURI = req.getParameter("content.uri");
068: if (contentURI != null) {
069: // Will contain the next render params
070: Map params = new HashMap();
071:
072: //
073: params.put("content.uri", new String[] { contentURI });
074:
075: //
076: for (Iterator i = req.getParameterMap().entrySet()
077: .iterator(); i.hasNext();) {
078: Map.Entry entry = (Map.Entry) i.next();
079: String contentParamName = (String) entry.getKey();
080: if (contentParamName.startsWith("content.param")) {
081: String[] contentParamValue = (String[]) entry
082: .getValue();
083: params.put(contentParamName, contentParamValue);
084: }
085: }
086:
087: //
088: String catParam = req.getParameter("cat");
089: if (catParam != null) {
090: params.put("cat", new String[] { catParam });
091: }
092:
093: String currentPage = req.getParameter("currentPage");
094: if (currentPage != null) {
095: params.put("currentPage",
096: new String[] { currentPage });
097: }
098:
099: String numberOfResults = req
100: .getParameter("numberOfResults");
101: if (numberOfResults != null) {
102: params.put("numberOfResults",
103: new String[] { numberOfResults });
104: }
105:
106: //
107: String queryParam = req.getParameter("query");
108: if (queryParam != null) {
109: params.put("query", new String[] { queryParam });
110: }
111:
112: String pickMethod = req.getParameter("gg_pick_method");
113: if (pickMethod != null) {
114: params.put("gg_pick_method",
115: new String[] { pickMethod });
116: }
117:
118: //
119: resp.setRenderParameters(params);
120: }
121: }
122: }
123:
124: protected void doView(RenderRequest req, RenderResponse resp)
125: throws PortletException, PortletSecurityException,
126: IOException {
127: resp.setContentType("text/html");
128: PrintWriter writer = resp.getWriter();
129: String uri = req.getParameter("uri");
130: Widget widget = provider.getWidget(uri);
131: if (widget != null) {
132: if (widget.getTitle() != null) {
133: resp.setTitle(widget.getTitle().getString(
134: req.getLocale(), true));
135: }
136: writer.print(widget.render(req.getParameterMap(), req
137: .getLocale()));
138: } else {
139: writer.print("Widget is not available");
140: }
141: writer.close();
142: }
143:
144: protected void doDispatch(RenderRequest req, RenderResponse resp)
145: throws PortletException, PortletSecurityException,
146: IOException {
147: if (EDIT_CONTENT.equals(req.getPortletMode())) {
148: doEditContent(req, resp);
149: } else {
150: super .doDispatch(req, resp);
151: }
152: }
153:
154: protected void doEditContent(RenderRequest req, RenderResponse resp)
155: throws PortletException, PortletSecurityException,
156: IOException {
157: resp.setContentType("text/html");
158: Map map = req.getParameterMap();
159: //
160: req.setAttribute("provider", provider);
161:
162: //
163: PortletRequestDispatcher dispatcher = getPortletContext()
164: .getRequestDispatcher("/WEB-INF/jsp/edit_content.jsp");
165: dispatcher.include(req, resp);
166: }
167: }
|