Пример #1
0
  protected DataResult performSearch(RequestContext context) {
    HttpServletRequest request = context.getRequest();
    String searchString = (String) request.getAttribute(SEARCH_STR);
    String viewMode = (String) request.getAttribute(VIEW_MODE);
    String whereToSearch = (String) request.getAttribute(WHERE_TO_SEARCH);
    Boolean invertResults =
        StringUtils.defaultString((String) request.getAttribute(INVERT_RESULTS)).equals("on");
    Boolean isFineGrained = (Boolean) request.getAttribute(FINE_GRAINED);

    ActionErrors errs = new ActionErrors();
    DataResult dr = null;
    try {
      dr =
          SystemSearchHelper.systemSearch(
              context, searchString, viewMode, invertResults, whereToSearch, isFineGrained);
    } catch (MalformedURLException e) {
      log.error("Caught Exception :" + e, e);
      errs.add(
          ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.connection_error"));
    } catch (XmlRpcFault e) {
      log.info("Caught Exception :" + e + ", code [" + e.getErrorCode() + "]", e);
      if (e.getErrorCode() == 100) {
        log.error("Invalid search query", e);
        errs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("packages.search.could_not_parse_query", searchString));
      } else if (e.getErrorCode() == 200) {
        log.error("Index files appear to be missing: ", e);
        errs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("packages.search.index_files_missing", searchString));
      } else {
        errs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("packages.search.could_not_execute_query", searchString));
      }
    } catch (XmlRpcException e) {
      log.error("Caught Exception :" + e, e);
      errs.add(
          ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.connection_error"));
    }
    if (dr == null) {
      ActionMessages messages = new ActionMessages();
      messages.add(
          ActionMessages.GLOBAL_MESSAGE, new ActionMessage("systemsearch_no_matches_found"));
      getStrutsDelegate().saveMessages(request, messages);
    }
    if (!errs.isEmpty()) {
      addErrors(request, errs);
    }
    return dr;
  }
Пример #2
0
  public void refresh() {
    final int maxPosts = 128;
    try {
      for (final Page p : wordpress.getRecentPosts(maxPosts)) {
        final Content postContent =
            pool.addContent(
                new Content() {

                  @Override
                  public String getURL() {
                    return p.getLink();
                  }

                  @Override
                  public String getTitle() {
                    return p.getTitle();
                  }

                  @Override
                  public String getContent() {
                    return p.getDescription();
                  }

                  @Override
                  public Content getParent() {
                    return null;
                  }

                  @Override
                  public void comment(String content) {
                    try {
                      newComment(p.getPostid(), content);
                    } catch (XmlRpcFault ex) {
                      logger.severe("Unable to comment on " + p + ": " + ex.toString());
                    }
                  }
                });
        int numComments = wordpress.getCommentsCount(p.getPostid()).getApproved();
        for (final Comment c : wordpress.getComments("approve", p.getPostid(), numComments, 0)) {
          pool.addContent(
              new Content() {

                @Override
                public String getURL() {
                  return c.getLink();
                }

                @Override
                public String getTitle() {
                  return null;
                }

                @Override
                public String getContent() {
                  return c.getContent();
                }

                @Override
                public Content getParent() {
                  return postContent;
                }

                @Override
                public void comment(String content) {
                  try {
                    newComment(p.getPostid(), content, c.getComment_id());
                  } catch (XmlRpcFault ex) {
                    logger.severe("Unable to comment on " + p + "#" + c + ": " + ex.toString());
                  }
                }
              });
        }
      }
    } catch (XmlRpcFault f) {
      logger.severe(f.toString());
    }
  }