|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This report was generated with an evaluation server license. Purchase Clover or configure your license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CombinedFormatLogEntryFormat | Line # 44 | 82 | 0% | 18 | 6 | 94,5% |
0.94495416
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(34) | |||
Result | |||
0.7614679
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRefererSpecified
![]() |
1 PASS | |
0.7614679
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRefererSpecified
![]() |
1 PASS | |
0.7614679
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenAgentSpecified
![]() |
1 PASS | |
0.7614679
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenAgentSpecified
![]() |
1 PASS | |
0.7522936
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenHostSpecified
![]() |
1 PASS | |
0.7522936
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenHostSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenAgentNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRefererNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenHostNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRefererNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRequestSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenHostNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenRequestSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testDateIsCorrectlyParsed
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testParseWhenAgentNotSpecified
![]() |
1 PASS | |
0.74311924
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testDateIsCorrectlyParsed
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenAgentNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRequestSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenHostNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenAgentSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRefererNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRefererNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRequestSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenAgentSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenHostNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenHostSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenHostSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRefererSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenAgentNotSpecified
![]() |
1 PASS | |
0.23853211
|
net.sourceforge.pebble.logging.CombinedFormatLogEntryFormatTest.testFormatWhenRefererSpecified
![]() |
1 PASS | |
0.018348623
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStopped
![]() |
1 PASS | |
0.018348623
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStopped
![]() |
1 PASS | |
0.018348623
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStarted
![]() |
1 PASS | |
0.018348623
|
net.sourceforge.pebble.domain.BlogTest.testListenersFiredWhenBlogStarted
![]() |
1 PASS | |
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 net.sourceforge.pebble.domain.Blog; | |
35 | ||
36 | import java.text.ParseException; | |
37 | import java.text.SimpleDateFormat; | |
38 | ||
39 | /** | |
40 | * Represents a log entry in the combined log file format. | |
41 | * | |
42 | * @author Simon Brown | |
43 | */ | |
44 | public class CombinedFormatLogEntryFormat { | |
45 | ||
46 | /** the format used for dates */ | |
47 | SimpleDateFormat dateFormatter = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]"); | |
48 | ||
49 | /** | |
50 | * Default, no args constructor. | |
51 | */ | |
52 | 1352 |
![]() |
53 | 1352 | dateFormatter.setTimeZone(blog.getTimeZone()); |
54 | } | |
55 | ||
56 | /** | |
57 | * Formats a given entry into the combined log file format. | |
58 | * | |
59 | * @param entry a log entry | |
60 | * @return a formatted String | |
61 | */ | |
62 | 30 |
![]() |
63 | 30 | StringBuffer buf = new StringBuffer(); |
64 | 30 | if (entry.getHost() != null) { |
65 | 4 | buf.append(entry.getHost()); |
66 | } else { | |
67 | 26 | buf.append("-"); |
68 | } | |
69 | 30 | buf.append(" "); |
70 | 30 | buf.append("-"); |
71 | 30 | buf.append(" "); |
72 | 30 | buf.append("-"); |
73 | 30 | buf.append(" "); |
74 | 30 | buf.append(dateFormatter.format(entry.getDate())); |
75 | 30 | buf.append(" "); |
76 | 30 | buf.append("\"" + entry.getRequest() + "\""); |
77 | 30 | buf.append(" "); |
78 | 30 | buf.append(entry.getStatusCode()); |
79 | 30 | buf.append(" "); |
80 | 30 | buf.append("-"); |
81 | 30 | buf.append(" "); |
82 | 30 | if (entry.getReferer() != null) { |
83 | 4 | buf.append("\"" + entry.getReferer() + "\""); |
84 | } else { | |
85 | 26 | buf.append("-"); |
86 | } | |
87 | 30 | buf.append(" "); |
88 | 30 | if (entry.getAgent() != null) { |
89 | 4 | buf.append("\"" + entry.getAgent() + "\""); |
90 | } else { | |
91 | 26 | buf.append("-"); |
92 | } | |
93 | ||
94 | 30 | return buf.toString(); |
95 | } | |
96 | ||
97 | /** | |
98 | * Parses a string in the combined log file format into a log entry. | |
99 | * | |
100 | * @param s the String to parse | |
101 | * @return a LogEntry instance | |
102 | */ | |
103 | 16 |
![]() |
104 | 16 | LogEntry logEntry = new LogEntry(); |
105 | ||
106 | // there are 9 tokens in the combined log file format | |
107 | 16 | int start = 0; |
108 | 16 | int end = s.indexOf(" ", start); |
109 | 16 | String host = s.substring(start, end); |
110 | 16 | start = end + 1; |
111 | 16 | end = s.indexOf(" ", start); |
112 | 16 | String rfc931 = s.substring(start, end); |
113 | 16 | start = end + 1; |
114 | 16 | end = s.indexOf(" ", start); |
115 | 16 | String authuser = s.substring(start, end); |
116 | 16 | start = end + 1; |
117 | 16 | end = s.indexOf("]", start); |
118 | 16 | String date = s.substring(start, end+1); |
119 | 16 | start = end + 2; |
120 | 16 | end = s.indexOf("\"", start+1); |
121 | 16 | String request = s.substring(start+1, end); |
122 | 16 | start = end + 2; |
123 | 16 | end = s.indexOf(" ", start); |
124 | 16 | String statusCode = s.substring(start, end); |
125 | 16 | start = end + 1; |
126 | 16 | end = s.indexOf(" ", start); |
127 | 16 | String bytes = s.substring(start, end); |
128 | 16 | start = end + 1; |
129 | 16 | String referer; |
130 | 16 | if (s.charAt(start) == '-') { |
131 | 14 | referer = "-"; |
132 | 14 | start = start + 2; |
133 | } else { | |
134 | 2 | end = s.indexOf("\"", start+1); |
135 | 2 | referer = s.substring(start+1, end); |
136 | 2 | start = end + 2; |
137 | } | |
138 | 16 | end = s.length(); |
139 | 16 | String agent; |
140 | 16 | if (s.charAt(start) == '-') { |
141 | 14 | agent = "-"; |
142 | 14 | start = start + 2; |
143 | } else { | |
144 | 2 | end = s.indexOf("\"", start+1); |
145 | 2 | agent = s.substring(start+1, end); |
146 | 2 | start = end + 2; |
147 | } | |
148 | ||
149 | 16 | if (!host.equals("-")) { |
150 | 2 | logEntry.setHost(host); |
151 | } | |
152 | ||
153 | 16 | if (!rfc931.equals("-")) { |
154 | //logEntry.setHost(host); | |
155 | } | |
156 | ||
157 | 16 | if (!authuser.equals("-")) { |
158 | //logEntry.setUser(authuser); | |
159 | } | |
160 | ||
161 | 16 | try { |
162 | 16 | logEntry.setDate(dateFormatter.parse(date)); |
163 | } catch (ParseException e) { | |
164 | // ignore | |
165 | } | |
166 | ||
167 | 16 | logEntry.setRequest(request); |
168 | ||
169 | 16 | if (!statusCode.equals("-")) { |
170 | 16 | try { |
171 | 16 | logEntry.setStatusCode(Integer.parseInt(statusCode)); |
172 | } catch (NumberFormatException e) { | |
173 | // ignore | |
174 | } | |
175 | } | |
176 | ||
177 | 16 | if (!bytes.equals("-")) { |
178 | 0 | try { |
179 | 0 | logEntry.setBytes(Long.parseLong(bytes)); |
180 | } catch (NumberFormatException e) { | |
181 | // ignore | |
182 | } | |
183 | } | |
184 | ||
185 | 16 | if (!referer.equals("-")) { |
186 | 2 | logEntry.setReferer(referer); |
187 | } | |
188 | ||
189 | 16 | if (!agent.equals("-")) { |
190 | 2 | logEntry.setAgent(agent); |
191 | } | |
192 | ||
193 | 16 | return logEntry; |
194 | } | |
195 | ||
196 | } | |
197 | ||
198 |
|