File Source: abstractlogger.java

         /* 
    P/P   *  Method: net.sourceforge.pebble.logging.AbstractLogger__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 net.sourceforge.pebble.domain.Blog;
    35  
         /* 
    P/P   *  Method: void net.sourceforge.pebble.logging.AbstractLogger(Blog)
          * 
          *  Postconditions:
          *    this.blog == blog
          *    init'ed(this.blog)
          */
    36  import javax.servlet.http.HttpServletRequest;
    37  import java.util.*;
    38  
    39  /**
    40   * Interface that all loggers implement.
    41   *
    42   * @author    Simon Brown
    43   */
    44  public abstract class AbstractLogger {
    45  
    46    /** the blog that this instance is associated with, and logging for */
    47    protected Blog blog;
    48  
    49    /**
    50     * Creates a new log associated with the given blog.
    51     *
    52     * @param blog    a Blog instance
    53     */
    54    public AbstractLogger(Blog blog) {
    55      this.blog = blog;
    56    }
    57  
    58    /**
    59     * Logs a HTTP request.
    60     *
    61     * @param request   a HttpServletRequest
    62     */
    63    public abstract void log(HttpServletRequest request, int status);
    64  
    65    /**
    66     * Called to start this logger.
    67     */
    68    public abstract void start();
    69  
    70    /**
    71     * Called to stop this logger.
    72     */
    73    public abstract void stop();
    74  
    75    /**
    76     * Gets a copy of the log file for a given year, month and day.
    77     *
    78     * @param year    the year to get entries for
    79     * @param month   the month to get entries for
    80     * @param day     the day to get entries for
    81     * @return    a String containing the contents of the requested log file
    82     */
    83    public abstract String getLogFile(int year, int month, int day);
    84  
    85    /**
    86     * Gets a copy of the log file for today.
    87     *
    88     * @return    a String containing the contents of the requested log file
    89     */
           /* 
    P/P     *  Method: String getLogFile()
            * 
            *  Preconditions:
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:get(...)@92 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@91 != null
            * 
            *  Postconditions:
            *    return_value != null
            */
    90    public String getLogFile() {
    91      Calendar cal = blog.getCalendar();
    92      return getLogFile(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
    93    }
    94  
    95    /**
    96     * Gets a copy of the log file for a given year and month.
    97     *
    98     * @param year    the year to get entries for
    99     * @param month   the month to get entries for
   100     * @return    a String containing the contents of the requested log file
   101     */
           /* 
    P/P     *  Method: String getLogFile(int, int)
            * 
            *  Preconditions:
            *    month >= -231+1
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:getActualMaximum(...)@107 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@104 != null
            * 
            *  Postconditions:
            *    return_value != null
            */
   102    public String getLogFile(int year, int month) {
   103      StringBuffer buf = new StringBuffer();
   104      Calendar cal = blog.getCalendar();
   105      cal.set(Calendar.YEAR, year);
   106      cal.set(Calendar.MONTH, month-1);
   107      for (int day = 1; day <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); day++) {
   108        buf.append(getLogFile(year, month, day));
   109      }
   110  
   111      return buf.toString();
   112    }
   113  
   114    /**
   115     * Gets the log for a given year, month and day.
   116     *
   117     * @param year    the year to get entries for
   118     * @param month   the month to get entries for
   119     * @param day     the day to get entries for
   120     * @return    a Log object
   121     */
   122    public abstract Log getLog(int year, int month, int day);
   123  
   124    /**
   125     * Gets the log for today.
   126     *
   127     * @return    a Log object
   128     */
           /* 
    P/P     *  Method: Log getLog()
            * 
            *  Preconditions:
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:get(...)@131 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@130 != null
            * 
            *  Postconditions:
            *    return_value != null
            *    new ArrayList(Log#1) num objects == 0
            *    new ArrayList(getLog#1*) num objects <= 1
            *    new ArrayList(getLog#2*) num objects <= 1
            *    new Log(getLog#1*) num objects <= 1
            *    new Log(getLog#1*).blog == this.blog
            *    new Log(getLog#1*).blog != null
            *    new Log(getLog#1*).logEntries != null
            *    new Log(getLog#6*) num objects <= 1
            *    new Log(getLog#6*).blog == this.blog
            *    ...
            */
   129    public Log getLog() {
   130      Calendar cal = blog.getCalendar();
   131      return getLog(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
   132    }
   133  
   134    /**
   135     * Gets the log for a given year and month.
   136     *
   137     * @param year    the year to get entries for
   138     * @param month   the month to get entries for
   139     * @return    a Log object
   140     */
           /* 
    P/P     *  Method: Log getLog(int, int)
            * 
            *  Preconditions:
            *    month >= -231+1
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:getActualMaximum(...)@146 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@143 != null
            * 
            *  Postconditions:
            *    return_value == &new Log(getLog#2)
            *    init'ed(new ArrayList(Log#1) num objects)
            *    new HashSet(getLog#1) num objects == 1
            *    new Log(getLog#2) num objects == 1
            *    return_value.blog == this.blog
            *    return_value.blog != null
            *    return_value.logEntries == &new HashSet(getLog#1)
            */
   141    public Log getLog(int year, int month) {
   142      Collection logEntries = new HashSet();
   143      Calendar cal = blog.getCalendar();
   144      cal.set(Calendar.YEAR, year);
   145      cal.set(Calendar.MONTH, month-1);
   146      for (int day = 1; day <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); day++) {
   147        logEntries.addAll(getLog(year, month, day).getLogEntries());
   148      }
   149  
   150      return new Log(blog, logEntries);
   151    }
   152  
   153    /**
   154     * Gets the log summary information for the given year, month and day.
   155     *
   156     * @param year    the year to get entries for
   157     * @param month   the month to get entries for
   158     * @param day     the day to get entries for
   159     * @return    a LogSummary object
   160     */
   161    public abstract LogSummary getLogSummary(int year, int month, int day);
   162  
   163    /**
   164     * Gets the log summary for today.
   165     *
   166     * @return    a LogSummary object
   167     */
           /* 
    P/P     *  Method: LogSummary getLogSummary()
            * 
            *  Preconditions:
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:get(...)@170 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@169 != null
            * 
            *  Postconditions:
            *    return_value != null
            *    new LogSummaryItem(getLogSummary#1*) num objects <= 1
            *    new LogSummaryItem(getLogSummary#1*).blog == this.blog
            *    new LogSummaryItem(getLogSummary#1*).blog != null
            *    init'ed(new LogSummaryItem(getLogSummary#1*).date)
            *    new LogSummaryItem(getLogSummary#1*).totalRequests == 0
            *    new LogSummaryItem(getLogSummary#4*) num objects <= 1
            *    new LogSummaryItem(getLogSummary#4*).blog == this.blog
            *    new LogSummaryItem(getLogSummary#4*).blog != null
            *    init'ed(new LogSummaryItem(getLogSummary#4*).date)
            *    ...
            */
   168    public LogSummary getLogSummary() {
   169      Calendar cal = blog.getCalendar();
   170      return getLogSummary(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH));
   171    }
   172  
   173    /**
   174     * Gets the log summary information for the given year and month.
   175     *
   176     * @param year  the year to get entries for
   177     * @param month the month to get entries for
   178     * @return a LogSummary object
   179     */
           /* 
    P/P     *  Method: LogSummary getLogSummary(int, int)
            * 
            *  Preconditions:
            *    month >= -231+1
            *    this.blog != null
            * 
            *  Presumptions:
            *    java.util.Calendar:getActualMaximum(...)@187 <= 232-2
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@181 != null
            * 
            *  Postconditions:
            *    return_value == &new LogSummaryContainer(getLogSummary#2)
            *    new ArrayList(getLogSummary#1) num objects == 1
            *    new LogSummaryContainer(getLogSummary#2) num objects == 1
            *    return_value.blog == this.blog
            *    return_value.blog != null
            *    init'ed(return_value.date)
            *    return_value.logSummaries == &new ArrayList(getLogSummary#1)
            */
   180    public LogSummary getLogSummary(int year, int month) {
   181      Calendar cal = blog.getCalendar();
   182      cal.set(Calendar.YEAR, year);
   183      cal.set(Calendar.DAY_OF_MONTH, 1);
   184      cal.set(Calendar.MONTH, month-1);
   185  
   186      List logSummaries = new ArrayList();
   187      for (int day = 1; day <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); day++) {
   188        logSummaries.add(getLogSummary(year, month, day));
   189      }
   190  
   191      return new LogSummaryContainer(blog, cal.getTime(), logSummaries);
   192    }
   193  
   194    /**
   195     * Gets the log summary information for the given year.
   196     *
   197     * @param year  the year to get entries for
   198     * @return a LogSummary object
   199     */
           /* 
    P/P     *  Method: LogSummary getLogSummary(int)
            * 
            *  Preconditions:
            *    this.blog != null
            * 
            *  Presumptions:
            *    net.sourceforge.pebble.domain.Blog:getCalendar(...)@201 != null
            * 
            *  Postconditions:
            *    return_value == &new LogSummaryContainer(getLogSummary#2)
            *    new ArrayList(getLogSummary#1) num objects == 1
            *    new LogSummaryContainer(getLogSummary#2) num objects == 1
            *    return_value.blog == this.blog
            *    return_value.blog != null
            *    init'ed(return_value.date)
            *    return_value.logSummaries == &new ArrayList(getLogSummary#1)
            */
   200    public LogSummary getLogSummary(int year) {
   201      Calendar cal = blog.getCalendar();
   202      cal.set(Calendar.YEAR, year);
   203  
   204      List logSummaries = new ArrayList();
   205      for (int month = 1; month <= 12; month++) {
   206        logSummaries.add(getLogSummary(year, month));
   207      }
   208  
   209      return new LogSummaryContainer(blog, cal.getTime(), logSummaries);
   210    }
   211  
   212  }








SofCheck Inspector Build Version : 2.22510
abstractlogger.java 2010-Jun-25 19:40:32
abstractlogger.class 2010-Jul-19 20:23:38