Esempio n. 1
0
  /* Get pager of users whose names begin with specified letter */
  public Pager getUsersByLetterPager(String letter, int sinceDays, int length) {

    String pagerUrl = null;
    if (feedRequest != null) {
      pagerUrl =
          urlStrategy.getWeblogFeedURL(
              weblog,
              weblogRequest.getLocale(),
              feedRequest.getType(),
              feedRequest.getFormat(),
              null,
              null,
              null,
              feedRequest.isExcerpts(),
              true);
    } else {
      pagerUrl =
          urlStrategy.getWeblogPageURL(
              weblog, weblogRequest.getLocale(), pageLink, null, null, null, null, 0, false);
    }

    if (letter != null && StringUtils.isEmpty(letter)) {
      letter = null;
    }

    return new UsersPager(
        urlStrategy, pagerUrl, letter, weblogRequest.getLocale(), sinceDays, pageNum, length);
  }
Esempio n. 2
0
  /**
   * Get pager ofWeblogEntry objects across all weblogs, in reverse chrono order by pubTime.
   *
   * @param queryWeblog Restrict to this weblog
   * @param user Restrict to this user
   * @param cat Restrict to this category
   * @param sinceDays Limit to past X days in past (or -1 for no limit)
   * @param length Max number of results to return
   */
  public Pager getWeblogEntriesPager(
      WeblogWrapper queryWeblog, User user, String cat, int sinceDays, int length) {

    String pagerUrl = null;
    if (feedRequest != null) {
      pagerUrl =
          urlStrategy.getWeblogFeedURL(
              weblog,
              weblogRequest.getLocale(),
              feedRequest.getType(),
              feedRequest.getFormat(),
              feedRequest.getWeblogCategoryName(),
              null,
              feedRequest.getTags(),
              feedRequest.isExcerpts(),
              true);
    } else {
      pagerUrl =
          urlStrategy.getWeblogPageURL(
              weblog, weblogRequest.getLocale(), pageLink, null, null, null, tags, 0, false);
    }

    return new WeblogEntriesListPager(
        urlStrategy,
        pagerUrl,
        queryWeblog.getPojo(),
        user,
        cat,
        tags,
        weblogRequest.getLocale(),
        sinceDays,
        pageNum,
        length);
  }
Esempio n. 3
0
  /** Get pager of weblogs whose handles begin with specified letter */
  public Pager getWeblogsByLetterPager(String letter, int sinceDays, int length) {

    String pagerUrl =
        urlStrategy.getWeblogPageURL(
            weblog, weblogRequest.getLocale(), pageLink, null, null, null, null, 0, false);

    if (letter != null && StringUtils.isEmpty(letter)) {
      letter = null;
    }

    return new WeblogsPager(
        urlStrategy, pagerUrl, letter, weblogRequest.getLocale(), sinceDays, pageNum, length);
  }
Esempio n. 4
0
  public void init(Map initData) throws WebloggerException {

    // we expect the init data to contain a weblogRequest object
    this.weblogRequest = (WeblogRequest) initData.get("parsedRequest");
    if (this.weblogRequest == null) {
      throw new WebloggerException("expected weblogRequest from init data");
    }

    if (weblogRequest instanceof WeblogPageRequest) {
      ThemeTemplate weblogPage = ((WeblogPageRequest) weblogRequest).getWeblogPage();
      pageLink = (weblogPage != null) ? weblogPage.getLink() : null;
      pageNum = ((WeblogPageRequest) weblogRequest).getPageNum();
      tags = ((WeblogPageRequest) weblogRequest).getTags();
    } else if (weblogRequest instanceof WeblogFeedRequest) {
      this.feedRequest = (WeblogFeedRequest) weblogRequest;
      tags = feedRequest.getTags();
      pageNum = feedRequest.getPage();
    }

    // look for url strategy
    urlStrategy = (URLStrategy) initData.get("urlStrategy");
    if (urlStrategy == null) {
      urlStrategy = WebloggerFactory.getWeblogger().getUrlStrategy();
    }

    // extract weblog object
    weblog = weblogRequest.getWeblog();
  }
Esempio n. 5
0
  /*
   * Get pager of most recent Comment objects across all weblogs,
   * in reverse chrono order by postTime.
   * @param offset   Offset into results (for paging)
   * @param len      Max number of results to return
   */
  public Pager getCommentsPager(int sinceDays, int length) {

    String pagerUrl = null;
    if (feedRequest != null) {
      pagerUrl =
          urlStrategy.getWeblogFeedURL(
              weblog,
              weblogRequest.getLocale(),
              feedRequest.getType(),
              feedRequest.getFormat(),
              null,
              null,
              null,
              feedRequest.isExcerpts(),
              true);
    } else {
      pagerUrl =
          urlStrategy.getWeblogPageURL(
              weblog, weblogRequest.getLocale(), pageLink, null, null, null, null, 0, false);
    }

    return new CommentsPager(
        urlStrategy, pagerUrl, null, weblogRequest.getLocale(), sinceDays, pageNum, length);
  }
Esempio n. 6
0
  /** Handle GET requests for weblog pages. */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    log.debug("Entering");

    Weblog weblog = null;

    WeblogRequest weblogRequest = null;
    try {
      weblogRequest = new WeblogRequest(request);

      // now make sure the specified weblog really exists
      weblog = weblogRequest.getWeblog();
      if (weblog == null) {
        throw new WebloggerException("Unable to lookup weblog: " + weblogRequest.getWeblogHandle());
      }

    } catch (Exception e) {
      // invalid rsd request format or weblog doesn't exist
      log.debug("error creating weblog request", e);
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // Respond with 304 Not Modified if it is not modified.
    long lastModified = System.currentTimeMillis();
    if (weblog.getLastModified() != null) {
      lastModified = weblog.getLastModified().getTime();
    }
    if (ModDateHeaderUtil.respondIfNotModified(request, response, lastModified)) {
      return;
    }

    // set last-modified date
    ModDateHeaderUtil.setLastModifiedHeader(response, lastModified);

    // set the content type
    response.setContentType("application/rsd+xml; charset=utf-8");

    // populate the model
    HashMap model = new HashMap();
    model.put("website", weblog);
    model.put("absBaseURL", WebloggerRuntimeConfig.getAbsoluteContextURL());

    // lookup Renderer we are going to use
    Renderer renderer = null;
    try {
      log.debug("Looking up renderer");
      Template template = new StaticTemplate("rsd.vm", "velocity");
      renderer = RendererManager.getRenderer(template, DeviceType.standard);
    } catch (Exception e) {
      // nobody wants to render my content :(
      log.error("Couldn't find renderer for rsd template", e);

      if (!response.isCommitted()) response.reset();
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // render content
    CachedContent rendererOutput = new CachedContent(4096);
    try {
      log.debug("Doing rendering");
      renderer.render(model, rendererOutput.getCachedWriter());

      // flush rendered output and close
      rendererOutput.flush();
      rendererOutput.close();
    } catch (Exception e) {
      // bummer, error during rendering
      log.error("Error during rendering for rsd template", e);

      if (!response.isCommitted()) response.reset();
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // post rendering process

    // flush rendered content to response
    log.debug("Flushing response output");
    response.setContentLength(rendererOutput.getContent().length);
    response.getOutputStream().write(rendererOutput.getContent());

    log.debug("Exiting");
  }