View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  //        System.out.println("HelloWorldPortlet: initializing portlet, config = " + config.getPortletName());
65          super.init(config);        
66      }
67      
68      /*
69       * The content is generated by <pre>/WEB-INF/hello.jsp</pre>
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         // response.getWriter().println("<br/><b>Render URL = " + url +  "</b>");        
108     }
109 }