| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  |  | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  |  | 
            
  
    | 19 |  |  | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  |  | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  |  | 
            
  
    | 25 |  |  | 
            
  
    | 26 |  |  | 
            
  
    | 27 |  |  | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
            
  
    | 31 |  |  | 
            
  
    | 32 |  | package net.sourceforge.pebble.web.action; | 
            
  
    | 33 |  |  | 
            
  
    | 34 |  | import net.sourceforge.pebble.Constants; | 
            
  
    | 35 |  | import net.sourceforge.pebble.domain.Blog; | 
            
  
    | 36 |  | import net.sourceforge.pebble.domain.Month; | 
            
  
    | 37 |  | import net.sourceforge.pebble.domain.Day; | 
            
  
    | 38 |  | import net.sourceforge.pebble.logging.Log; | 
            
  
    | 39 |  |  | 
            
  
    | 40 |  | import javax.servlet.ServletException; | 
            
  
    | 41 |  | import javax.servlet.http.HttpServletRequest; | 
            
  
    | 42 |  | import javax.servlet.http.HttpServletResponse; | 
            
  
    | 43 |  | import java.text.SimpleDateFormat; | 
            
  
    | 44 |  | import java.util.Calendar; | 
            
  
    | 45 |  |  | 
            
  
    | 46 |  |  | 
            
  
    | 47 |  |  | 
            
  
    | 48 |  |  | 
            
  
    | 49 |  | @author | 
            
  
    | 50 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 110 (110) | Complexity: 31 | Complexity Density: 0,35 |  | 
  
  
    | 51 |  | public abstract class AbstractLogAction extends SecureAction { | 
            
  
    | 52 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 40 (40) | Complexity: 11 | Complexity Density: 0,31 |  | 
  
  
    | 53 | 0 |  protected Log getLog(HttpServletRequest request, HttpServletResponse response) throws ServletException {... | 
            
  
    | 54 | 0 | Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); | 
            
  
    | 55 |  |  | 
            
  
    | 56 | 0 | String yearAsString = request.getParameter("year"); | 
            
  
    | 57 | 0 | String monthAsString = request.getParameter("month"); | 
            
  
    | 58 | 0 | String dayAsString = request.getParameter("day"); | 
            
  
    | 59 |  |  | 
            
  
    | 60 | 0 | Calendar cal = blog.getCalendar(); | 
            
  
    | 61 | 0 | Log log = null; | 
            
  
    | 62 | 0 | String logPeriod = ""; | 
            
  
    | 63 |  |  | 
            
  
    | 64 | 0 | if (yearAsString != null && yearAsString.length() > 0 && | 
            
  
    | 65 |  | monthAsString != null && monthAsString.length() > 0 && | 
            
  
    | 66 |  | dayAsString != null && dayAsString.length() > 0) { | 
            
  
    | 67 | 0 | int year = Integer.parseInt(yearAsString); | 
            
  
    | 68 | 0 | int month = Integer.parseInt(monthAsString); | 
            
  
    | 69 | 0 | int day = Integer.parseInt(dayAsString); | 
            
  
    | 70 | 0 | cal.set(Calendar.YEAR, year); | 
            
  
    | 71 | 0 | cal.set(Calendar.MONTH, month-1); | 
            
  
    | 72 | 0 | cal.set(Calendar.DAY_OF_MONTH, day); | 
            
  
    | 73 | 0 | log = blog.getLogger().getLog(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH)); | 
            
  
    | 74 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale()); | 
            
  
    | 75 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 76 | 0 | registerObjectsForNavigation(blog, blog.getBlogForDay(year, month, day)); | 
            
  
    | 77 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 78 | 0 | } else if (yearAsString != null && yearAsString.length() > 0 && | 
            
  
    | 79 |  | monthAsString != null && monthAsString.length() > 0) { | 
            
  
    | 80 | 0 | int year = Integer.parseInt(yearAsString); | 
            
  
    | 81 | 0 | int month = Integer.parseInt(monthAsString); | 
            
  
    | 82 | 0 | cal.set(Calendar.YEAR, year); | 
            
  
    | 83 | 0 | cal.set(Calendar.MONTH, month-1); | 
            
  
    | 84 | 0 | log = blog.getLogger().getLog(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1); | 
            
  
    | 85 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", blog.getLocale()); | 
            
  
    | 86 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 87 | 0 | registerObjectsForNavigation(blog, blog.getBlogForMonth(year, month)); | 
            
  
    | 88 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 89 |  | } else { | 
            
  
    | 90 |  |  | 
            
  
    | 91 | 0 | log = blog.getLogger().getLog(); | 
            
  
    | 92 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale()); | 
            
  
    | 93 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 94 | 0 | registerObjectsForNavigation(blog, blog.getBlogForToday()); | 
            
  
    | 95 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 96 |  | } | 
            
  
    | 97 |  |  | 
            
  
    | 98 | 0 | getModel().put("logPeriod", logPeriod); | 
            
  
    | 99 |  |  | 
            
  
    | 100 | 0 | return log; | 
            
  
    | 101 |  | } | 
            
  
    | 102 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 40 (40) | Complexity: 11 | Complexity Density: 0,31 |  | 
  
  
    | 103 | 0 |  protected String getLogFile(HttpServletRequest request, HttpServletResponse response) throws ServletException {... | 
            
  
    | 104 | 0 | Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); | 
            
  
    | 105 |  |  | 
            
  
    | 106 | 0 | String yearAsString = request.getParameter("year"); | 
            
  
    | 107 | 0 | String monthAsString = request.getParameter("month"); | 
            
  
    | 108 | 0 | String dayAsString = request.getParameter("day"); | 
            
  
    | 109 |  |  | 
            
  
    | 110 | 0 | Calendar cal = blog.getCalendar(); | 
            
  
    | 111 | 0 | String log = null; | 
            
  
    | 112 | 0 | String logPeriod = ""; | 
            
  
    | 113 |  |  | 
            
  
    | 114 | 0 | if (yearAsString != null && yearAsString.length() > 0 && | 
            
  
    | 115 |  | monthAsString != null && monthAsString.length() > 0 && | 
            
  
    | 116 |  | dayAsString != null && dayAsString.length() > 0) { | 
            
  
    | 117 | 0 | int year = Integer.parseInt(yearAsString); | 
            
  
    | 118 | 0 | int month = Integer.parseInt(monthAsString); | 
            
  
    | 119 | 0 | int day = Integer.parseInt(dayAsString); | 
            
  
    | 120 | 0 | cal.set(Calendar.YEAR, year); | 
            
  
    | 121 | 0 | cal.set(Calendar.MONTH, month-1); | 
            
  
    | 122 | 0 | cal.set(Calendar.DAY_OF_MONTH, day); | 
            
  
    | 123 | 0 | log = blog.getLogger().getLogFile(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH)); | 
            
  
    | 124 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale()); | 
            
  
    | 125 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 126 | 0 | registerObjectsForNavigation(blog, blog.getBlogForDay(year, month, day)); | 
            
  
    | 127 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 128 | 0 | } else if (yearAsString != null && yearAsString.length() > 0 && | 
            
  
    | 129 |  | monthAsString != null && monthAsString.length() > 0) { | 
            
  
    | 130 | 0 | int year = Integer.parseInt(yearAsString); | 
            
  
    | 131 | 0 | int month = Integer.parseInt(monthAsString); | 
            
  
    | 132 | 0 | cal.set(Calendar.YEAR, year); | 
            
  
    | 133 | 0 | cal.set(Calendar.MONTH, month-1); | 
            
  
    | 134 | 0 | log = blog.getLogger().getLogFile(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1); | 
            
  
    | 135 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", blog.getLocale()); | 
            
  
    | 136 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 137 | 0 | registerObjectsForNavigation(blog, blog.getBlogForMonth(year, month)); | 
            
  
    | 138 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 139 |  | } else { | 
            
  
    | 140 |  |  | 
            
  
    | 141 | 0 | log = blog.getLogger().getLogFile(); | 
            
  
    | 142 | 0 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", blog.getLocale()); | 
            
  
    | 143 | 0 | dateFormat.setTimeZone(blog.getTimeZone()); | 
            
  
    | 144 | 0 | registerObjectsForNavigation(blog, blog.getBlogForToday()); | 
            
  
    | 145 | 0 | logPeriod = dateFormat.format(cal.getTime()); | 
            
  
    | 146 |  | } | 
            
  
    | 147 |  |  | 
            
  
    | 148 | 0 | getModel().put("logPeriod", logPeriod); | 
            
  
    | 149 |  |  | 
            
  
    | 150 | 0 | return log; | 
            
  
    | 151 |  | } | 
            
  
    | 152 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 12 (12) | Complexity: 4 | Complexity Density: 0,5 |  | 
  
  
    | 153 | 0 |  private void registerObjectsForNavigation(Blog blog, Month month) {... | 
            
  
    | 154 | 0 | Month firstMonth = blog.getBlogForFirstMonth(); | 
            
  
    | 155 | 0 | Month previousMonth = month.getPreviousMonth(); | 
            
  
    | 156 | 0 | Month nextMonth = month.getNextMonth(); | 
            
  
    | 157 |  |  | 
            
  
    | 158 | 0 | if (!previousMonth.before(firstMonth)) { | 
            
  
    | 159 | 0 | getModel().put("previousMonth", previousMonth); | 
            
  
    | 160 |  | } | 
            
  
    | 161 |  |  | 
            
  
    | 162 | 0 | if (!nextMonth.getDate().after(blog.getCalendar().getTime()) || nextMonth.before(firstMonth)) { | 
            
  
    | 163 | 0 | getModel().put("nextMonth", nextMonth); | 
            
  
    | 164 |  | } | 
            
  
    | 165 | 0 | getModel().put("displayMode", "logSummaryForMonth"); | 
            
  
    | 166 |  | } | 
            
  
    | 167 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 12 (12) | Complexity: 4 | Complexity Density: 0,5 |  | 
  
  
    | 168 | 0 |  private void registerObjectsForNavigation(Blog blog, Day day) {... | 
            
  
    | 169 | 0 | Day firstDay = blog.getBlogForFirstMonth().getBlogForFirstDay(); | 
            
  
    | 170 | 0 | Day previousDay = day.getPreviousDay(); | 
            
  
    | 171 | 0 | Day nextDay = day.getNextDay(); | 
            
  
    | 172 |  |  | 
            
  
    | 173 | 0 | if (!previousDay.before(firstDay)) { | 
            
  
    | 174 | 0 | getModel().put("previousDay", previousDay); | 
            
  
    | 175 |  | } | 
            
  
    | 176 |  |  | 
            
  
    | 177 | 0 | if (!nextDay.getDate().after(blog.getCalendar().getTime()) || nextDay.before(firstDay)) { | 
            
  
    | 178 | 0 | getModel().put("nextDay", nextDay); | 
            
  
    | 179 |  | } | 
            
  
    | 180 | 0 | getModel().put("displayMode", "logSummaryForDay"); | 
            
  
    | 181 |  | } | 
            
  
    | 182 |  |  | 
            
  
    | 183 |  |  | 
            
  
    | 184 |  |  | 
            
  
    | 185 |  |  | 
            
  
    | 186 |  | @return | 
            
  
    | 187 |  | @param | 
            
  
    | 188 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 189 | 0 |  public String[] getRoles(HttpServletRequest request) {... | 
            
  
    | 190 | 0 | return new String[]{Constants.BLOG_ADMIN_ROLE, Constants.BLOG_OWNER_ROLE, Constants.BLOG_PUBLISHER_ROLE, Constants.BLOG_CONTRIBUTOR_ROLE}; | 
            
  
    | 191 |  | } | 
            
  
    | 192 |  |  | 
            
  
    | 193 |  | } |