Source Code Cross Referenced for RefererBean.java in  » Portal » DLOG4J » dlog4j » beans » 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 » Portal » DLOG4J » dlog4j.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This program is free software; you can redistribute it and/or modify
003:         *  it under the terms of the GNU General Public License as published by
004:         *  the Free Software Foundation; either version 2 of the License, or
005:         *  (at your option) any later version.
006:         *
007:         *  This program is distributed in the hope that it will be useful,
008:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *  GNU Library General Public License for more details.
011:         *
012:         *  You should have received a copy of the GNU General Public License
013:         *  along with this program; if not, write to the Free Software
014:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015:         */
016:        package dlog4j.beans;
017:
018:        import java.io.Serializable;
019:        import java.net.URL;
020:        import java.text.DateFormat;
021:        import java.text.SimpleDateFormat;
022:        import java.util.Date;
023:
024:        import javax.servlet.http.HttpServletRequest;
025:
026:        /**
027:         * 外部网站引用记录,对应表dlog_site_referer的一条记录
028:         * 建表语句:
029:         * create table dlog_visit (
030:         visitID              INTEGER              not null,
031:         remoteAddr           CHAR(15)             not null,
032:         requestURL           VARCHAR(100)         not null,
033:         userAgent            VARCHAR(100)         null,
034:         visitDate            CHAR(8)              not null,
035:         visitTime            CHAR(6)              not null,
036:         refererURL           VARCHAR(200)         null,
037:         constraint PK_DLOG_VISIT primary key  (visitID)
038:         )
039:         * @author Winter Lau
040:         */
041:        public class RefererBean implements  Serializable {
042:
043:            public final static String DATE_FORMAT = "yyyyMMdd";
044:            public final static String TIME_FORMAT = "HHmmss";
045:
046:            public final static DateFormat DATE = new SimpleDateFormat(
047:                    DATE_FORMAT);
048:            public final static DateFormat TIME = new SimpleDateFormat(
049:                    TIME_FORMAT);
050:
051:            protected int id;
052:            protected String remoteAddr;
053:            protected String refererURL;
054:            protected String requestURL;
055:            protected String userAgent;
056:            protected String visitDate;
057:            protected String visitTime;
058:
059:            /**
060:             * 该构造函数是提供给Hibernate初始化Bean时用
061:             */
062:            public RefererBean() {
063:            }
064:
065:            /**
066:             * 从反问请求实例中初始化外部引用记录
067:             * @param request
068:             */
069:            public RefererBean(HttpServletRequest request) {
070:                refererURL = request.getHeader("referer");
071:                remoteAddr = request.getRemoteAddr();
072:                userAgent = request.getHeader("user-agent");
073:                StringBuffer ru = request.getRequestURL();
074:                if (request.getQueryString() != null) {
075:                    ru.append('?');
076:                    ru.append(request.getQueryString());
077:                }
078:                setRequestURL(ru.toString());
079:                Date curTime = new Date();
080:                visitDate = DATE.format(curTime);
081:                visitTime = TIME.format(curTime);
082:                curTime = null;
083:            }
084:
085:            /**
086:             * 判断该外部引用是否来自于自身站点
087:             * @param request
088:             * @return
089:             */
090:            public boolean isFromOutsite() {
091:                if (refererURL != null)
092:                    try {
093:                        URL req_url = new URL(requestURL);
094:                        URL ref_url = new URL(refererURL);
095:                        return !req_url.getHost().equalsIgnoreCase(
096:                                ref_url.getHost());
097:                    } catch (Exception e) {
098:                    }
099:                return false;
100:            }
101:
102:            public int getId() {
103:                return id;
104:            }
105:
106:            public void setId(int id) {
107:                this .id = id;
108:            }
109:
110:            public String getRequestURL() {
111:                return requestURL;
112:            }
113:
114:            public void setRequestURL(String reqUrl) {
115:                this .requestURL = reqUrl;
116:                trimReqUrl();
117:            }
118:
119:            protected void trimReqUrl() {
120:                if (requestURL == null)
121:                    return;
122:                String url = "";
123:                int mainParamIdx = requestURL.indexOf("main=");
124:                if (mainParamIdx != -1) {
125:                    int splitIdx = requestURL.indexOf("&", mainParamIdx);
126:                    if (splitIdx != -1) {
127:                        url = requestURL.substring(0, mainParamIdx);
128:                        if ((splitIdx + 1) < requestURL.length()) {
129:                            url += requestURL.substring(splitIdx + 1);
130:                        }
131:                    } else {
132:                        url = requestURL.substring(0, mainParamIdx - 1);
133:                    }
134:                    requestURL = url;
135:                }
136:            }
137:
138:            public String getRefererURL() {
139:                return refererURL;
140:            }
141:
142:            public void setRefererURL(String refererURL) {
143:                this .refererURL = refererURL;
144:            }
145:
146:            public String getRemoteAddr() {
147:                return remoteAddr;
148:            }
149:
150:            public void setRemoteAddr(String remoteAddr) {
151:                this .remoteAddr = remoteAddr;
152:            }
153:
154:            public String getUserAgent() {
155:                return userAgent;
156:            }
157:
158:            public void setUserAgent(String userAgent) {
159:                this .userAgent = userAgent;
160:            }
161:
162:            public String getVisitDate() {
163:                return visitDate;
164:            }
165:
166:            public void setVisitDate(String visitDate) {
167:                this .visitDate = visitDate;
168:            }
169:
170:            public String getVisitTime() {
171:                return visitTime;
172:            }
173:
174:            public void setVisitTime(String visitTime) {
175:                this .visitTime = visitTime;
176:            }
177:
178:            public static void main(String[] args) {
179:                Date curTime = new Date();
180:                String visitDate = DATE.format(curTime);
181:                String visitTime = TIME.format(curTime);
182:                System.out.println("visitDate=" + visitDate);
183:                System.out.println("visitTime=" + visitTime);
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.