Source Code Cross Referenced for BasePO.java in  » J2EE » Enhydra-Demos » scioworks » imap » presentation » base » 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 » J2EE » Enhydra Demos » scioworks.imap.presentation.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* -----------------------------------------------------------------------------
002:         * Copyright (c) 2001, Low Kin Onn
003:         * All rights reserved.
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         *
008:         * Redistributions of source code must retain the above copyright notice, this
009:         * list of conditions and the following disclaimer.
010:         *
011:         * Redistributions in binary form must reproduce the above copyright notice,
012:         * this list of conditions and the following disclaimer in the documentation
013:         * and/or other materials provided with the distribution.
014:         *
015:         * Neither name of the Scioworks Pte. Ltd. nor the names of its contributors
016:         * may beused to endorse or promote products derived from this software without
017:         * specific prior written permission.
018:         *
019:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
021:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022:         * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
023:         * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
024:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025:         * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
026:         * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
028:         * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         *
030:         * -----------------------------------------------------------------------------
031:         */
032:
033:        package scioworks.imap.presentation.base;
034:
035:        import java.util.Vector;
036:
037:        import com.lutris.appserver.server.httpPresentation.*;
038:        import com.lutris.util.KeywordValueException;
039:
040:        import org.w3c.dom.*;
041:        import org.w3c.dom.html.*;
042:
043:        import scioworks.imap.presentation.ImapWebSessionData;
044:        import scioworks.imap.presentation.*;
045:        import scioworks.imap.presentation.KMSPresentationException;
046:
047:        public abstract class BasePO implements  HttpPresentation,
048:                BaseParameters, BaseEvents, BaseMessages, BaseURLs {
049:
050:            protected static final int m_firstEntryIndex = 1;
051:            protected static final int m_pageLength = 10;
052:
053:            protected HttpPresentationComms m_comms = null;
054:            protected ImapWebSessionData m_ImapWebSessionData = null;
055:
056:            abstract public String handleDefault()
057:                    throws HttpPresentationException,
058:                    ServerPageRedirectException;
059:
060:            /**
061:             * Default required login, override otherwise
062:             */
063:            protected boolean isLoginRequired() {
064:                return true;
065:            }
066:
067:            /**
068:             * @return The saved comms objects
069:             * to whichever subclass needs it
070:             */
071:            public HttpPresentationComms getComms() {
072:                return m_comms;
073:            }
074:
075:            public ImapWebSessionData getImapWebSessionData() {
076:                return m_ImapWebSessionData;
077:            }
078:
079:            public void setSessionData(ImapWebSessionData sessionData) {
080:                this .m_ImapWebSessionData = sessionData;
081:            }
082:
083:            protected void initSessionData(HttpPresentationComms comms)
084:                    throws KMSPresentationException {
085:
086:                this .m_comms = comms;
087:                try {
088:
089:                    // try to get the imapWeb session data (if any)
090:                    Object obj = getComms().sessionData
091:                            .get(ImapWebSessionData.SESSION_KEY);
092:
093:                    // If we found the session data, save it in a private data member
094:                    if (null != obj) {
095:                        m_ImapWebSessionData = (ImapWebSessionData) obj;
096:
097:                    } else {
098:
099:                        // If no session data was found, create a new session data instance
100:                        this .m_ImapWebSessionData = new ImapWebSessionData(null);
101:                        getComms().sessionData.set(
102:                                ImapWebSessionData.SESSION_KEY,
103:                                this .m_ImapWebSessionData);
104:                    }
105:                } catch (KeywordValueException ex) {
106:                    System.out
107:                            .println("Problem getting session data from session: "
108:                                    + ex.getMessage());
109:                }
110:            }
111:
112:            /**
113:             * Checks the session data for a User, if not there then redirects to the login page
114:             */
115:            protected void checkForUserLogin() throws KMSPresentationException {
116:
117:                try {
118:                    if (!m_ImapWebSessionData.isValidSession()) {
119:
120:                        String requestedPO = getComms().request.getRequestURI();
121:                        getComms().response.writeHTML(this .showErrorPage(
122:                                "Session Expired",
123:                                "You session has expired. Please re-login",
124:                                "Re-login", URL_login, "_parent"));
125:                    } else {
126:                        //System.out.println("USER ALREADY LOGGED IN WITH A SESSION");
127:                    }
128:                } catch (Exception ex) {
129:                    throw new KMSPresentationException(
130:                            "Trouble checking for user login status", ex);
131:                }
132:            }
133:
134:            public void run(HttpPresentationComms comms)
135:                    throws KMSPresentationException {
136:
137:                // Initialize new or get the existing session data
138:                initSessionData(comms);
139:
140:                // Check if the user needs to be logged in for this request.
141:                if (isLoginRequired()) {
142:                    checkForUserLogin();
143:                }
144:
145:                try {
146:                    // Handle the incoming event request
147:                    handleEvent(comms);
148:                } catch (HttpPresentationException e) {
149:                    Logger.writeError("BasePO::run", e);
150:                    throw new KMSPresentationException(
151:                            "An error has occured. "
152:                                    + "Please contact your administrator. Error message: "
153:                                    + e.getMessage());
154:                }
155:
156:            }
157:
158:            public void handleEvent(HttpPresentationComms comms)
159:                    throws HttpPresentationException {
160:
161:                String returnHTML = null;
162:
163:                try {
164:                    if (this .getStringParameter(PARAM_imageData).equals("y")) {
165:                        String returnMimeType = handleDefault();
166:                        comms.response.setContentType(returnMimeType);
167:                        return;
168:
169:                    } else {
170:                        returnHTML = handleDefault();
171:                    }
172:                } catch (Exception e) {
173:                    returnHTML = this .showErrorPage("Internal Error",
174:                            "An error has occured. Please contact your administrator. "
175:                                    + "Error message: " + e.getMessage(), "",
176:                            "");
177:                    Logger.writeError("BasePO::handleEvent", e);
178:                }
179:
180:                getComms().response.writeHTML(returnHTML);
181:            }
182:
183:            protected long getLongParameter(String parm)
184:                    throws HttpPresentationException, NumberFormatException {
185:                long res = 0;
186:                try {
187:                    res = Long.parseLong(m_comms.request.getParameter(parm));
188:                } catch (NumberFormatException e) {
189:                    res = -1;
190:                }
191:                return res;
192:            }
193:
194:            protected int getIntParameter(String parm)
195:                    throws HttpPresentationException, NumberFormatException {
196:                int res = 0;
197:                try {
198:                    res = Integer.parseInt(m_comms.request.getParameter(parm));
199:                } catch (NumberFormatException e) {
200:                    res = -1;
201:                }
202:                return res;
203:            }
204:
205:            protected String getStringParameter(String parm)
206:                    throws HttpPresentationException {
207:                String value = m_comms.request.getParameter(parm);
208:                if ((value == null) || (value.length() == 0)) {
209:                    value = "";
210:                }
211:                return value;
212:            }
213:
214:            protected String[] getStringParameterArray(String parm)
215:                    throws HttpPresentationException {
216:                return m_comms.request.getParameterValues(parm);
217:            }
218:
219:            protected void setStringParameter(String name, String value)
220:                    throws HttpPresentationException {
221:
222:                m_comms.response.setHeader(name, value);
223:            }
224:
225:            protected long[] getLongParameterArray(String parm)
226:                    throws HttpPresentationException {
227:                String[] strArr = m_comms.request.getParameterValues(parm);
228:                long[] longArr = new long[strArr.length];
229:                for (int i = 0; i < strArr.length; i++) {
230:                    longArr[i] = Long.parseLong(strArr[i]);
231:                }
232:                return longArr;
233:            }
234:
235:            protected String showErrorPage(String errorHeader,
236:                    String errorText, String errorLinkText, String errorLink,
237:                    String target) {
238:                errorPageHTML page = (errorPageHTML) m_comms.xmlcFactory
239:                        .create(errorPageHTML.class);
240:                page.setTextErrorHeader(errorHeader);
241:                page.setTextErrorText(errorText);
242:                page.setTextErrorLinkText(errorLinkText);
243:
244:                HTMLAnchorElement fileLink;
245:                fileLink = page.getElementErrorLink();
246:                if (errorLinkText.equals("") || errorLink.equals("")) {
247:                    this .removeElement(page, fileLink);
248:                } else {
249:                    fileLink.setHref(errorLink);
250:                    if (!target.equals("")) {
251:                        fileLink.setTarget(target);
252:                    }
253:                }
254:                return page.toDocument();
255:            }
256:
257:            protected String showErrorPage(String errorHeader,
258:                    String errorText, String errorLinkText, String errorLink) {
259:                return showErrorPage(errorHeader, errorText, errorLinkText,
260:                        errorLink, "");
261:            }
262:
263:            protected String showCompletionPage(String header, String text,
264:                    String linkText, String link) {
265:                messagePageHTML page = (messagePageHTML) m_comms.xmlcFactory
266:                        .create(messagePageHTML.class);
267:                page.setTextMessageHeader(header);
268:                page.setTextMessageText(text);
269:                page.setTextMessageLinkText(linkText);
270:
271:                HTMLAnchorElement fileLink = page.getElementMessageLink();
272:                if (linkText.equals("") || link.equals("")) {
273:                    this .removeElement(page, fileLink);
274:                } else {
275:                    fileLink.setHref(link);
276:                    /*
277:                    if(!target.equals("")) {
278:                      fileLink.setTarget(target);
279:                    }
280:                     */
281:                }
282:                return page.toDocument();
283:            }
284:
285:            protected void removeElement(
286:                    org.enhydra.xml.xmlc.html.HTMLObjectImpl page,
287:                    Element currElement) {
288:                if (currElement != null) {
289:                    Node parentNode = currElement.getParentNode();
290:                    parentNode.removeChild(currElement);
291:                } else {
292:                    Logger.writeDebug("Error: unfound element "
293:                            + currElement.getLocalName());
294:                }
295:            }
296:
297:            protected void removeElement(
298:                    org.enhydra.xml.xmlc.html.HTMLObjectImpl page,
299:                    java.util.HashSet elementSet) {
300:                Element currElement;
301:                java.util.Iterator it = elementSet.iterator();
302:                Node parentNode;
303:                while (it.hasNext()) {
304:                    currElement = (Element) it.next();
305:                    if (currElement != null) {
306:                        parentNode = currElement.getParentNode();
307:                        parentNode.removeChild(currElement);
308:                    } else {
309:                        Logger.writeDebug("Error: unfound element "
310:                                + currElement.getLocalName());
311:                    }
312:                }
313:            }
314:
315:            protected void processSelectList(
316:                    org.enhydra.xml.xmlc.html.HTMLObjectImpl page,
317:                    HTMLSelectElement lookUpElement, Vector displayList,
318:                    Vector valueList, String selectedItem) {
319:
320:                // remove the hard coded drop down elements
321:                for (int i = lookUpElement.getLength() - 1; i >= 0; i--) {
322:                    lookUpElement.remove(i);
323:                }
324:
325:                for (int i = 0; i < valueList.size(); i++) {
326:                    // Create and append options, set to select if matches value
327:                    HTMLOptionElement o1 = (HTMLOptionElement) page
328:                            .createElement("OPTION");
329:                    o1.setValue((String) valueList.elementAt(i));
330:                    o1.appendChild(page.createTextNode((String) displayList
331:                            .elementAt(i)));
332:                    if (selectedItem.equals((String) valueList.elementAt(i))) {
333:                        o1.setAttribute("selected", "selected");
334:                    }
335:                    lookUpElement.appendChild(o1);
336:                }
337:            }
338:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.