1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlet.helloworld;
18
19 import java.io.IOException;
20 import java.util.ResourceBundle;
21
22 import javax.portlet.GenericPortlet;
23 import javax.portlet.PortletConfig;
24 import javax.portlet.PortletContext;
25 import javax.portlet.PortletException;
26 import javax.portlet.PortletRequestDispatcher;
27 import javax.portlet.RenderRequest;
28 import javax.portlet.RenderResponse;
29
30
31 /***
32 * This example portlet will display text <pre>This is a test from hello.jsp</pre>
33 *
34 * <strong>data/portletentityregistry.xml</strong><br/>
35 * The following defines the associates the portlet 5.1 to
36 * the portlet HelloPortlet in the PortletContainer HW_App.<br/>
37 * <pre>
38 * <application id="5">
39 * <desc>HW_App</desc>
40 * <portlet id="1">
41 * <desc>HW_App.HelloPortlet</desc>
42 * </portlet>
43 * </application>
44 * </pre>
45 *
46 * <strong>data/portletregistry.xml</strong><br>
47 * The following will include the portlet 5.3 in the fragment named P2.<br/>
48 * <pre>
49 * <fragment name="p2" type="portlet">
50 * <property name="portlet" value="5.1"/>
51 * </fragment>
52 * </pre>
53 *
54 * Also make sure <pre>container.jar</pre> is in <pre>WEB-INF/lib</pre>
55 *
56 * @author paul
57 */
58 public class HelloWorld extends GenericPortlet
59 {
60
61 public void init(PortletConfig config)
62 throws PortletException
63 {
64
65 super.init(config);
66 }
67
68
69
70
71 public void doEdit(RenderRequest request, RenderResponse response)
72 throws PortletException, IOException
73 {
74 PortletContext context = getPortletContext();
75 PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/hello.jsp");
76 rd.include(request,response);
77 }
78
79 public void doHelp(RenderRequest request, RenderResponse response)
80 throws PortletException, IOException
81 {
82 PortletContext context = getPortletContext();
83 PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/hello.jsp");
84 rd.include(request,response);
85 }
86
87 public void doView(RenderRequest request, RenderResponse response)
88 throws PortletException, IOException
89 {
90 PortletContext context = getPortletContext();
91 ResourceBundle resource = getPortletConfig().getResourceBundle(request.getLocale());
92 String contentType = request.getResponseContentType();
93 if (contentType.startsWith("text/html"))
94 {
95 response.setContentType("text/html");
96 response.getWriter().println("<br/><b>"+resource.getString("helloworld.label.InitParamHello")+" = " + this.getInitParameter("hello") + "</b>");
97 PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/hello.jsp");
98 rd.include(request, response);
99 }
100 else if (contentType.startsWith("text/vnd.wap.wml"))
101 {
102 response.setContentType("text/vnd.wap.wml");
103 response.getWriter().println("<p><b>WML: "+resource.getString("helloworld.label.InitParamHello")+" = " + this.getInitParameter("hello") + "</b></p>");
104 PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/hello-wml.jsp");
105 rd.include(request, response);
106 }
107
108 }
109 }