Source Code Cross Referenced for Contents.java in  » J2EE » Enhydra-Demos » golfShop » presentation » xmlc » cart » 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 » golfShop.presentation.xmlc.cart 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server 
003:         * The Initial Developer of the Original Code is Lutris Technologies Inc. 
004:         * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005:         * Inc. 
006:         * All Rights Reserved. 
007:         *
008:         * The contents of this file are subject to the Enhydra Public License Version
009:         * 1.0 (the "License"); you may not use this file except in compliance with the
010:         * License. You may obtain a copy of the License at
011:         * http://www.enhydra.org/software/license/epl.html 
012:         *
013:         * Software distributed under the License is distributed on an "AS IS" basis,
014:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing rights and limitations under the
016:         * License. 
017:         *
018:         * 
019:         */
020:
021:        package golfShop.presentation.xmlc.cart;
022:
023:        import org.enhydra.xml.xmlc.*;
024:        import org.enhydra.xml.xmlc.html.*;
025:        import com.lutris.appserver.server.httpPresentation.*;
026:        import java.io.*;
027:        import java.net.URLEncoder;
028:        import org.w3c.dom.*;
029:        import org.w3c.dom.html.*;
030:        import golfShop.presentation.xmlc.utilities.*;
031:        import java.math.BigDecimal;
032:        import java.util.Enumeration;
033:        import golfShop.spec.cart.*;
034:
035:        /**
036:         * This presentation object dynamically creates an HTML page showing the 
037:         * cart contents in an tabulated form or, if the user wants to go to the
038:         * Checkout PO, they will be redirected appropriately.
039:         */
040:        public class Contents implements  HttpPresentation {
041:            //FIXME: Make this work...
042:            /**
043:             * Active and inactive buttons images and alt text.
044:             */
045:            private static final String ADD_INACTIVE_GIF = "";
046:
047:            /**
048:             * URL to reference the this presentation object.
049:             */
050:            private static final String CONTENTS_URL = "Contents.po";
051:
052:            /**
053:             * URL to reference the checkout presentation object.
054:             */
055:            private static final String CHECKOUT_URL = "../checkout/Main.po";
056:
057:            /**
058:             * URL of the undo-inactive images.
059:             */
060:            private static final String UNDO_INACTIVE_IMG = "../media/Undo_d.gif";
061:
062:            /**
063:             * URL of the redo-inactive images.
064:             */
065:            private static final String REDO_INACTIVE_IMG = "../media/Redo_d.gif";
066:
067:            /**
068:             * Requested action.  If null, just display.
069:             */
070:            String action;
071:
072:            /**
073:             * Cart object for session.
074:             */
075:            Cart cart;
076:
077:            /**
078:             * Process the submission of an update.
079:             */
080:            private void processUpdate(HttpPresentationComms comms)
081:                    throws HttpPresentationException {
082:                // Variable to track cart modifications.
083:                boolean modified = false;
084:
085:                // Search parameters for form update names.
086:                Enumeration params = comms.request.getParameterNames();
087:                while (params.hasMoreElements()) {
088:                    String name = (String) params.nextElement();
089:                    if (name.startsWith(ContentsTableFormatter.QTY_PREFIX)) {
090:                        // Change the quantities of the cart items
091:                        long objectId = Long.parseLong(name
092:                                .substring(ContentsTableFormatter.QTY_PREFIX
093:                                        .length()));
094:                        String qtyString = comms.request.getParameter(name);
095:
096:                        int oldQty = 0;
097:                        try {
098:                            oldQty = cart.getQuantity(objectId);
099:                            /*
100:                             * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run GolfShop_pres )
101:                             * if cart is null ( we set it in CartUtils when we catch NullPointerExceptiont ) the response will be default HTML page 
102:                             *We need  to allow GolfShop_pres to be functional
103:                             */
104:                        } catch (NullPointerException ex) {
105:                            throw new ClientPageRedirectException(CONTENTS_URL);
106:                        }
107:                        try {
108:                            int newQty = Integer.valueOf(qtyString).intValue();
109:                            // Only change if there is a new value.
110:                            if (newQty != oldQty && newQty >= 0
111:                                    && newQty < 1000) {
112:                                cart.setQuantity(objectId, newQty);
113:                                modified = true;
114:
115:                            }
116:                        } catch (NumberFormatException nfe) {
117:                            // Ignore bogus numbers
118:                        }
119:                    } else if (name
120:                            .startsWith(ContentsTableFormatter.DEL_PREFIX)) {
121:                        // Delete items from the cart, if requested.
122:                        long objectId = Long.parseLong(name
123:                                .substring(ContentsTableFormatter.DEL_PREFIX
124:                                        .length()));
125:                        if (cart.getQuantity(objectId) != -1) {
126:                            cart.removeItem(objectId);
127:                            modified = true;
128:                        }
129:                    }
130:                }
131:
132:                // If we made any changes above, notify the cart we are done.
133:                if (modified) {
134:                    cart.doneModifying();
135:                }
136:
137:                // Must redirect to this page without the CGI arguments, or reload
138:                // will result in page being updated again.
139:                throw new ClientPageRedirectException(CONTENTS_URL);
140:            }
141:
142:            /**
143:             * Disable one either the undo or redo anchor and image.  It is expected
144:             * that the button is in the enabled state by default.
145:             * 
146:             * @param anchor The anchor element.
147:             * @param img The contained img element.
148:             * @param inactiveImgUrl The URL for the inactive image.
149:             */
150:            private void disableButton(HTMLAnchorElement anchor,
151:                    HTMLImageElement img, String inactiveImgUrl) {
152:                // Disable anchor by clearing href and mouseOver attributes.
153:                anchor.removeAttribute("href");
154:                anchor.removeAttribute("onmouseover");
155:                anchor.removeAttribute("onmouseout");
156:
157:                // Set image to the inactive version.
158:                img.setSrc(inactiveImgUrl);
159:            }
160:
161:            /**
162:             * Configure the undo/redo `buttons' based on the state of the cart.
163:             */
164:            private void configureUndoRedo(ContentsHTML htmlObj) {
165:                if (!cart.canUndo()) {
166:                    disableButton(htmlObj.getElementUndoAnchor(), htmlObj
167:                            .getElementUndoImg(), UNDO_INACTIVE_IMG);
168:                }
169:                if (!cart.canRedo()) {
170:                    disableButton(htmlObj.getElementRedoAnchor(), htmlObj
171:                            .getElementRedoImg(), REDO_INACTIVE_IMG);
172:                }
173:            }
174:
175:            /**
176:             * Output the page, setting dynamic values.
177:             */
178:            private void outputPage(HttpPresentationComms comms)
179:                    throws HttpPresentationException {
180:                ContentsHTML htmlObj = (ContentsHTML) comms.xmlcFactory
181:                        .create(ContentsHTML.class);
182:
183:                ContentsTableFormatter.fillInTable(htmlObj, cart, true);
184:                try {
185:                    configureUndoRedo(htmlObj);
186:                    //same thing
187:                } catch (NullPointerException ex) {
188:                }
189:                comms.response.writeDOM(htmlObj);
190:            }
191:
192:            /**
193:             * Parse CGI arguments into fields.
194:             */
195:            private void parseArgs(HttpPresentationRequest request)
196:                    throws HttpPresentationException {
197:                action = request.getParameter("action");
198:                if (action == null) {
199:                    action = "display";
200:                }
201:            }
202:
203:            /**
204:             * Entry.
205:             */
206:            public void run(HttpPresentationComms comms)
207:                    throws HttpPresentationException {
208:
209:                parseArgs(comms.request);
210:                cart = CartUtils.getCart(comms.session);
211:
212:                // Process specified action, if any.
213:                if (action.equals("update")) {
214:                    processUpdate(comms);
215:                } else if (action.equals("undo")) {
216:                    try {
217:                        if (cart.canUndo()) {
218:                            cart.undo();
219:                        }
220:                        /*
221:                         * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run GolfShop_pres )
222:                         * if cart is null ( we set it in CartUtils when we catch NullPointerExceptiont ) the response will be default HTML page 
223:                         *We need  to allow GolfShop_pres to be functional
224:                         */
225:                    } catch (NullPointerException ex) {
226:                        throw new ClientPageRedirectException(CONTENTS_URL);
227:                    }
228:
229:                } else if (action.equals("redo")) {
230:                    try {
231:                        if (cart.canRedo()) {
232:                            cart.redo();
233:                        }
234:                        //same thing
235:                    } catch (NullPointerException ex) {
236:                        throw new ClientPageRedirectException(CONTENTS_URL);
237:                    }
238:
239:                }
240:
241:                outputPage(comms);
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.