Source Code Cross Referenced for Display.java in  » J2EE » Enhydra-Demos » com » lutris » airsent » presentation » messenger » 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 » com.lutris.airsent.presentation.messenger 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003:         * Reserved.
004:         * 
005:         * This source code file is distributed by Lutris Technologies, Inc. for
006:         * use only by licensed users of product(s) that include this source
007:         * file. Use of this source file or the software that uses it is covered
008:         * by the terms and conditions of the Lutris Enhydra Development License
009:         * Agreement included with this product.
010:         * 
011:         * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012:         * ANY KIND, either express or implied. See the License for the specific terms
013:         * governing rights and limitations under the License.
014:         * 
015:         * Contributor(s):
016:         * 
017:         * $Id: Display.java,v 1.1 2006-09-11 12:29:26 sinisa Exp $
018:         */
019:
020:        package com.lutris.airsent.presentation.messenger;
021:
022:        import com.lutris.appserver.server.httpPresentation.*;
023:        import com.lutris.appserver.server.session.*;
024:        import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
025:        import org.enhydra.xml.xmlc.XMLCUtil;
026:        import org.w3c.dom.*;
027:        import org.enhydra.xml.xmlc.XMLObject;
028:        import java.util.Date;
029:        import com.lutris.airsent.presentation.AirSentPresentationException;
030:        import com.lutris.airsent.presentation.AirSentConstants;
031:        import com.lutris.airsent.presentation.DeviceBasePO;
032:        import com.lutris.airsent.presentation.DeviceUtils;
033:        import org.enhydra.wireless.wml.dom.WMLAElement;
034:        import com.lutris.airsent.spec.delivery.Delivery;
035:        import com.lutris.airsent.presentation.customer.EmailConfirmationHTML;
036:        import java.lang.reflect.Method;
037:
038:        /**
039:         * Display.java handles the displaying of a messenger's
040:         * pickups and dropoffs as well as handling the actual
041:         * pickup and delivery and confirmation email.
042:         *
043:         * @author
044:         * @version
045:         */
046:        public class Display extends DeviceBasePO {
047:
048:            /**
049:             * Constants
050:             */
051:            private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER;
052:
053:            /**
054:             * Superclass method override.
055:             * returns the authorization level necessary to access this po.
056:             * 
057:             * @return int required authorization level
058:             */
059:            public int getRequiredAuthLevel() {
060:                return AUTH_LEVEL;
061:            }
062:
063:            /**
064:             * Default event. Just show the page.
065:             * 
066:             * @return XMLOBject document
067:             * @exception HttpPresentationException
068:             */
069:            public XMLObject handleDefault() throws HttpPresentationException {
070:
071:                return showPage(null);
072:            }
073:
074:            /**
075:             * Displays the Display page.
076:             * 
077:             * @param errorMsg, the error messages
078:             * @return wml document
079:             * @exception HttpPresentationException
080:             */
081:            public XMLObject showPage(String errorMsg)
082:                    throws HttpPresentationException {
083:
084:                Class tempClass = null;
085:                Object page = null;
086:                Method setTextErrorText = null;
087:                Method getTextErrorText = null;
088:                Method getTagDisplayTemplateName = null;
089:                Method getTagDisplayTemplateComplete = null;
090:                Method getTagDisplayTemplateRow = null;
091:                Method setTextNameField = null;
092:                Method setTextDisplayTemplateName = null;
093:                Method setTextDisplayTemplateComplete = null;
094:
095:                try {
096:                    Class stringClass = Class.forName("java.lang.String");
097:                    tempClass = Class
098:                            .forName(DeviceUtils
099:                                    .getPageName(myComms,
100:                                            "com.lutris.airsent.presentation.messenger.Display"));
101:                    page = myComms.xmlcFactory.create((Class) tempClass);
102:                    Class[] argTypeArr = { stringClass };
103:                    setTextErrorText = tempClass.getMethod("setTextErrorText",
104:                            argTypeArr);
105:                    setTextNameField = tempClass.getMethod("setTextNameField",
106:                            argTypeArr);
107:                    setTextDisplayTemplateName = tempClass.getMethod(
108:                            "setTextDisplayTemplateName", argTypeArr);
109:                    setTextDisplayTemplateComplete = tempClass.getMethod(
110:                            "setTextDisplayTemplateComplete", argTypeArr);
111:                    getTextErrorText = tempClass.getMethod(
112:                            "getElementErrorText", null);
113:                    getTagDisplayTemplateName = tempClass.getMethod(
114:                            "getElementDisplayTemplateName", null);
115:                    getTagDisplayTemplateComplete = tempClass.getMethod(
116:                            "getElementDisplayTemplateComplete", null);
117:                    getTagDisplayTemplateRow = tempClass.getMethod(
118:                            "getElementDisplayTemplateRow", null);
119:                } catch (Exception e) {
120:                }
121:
122:                //	DisplayPage page = 
123:                //    (DisplayPage) create("com.lutris.airsent.presentation.messenger.Display");
124:                try {
125:                    if (null != errorMsg
126:                            || null != (errorMsg = this .getSessionData()
127:                                    .getAndClearUserMessage())) {
128:                        Object[] temp = { errorMsg };
129:                        setTextErrorText.invoke(page, temp);
130:                        //page.setTextErrorText(errorMsg);
131:                    } else {
132:                        Object[] temp = { "" };
133:                        setTextErrorText.invoke(page, temp);
134:                        //page.setTextErrorText("");
135:                    }
136:                } catch (Exception e) {
137:                }
138:                //handleSelection(page);	
139:
140:                String pageSelection = myComms.request
141:                        .getParameter(AirSentConstants.SELECTION_NAME);
142:
143:                int pickupCount = 0;
144:
145:                try {
146:                    Delivery[] deliveryList = getApplication().getHomeManager()
147:                            .getDeliveryManager().findByMessenger(
148:                                    getSessionData().getMessenger());
149:                    Element templateName = (Element) getTagDisplayTemplateName
150:                            .invoke(page, null);
151:                    //Element    templateName = page.getTagDisplayTemplateName();
152:                    Element templateLink = (Element) getTagDisplayTemplateComplete
153:                            .invoke(page, null);
154:                    //Element    templateLink = page.getTagDisplayTemplateComplete();
155:                    Element templateRow = (Element) getTagDisplayTemplateRow
156:                            .invoke(page, null);
157:                    //Element    templateRow = page.getTagDisplayTemplateRow();
158:
159:                    // Remove ids to prevent duplicates
160:                    templateName.removeAttribute("id");
161:                    templateLink.removeAttribute("id");
162:                    templateRow.removeAttribute("id");
163:
164:                    Delivery currentDelivery = null;
165:                    // Get collection of Deliveries and loop through collection
166:                    // to add each disc as a row in the table.
167:                    for (int numDeliveries = 0; numDeliveries < deliveryList.length; numDeliveries++) {
168:
169:                        currentDelivery = deliveryList[numDeliveries];
170:
171:                        if (pageSelection.equals(AirSentConstants.PICKUP)) {
172:                            Object[] temp1 = { AirSentConstants.PICKUP };
173:                            setTextNameField.invoke(page, temp1);
174:                            //page.setTextNameField(AirSentConstants.PICKUP);
175:
176:                            // Check to see if this has already been picked up:    
177:                            if (!currentDelivery.isPickedUp()) {
178:                                pickupCount++;
179:                                Object[] temp2 = { "PickUps" };
180:                                setTextNameField.invoke(page, temp2);
181:                                //page.setTextNameField("PickUps");
182:                                Object[] temp3 = { currentDelivery.getPickUp()
183:                                        .getName()
184:                                        + "("
185:                                        + currentDelivery.getHandle()
186:                                        + ")" };
187:                                setTextDisplayTemplateName.invoke(page, temp3);
188:                                //page.setTextDisplayTemplateName(currentDelivery.getPickUp().getName() + "(" + 
189:                                //			currentDelivery.getHandle() + ")");
190:                                Object[] temp4 = { "Done" };
191:                                setTextDisplayTemplateComplete.invoke(page,
192:                                        temp4);
193:                                //page.setTextDisplayTemplateComplete("Done");
194:                                templateName
195:                                        .getAttributeNode("href")
196:                                        .setValue(
197:                                                AirSentConstants.DETAILS_PO
198:                                                        + "?deliveryID="
199:                                                        + currentDelivery
200:                                                                .getHandle()
201:                                                        + "&"
202:                                                        + AirSentConstants.SELECTION_NAME
203:                                                        + "=" + pageSelection);
204:                                templateLink
205:                                        .getAttributeNode("href")
206:                                        .setValue(
207:                                                AirSentConstants.DISPLAY_PO
208:                                                        + "?event=complete"
209:                                                        + "&"
210:                                                        + "deliveryID="
211:                                                        + currentDelivery
212:                                                                .getHandle()
213:                                                        + "&"
214:                                                        + AirSentConstants.SELECTION_NAME
215:                                                        + "=" + pageSelection);
216:                                // Add a deep clone of the table row to the DOM
217:                                Node clonedNode = templateRow.cloneNode(true);
218:                                templateRow.getParentNode().appendChild(
219:                                        clonedNode);
220:                            }
221:                        } else {
222:                            Object[] temp5 = { "DropOffs" };
223:                            setTextNameField.invoke(page, temp5);
224:                            //page.setTextNameField("DropOffs");
225:                            Object[] temp6 = { currentDelivery.getDropOff()
226:                                    .getName()
227:                                    + "(" + currentDelivery.getHandle() + ")" };
228:                            setTextDisplayTemplateName.invoke(page, temp6);
229:                            //page.setTextDisplayTemplateName(currentDelivery.getDropOff().getName() + "(" + 
230:                            //	    currentDelivery.getHandle() + ")");
231:                            Object[] temp7 = { "Done" };
232:                            setTextDisplayTemplateComplete.invoke(page, temp7);
233:                            //page.setTextDisplayTemplateComplete("Done");
234:                            templateName.getAttributeNode("href").setValue(
235:                                    AirSentConstants.DETAILS_PO
236:                                            + "?deliveryID="
237:                                            + currentDelivery.getHandle() + "&"
238:                                            + AirSentConstants.SELECTION_NAME
239:                                            + "=" + pageSelection);
240:                            templateLink.getAttributeNode("href").setValue(
241:                                    AirSentConstants.DISPLAY_PO
242:                                            + "?event=complete" + "&"
243:                                            + "deliveryID="
244:                                            + currentDelivery.getHandle() + "&"
245:                                            + AirSentConstants.SELECTION_NAME
246:                                            + "=" + pageSelection);
247:                            // Add a deep clone of the table row to the DOM
248:                            Node clonedNode = templateRow.cloneNode(true);
249:                            templateRow.getParentNode().appendChild(clonedNode);
250:                        }
251:                    }
252:
253:                    /**No deliveries, just put a 'None'
254:                     **button.
255:                     **
256:                     **/
257:                    if (deliveryList.length > 0) {
258:
259:                        if (pageSelection.equals(AirSentConstants.PICKUP)
260:                                && pickupCount == 0) {
261:                            Object[] temp8 = { "None" };
262:                            setTextDisplayTemplateName.invoke(page, temp8);
263:                            //page.setTextDisplayTemplateName("None");
264:                            templateName.getAttributeNode("href").setValue(
265:                                    AirSentConstants.MESSENGER_MAIN_PAGE);
266:                            templateLink.getParentNode().removeChild(
267:                                    templateLink);
268:                        } else {
269:                            templateRow.getParentNode()
270:                                    .removeChild(templateRow);
271:                        }
272:                    } else {
273:                        Object[] temp9 = { "None" };
274:                        setTextDisplayTemplateName.invoke(page, temp9);
275:                        //page.setTextDisplayTemplateName("None");
276:                        templateName.getAttributeNode("href").setValue(
277:                                AirSentConstants.MESSENGER_MAIN_PAGE);
278:                        templateLink.getParentNode().removeChild(templateLink);
279:                    }
280:                } catch (Exception ex) {
281:                    throw new AirSentPresentationException(
282:                            "Error getting deliveries for user: ", ex);
283:                }
284:
285:                DeviceUtils.setURLTimeStamp((XMLObject) page);
286:                return ((XMLObject) page);
287:            }
288:
289:            /**
290:             * Handles the selection from the
291:             * main page, and based on the query string,
292:             * displays the list of pickups, or the list
293:             * of deliveries.
294:             * @param page
295:             * 
296:             * @throws HttpPresentationException
297:             * 
298:             * @see
299:             */
300:
301:            /**
302:             public void handleSelection(DisplayPage page) 
303:             throws HttpPresentationException {
304:             String pageSelection = 
305:             myComms.request.getParameter(AirSentConstants.SELECTION_NAME);
306:            
307:             int pickupCount = 0;
308:            
309:             try {
310:             Delivery[] deliveryList = 
311:             getApplication().getHomeManager().getDeliveryManager().findByMessenger(getSessionData().getMessenger());
312:             Element    templateName = page.getTagDisplayTemplateName();
313:             Element    templateLink = page.getTagDisplayTemplateComplete();
314:             Element    templateRow = page.getTagDisplayTemplateRow();
315:            
316:             // Remove ids to prevent duplicates
317:             templateName.removeAttribute("id");
318:             templateLink.removeAttribute("id");
319:             templateRow.removeAttribute("id");
320:            
321:             Delivery currentDelivery = null;
322:             // Get collection of Deliveries and loop through collection
323:             // to add each disc as a row in the table.
324:             for (int numDeliveries = 0; numDeliveries < deliveryList.length; 
325:             numDeliveries++) {
326:            
327:             currentDelivery = deliveryList[numDeliveries];
328:            
329:             if (pageSelection.equals(AirSentConstants.PICKUP)) {
330:             page.setTextNameField(AirSentConstants.PICKUP);
331:
332:             // Check to see if this has already been picked up:    
333:             if (!currentDelivery.isPickedUp()) {
334:             pickupCount++;			
335:             page.setTextNameField("PickUps");
336:             page.setTextDisplayTemplateName(currentDelivery.getPickUp().getName() + "(" + 
337:             currentDelivery.getHandle() + ")");
338:             page.setTextDisplayTemplateComplete("Done");
339:             templateName.getAttributeNode("href").setValue(AirSentConstants.DETAILS_PO 
340:             + "?deliveryID=" 
341:             + currentDelivery.getHandle() 
342:             + "&" 
343:             + AirSentConstants.SELECTION_NAME 
344:             + "=" + pageSelection);
345:             templateLink.getAttributeNode("href").setValue(AirSentConstants.DISPLAY_PO 
346:             + "?event=complete" + "&" 
347:             + "deliveryID=" 
348:             + currentDelivery.getHandle() 
349:             + "&" 
350:             + AirSentConstants.SELECTION_NAME 
351:             + "=" + pageSelection);
352:             // Add a deep clone of the table row to the DOM
353:             Node clonedNode = templateRow.cloneNode(true);
354:             templateRow.getParentNode().appendChild(clonedNode);
355:             }
356:             } else {
357:             page.setTextNameField("DropOffs");
358:             page.setTextDisplayTemplateName(currentDelivery.getDropOff().getName() + "(" + 
359:             currentDelivery.getHandle() + ")");
360:             page.setTextDisplayTemplateComplete("Done");
361:             templateName.getAttributeNode("href").setValue(AirSentConstants.DETAILS_PO 
362:             + "?deliveryID=" 
363:             + currentDelivery.getHandle() 
364:             + "&" 
365:             + AirSentConstants.SELECTION_NAME 
366:             + "=" + pageSelection);
367:             templateLink.getAttributeNode("href").setValue(AirSentConstants.DISPLAY_PO 
368:             + "?event=complete" + "&" 
369:             + "deliveryID=" 
370:             + currentDelivery.getHandle() 
371:             + "&" 
372:             + AirSentConstants.SELECTION_NAME 
373:             + "=" + pageSelection);
374:             // Add a deep clone of the table row to the DOM
375:             Node clonedNode = templateRow.cloneNode(true);
376:             templateRow.getParentNode().appendChild(clonedNode);
377:             }
378:             } 
379:            
380:             if(deliveryList.length > 0) {
381:            
382:             if(pageSelection.equals(AirSentConstants.PICKUP) && pickupCount == 0) {
383:             page.setTextDisplayTemplateName("None");
384:             templateName.getAttributeNode("href").setValue(AirSentConstants.MESSENGER_MAIN_PAGE); 
385:             templateLink.getParentNode().removeChild(templateLink);
386:             }
387:             else {
388:             templateRow.getParentNode().removeChild(templateRow);
389:             }
390:             }
391:             else {
392:             page.setTextDisplayTemplateName("None");
393:             templateName.getAttributeNode("href").setValue(AirSentConstants.MESSENGER_MAIN_PAGE); 
394:             templateLink.getParentNode().removeChild(templateLink);
395:             }
396:             } catch (Exception ex) {
397:             throw new AirSentPresentationException("Error getting deliveries for user: ", 
398:             ex);
399:             } 
400:             } 
401:             */
402:
403:            /**
404:             * Process either a pickup or a delivery by
405:             * using the query string to determine the
406:             * type and delivery number.
407:             * @return the Document as XMLObject
408:             */
409:            public XMLObject handleComplete() throws HttpPresentationException {
410:                String deliveryID = myComms.request
411:                        .getParameter(AirSentConstants.DELIVERYID);
412:                String status = myComms.request
413:                        .getParameter(AirSentConstants.SELECTION_NAME);
414:
415:                try {
416:                    Delivery delivery = null;
417:                    if (deliveryID != null
418:                            && (delivery = getApplication().getHomeManager()
419:                                    .getDeliveryManager().findByHandle(
420:                                            deliveryID)) != null) {
421:                        if (status != null
422:                                && status.equals(AirSentConstants.DROPOFF)) {
423:
424:                            if (!delivery.isPickedUp()) {
425:                                this .getSessionData().setUserMessage(
426:                                        "Need to pickup package first!");
427:                                throw new ClientPageRedirectException(
428:                                        AirSentConstants.MESSENGER_MAIN_PAGE);
429:                            }
430:
431:                            delivery.dropOff();
432:
433:                            // Generate an email message
434:                            // Send email confimation
435:                            //
436:                            String body = handleEmailConfirmation(delivery);
437:                            String subject = "Delivery notice from AirSent.";
438:                            String type = "text/html";
439:                            getApplication().getHomeManager().getEmailManager()
440:                                    .send(
441:                                            delivery.getCustomer()
442:                                                    .getFirstName()
443:                                                    + delivery.getCustomer()
444:                                                            .getLastName(),
445:                                            delivery.getCustomer().getEmail(),
446:                                            subject, body, type);
447:
448:                        } else if (status != null
449:                                && status.equals(AirSentConstants.PICKUP)) {
450:                            delivery.pickUp();
451:                        }
452:                    } else {
453:                        this .getSessionData().setUserMessage(
454:                                "Error occured in completing delivery.");
455:                        throw new ClientPageRedirectException(
456:                                AirSentConstants.MESSENGER_MAIN_PAGE);
457:                    }
458:
459:                    throw new ClientPageRedirectException(
460:                            AirSentConstants.MESSENGER_MAIN_PAGE);
461:                } catch (Exception ex) {
462:                    throw new AirSentPresentationException(
463:                            "Error occured in completing delivery", ex);
464:                }
465:            }
466:
467:            /**
468:             * Creates a personalized email confirmation.
469:             * @param error messages
470:             * @return HTML page as string.
471:             */
472:            public String handleEmailConfirmation(Delivery delivery)
473:                    throws AirSentPresentationException {
474:                EmailConfirmationHTML page = (EmailConfirmationHTML) myComms.xmlcFactory
475:                        .create(EmailConfirmationHTML.class);
476:
477:                try {
478:                    if (delivery == null)
479:                        System.out.println("DELIVERY IS NULL");
480:                    if (delivery.getCustomer() == null)
481:                        System.out.println("CUSTOMER IS NULL");
482:                    page.setTextDescription(delivery.getDescription());
483:                    page.setTextName(delivery.getCustomer().getFirstName()
484:                            + " " + delivery.getCustomer().getLastName());
485:                    page.setTextPickupname(delivery.getPickUp().getName());
486:                    page
487:                            .setTextPickupaddress(delivery.getPickUp()
488:                                    .getStreet1());
489:                    page.setTextPickuptime(delivery.getPickedUpTime());
490:                    page.setTextDropoffname(delivery.getDropOff().getName());
491:                    page.setTextDropoffaddress(delivery.getDropOff()
492:                            .getStreet1());
493:                    page.setTextDropofftime(delivery.getDroppedOffTime());
494:
495:                } catch (Exception ex) {
496:                    throw new AirSentPresentationException(
497:                            "Error in email confimation", ex);
498:                }
499:
500:                //Write to text to insert into email.
501:                return page.toDocument();
502:            }
503:
504:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.