Source Code Cross Referenced for HelloWorldPortlet.java in  » EJB-Server-resin-3.1.5 » examples » example » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server resin 3.1.5 » examples » example 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:
006:        import java.text.MessageFormat;
007:
008:        import java.util.Locale;
009:        import java.util.ResourceBundle;
010:        import java.util.logging.Level;
011:        import java.util.logging.Logger;
012:
013:        import javax.portlet.*;
014:
015:        public class HelloWorldPortlet implements  Portlet {
016:            static protected final Logger log = Logger
017:                    .getLogger(HelloWorldPortlet.class.getName());
018:
019:            final private PortletMode MODE_VIEW = PortletMode.VIEW;
020:            final private PortletMode MODE_EDIT = PortletMode.EDIT;
021:            final private PortletMode MODE_GOODBYE = new PortletMode("goodbye");
022:
023:            private String[][] _locales = new String[][] {
024:                    { "default", "Default for Browser" }, { "en", "English" },
025:                    { "es", "Español" }, { "fr", "Français" }, };
026:
027:            private PortletConfig _config;
028:
029:            public HelloWorldPortlet() {
030:            }
031:
032:            public void init(PortletConfig config) throws PortletException {
033:                _config = config;
034:            }
035:
036:            /** 
037:             * This portlet allows a preference named 'locale' to override the locale
038:             * specified by the browser.
039:             */
040:            protected Locale getLocale(PortletRequest request) {
041:                PortletPreferences pref = request.getPreferences();
042:                String locale = pref.getValue("locale", null);
043:
044:                return (locale != null) ? new Locale(locale) : request
045:                        .getLocale();
046:            }
047:
048:            protected ResourceBundle getBundle(PortletRequest request) {
049:                return _config.getResourceBundle(getLocale(request));
050:            }
051:
052:            public void processAction(ActionRequest request,
053:                    ActionResponse response) throws PortletException,
054:                    IOException {
055:                PortletMode mode = request.getPortletMode();
056:
057:                if (mode.equals(MODE_VIEW))
058:                    actionView(request, response);
059:                else if (mode.equals(MODE_EDIT))
060:                    actionEdit(request, response);
061:            }
062:
063:            public void render(RenderRequest request, RenderResponse response)
064:                    throws PortletException, IOException {
065:                PortletMode mode = request.getPortletMode();
066:                WindowState winstate = request.getWindowState();
067:
068:                if (winstate.equals(WindowState.MINIMIZED))
069:                    return;
070:
071:                response.setContentType("text/html");
072:                response.setTitle(getBundle(request).getString(
073:                        "javax.portlet.title"));
074:
075:                if (mode.equals(MODE_VIEW))
076:                    doView(request, response);
077:                else if (mode.equals(MODE_EDIT))
078:                    doEdit(request, response);
079:                else if (mode.equals(MODE_GOODBYE))
080:                    doGoodbye(request, response);
081:                else
082:                    throw new PortletException("unknown portlet mode: " + mode);
083:            }
084:
085:            protected void doView(RenderRequest request, RenderResponse response)
086:                    throws PortletException, IOException {
087:                ResourceBundle bundle = getBundle(request);
088:
089:                String salutation = request.getParameter("salutation");
090:                if (salutation == null)
091:                    salutation = bundle.getString("world");
092:
093:                PrintWriter out = new PrintWriter(response.getWriter());
094:
095:                String hello = bundle.getString("hello");
096:                out.println("<p>" + hello + " " + salutation + "</p>");
097:
098:                PortletURL goodbyeUrl = response.createRenderURL();
099:                goodbyeUrl.setPortletMode(MODE_GOODBYE);
100:
101:                String youcansaygoodbye = MessageFormat.format(bundle
102:                        .getString("youcansaygoodbye"), new Object[] {
103:                        "<a href='" + goodbyeUrl + "'>", "</a>" });
104:
105:                out.println("<p>" + youcansaygoodbye + "</p>");
106:
107:                PortletURL actionUrl = response.createActionURL();
108:                String locale = request.getPreferences().getValue("locale",
109:                        "default");
110:                out.println("<form method='POST' action='" + actionUrl + "'>");
111:                out.println("<select name='locale'>");
112:                for (int i = 0; i < _locales.length; i++) {
113:                    String value = _locales[i][0];
114:                    String text = _locales[i][1];
115:                    out.print("<option value='" + value + "'");
116:                    if (value.equals(locale))
117:                        out.print(" selected='SELECTED'");
118:                    out.println(">" + text + "</option>");
119:                }
120:                out.println("</select>");
121:
122:                String ok = bundle.getString("ok");
123:                out.println("<input type='submit' value='" + ok + "'/><br>");
124:                out.println("</form>");
125:            }
126:
127:            public void actionView(ActionRequest request,
128:                    ActionResponse response) throws PortletException,
129:                    IOException {
130:                String locale = request.getParameter("locale");
131:                if (locale != null) {
132:                    if (locale.equals("default"))
133:                        locale = null;
134:
135:                    PortletPreferences pref = request.getPreferences();
136:
137:                    pref.setValue("locale", locale);
138:                    pref.store();
139:                }
140:            }
141:
142:            protected void doEdit(RenderRequest request, RenderResponse response)
143:                    throws PortletException, IOException {
144:                ResourceBundle bundle = getBundle(request);
145:                String salutation = request.getParameter("salutation");
146:                if (salutation == null)
147:                    salutation = bundle.getString("world");
148:
149:                PrintWriter out = new PrintWriter(response.getWriter());
150:
151:                PortletURL submitUrl = response.createActionURL();
152:                String ok = bundle.getString("ok");
153:                String cancel = bundle.getString("cancel");
154:                out.println("<form method='POST' action='" + submitUrl + "'>");
155:                out.println("<p>");
156:                out.println("<input name='salutation' value='" + salutation
157:                        + "'/><br>");
158:                out.println("</p>");
159:                out.println("<input type='submit' value='" + ok + "'/>");
160:                out.println("<input type='submit' name='CANCEL' value='"
161:                        + cancel + "'/>");
162:                out.println("</form>");
163:            }
164:
165:            public void actionEdit(ActionRequest request,
166:                    ActionResponse response) throws PortletException,
167:                    IOException {
168:                if (request.getParameter("CANCEL") != null) {
169:                    response.setPortletMode(MODE_VIEW);
170:                    return;
171:                }
172:
173:                ResourceBundle bundle = getBundle(request);
174:
175:                String salutation = request.getParameter("salutation");
176:                if (salutation == null)
177:                    salutation = bundle.getString("world");
178:                if (salutation != null)
179:                    response.setRenderParameter("salutation", salutation);
180:
181:                // after a sucessful EDIT, switch to VIEW
182:                response.setPortletMode(MODE_VIEW);
183:            }
184:
185:            protected void doGoodbye(RenderRequest request,
186:                    RenderResponse response) throws PortletException,
187:                    IOException {
188:                ResourceBundle bundle = getBundle(request);
189:
190:                String salutation = request.getParameter("salutation");
191:                if (salutation == null)
192:                    salutation = bundle.getString("world");
193:
194:                PrintWriter out = new PrintWriter(response.getWriter());
195:                String goodbye = bundle.getString("goodbye");
196:                out.println("<p>" + goodbye + " " + salutation + "</p>");
197:            }
198:
199:            public void destroy() {
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.