Package net.sourceforge.pebble.domain

Examples of net.sourceforge.pebble.domain.Day


  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;");
          }
        }
View Full Code Here


   * @param o2  object 2
   * @return  -n, 0 or +n if the date represented by the second day is less than,
   *          the same as or greater than the first, respectively
   */
  public int compare(Object o1, Object o2) {
    Day b1 = (Day)o1;
    Day b2 = (Day)o2;

    return b2.getDate().compareTo(b1.getDate());
  }
View Full Code Here

        if (month != null) {
          setName("Month : " + formatter.format(month.getDate()));
          setPageView(true);
        }
      } else if (permalinkProvider.isDayPermalink(url)) {
        Day day = null;
        day = permalinkProvider.getDay(url);
        SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy", blog
            .getLocale());
        formatter.setTimeZone(blog.getTimeZone());
        if (day != null) {
          setName("Day : " + formatter.format(day.getDate()));
          setPageView(true);
        }
      }
    } catch (IllegalArgumentException e) {
      setName("Error: " + url);
View Full Code Here

    }
    getModel().put("displayMode", "logSummaryForMonth");
  }

  private void registerObjectsForNavigation(Blog blog, Day day) {
    Day firstDay = blog.getBlogForFirstMonth().getBlogForFirstDay();
    Day previousDay = day.getPreviousDay();
    Day nextDay = day.getNextDay();

    if (!previousDay.before(firstDay)) {
      getModel().put("previousDay", previousDay);
    }

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

   *
   * @return the title as a String
   */
  public String getTitle() {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    Day daily = (Day)getModel().get(Constants.DAILY_BLOG);
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, blog.getLocale());
    dateFormat.setTimeZone(blog.getTimeZone());
    return dateFormat.format(daily.getDate());

  }
View Full Code Here

*/
public class DayComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    DayComparator comp = new DayComparator();
    Day d1 = blog.getBlogForDay(2003, 04, 01);
    Day d2 = blog.getBlogForDay(2003, 04, 01);
    assertTrue(comp.compare(d1, d2) == 0);
    assertTrue(comp.compare(d2, d1) == 0);

    d2 = blog.getBlogForDay(2003, 03, 31);
    assertTrue(comp.compare(d1, d2) < 0);
View Full Code Here

  /**
   * Tests that a day permalink can be generated.
   */
  public void testGetPermalinkForDay() {
    Day day = blog.getBlogForDay(2004, 07, 14);
    assertEquals("/2004/07/14", permalinkProvider.getPermalink(day));
  }
View Full Code Here

*/
public class BlogEntryComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    BlogEntryComparator comp = new BlogEntryComparator();
    Day day = blog.getBlogForDay(2003, 04, 01);

    Calendar cal1 = blog.getCalendar();
    cal1.set(Calendar.HOUR_OF_DAY, 9);
    Calendar cal2 = blog.getCalendar();
    cal2.set(Calendar.HOUR_OF_DAY, 10);
View Full Code Here

   *
   * @param blogEntries   a List of BlogEntry instances
   */
  public synchronized void index(Collection<BlogEntry> blogEntries) {
    for (BlogEntry blogEntry : blogEntries) {
      Day day = blog.getBlogForDay(blogEntry.getDate());
      if (blogEntry.isPublished()) {
        publishedIndexEntries.add(blogEntry.getId());
        day.addPublishedBlogEntry(blogEntry.getId());
      } else {
        unpublishedIndexEntries.add(blogEntry.getId());
        day.addUnpublishedBlogEntry(blogEntry.getId());
      }
      indexEntries.add(blogEntry.getId());
    }

    Collections.sort(indexEntries, new ReverseBlogEntryIdComparator());
View Full Code Here

   * Indexes a single blog entry.
   *
   * @param blogEntry   a BlogEntry instance
   */
  public synchronized void index(BlogEntry blogEntry) {
    Day day = blog.getBlogForDay(blogEntry.getDate());
    if (blogEntry.isPublished()) {
      publishedIndexEntries.add(blogEntry.getId());
      day.addPublishedBlogEntry(blogEntry.getId());
      writeIndex(true);
    } else {
      unpublishedIndexEntries.add(blogEntry.getId());
      day.addUnpublishedBlogEntry(blogEntry.getId());
      writeIndex(false);
    }
    indexEntries.add(blogEntry.getId());

    Collections.sort(indexEntries, new ReverseBlogEntryIdComparator());
View Full Code Here

TOP

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

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.