KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > tutorial > portal > portlets > HelloPortletInterface


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.tutorial.portal.portlets;
17
18 import java.util.Date JavaDoc;
19
20 import org.apache.jetspeed.portal.Portlet;
21 import org.apache.jetspeed.portal.PortletException;
22 import org.apache.jetspeed.portal.portlets.AbstractInstancePortlet;
23
24 import org.apache.turbine.util.RunData;
25 import org.apache.jetspeed.services.rundata.JetspeedRunData;
26
27 import org.apache.jetspeed.capability.CapabilityMap;
28 import org.apache.jetspeed.util.MimeType;
29 import org.apache.jetspeed.portal.PortletConfig;
30
31 import org.apache.turbine.om.security.User;
32 import org.apache.ecs.ConcreteElement;
33 import org.apache.ecs.StringElement;
34
35 /**
36  * Introduction to the Portlet interface
37  *
38  * @author <a HREF="mailto:taylor@apache.org">David Sean Taylor</a>
39  * @version $Id: HelloPortletInterface.java,v 1.1 2004/04/08 17:03:54 taylor Exp $
40  */

41 public class HelloPortletInterface extends AbstractInstancePortlet
42 {
43
44     public void init() throws PortletException
45     {
46     }
47
48     public ConcreteElement getContent(RunData rundata)
49     {
50         JetspeedRunData jrun = (JetspeedRunData) rundata;
51         PortletConfig pc = this.getPortletConfig();
52
53         CapabilityMap map = jrun.getCapability();
54         
55         StringBuffer JavaDoc text = new StringBuffer JavaDoc();
56         
57         String JavaDoc mimeType = map.getPreferredType().toString();
58
59         if (this.supportsType(map.getPreferredType()))
60         {
61             text.append("Supports preferred MimeType: " + mimeType);
62         }
63         else
64         {
65             text.append("Doesn't support preferred MimeType: " + mimeType);
66         }
67         
68
69         // **** getPortletConfig().getInitParameter() example
70
//String greeting = getPortletConfig ().getInitParameter ("greeting");
71
//text.append(greeting);
72
text.append("<BR/>"); // bad bad bad
73

74         String JavaDoc name = rundata.getUser().getFirstName();
75         if (name == null)
76             name ="Anonymous";
77         text.append (name);
78         text.append ("!");
79
80         text.append("<BR/>"); // bad bad bad
81

82         text.append("Portlet id = " + this.getID());
83         text.append("<BR/>"); // bad bad bad
84
text.append("Init Parameter (version): " + pc.getInitParameter("version", "NOT FOUND!"));
85         text.append("<BR/>"); // bad bad bad
86
text.append("Page Attribute (city): " + this.getAttribute("city", "NOT FOUND!", rundata));
87         text.append("<BR/>"); // bad bad bad
88

89         switch (jrun.getMode())
90         {
91         case JetspeedRunData.NORMAL:
92             text.append("MODE = VIEW");
93             break;
94         case JetspeedRunData.CUSTOMIZE:
95             text.append("MODE = CUSTOMIZE");
96             break;
97         case JetspeedRunData.MAXIMIZE:
98             text.append("MODE = MINIMIZE");
99             break;
100         default:
101             text.append("MODE = UNKNOWN");
102             break;
103         }
104
105         return (new StringElement(text.toString()));
106     }
107
108 /***
109     For Tutorial section 6.2 on Portlet Life Cycle
110     
111     public static Object getHandle(Object config)
112     {
113         PortletConfig pc = null;
114
115         if (!(config instanceof PortletConfig))
116         {
117             return null;
118         }
119         return pc.getName();
120     }
121 ***/

122
123 }
124
125
Popular Tags