File Source: logentry.java
/*
P/P * Method: net.sourceforge.pebble.logging.LogEntry__static_init
*/
1 /*
2 * Copyright (c) 2003-2006, Simon Brown
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * - Neither the name of Pebble nor the names of its contributors may
17 * be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 package net.sourceforge.pebble.logging;
33
34 import java.util.Date;
35
36 /**
37 * Represents an entry (line) in a log file.
38 *
39 * @author Simon Brown
40 */
/*
P/P * Method: void net.sourceforge.pebble.logging.LogEntry()
*
* Postconditions:
* this.bytes == -1
* this.date == &new Date(LogEntry#1)
* this.request == &""
* this.statusCode == 200
* new Date(LogEntry#1) num objects == 1
*/
41 public class LogEntry {
42
43 /** the host that made the request */
44 private String host;
45
46 /** the date the request was made */
47 private Date date = new Date();
48
49 /** the HTTP request */
50 private String request = "";
51
52 /** the HTTP status code returned */
53 private int statusCode = 200;
54
55 /** the number of bytes returned */
56 private long bytes = -1;
57
58 /** the referer (if applicable) */
59 private String referer;
60
61 /** the user-agent (if applicable) */
62 private String agent;
63
64 /**
65 * Gets the host (an IP address or DNS name).
66 *
67 * @return the host as a String
68 */
69 public String getHost() {
/*
P/P * Method: String getHost()
*
* Preconditions:
* init'ed(this.host)
*
* Postconditions:
* return_value == this.host
* init'ed(return_value)
*/
70 return host;
71 }
72
73 /**
74 * Sets the host (an IP address or DNS name).
75 *
76 * @param host the host as a String
77 */
78 public void setHost(String host) {
/*
P/P * Method: void setHost(String)
*
* Postconditions:
* this.host == host
* init'ed(this.host)
*/
79 this.host = host;
80 }
81
82 /**
83 * Gets the date.
84 *
85 * @return a Date
86 */
87 public Date getDate() {
/*
P/P * Method: Date getDate()
*
* Preconditions:
* init'ed(this.date)
*
* Postconditions:
* return_value == this.date
* init'ed(return_value)
*/
88 return date;
89 }
90
91 /**
92 * Sets the date.
93 *
94 * @param date a Date instance
95 */
96 public void setDate(Date date) {
/*
P/P * Method: void setDate(Date)
*
* Postconditions:
* this.date == date
* init'ed(this.date)
*/
97 this.date = date;
98 }
99
100 /**
101 * Gets the request.
102 *
103 * @return the request as a String
104 */
105 public String getRequest() {
/*
P/P * Method: String getRequest()
*
* Preconditions:
* init'ed(this.request)
*
* Postconditions:
* return_value == this.request
* init'ed(return_value)
*/
106 return request;
107 }
108
109 /**
110 * Gets just the method portion of the request.
111 *
112 * @return the request method as a String
113 */
114 public String getRequestMethod() {
/*
P/P * Method: String getRequestMethod()
*
* Preconditions:
* this.request != null
*
* Presumptions:
* java.lang.String:indexOf(...)@115 >= -231+1
*
* Postconditions:
* return_value != null
*/
115 return request.substring(0, request.indexOf("/")-1);
116 }
117
118 /**
119 * Gets just the URI portion of the request.
120 *
121 * @return the request URI as a String
122 */
123 public String getRequestUri() {
/*
P/P * Method: String getRequestUri()
*
* Preconditions:
* this.request != null
*
* Postconditions:
* return_value != null
*/
124 return request.substring(request.indexOf("/"));
125 }
126
127 /**
128 * Sets the request.
129 *
130 * @param request the HTTP request as a String
131 */
132 public void setRequest(String request) {
/*
P/P * Method: void setRequest(String)
*
* Postconditions:
* this.request == request
* init'ed(this.request)
*/
133 this.request = request;
134 }
135
136 /**
137 * Gets the HTTP status code.
138 *
139 * @return the status code as an int (-1 if not set)
140 */
141 public int getStatusCode() {
/*
P/P * Method: int getStatusCode()
*
* Preconditions:
* init'ed(this.statusCode)
*
* Postconditions:
* return_value == this.statusCode
* init'ed(return_value)
*/
142 return statusCode;
143 }
144
145 /**
146 * Sets the HTTP status code.
147 *
148 * @param statusCode the status code
149 */
150 public void setStatusCode(int statusCode) {
/*
P/P * Method: void setStatusCode(int)
*
* Postconditions:
* this.statusCode == statusCode
* init'ed(this.statusCode)
*/
151 this.statusCode = statusCode;
152 }
153
154 /**
155 * Gets the number of bytes sent.
156 *
157 * @return the number of bytes as a long (-1 if not set)
158 */
159 public long getBytes() {
/*
P/P * Method: long getBytes()
*
* Preconditions:
* init'ed(this.bytes)
*
* Postconditions:
* return_value == this.bytes
* init'ed(return_value)
*/
160 return bytes;
161 }
162
163 /**
164 * Sets the number of bytes sent.
165 *
166 * @param bytes the number of bytes sent
167 */
168 public void setBytes(long bytes) {
/*
P/P * Method: void setBytes(long)
*
* Postconditions:
* this.bytes == bytes
* init'ed(this.bytes)
*/
169 this.bytes = bytes;
170 }
171
172 /**
173 * Gets the referer.
174 *
175 * @return the refering URL as a String
176 */
177 public String getReferer() {
/*
P/P * Method: String getReferer()
*
* Preconditions:
* init'ed(this.referer)
*
* Postconditions:
* return_value == this.referer
* init'ed(return_value)
*/
178 return referer;
179 }
180
181 /**
182 * Sets the referer.
183 *
184 * @param referer the refering URL as a String
185 */
186 public void setReferer(String referer) {
/*
P/P * Method: void setReferer(String)
*
* Postconditions:
* this.referer == referer
* init'ed(this.referer)
*/
187 this.referer = referer;
188 }
189
190 /**
191 * Gets the user agent (e.g. Mozilla, Internet Explorer, Safari, etc).
192 *
193 * @return the user agent as a String
194 */
195 public String getAgent() {
/*
P/P * Method: String getAgent()
*
* Preconditions:
* init'ed(this.agent)
*
* Postconditions:
* return_value == this.agent
* init'ed(return_value)
*/
196 return agent;
197 }
198
199 /**
200 * Sets the user agent.
201 *
202 * @param agent the user agent as a String
203 */
204 public void setAgent(String agent) {
/*
P/P * Method: void setAgent(String)
*
* Postconditions:
* this.agent == agent
* init'ed(this.agent)
*/
205 this.agent = agent;
206 }
207
208 }
SofCheck Inspector Build Version : 2.22510
| logentry.java |
2010-Jun-25 19:40:32 |
| logentry.class |
2010-Jul-19 20:23:38 |