Source Code Cross Referenced for BaseController.java in  » J2EE » Sofia » com » salmonllc » examples » 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 » Sofia » com.salmonllc.examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.examples;
002:
003:        //The Salmon Open Framework for Internet Applications (SOFIA)
004:        //Copyright (C) 1999 - 2002, Salmon LLC
005:        //
006:        //This program is free software; you can redistribute it and/or
007:        //modify it under the terms of the GNU General Public License version 2
008:        //as published by the Free Software Foundation;
009:        //
010:        //This program is distributed in the hope that it will be useful,
011:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
012:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:        //GNU General Public License for more details.
014:        //
015:        //You should have received a copy of the GNU General Public License
016:        //along with this program; if not, write to the Free Software
017:        //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:        //
019:        //For more information please visit http://www.salmonllc.com
020:
021:        import com.salmonllc.examples.SessionManager;
022:        import com.salmonllc.html.events.*;
023:        import com.salmonllc.jsp.JspController;
024:        import com.salmonllc.jsp.JspLink;
025:        import com.salmonllc.util.MessageLog;
026:        import com.salmonllc.sql.DBConnection;
027:
028:        import javax.servlet.http.Cookie;
029:
030:        /**
031:         This controller is used as the ancestor for the other controllers in the example app.
032:         Generally, every controller will extend from this one, but the examples all extend JspController in order to keep them encapsulated.
033:         This controller has more functionality than is requied by the sample application so it can be copied and used as a starting point for your application's base controller.
034:         It implements frequently used interfaces at the base level to avoid having to implement all the methods in each controller.
035:         Also, it provides some basic functionality such as checking if the session or page is required and redirecting the user to the appropriate page.
036:         */
037:        public class BaseController extends JspController implements 
038:                SubmitListener, PageListener {
039:
040:            public com.salmonllc.jsp.JspContainer _noCache;
041:
042:            private boolean _redirected = true;
043:            private boolean _checkSessionExpired = true;
044:            private boolean _checkPageExpired = false;
045:            private boolean _checkDB = true;
046:
047:            /**
048:             *	This method tries to get the string parameter passed into this function from the URL.  It then checks to see if that "name" parameter is of boolean type.  The default is FALSE.
049:             *	@param name - name of the parameter that is being looked up
050:             */
051:
052:            public boolean getBooleanParameter(String name) {
053:                String s = getParameter(name);
054:                return s != null
055:                        && (s.equals("true") || s.equals("TRUE") || s
056:                                .equals("1"));
057:            }
058:
059:            /**
060:             * Return the text of the request referer, if available, else null.
061:             * @param key - name of the cookie
062:             * @return java.lang.String
063:             */
064:            public Cookie getCookie(String key) {
065:                Cookie ret = null;
066:
067:                Cookie cookArr[] = getCurrentRequest().getCookies();
068:                if (cookArr != null) {
069:                    for (int i = 0; i < cookArr.length; i++) {
070:                        if (cookArr[i].getName().equals(key)) {
071:                            ret = cookArr[i];
072:                        }
073:                        break;
074:                    }
075:                }
076:                return ret;
077:            }
078:
079:            /**
080:             *	This method tries to get the integer value from the parameter in the URL called passed into this method.  If the value of the parameter is not an integer, a -1 value will be returned.
081:             *	@param name - name of the parameter that is being looked up
082:             * 	@return int - returns the value of the parameter as an int, if the value can NOT be cast to an int -1 is returned
083:             */
084:
085:            public int getIntParameter(String name) {
086:                String s = getParameter(name);
087:                try {
088:                    return Integer.parseInt(s);
089:                } catch (Exception e) {
090:                    return -1;
091:                }
092:            }
093:
094:            /**
095:             * Gets the SessionManager for this application.
096:             */
097:            public SessionManager getSessionManager() {
098:                return new SessionManager(getSession(), getApplicationName());
099:            }
100:
101:            /**
102:             * This method
103:             *  - creates a SessionManager a page Listener
104:             *  - adds a page Listener
105:             *  - adds a page Listener
106:             * @throws Exception if anything goes wrong
107:             */
108:            public void initialize() throws Exception {
109:                //make this controller listen for page events
110:                addPageListener(this );
111:                //check if there is a return to link in the page. If there is, set the url
112:                JspLink l = (JspLink) getComponent("retToHome");
113:                if (l != null)
114:                    l.setHref("HomePage.jsp");
115:            }
116:
117:            /**
118:             * 	This method/event will get fired each time a page is requested by the browser before Html is generated and sent back.
119:             *	@param p PageEvent
120:             *  @throws Exception if anything goes wrong
121:             */
122:            public void pageRequested(PageEvent p) throws Exception {
123:                checkPageRedirect();
124:                if (hasPageRedirected())
125:                    p.setContinueProcessing(false);
126:            }
127:
128:            /**
129:             * 	This method/event will get fired each time a page is requested by the browser after Html is generated and sent back.
130:             *	@param p PageEvent
131:             *  @throws Exception if anything goes wrong
132:             */
133:            public void pageRequestEnd(PageEvent p) throws Exception {
134:
135:            }
136:
137:            /**
138:             * 	This method occurs each time a page is submitted before submit values are copied to components.
139:             *	@param p PageEvent
140:             */
141:            public void pageSubmitted(PageEvent p) {
142:                checkPageRedirect();
143:                if (hasPageRedirected())
144:                    p.setContinueProcessing(false);
145:            }
146:
147:            /**
148:             * 	This method occurs each time a page is submitted after submit values are copied to components.
149:             *	@param p PageEvent
150:             */
151:            public void pageSubmitEnd(PageEvent p) {
152:
153:            }
154:
155:            /**
156:             *	This method is used to signal that a submit button has been pressed, and that the user has intended
157:             *  to submit the descendant class/page.
158:             *	@param e SubmitEvent
159:             *  @throws Exception if anything goes wrong
160:             *	@return true to continue processing events on the page or false to abort
161:             */
162:
163:            public boolean submitPerformed(SubmitEvent e) throws Exception {
164:                return true;
165:            }
166:
167:            /**
168:             * This method will check if the page is expired or the session is expired and redirect to the appropriate page
169:             */
170:            private void checkPageRedirect() {
171:
172:                try {
173:                    _redirected = false;
174:                    if (_checkSessionExpired)
175:                        if (isSessionExpired()) {
176:                            _redirected = true;
177:                            gotoSiteMapPage(SiteMapConstants.SESSION_EXPIRED);
178:                            return;
179:                        }
180:
181:                    if (_checkPageExpired)
182:                        if (isExpired()) {
183:                            _redirected = true;
184:                            gotoSiteMapPage(SiteMapConstants.PAGE_EXPIRED);
185:                            return;
186:                        }
187:
188:                    if (_checkDB) {
189:                        DBConnection conn = null;
190:                        try {
191:                            conn = DBConnection
192:                                    .getConnection(getApplicationName());
193:                        } catch (Exception e) {
194:                            _redirected = true;
195:                            gotoSiteMapPage(SiteMapConstants.DB_CONNECT_ERROR);
196:                        } finally {
197:                            if (conn != null)
198:                                conn.freeConnection();
199:                        }
200:                    }
201:
202:                } catch (Exception e) {
203:                    MessageLog
204:                            .writeErrorMessage("checkPageRedirect()", e, this );
205:                }
206:            }
207:
208:            /**
209:             * Returns true if either the page or the session is expired and the page has been redirected to another page indicating that
210:             */
211:            public boolean hasPageRedirected() {
212:                return _redirected;
213:            }
214:
215:            /**
216:             * Tells the page whether or not it should check whether the page is expired on each request
217:             */
218:            public void setCheckPageExpired(boolean check) {
219:                _checkPageExpired = check;
220:            }
221:
222:            /**
223:             * Tells the page whether or not it should check whether the session is expired on each request
224:             */
225:            public void setCheckSessionExpired(boolean check) {
226:                _checkSessionExpired = check;
227:            }
228:
229:            /**
230:             * If you want to have the browser cache this page instead of reloading it each time call this method with a true argument.
231:             */
232:            public void setNoCache(boolean noCache) {
233:                _noCache.setVisible(noCache);
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.