001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037:
038: package com.sun.portal.portlet.ipc1;
039:
040: import com.sun.portal.portletappengine.ipc.EventRequest;
041: import com.sun.portal.portletappengine.ipc.EventResponse;
042: import com.sun.portal.portletappengine.ipc.PortletEvent;
043: import com.sun.portal.portletappengine.ipc.PortletEventListener;
044:
045: import javax.portlet.GenericPortlet;
046: import javax.portlet.PortletConfig;
047: import javax.portlet.PortletContext;
048: import javax.portlet.PortletException;
049: import javax.portlet.PortletRequestDispatcher;
050: import javax.portlet.RenderRequest;
051: import javax.portlet.RenderResponse;
052: import java.io.IOException;
053:
054: /**
055: * The ListPortlet participates in the InterPortletCommunication.
056: * This consumes the event generated by the SearchPortlet which is in a
057: * diferent web application.
058: */
059: public class ListPortlet extends GenericPortlet implements
060: PortletEventListener {
061: private PortletContext pContext;
062:
063: public void init(PortletConfig config) throws PortletException {
064: super .init(config);
065: pContext = config.getPortletContext();
066: }
067:
068: public void handleEvent(EventRequest ereq, EventResponse eres) {
069: String eventName = ereq.getEventName();
070: if (eventName
071: .equalsIgnoreCase(PortletEvent.EVENT_HANDLING_FAILED)) {
072: String data = "eventHandlingFailed";
073: eres.setRenderParameter("search", data);
074: eres.setRenderParameter("data", data); // will be used in jsp
075: } else {
076: String search = (String) ereq.getEventData();
077: String[] bookSet = new String[5];
078: if (search.equalsIgnoreCase("java")) {
079: bookSet[0] = ("Java(tm)2: A Beginner's Guide");
080: bookSet[1] = ("Java 2: The Complete Reference, Fifth Edition");
081: bookSet[2] = ("Head First Java");
082: bookSet[3] = ("Java In A Nutshell (In a Nutshell)");
083: bookSet[4] = ("Effective Java Programming Language Guide");
084: } else if (search.equalsIgnoreCase("J2EE")) {
085: bookSet[0] = ("The J2EE Tutorial, Second Edition");
086: bookSet[1] = ("The J2EE Architect's Handbook");
087: bookSet[2] = ("Beginning J2EE 1.4: From Novice to Professional");
088: bookSet[3] = ("Expert One-on-One J2EE Design and Development");
089: bookSet[4] = ("Sams Teach Yourself J2EE in 21 Days");
090: } else if (search.equalsIgnoreCase("C++")) {
091: bookSet[0] = ("C++ for Dummies");
092: bookSet[1] = ("Beginning C++ Game Programming");
093: bookSet[2] = ("C++ Primer");
094: bookSet[3] = ("C++ Common Knowledge : Essential Intermediate Programming");
095: bookSet[4] = ("Imperfect C++ : Practical Solutions for Real-Life Programming");
096: } else if (search.equalsIgnoreCase("C")) {
097: bookSet[0] = ("The C Programming Language");
098: bookSet[1] = ("Practical C Programming");
099: bookSet[2] = ("Expert C Programming");
100: bookSet[3] = ("C How to Program, Fourth Edition");
101: bookSet[4] = ("C Programming: A Modern Approach");
102: } else if (search.equalsIgnoreCase("LISP")) {
103: bookSet[0] = ("Lisp Lore: A Guide to Programming the Lisp Machine");
104: bookSet[1] = ("Visual Lisp: A Guide to Artful Programming");
105: bookSet[2] = ("Object-Oriented Programming in Common Lisp: A Programmer's Guide to CLOS");
106: bookSet[3] = ("Lisp in Small Pieces");
107: bookSet[4] = ("Art of Lisp Programming");
108: } else if (search.equalsIgnoreCase("Perl")) {
109: bookSet[0] = ("Learning Perl, Third Edition");
110: bookSet[1] = ("Programming Perl (3rd Edition)");
111: bookSet[2] = ("Perl Database Programming");
112: bookSet[3] = ("Programming Perls (2nd Edition)");
113: bookSet[4] = ("Perl Visual Editor");
114: }
115: eres.setRenderParameter("search", search);
116: eres.setRenderParameter("bookSet", bookSet);
117: }
118: }
119:
120: public void doView(RenderRequest request, RenderResponse response)
121: throws PortletException, IOException {
122: String contentPage = null;
123: String search = (String) request.getParameter("search");
124:
125: if (search == null || search.equals("eventHandlingFailed")) {
126: contentPage = "/listportlet/content.jsp";
127: } else {
128: contentPage = "/listportlet/list.jsp";
129: }
130: response.setContentType(request.getResponseContentType());
131: if (contentPage != null && contentPage.length() != 0) {
132: try {
133: PortletRequestDispatcher dispatcher = pContext
134: .getRequestDispatcher(contentPage);
135: dispatcher.include(request, response);
136: } catch (IOException e) {
137: throw new PortletException(
138: "ListPortlet.doView exception", e);
139: }
140: }
141: }
142: }
|