Exemple #1
0
  @Override
  public Page getPage(int pageNum, String lastMod)
      throws ContentGetException, ContentParseException {
    String[] wgetReply = this.wgetText(this.linkPage(pageNum), lastMod);
    String pageText = wgetReply[0];
    String newLastMod = wgetReply[1];

    Page p = new Page(pageNum);
    Topic t = null;

    Matcher mat = postGetPattern.matcher(pageText);

    while (mat.find()) {
      String text = mat.group(1);
      String type = mat.group(2);

      if (type.equals("opContainer")) {
        t = this.parseThread(text);
        p.addThread(t);
      } else {
        if (t != null) t.addPost(this.parsePost(text, t.getNum()));
      }
    }

    p.setLastMod(newLastMod);
    return p;
  }
Exemple #2
0
  @Override
  public Topic getThread(int threadNum, String lastMod)
      throws ContentGetException, ContentParseException {
    String[] wgetReply = this.wgetText(this.linkThread(threadNum), lastMod);
    String threadText = wgetReply[0];
    String newLastMod = wgetReply[1];

    Topic t = null;

    Matcher mat = postGetPattern.matcher(threadText);

    while (mat.find()) {
      String text = mat.group(1);
      String type = mat.group(2);
      if (type.equals("opContainer")) {
        if (t == null) {
          t = this.parseThread(text);
        } else {
          throw new ContentParseException("Two OP posts in thread in " + threadNum);
        }
      } else {
        if (t != null) {
          t.addPost(this.parsePost(text, t.getNum()));
        } else {
          throw new ContentParseException("Thread without OP post in " + threadNum);
        }
      }
    }

    t.setLastMod(newLastMod);
    return t;
  }
Exemple #3
0
  public Topic parseThread(String text) throws ContentParseException {
    int omPosts = 0;
    Matcher mat = omPostsPattern.matcher(text);
    if (mat.find()) omPosts = Integer.parseInt(mat.group(1));

    int omImages = 0;
    mat = omImagesPattern.matcher(text);
    if (mat.find()) omImages = Integer.parseInt(mat.group(1));

    Post op = this.parsePost(text, 0);
    Topic thread = new Topic(op.getNum(), omPosts, omImages);
    thread.addPost(op);

    return thread;
  }