@RequestMapping(value = "/view-news.jsp", method = RequestMethod.GET)
  public ModelAndView showNews(
      @RequestParam(value = "month", required = false) Integer month,
      @RequestParam(value = "year", required = false) Integer year,
      @RequestParam(value = "section", required = false) Integer sectionid,
      @RequestParam(value = "group", required = false) Integer groupid,
      @RequestParam(value = "tag", required = false) String tag,
      @RequestParam(value = "offset", required = false) Integer offset,
      HttpServletResponse response)
      throws Exception {
    Connection db = null;

    Map<String, Object> params = new HashMap<String, Object>();

    try {
      if (month == null) {
        response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000);
        response.setDateHeader("Last-Modified", System.currentTimeMillis());
      } else {
        long expires = System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L;

        if (year == null) {
          throw new ServletParameterMissingException("year");
        }

        params.put("year", year);
        params.put("month", month);

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1);
        calendar.add(Calendar.MONTH, 1);

        long lastmod = calendar.getTimeInMillis();

        if (lastmod < System.currentTimeMillis()) {
          response.setDateHeader("Expires", expires);
          response.setDateHeader("Last-Modified", lastmod);
        } else {
          response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000);
          response.setDateHeader("Last-Modified", System.currentTimeMillis());
        }
      }

      db = LorDataSource.getConnection();

      Section section = null;

      if (sectionid != null) {
        section = new Section(db, sectionid);

        params.put("section", section);
      }

      Group group = null;

      if (groupid != null) {
        group = new Group(db, groupid);

        if (group.getSectionId() != sectionid) {
          throw new ScriptErrorException(
              "группа #" + groupid + " не принадлежит разделу #" + sectionid);
        }

        params.put("group", group);
      }

      if (tag != null) {
        Tags.checkTag(tag);
        params.put("tag", tag);
      }

      if (section == null && tag == null) {
        throw new ServletParameterException("section or tag required");
      }

      String navtitle;
      if (section != null) {
        navtitle = section.getName();
      } else {
        navtitle = tag;
      }

      if (group != null) {
        navtitle =
            "<a href=\"view-news.jsp?section="
                + section.getId()
                + "\">"
                + section.getName()
                + "</a> - "
                + group.getTitle();
      }

      String ptitle;

      if (month == null) {
        if (section != null) {
          ptitle = section.getName();
          if (group != null) {
            ptitle += " - " + group.getTitle();
          }

          if (tag != null) {
            ptitle += " - " + tag;
          }
        } else {
          ptitle = tag;
        }
      } else {
        ptitle = "Архив: " + section.getName();

        if (group != null) {
          ptitle += " - " + group.getTitle();
        }

        if (tag != null) {
          ptitle += " - " + tag;
        }

        ptitle += ", " + year + ", " + DateUtil.getMonth(month);
        navtitle += " - Архив " + year + ", " + DateUtil.getMonth(month);
      }

      params.put("ptitle", ptitle);
      params.put("navtitle", navtitle);

      NewsViewer newsViewer = new NewsViewer();

      if (section != null) {
        newsViewer.addSection(sectionid);
      }

      if (group != null) {
        newsViewer.setGroup(group.getId());
      }

      if (tag != null) {
        newsViewer.setTag(tag);
      }

      offset = fixOffset(offset);

      if (month != null) {
        newsViewer.setDatelimit(
            "postdate>='"
                + year
                + '-'
                + month
                + "-01'::timestamp AND (postdate<'"
                + year
                + '-'
                + month
                + "-01'::timestamp+'1 month'::interval)");
      } else if (tag == null) {
        if (section.isPremoderated()) {
          newsViewer.setDatelimit("(commitdate>(CURRENT_TIMESTAMP-'6 month'::interval))");
        } else {
          newsViewer.setDatelimit("(postdate>(CURRENT_TIMESTAMP-'6 month'::interval))");
        }

        newsViewer.setLimit("LIMIT 20" + (offset > 0 ? (" OFFSET " + offset) : ""));
      } else {
        newsViewer.setLimit("LIMIT 20" + (offset > 0 ? (" OFFSET " + offset) : ""));
      }

      params.put("messages", newsViewer.getMessagesCached(db));

      params.put("offsetNavigation", month == null);
      params.put("offset", offset);

      if (section != null) {
        String rssLink = "section-rss.jsp?section=" + section.getId();
        if (group != null) {
          rssLink += "&group=" + group.getId();
        }

        params.put("rssLink", rssLink);
      }

      return new ModelAndView("view-news", params);
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }
示例#2
0
  private void process(final Resource resource, final Path classpath, final File root) {
    log("Preparing javadoc for output to: " + root);

    final Javadoc javadoc = (Javadoc) getProject().createTask(JAVADOC_TASK_NAME);
    javadoc.setTaskName(getTaskName());
    javadoc.init();
    javadoc.setDestdir(root);
    javadoc.setUse(true);
    javadoc.createClasspath().add(classpath);

    String excludes = getPackageExcludes();
    if (null != excludes) {
      javadoc.setExcludePackageNames(excludes);
    }

    Javadoc.PackageName[] excludesList = m_excludes.toArray(new Javadoc.PackageName[0]);
    for (Javadoc.PackageName exclude : excludesList) {
      javadoc.addExcludePackage(exclude);
    }

    final Path source = javadoc.createSourcepath();
    addSourcePath(resource, javadoc, source);

    if (null == m_access) {
      String access = getContext().getProperty(JAVADOC_ACCESS_KEY, "protected");
      AccessType type = new AccessType();
      type.setValue(access);
      javadoc.setAccess(type);
    } else {
      javadoc.setAccess(m_access);
    }

    if ("true".equals(getContext().getProperty(JAVADOC_LINK_SOURCE_KEY, "false"))) {
      javadoc.setLinksource(true);
    }

    aggregateLinks(javadoc, resource);
    Link[] links = m_links.toArray(new Link[0]);
    for (int i = 0; i < links.length; i++) {
      Link link = links[i];
      Javadoc.LinkArgument arg = javadoc.createLink();
      String href = link.getHref();
      log("Adding link: " + href);
      arg.setHref(href);
    }

    final String title = resource.getName() + " API";
    if (null != m_windowTitle) {
      javadoc.setWindowtitle(m_windowTitle);
    } else {
      javadoc.setWindowtitle(title);
    }

    if (null == m_title) {
      javadoc.setDoctitle(title);
    } else {
      javadoc.setDoctitle(m_title);
    }

    if (null != m_overview) {
      javadoc.setOverview(m_overview);
    }

    Group[] groups = getGroups();
    for (int i = 0; i < groups.length; i++) {
      Group group = groups[i];
      Javadoc.GroupArgument jgroup = javadoc.createGroup();
      jgroup.setTitle(group.getTitle());
      Group.Package[] packages = group.getPackages();
      for (int j = 0; j < packages.length; j++) {
        Javadoc.PackageName name = new Javadoc.PackageName();
        name.setName(packages[j].getName());
        jgroup.addPackage(name);
      }
    }

    log("Generating: " + resource.getName() + " API");
    javadoc.execute();
  }