Coverage Report - net.sourceforge.pebble.logging.LogEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
LogEntry
89%
25/28
N/A
1
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, 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  
  */
 41  316
 public class LogEntry {
 42  
 
 43  
   /** the host that made the request */
 44  
   private String host;
 45  
 
 46  
   /** the date the request was made */
 47  316
   private Date date = new Date();
 48  
 
 49  
   /** the HTTP request */
 50  316
   private String request = "";
 51  
 
 52  
   /** the HTTP status code returned */
 53  316
   private int statusCode = 200;
 54  
 
 55  
   /** the number of bytes returned */
 56  316
   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() {
 70  80
     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) {
 79  24
     this.host = host;
 80  24
   }
 81  
 
 82  
   /**
 83  
    * Gets the date.
 84  
    *
 85  
    * @return  a Date
 86  
    */
 87  
   public Date getDate() {
 88  100
     return date;
 89  
   }
 90  
 
 91  
   /**
 92  
    * Sets the date.
 93  
    *
 94  
    * @param date    a Date instance
 95  
    */
 96  
   public void setDate(Date date) {
 97  36
     this.date = date;
 98  36
   }
 99  
 
 100  
   /**
 101  
    * Gets the request.
 102  
    *
 103  
    * @return  the request as a String
 104  
    */
 105  
   public String getRequest() {
 106  68
     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() {
 115  4
     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() {
 124  4
     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) {
 133  44
     this.request = request;
 134  44
   }
 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() {
 142  64
     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) {
 151  36
     this.statusCode = statusCode;
 152  36
   }
 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() {
 160  0
     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) {
 169  0
     this.bytes = bytes;
 170  0
   }
 171  
 
 172  
   /**
 173  
    * Gets the referer.
 174  
    *
 175  
    * @return  the refering URL as a String
 176  
    */
 177  
   public String getReferer() {
 178  80
     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) {
 187  24
     this.referer = referer;
 188  24
   }
 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() {
 196  80
     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) {
 205  24
     this.agent = agent;
 206  24
   }
 207  
 
 208  
 }