Source Code Cross Referenced for VisitHandler.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » content » stats » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.content.stats 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: VisitHandler.java,v 1.3 2004/02/11 06:04:20 jonesde Exp $
003:         *
004:         *  Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         *  Permission is hereby granted, free of charge, to any person obtaining a
007:         *  copy of this software and associated documentation files (the "Software"),
008:         *  to deal in the Software without restriction, including without limitation
009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         *  and/or sell copies of the Software, and to permit persons to whom the
011:         *  Software is furnished to do so, subject to the following conditions:
012:         *
013:         *  The above copyright notice and this permission notice shall be included
014:         *  in all copies or substantial portions of the Software.
015:         *
016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:        package org.ofbiz.content.stats;
025:
026:        import java.net.InetAddress;
027:        import java.sql.Timestamp;
028:
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpSession;
031:
032:        import org.ofbiz.base.util.Debug;
033:        import org.ofbiz.base.util.UtilHttp;
034:        import org.ofbiz.base.util.UtilProperties;
035:        import org.ofbiz.base.util.UtilValidate;
036:        import org.ofbiz.entity.GenericDelegator;
037:        import org.ofbiz.entity.GenericEntityException;
038:        import org.ofbiz.entity.GenericValue;
039:
040:        /**
041:         * Handles saving and maintaining visit information
042:         *
043:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
044:         * @version    $Revision: 1.3 $
045:         * @since      2.0
046:         */
047:        public class VisitHandler {
048:            // Debug module name
049:            public static final String module = VisitHandler.class.getName();
050:
051:            // this is not an event because it is required to run; as an event it could be disabled.
052:            public static void setInitialVisit(HttpServletRequest request) {
053:                HttpSession session = request.getSession();
054:                String webappName = UtilHttp.getApplicationName(request);
055:                StringBuffer fullRequestUrl = UtilHttp
056:                        .getFullRequestUrl(request);
057:                String initialLocale = request.getLocale() != null ? request
058:                        .getLocale().toString() : "";
059:                String initialRequest = fullRequestUrl.toString();
060:                String initialReferrer = request.getHeader("Referer") != null ? request
061:                        .getHeader("Referer")
062:                        : "";
063:                String initialUserAgent = request.getHeader("User-Agent") != null ? request
064:                        .getHeader("User-Agent")
065:                        : "";
066:
067:                session.setAttribute("_CLIENT_LOCALE_", request.getLocale());
068:                session.setAttribute("_CLIENT_REQUEST_", initialRequest);
069:                session.setAttribute("_CLIENT_USER_AGENT_", initialUserAgent);
070:                session.setAttribute("_CLIENT_REFERER_", initialUserAgent);
071:                VisitHandler.setInitials(request, session, initialLocale,
072:                        initialRequest, initialReferrer, initialUserAgent,
073:                        webappName);
074:            }
075:
076:            public static void setInitials(HttpServletRequest request,
077:                    HttpSession session, String initialLocale,
078:                    String initialRequest, String initialReferrer,
079:                    String initialUserAgent, String webappName) {
080:                GenericValue visit = getVisit(session);
081:
082:                if (visit != null) {
083:                    visit.set("initialLocale", initialLocale);
084:                    if (initialRequest != null)
085:                        visit.set("initialRequest",
086:                                initialRequest.length() > 250 ? initialRequest
087:                                        .substring(0, 250) : initialRequest);
088:                    if (initialReferrer != null)
089:                        visit
090:                                .set("initialReferrer", initialReferrer
091:                                        .length() > 250 ? initialReferrer
092:                                        .substring(0, 250) : initialReferrer);
093:                    if (initialUserAgent != null)
094:                        visit
095:                                .set("initialUserAgent", initialUserAgent
096:                                        .length() > 250 ? initialUserAgent
097:                                        .substring(0, 250) : initialUserAgent);
098:                    visit.set("webappName", webappName);
099:                    visit.set("clientIpAddress", request.getRemoteAddr());
100:                    visit.set("clientHostName", request.getRemoteHost());
101:                    visit.set("clientUser", request.getRemoteUser());
102:
103:                    try {
104:                        visit.store();
105:                    } catch (GenericEntityException e) {
106:                        Debug.logError(e, "Could not update visit:", module);
107:                    }
108:                }
109:            }
110:
111:            public static void setUserLogin(HttpSession session,
112:                    GenericValue userLogin, boolean userCreated) {
113:                if (userLogin == null)
114:                    return;
115:                GenericValue visit = getVisit(session);
116:
117:                if (visit != null) {
118:                    visit.set("userLoginId", userLogin.get("userLoginId"));
119:                    visit.set("partyId", userLogin.get("partyId"));
120:                    visit.set("userCreated", new Boolean(userCreated));
121:
122:                    try {
123:                        visit.store();
124:                    } catch (GenericEntityException e) {
125:                        Debug.logError(e, "Could not update visit:", module);
126:                    }
127:                }
128:            }
129:
130:            public static String getVisitId(HttpSession session) {
131:                GenericValue visit = getVisit(session);
132:
133:                if (visit != null) {
134:                    return visit.getString("visitId");
135:                } else {
136:                    return null;
137:                }
138:            }
139:
140:            /** Get the visit from the session, or create if missing */
141:            public static GenericValue getVisit(HttpSession session) {
142:                // this defaults to true: ie if anything but "false" it will be true
143:                if (!UtilProperties.propertyValueEqualsIgnoreCase(
144:                        "serverstats", "stats.persist.visit", "false")) {
145:                    GenericValue visit = (GenericValue) session
146:                            .getAttribute("visit");
147:
148:                    if (visit == null) {
149:                        GenericDelegator delegator = null;
150:                        String delegatorName = (String) session
151:                                .getAttribute("delegatorName");
152:
153:                        if (UtilValidate.isNotEmpty(delegatorName)) {
154:                            delegator = GenericDelegator
155:                                    .getGenericDelegator(delegatorName);
156:                        }
157:                        if (delegator == null) {
158:                            Debug
159:                                    .logError(
160:                                            "Could not find delegator with delegatorName ["
161:                                                    + delegatorName
162:                                                    + "] in session, not creating Visit entity",
163:                                            module);
164:                        } else {
165:                            visit = delegator.makeValue("Visit", null);
166:                            Long nextId = delegator.getNextSeqId("Visit");
167:
168:                            if (nextId == null) {
169:                                Debug
170:                                        .logError(
171:                                                "Not persisting visit, could not get next seq id",
172:                                                module);
173:                                visit = null;
174:                            } else {
175:                                visit.set("visitId", nextId.toString());
176:                                visit.set("sessionId", session.getId());
177:                                visit.set("fromDate", new Timestamp(session
178:                                        .getCreationTime()));
179:                                // get localhost ip address and hostname to store
180:                                try {
181:                                    InetAddress address = InetAddress
182:                                            .getLocalHost();
183:
184:                                    if (address != null) {
185:                                        visit.set("serverIpAddress", address
186:                                                .getHostAddress());
187:                                        visit.set("serverHostName", address
188:                                                .getHostName());
189:                                    } else {
190:                                        Debug
191:                                                .logError(
192:                                                        "Unable to get localhost internet address, was null",
193:                                                        module);
194:                                    }
195:                                } catch (java.net.UnknownHostException e) {
196:                                    Debug.logError(
197:                                            "Unable to get localhost internet address: "
198:                                                    + e.toString(), module);
199:                                }
200:                                try {
201:                                    visit.create();
202:                                    session.setAttribute("visit", visit);
203:                                } catch (GenericEntityException e) {
204:                                    Debug.logError(e,
205:                                            "Could not create new visit:",
206:                                            module);
207:                                    visit = null;
208:                                }
209:                            }
210:                        }
211:                    }
212:                    if (visit == null) {
213:                        Debug
214:                                .logWarning(
215:                                        "Could not find or create the visit...",
216:                                        module);
217:                    }
218:                    return visit;
219:                } else {
220:                    return null;
221:                }
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.