Package net.sourceforge.pebble.domain

Examples of net.sourceforge.pebble.domain.Month


   */
  public int doStartTag() throws JspException {

    HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
    Blog blog = (Blog)request.getAttribute(Constants.BLOG_KEY);
    Month month = (Month)request.getAttribute(Constants.MONTHLY_BLOG);
    Day today = blog.getBlogForToday();
    Calendar now = blog.getCalendar();

    if (month == null) {
      month = today.getMonth();
    }

    Calendar firstDayOfMonth = blog.getCalendar();
    firstDayOfMonth.setTime(month.getBlogForDay(1).getDate());

    SimpleDateFormat monthAndYearFormatter = new SimpleDateFormat("MMMM yyyy", blog.getLocale());
    monthAndYearFormatter.setTimeZone(blog.getTimeZone());
    SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM", blog.getLocale());
    monthFormatter.setTimeZone(blog.getTimeZone());
    NumberFormat numberFormatter = NumberFormat.getIntegerInstance(blog.getLocale());

    Month firstMonth = blog.getBlogForFirstMonth();

    try {
      JspWriter out = pageContext.getOut();

      out.write("<div class=\"calendar\">");
      out.write("<table width=\"100%\">");
      out.write("<tr>");
      out.write("<td colspan=\"7\" align=\"center\">");
      if (month.before(firstMonth)) {
        out.write("<b>");
        out.write(monthAndYearFormatter.format(month.getDate()));
        out.write("</b>");
      } else {
        out.write("<b><a href=\"");
        out.write(UrlRewriter.doRewrite(month.getPermalink()));
        out.write("\">");
        out.write(monthAndYearFormatter.format(month.getDate()));
        out.write("</a></b>");
      }
      out.write("</td>");
      out.write("</tr>");

      int firstDayOfWeek = now.getFirstDayOfWeek();

      // write out the calendar header
      DateFormatSymbols symbols = new DateFormatSymbols(blog.getLocale());
      String[] days = symbols.getShortWeekdays();
      out.write("<tr>");
      for (int i = firstDayOfWeek; i <= 7; i++) {
        out.write("<td class=\"calendarDayHeader\" width=\"14%\">" + days[i] + "</td>");
      }
      for (int i = 1; i < firstDayOfWeek; i++) {
        out.write("<td class=\"calendarDayHeader\">" + days[i] + "</td>");
      }
      out.write("</tr>");

      // write out the body of the calendar
      Iterator it = getDatesForCompleteWeeks(blog, month).iterator();
      Calendar cal;
      int count = 0;
      while (it.hasNext()) {
        cal = (Calendar)it.next();
        Day daily = blog.getBlogForDay(cal.getTime());

        String formattedNumber = numberFormatter.format(cal.get(Calendar.DAY_OF_MONTH));
        if (formattedNumber.length() == 1) {
          formattedNumber = "&nbsp;" + formattedNumber;
        }

        if (count % 7 == 0) {
          out.write("<tr>");
        }

        // output padding if the date to display isn't in the month
        if (cal.get(Calendar.MONTH) != firstDayOfMonth.get(Calendar.MONTH)) {
          out.write("<td class=\"calendarDay\">&nbsp;");
        } else if (now.get(Calendar.YEAR) == cal.get(Calendar.YEAR) &&
          now.get(Calendar.MONTH) == cal.get(Calendar.MONTH) &&
          now.get(Calendar.DAY_OF_MONTH) == cal.get(Calendar.DAY_OF_MONTH)) {
          out.write("<td class=\"calendarToday\">");
          if (daily.hasBlogEntries()) {
            out.write("&nbsp;<a href=\"" + UrlRewriter.doRewrite(daily.getPermalink()) + "\">" + formattedNumber + "</a>&nbsp;");
          } else {
            out.write("&nbsp;" + formattedNumber + "&nbsp;");
          }
        } else {
          if (daily.hasBlogEntries()) {
            out.write("<td class=\"calendarDayWithEntries\">");
            out.write("&nbsp;<a href=\"" + UrlRewriter.doRewrite(daily.getPermalink()) + "\">" + formattedNumber + "</a>&nbsp;");
          } else {
            out.write("<td class=\"calendarDay\">");
            out.write("&nbsp;" + formattedNumber + "&nbsp;");
          }
        }
        out.write("</td>");

        if (count % 7 == 6) {
          out.write("</tr>");
        }

        count++;
      }

      // write out the footer of the calendar
      Month previous = month.getPreviousMonth();
      Month next = month.getNextMonth();

      out.write("<tr>");
      out.write("<td colspan=\"7\" align=\"center\">");

      // only display the previous month link if there are blog entries
      if (previous.before(firstMonth)) {
        out.write(monthFormatter.format(previous.getDate()));
      } else {
        out.write("<a href=\"" + UrlRewriter.doRewrite(previous.getPermalink()) + "\">" + monthFormatter.format(previous.getDate()) + "</a>");
      }

      String todayText = I18n.getMessage(blog, "common.today");
      out.write("&nbsp; | &nbsp;");
      out.write("<a href=\"" + UrlRewriter.doRewrite(today.getPermalink()) + "\">" + todayText + "</a>");
      out.write("&nbsp; | &nbsp;");

      // only display the next month date if it's not in the future
      if (next.getDate().after(now.getTime()) || next.before(firstMonth)) {
        out.write(monthFormatter.format(next.getDate()));
      } else {
        out.write("<a href=\"" + UrlRewriter.doRewrite(next.getPermalink()) + "\">" + monthFormatter.format(next.getDate()) + "</a>");
      }
      out.write("</td>");
      out.write("</tr>");

      out.write("</table>");
View Full Code Here


        if (blogEntry != null) {
          setName("Blog Entry : " + blogEntry.getTitle());
          setPageView(true);
        }
      } else if (permalinkProvider.isMonthPermalink(url)) {
        Month month = permalinkProvider.getMonth(url);
        SimpleDateFormat formatter = new SimpleDateFormat("MMMM yyyy", blog
            .getLocale());
        formatter.setTimeZone(blog.getTimeZone());
        if (month != null) {
          setName("Month : " + formatter.format(month.getDate()));
          setPageView(true);
        }
      } else if (permalinkProvider.isDayPermalink(url)) {
        Day day = null;
        day = permalinkProvider.getDay(url);
View Full Code Here

    return log;
  }

  private void registerObjectsForNavigation(Blog blog, Month month) {
    Month firstMonth = blog.getBlogForFirstMonth();
    Month previousMonth = month.getPreviousMonth();
    Month nextMonth = month.getNextMonth();

    if (!previousMonth.before(firstMonth)) {
      getModel().put("previousMonth", previousMonth);
    }

    if (!nextMonth.getDate().after(blog.getCalendar().getTime()) || nextMonth.before(firstMonth)) {
      getModel().put("nextMonth", nextMonth);
    }
    getModel().put("displayMode", "logSummaryForMonth");
  }
View Full Code Here

  /**
   * Tests that a monthly blog permalink can be generated.
   */
  public void testGetPermalinkForMonth() {
    Month month = blog.getBlogForMonth(2004, 01);
    assertEquals("/2004/01", permalinkProvider.getPermalink(month));
  }
View Full Code Here

    return view;
  }

  private void registerObjectsForNavigation(Blog blog, Month month) {
    Month firstMonth = blog.getBlogForFirstMonth();
    Month previousMonth = month.getPreviousMonth();
    Month nextMonth = month.getNextMonth();

    if (!previousMonth.before(firstMonth)) {
      getModel().put("previousMonth", previousMonth);
    }

    if (!nextMonth.getDate().after(blog.getCalendar().getTime()) || nextMonth.before(firstMonth)) {
      getModel().put("nextMonth", nextMonth);
    }
    getModel().put("displayMode", "logSummaryForMonth");
  }
View Full Code Here

   *
   * @return the title as a String
   */
  public String getTitle() {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    Month month = (Month)getModel().get(Constants.MONTHLY_BLOG);
    SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy", blog.getLocale());
    sdf.setTimeZone(blog.getTimeZone());
    return sdf.format(month.getDate());
  }
View Full Code Here

  /**
   * Tests that a monthly blog permalink can be generated.
   */
  public void testGetPermalinkForMonth() {
    Month month = blog.getBlogForMonth(2004, 01);
    assertEquals("/2004/01.html", permalinkProvider.getPermalink(month));
  }
View Full Code Here

  /**
   * Tests thet the correct monthly blog can be found from a permalink.
   */
  public void testGetMonth() {
    Month month = permalinkProvider.getMonth("/2004/07.html");
    assertEquals(2004, month.getYear().getYear());
    assertEquals(7, month.getMonth());
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.domain.Month

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.