001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: ActionPortlet.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005: package org.gridsphere.provider.portlet.jsr;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009: import org.gridsphere.portlet.impl.ActionRequestImpl;
010: import org.gridsphere.portlet.impl.SportletProperties;
011: import org.gridsphere.portlet.service.PortletService;
012: import org.gridsphere.portlet.service.PortletServiceException;
013: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
014: import org.gridsphere.portletcontainer.DefaultPortletAction;
015: import org.gridsphere.portletcontainer.DefaultPortletRender;
016: import org.gridsphere.provider.event.jsr.ActionFormEvent;
017: import org.gridsphere.provider.event.jsr.FormEvent;
018: import org.gridsphere.provider.event.jsr.RenderFormEvent;
019: import org.gridsphere.provider.event.jsr.impl.ActionFormEventImpl;
020: import org.gridsphere.provider.event.jsr.impl.RenderFormEventImpl;
021: import org.gridsphere.provider.portletui.beans.MessageBoxBean;
022: import org.gridsphere.provider.portletui.beans.MessageStyle;
023: import org.gridsphere.provider.portletui.beans.TagBean;
024:
025: import javax.portlet.*;
026: import javax.servlet.http.HttpServletRequestWrapper;
027: import java.io.File;
028: import java.io.IOException;
029: import java.lang.reflect.InvocationTargetException;
030: import java.lang.reflect.Method;
031: import java.util.*;
032:
033: /**
034: * An <code>ActionPortlet</code> provides an abstraction on top of
035: * <code>GenericPortlet</code> to develop portlets under the action provider model.
036: */
037: public class ActionPortlet extends GenericPortlet {
038:
039: public Log log = LogFactory.getLog(ActionPortlet.class);
040:
041: // Default error page
042: protected String ERROR_PAGE = "doError";
043:
044: // Default VIEW mode
045: protected String DEFAULT_VIEW_PAGE = "view.jsp";
046:
047: // Default EDIT mode
048: protected String DEFAULT_EDIT_PAGE = "edit.jsp";
049:
050: // Default HELP mode
051: protected String DEFAULT_HELP_PAGE = "help.jsp";
052:
053: // Default CONFIGURE mode
054: protected String DEFAULT_CONFIGURE_PAGE = "configure.jsp";
055:
056: public void init(PortletConfig config) throws PortletException {
057: super .init(config);
058: }
059:
060: protected void setFileDownloadEvent(PortletRequest req,
061: String fileName, String path) {
062: setFileDownloadEvent(req, fileName, path, false);
063: }
064:
065: protected void setFileDownloadEvent(PortletRequest req,
066: String fileName, String path, boolean deleteFile) {
067: req.setAttribute(SportletProperties.FILE_DOWNLOAD_NAME,
068: fileName);
069: req.setAttribute(SportletProperties.FILE_DOWNLOAD_PATH, path);
070: req.setAttribute(SportletProperties.FILE_DELETE, Boolean
071: .valueOf(deleteFile));
072: }
073:
074: protected void setFileDownloadEvent(PortletRequest req, File file) {
075: req.setAttribute(SportletProperties.FILE_DOWNLOAD_NAME, file
076: .getName());
077: req.setAttribute(SportletProperties.FILE_DOWNLOAD_BINARY, file);
078: }
079:
080: /**
081: * Sets the next display state. The state specified may be either a JSP or it can
082: * be another method name to invoke.
083: *
084: * @param request the <code>Portletrequest</code>
085: * @param state the next display state
086: */
087: protected void setNextState(PortletRequest request, String state) {
088: String id = getUniqueId();
089: request.getPortletSession(true).setAttribute(id + ".state",
090: state, PortletSession.PORTLET_SCOPE);
091: log.debug("in ActionPortlet in setNextState: setting state to "
092: + state);
093: }
094:
095: /**
096: * Returns the next display state. The state specified may be either a JSP or it can
097: * be another method name to invoke.
098: *
099: * @param request the <code>PortletRequest</code>
100: * @return the next display state, either the JSP to include or a method to invoke
101: */
102: protected String getNextState(PortletRequest request) {
103: String id = getUniqueId();
104: return (String) request.getPortletSession(true).getAttribute(
105: id + ".state", PortletSession.PORTLET_SCOPE);
106: }
107:
108: protected void removeNextState(PortletRequest request) {
109: String id = getUniqueId();
110: request.getPortletSession(true).removeAttribute(id + ".state",
111: PortletSession.PORTLET_SCOPE);
112: }
113:
114: /**
115: * Sets the tag beans obtained from the FormEvent. Used internally and should not
116: * normally need to be invoked by portlet developers.
117: *
118: * @param request the <code>PortletRequest</code>
119: * @param tagBeans a <code>Map</code> containing the portlet UI visual beans
120: */
121: protected void setTagBeans(PortletRequest request, Map tagBeans) {
122: String id = getUniqueId();
123: log.debug("saving tag beans in session " + id + ".beans");
124: request.getPortletSession(true).setAttribute(id + ".beans",
125: tagBeans, PortletSession.PORTLET_SCOPE);
126: }
127:
128: protected void removeTagBeans(PortletRequest request) {
129: String id = getUniqueId();
130: log.debug("removing tag beans from session " + id + ".beans");
131: request.getPortletSession(true).removeAttribute(id + ".beans",
132: PortletSession.PORTLET_SCOPE);
133: }
134:
135: /**
136: * Returns the tag beans obtained from the FormEvent. Used internally and should not
137: * normally need to be invoked by portlet developers.
138: *
139: * @param request the <code>PortletRequest</code>
140: * @return the visual beans
141: */
142: protected Map<String, TagBean> getTagBeans(PortletRequest request) {
143: String id = getUniqueId();
144: log.debug("getting tag beans from session " + id + ".beans");
145: return (Map<String, TagBean>) request.getPortletSession(true)
146: .getAttribute(id + ".beans",
147: PortletSession.PORTLET_SCOPE);
148: }
149:
150: /**
151: * Uses the action name obtained from the <code>ActionEvent</code> to invoke the
152: * appropriate portlet action method.
153: *
154: * @param actionRequest the <code>ActionRequest</code>
155: * @param actionResponse the <code>ActionResponse</code>
156: * @throws PortletException if a portlet exception occurs
157: */
158: public void processAction(ActionRequest actionRequest,
159: ActionResponse actionResponse) throws PortletException {
160: log.debug("in ActionPortlet: processAction\t\t\t");
161:
162: // if cid is null (true in non-GS portlet container) then use the portlet name
163: String cid = (String) actionRequest
164: .getAttribute(SportletProperties.COMPONENT_ID);
165: if (cid == null)
166: actionRequest.setAttribute(SportletProperties.COMPONENT_ID,
167: getUniqueId());
168:
169: DefaultPortletAction action = (DefaultPortletAction) actionRequest
170: .getAttribute(SportletProperties.ACTION_EVENT);
171: // In non-GS container this will need to be created
172:
173: // TODO
174: if (!(actionRequest instanceof ActionRequestImpl)) {
175: //action = GridSphereEventImpl.createAction(actionRequest);
176: //System.err.println("action name" + action.getName());
177: }
178: ActionFormEvent formEvent = new ActionFormEventImpl(action,
179: actionRequest, actionResponse);
180:
181: Class[] parameterTypes = new Class[] { ActionFormEvent.class };
182: Object[] arguments = new Object[] { formEvent };
183:
184: String methodName = formEvent.getAction().getName();
185: // reset next state
186: removeNextState(actionRequest);
187:
188: doAction(actionRequest, actionResponse, methodName,
189: parameterTypes, arguments);
190: //System.err.println("in processAction: befoire store cid=" + actionRequest.getAttribute(SportletProperties.COMPONENT_ID));
191:
192: // If it's a POST then remove state
193: /*
194: if (((HttpServletRequest)actionRequest).getMethod().toUpperCase().equals("POST")) {
195: removeNextState(actionRequest);
196: removeTagBeans(actionRequest);
197: removeNextTitle(actionRequest);
198: }
199: */
200: setTagBeans(actionRequest, formEvent.getTagBeans());
201: }
202:
203: /**
204: * Invokes the appropriate portlet action method based on the portlet action received
205: *
206: * @param request the portlet request
207: * @param response the portlet response
208: * @param methodName the method name to invoke
209: * @param parameterTypes the method parameters
210: * @param arguments the method arguments
211: * @throws PortletException if a portlet error occurs
212: */
213: protected void doAction(PortletRequest request,
214: PortletResponse response, String methodName,
215: Class[] parameterTypes, Object[] arguments)
216: throws PortletException {
217:
218: // Get object and class references
219: Class this Class = this .getClass();
220: // Call method specified by action name
221: try {
222: Method method = this Class.getMethod(methodName,
223: parameterTypes);
224:
225: method.invoke(this , arguments);
226:
227: StringBuffer sb = new StringBuffer();
228: sb.append("Invoking portlet action ").append(
229: this Class.getName()).append("#").append(methodName);
230: if (request.getUserPrincipal() != null) {
231: sb.append(" user=").append(
232: request.getUserPrincipal().getName());
233: sb.append(" session id=").append(
234: request.getPortletSession().getId());
235: }
236: if (request instanceof HttpServletRequestWrapper) {
237: sb.append(" remote ip=").append(
238: ((HttpServletRequestWrapper) request)
239: .getRemoteAddr());
240: sb.append(" user agent=").append(
241: ((HttpServletRequestWrapper) request)
242: .getHeader("user-agent"));
243: }
244: log.info(sb.toString());
245:
246: } catch (NoSuchMethodException e) {
247: String error = "No such method: " + methodName + "\n"
248: + e.getMessage();
249: log.error(error, e);
250: throw new PortletException(error, e);
251: } catch (IllegalAccessException e) {
252: String error = "Error accessing action method: "
253: + methodName + "\n" + e.getMessage();
254: log.error(error, e);
255: throw new PortletException(error, e);
256: } catch (InvocationTargetException e) {
257: String error = "Error invoking action method: "
258: + methodName;
259: log.error(error, e.getTargetException());
260: throw new PortletException(error, e.getTargetException());
261: }
262:
263: }
264:
265: /**
266: * Renders the supplied JSP page.
267: *
268: * @param request the portlet request
269: * @param response the portlet response
270: * @param jsp the JSP page to include
271: * @throws PortletException if a portlet exception occurs
272: */
273: public void doViewJSP(RenderRequest request,
274: RenderResponse response, String jsp)
275: throws PortletException {
276: log.debug("Including JSP page:" + jsp);
277: response.setContentType("text/html; charset=utf-8");
278: try {
279: if (jsp.startsWith("/")) {
280: getPortletConfig().getPortletContext()
281: .getRequestDispatcher(jsp).include(request,
282: response);
283: } else {
284: getPortletConfig().getPortletContext()
285: .getRequestDispatcher("/jsp/" + jsp).include(
286: request, response);
287: }
288: } catch (Exception e) {
289: throw new PortletException("Unable to include JSP", e);
290: }
291: }
292:
293: /**
294: * Uses #getNextState to either render a JSP or invoke the specified render action method
295: *
296: * @param request the portlet request
297: * @param response the portlet response
298: * @throws PortletException if a portlet exception occurs
299: * @throws IOException if an I/O error occurs
300: */
301: public void doView(RenderRequest request, RenderResponse response)
302: throws PortletException, IOException {
303: String next = getNextState(request);
304: if (next == null) {
305: log
306: .debug("in ActionPortlet: state is null-- setting to DEFAULT_VIEW_PAGE");
307: setNextState(request, DEFAULT_VIEW_PAGE);
308: }
309: doMode(request, response);
310: }
311:
312: protected void doMode(RenderRequest request, RenderResponse response)
313: throws PortletException {
314: String next = getNextState(request);
315: log.debug("in ActionPortlet: portlet id= " + getUniqueId()
316: + " next page is= " + next);
317:
318: // if cid is null (true in non-GS portlet container) then use the portlet name
319: String cid = (String) request
320: .getAttribute(SportletProperties.COMPONENT_ID);
321: if (cid == null)
322: request.setAttribute(SportletProperties.COMPONENT_ID,
323: getUniqueId());
324:
325: DefaultPortletRender render = (DefaultPortletRender) request
326: .getAttribute(SportletProperties.RENDER_EVENT);
327:
328: Map<String, TagBean> tagBeans = getTagBeans(request);
329: RenderFormEvent formEvent = new RenderFormEventImpl(render,
330: request, response, tagBeans);
331:
332: // check to see if this render event should invoke a render method
333: if (render != null) {
334: String methodName = render.getName();
335: if (!methodName.equals(""))
336: next = methodName;
337: }
338:
339: if (next.endsWith(".jsp")) {
340: // this is necessary in case beans were modified in action method and set next state is a JSP to render which needs the beans
341: formEvent.store();
342: doViewJSP(request, response, next);
343: } else {
344: Class[] paramTypes = new Class[] { RenderFormEvent.class };
345: Object[] arguments = new Object[] { formEvent };
346:
347: doAction(request, response, next, paramTypes, arguments);
348:
349: //System.err.println("in doMode: before store cid=" + request.getAttribute(SportletProperties.COMPONENT_ID));
350: formEvent.store();
351: next = getNextState(request);
352: if ((next != null) && (next.endsWith(".jsp"))) {
353: log.debug("in doMode: next page is= " + next);
354: doViewJSP(request, response, next);
355: }
356: }
357: removeTagBeans(request);
358: removeNextState(request);
359: }
360:
361: protected void doDispatch(RenderRequest request,
362: RenderResponse response) throws PortletException,
363: IOException {
364:
365: // if cid is null (true in non-GS portlet container) then use the portlet name
366: String cid = (String) request
367: .getAttribute(SportletProperties.COMPONENT_ID);
368: if (cid == null)
369: request.setAttribute(SportletProperties.COMPONENT_ID,
370: getUniqueId());
371:
372: WindowState state = request.getWindowState();
373:
374: try {
375: super .doDispatch(request, response);
376: } catch (PortletException e) {
377: if (!state.equals(WindowState.MINIMIZED)) {
378: PortletMode mode = request.getPortletMode();
379: if (mode.toString().equalsIgnoreCase("CONFIG")) {
380: doConfigure(request, response);
381: return;
382: }
383: }
384: throw e;
385: }
386:
387: }
388:
389: /**
390: * Simply forwards to #doView
391: *
392: * @param request the portlet request
393: * @param response the portlet response
394: * @throws PortletException if a portlet exception occurs
395: * @throws java.io.IOException if an I/O error occurs
396: */
397: public void doEdit(RenderRequest request, RenderResponse response)
398: throws PortletException, IOException {
399: log.debug("ActionPortlet: in doEdit");
400: String next = getNextState(request);
401: if (next == null) {
402: log
403: .debug("in ActionPortlet: state is null-- setting to DEFAULT_EDIT_PAGE");
404: setNextState(request, DEFAULT_EDIT_PAGE);
405: }
406: doMode(request, response);
407: }
408:
409: /**
410: * Simply forwards to #doView
411: *
412: * @param request the portlet request
413: * @param response the portlet response
414: * @throws PortletException if a portlet exception occurs
415: * @throws IOException if an I/O error occurs
416: */
417: public void doConfigure(RenderRequest request,
418: RenderResponse response) throws PortletException,
419: IOException {
420: log.debug("ActionPortlet: in doConfigure");
421: String next = getNextState(request);
422: if (next == null) {
423: log
424: .debug("in ActionPortlet: state is null-- setting to DEFAULT_CONFIGURE_PAGE");
425: setNextState(request, DEFAULT_CONFIGURE_PAGE);
426: }
427: doMode(request, response);
428: }
429:
430: /**
431: * Simply forwards to #doView
432: *
433: * @param request the portlet request
434: * @param response the portlet response
435: * @throws PortletException if a portlet exception occurs
436: * @throws IOException if an I/O error occurs
437: */
438: public void doHelp(RenderRequest request, RenderResponse response)
439: throws PortletException, IOException {
440: log.debug("ActionPortlet: in doHelp");
441: setNextState(request, DEFAULT_HELP_PAGE);
442: doView(request, response);
443: }
444:
445: protected String getLocalizedText(PortletRequest req, String key) {
446: Locale locale = req.getLocale();
447: ResourceBundle bundle = ResourceBundle.getBundle("Portlet",
448: locale);
449: return bundle.getString(key);
450: }
451:
452: public String getParameter(PortletRequest request, String param) {
453: String value = request.getParameter(param);
454: return (value == null) ? "" : value;
455: }
456:
457: public String getParameter(PortletRequest request, String param,
458: String defaultValue) {
459: String value = request.getParameter(param);
460: return (value == null) ? defaultValue : value;
461: }
462:
463: public String[] getParameterValues(PortletRequest request,
464: String param) {
465: String values[] = request.getParameterValues(param);
466: return (values == null) ? new String[0] : values;
467: }
468:
469: public int getParameterAsInt(PortletRequest request, String param) {
470: return getParameterAsInt(request, param, 0);
471: }
472:
473: public int getParameterAsInt(PortletRequest request, String param,
474: int defaultValue) {
475: String value = request.getParameter(param);
476: if (value == null)
477: return defaultValue;
478: if (value.equals(""))
479: return defaultValue;
480: try {
481: return (new Integer(value)).intValue();
482: } catch (Exception e) {
483: return defaultValue;
484: }
485: }
486:
487: public int[] getParameterValuesAsInt(PortletRequest request,
488: String param) {
489: String values[] = request.getParameterValues(param);
490: if (values == null) {
491: return new int[0];
492: } else {
493: int objs[] = new int[values.length];
494: for (int ii = 0; ii < values.length; ++ii) {
495: String value = values[ii];
496: try {
497: objs[ii] = (new Integer(value)).intValue();
498: } catch (Exception e) {
499: objs[ii] = 0;
500: }
501: }
502: return objs;
503: }
504: }
505:
506: public long getParameterAsLng(PortletRequest request, String param) {
507: return getParameterAsLng(request, param, 0);
508: }
509:
510: public long getParameterAsLng(PortletRequest request, String param,
511: long defaultValue) {
512: String value = request.getParameter(param);
513: if (value == null)
514: return defaultValue;
515: if (value.equals(""))
516: return defaultValue;
517: try {
518: return (new Long(value)).longValue();
519: } catch (Exception e) {
520: return defaultValue;
521: }
522: }
523:
524: public long[] getParameterValuesAsLng(PortletRequest request,
525: String param) {
526: String values[] = request.getParameterValues(param);
527: if (values == null) {
528: return new long[0];
529: } else {
530: long objs[] = new long[values.length];
531: for (int ii = 0; ii < values.length; ++ii) {
532: String value = values[ii];
533: try {
534: objs[ii] = (new Long(value)).longValue();
535: } catch (Exception e) {
536: objs[ii] = 0;
537: }
538: }
539: return objs;
540: }
541: }
542:
543: public float getParameterAsFlt(PortletRequest request, String param) {
544: return getParameterAsFlt(request, param, (float) 0.0);
545: }
546:
547: public float getParameterAsFlt(PortletRequest request,
548: String param, float defaultValue) {
549: String value = request.getParameter(param);
550: if (value == null)
551: return defaultValue;
552: if (value.equals(""))
553: return defaultValue;
554: try {
555: return (new Float(value)).floatValue();
556: } catch (Exception e) {
557: return defaultValue;
558: }
559: }
560:
561: public float[] getParameterValuesAsFlt(PortletRequest request,
562: String param) {
563: String values[] = request.getParameterValues(param);
564: if (values == null) {
565: return new float[0];
566: } else {
567: float objs[] = new float[values.length];
568: for (int ii = 0; ii < values.length; ++ii) {
569: String value = values[ii];
570: try {
571: objs[ii] = (new Float(value)).floatValue();
572: } catch (Exception e) {
573: objs[ii] = 0;
574: }
575: }
576: return objs;
577: }
578: }
579:
580: public double getParameterAsDbl(PortletRequest request, String param) {
581: return getParameterAsDbl(request, param, 0.0);
582: }
583:
584: public double getParameterAsDbl(PortletRequest request,
585: String param, double defaultValue) {
586: String value = request.getParameter(param);
587: if (value == null)
588: return defaultValue;
589: if (value.equals(""))
590: return defaultValue;
591: try {
592: return (new Double(value)).doubleValue();
593: } catch (Exception e) {
594: return defaultValue;
595: }
596: }
597:
598: public double[] getParameterValuesAsDbl(PortletRequest request,
599: String param) {
600: String values[] = request.getParameterValues(param);
601: if (values == null) {
602: return new double[0];
603: } else {
604: double objs[] = new double[values.length];
605: for (int ii = 0; ii < values.length; ++ii) {
606: String value = values[ii];
607: try {
608: objs[ii] = (new Double(value)).doubleValue();
609: } catch (Exception e) {
610: objs[ii] = 0;
611: }
612: }
613: return objs;
614: }
615: }
616:
617: public boolean getParameterAsBool(PortletRequest request,
618: String param) {
619: String value = request.getParameter(param);
620: if (value == null)
621: return false;
622: if (value.equals(""))
623: return false;
624: if (value.equals("true"))
625: return true;
626: return false;
627: }
628:
629: public boolean[] getParameterValuesAsBool(PortletRequest request,
630: String param) {
631: String values[] = request.getParameterValues(param);
632: if (values == null) {
633: return new boolean[0];
634: } else {
635: boolean objs[] = new boolean[values.length];
636: for (int ii = 0; ii < values.length; ++ii) {
637: String value = values[ii];
638: if (value.equals(""))
639: objs[ii] = false;
640: if (value.equals("true"))
641: objs[ii] = true;
642: objs[ii] = false;
643: }
644: return objs;
645: }
646: }
647:
648: public Integer getParameterAsInteger(PortletRequest request,
649: String param) {
650: String value = request.getParameter(param);
651: if (value == null)
652: return (new Integer(0));
653: if (value.equals(""))
654: value = "0";
655: try {
656: return (new Integer(value));
657: } catch (Exception e) {
658: return (new Integer(0));
659: }
660: }
661:
662: public Integer[] getParameterValuesAsInteger(
663: PortletRequest request, String param) {
664: String values[] = request.getParameterValues(param);
665: if (values == null) {
666: return new Integer[0];
667: } else {
668: Integer objs[] = new Integer[values.length];
669: for (int ii = 0; ii < values.length; ++ii) {
670: String value = values[ii];
671: try {
672: objs[ii] = (new Integer(value));
673: } catch (Exception e) {
674: objs[ii] = (new Integer(0));
675: }
676: }
677: return objs;
678: }
679: }
680:
681: public Float getParameterAsFloat(PortletRequest request,
682: String param) {
683: String value = request.getParameter(param);
684: if (value == null)
685: return (new Float(0.0));
686: if (value.equals(""))
687: value = "0";
688: try {
689: return (new Float(value));
690: } catch (Exception e) {
691: return (new Float(0.0));
692: }
693: }
694:
695: public Float[] getParameterValuesAsFloat(PortletRequest request,
696: String param) {
697: String values[] = request.getParameterValues(param);
698: if (values == null) {
699: return new Float[0];
700: } else {
701: Float objs[] = new Float[values.length];
702: for (int ii = 0; ii < values.length; ++ii) {
703: String value = values[ii];
704: try {
705: objs[ii] = (new Float(value));
706: } catch (Exception e) {
707: objs[ii] = (new Float(0.0));
708: }
709: }
710: return objs;
711: }
712: }
713:
714: public Double getParameterAsDouble(PortletRequest request,
715: String param) {
716: String value = request.getParameter(param);
717: if (value == null)
718: return (new Double(0.0));
719: if (value.equals(""))
720: value = "0";
721: try {
722: return (new Double(value));
723: } catch (Exception e) {
724: return (new Double(0.0));
725: }
726: }
727:
728: public Double[] getParameterValuesAsDouble(PortletRequest request,
729: String param) {
730: String values[] = request.getParameterValues(param);
731: if (values == null) {
732: return new Double[0];
733: } else {
734: Double objs[] = new Double[values.length];
735: for (int ii = 0; ii < values.length; ++ii) {
736: String value = values[ii];
737: try {
738: objs[ii] = (new Double(value));
739: } catch (Exception e) {
740: objs[ii] = (new Double(0.0));
741: }
742: }
743: return objs;
744: }
745: }
746:
747: public Boolean getParameterAsBoolean(PortletRequest request,
748: String param) {
749: String value = request.getParameter(param);
750: if (value == null)
751: return Boolean.FALSE;
752: if (value.equals(""))
753: return Boolean.FALSE;
754: if (value.equals("true"))
755: return Boolean.TRUE;
756: return Boolean.FALSE;
757: }
758:
759: public Boolean[] getParameterValuesAsBoolean(
760: PortletRequest request, String param) {
761: String values[] = request.getParameterValues(param);
762: if (values == null) {
763: return new Boolean[0];
764: } else {
765: Boolean objs[] = new Boolean[values.length];
766: for (int ii = 0; ii < values.length; ++ii) {
767: String value = values[ii];
768: if (value.equals(""))
769: objs[ii] = Boolean.FALSE;
770: if (value.equals("true"))
771: objs[ii] = Boolean.TRUE;
772: objs[ii] = Boolean.FALSE;
773: }
774: return objs;
775: }
776: }
777:
778: public List<String> getParameterValuesAsList(
779: PortletRequest request, String param) {
780: // Create list for values
781: List<String> listValues = new ArrayList<String>();
782: // Get parameter values
783: String paramValues[] = getParameterValues(request, param);
784: for (int ii = 0; ii < paramValues.length; ++ii) {
785: listValues.add(paramValues[ii]);
786: }
787: return listValues;
788: }
789:
790: public Map getParameterValuesAsMap(PortletRequest request,
791: String param) {
792: // Create list for values
793: Map<String, String> mapValues = new HashMap<String, String>();
794: // Get parameter values
795: String paramValues[] = getParameterValues(request, param);
796: for (int ii = 0; ii < paramValues.length; ++ii) {
797: String paramValue = paramValues[ii];
798: int index = paramValue.indexOf(":");
799: if (index < 0) {
800: continue;
801: }
802: String key = paramValue.substring(0, index);
803: String value = paramValue.substring(index + 1, paramValue
804: .length());
805: mapValues.put(key, value);
806: }
807: return mapValues;
808: }
809:
810: protected String getUniqueId() {
811: //log.debug("setting unique cid: " + this.getPortletConfig().getPortletName());
812: return this .getPortletConfig().getPortletName();
813: }
814:
815: public PortletService createPortletService(Class serviceClass)
816: throws PortletServiceException {
817: return PortletServiceFactory.createPortletService(serviceClass,
818: true);
819: }
820:
821: protected void createErrorMessage(FormEvent evt, String text) {
822: MessageBoxBean msgBox = evt.getMessageBoxBean("msg");
823: msgBox.setMessageType(MessageStyle.MSG_ERROR);
824: String msgOld = msgBox.getValue();
825: msgBox.setValue((msgOld != null ? msgOld : "") + "\n" + text);
826: }
827:
828: protected void createSuccessMessage(FormEvent evt, String text) {
829: MessageBoxBean msg = evt.getMessageBoxBean("msg");
830: msg.setValue(text);
831: msg.setMessageType(MessageStyle.MSG_SUCCESS);
832: }
833:
834: }
|