Exemple #1
0
  public Post newYotsubaPost(
      String link,
      String mediaOrig,
      boolean spoiler,
      String filesize,
      int width,
      int height,
      String filename,
      int tWidth,
      int tHeight,
      String md5,
      int num,
      String title,
      String email,
      String name,
      String trip,
      String capcode,
      int dateUtc,
      boolean sticky,
      String comment,
      boolean omitted,
      int threadNum)
      throws ContentParseException {

    String type = "";
    String previewOrig = null;

    // TODO add the following variables
    String exif = null;
    int timeStampExpired = 0;
    String posterHash = null;

    if (threadNum == 0) threadNum = num;
    boolean op = (threadNum == num);

    if (name.equals("")) name = null;
    if (comment.equals("")) comment = null;
    if (title.equals("")) title = null;

    if (link != null) {
      Pattern pat = Pattern.compile("/src/(\\d+)\\.(\\w+)");
      Matcher mat = pat.matcher(link);
      mat.find();

      String number = mat.group(1);
      type = mat.group(2);

      // mediaOrig = number + "." + type;
      filename = (filename != null) ? filename : (number + "." + type);
      if (mediaOrig == null) mediaOrig = number + "." + type;
      previewOrig = number + "s.jpg";
    }

    if (spoiler) {
      tWidth = 0;
      tHeight = 0;
    }

    int timeStamp;
    int mediaSize;
    try {
      timeStamp = this.parseDate(dateUtc);
      mediaSize = this.parseFilesize(filesize);
    } catch (IllegalArgumentException e) {
      throw new ContentParseException("Could not create post " + num, e);
    }

    Post post = new Post();
    post.setLink(link);
    post.setType(type);
    post.setMediaOrig(mediaOrig);
    post.setMediaHash(md5);
    post.setMediaFilename(filename);
    post.setMediaSize(mediaSize);
    post.setMediaW(width);
    post.setMediaH(height);
    post.setPreviewOrig(previewOrig);
    post.setPreviewW(tWidth);
    post.setPreviewH(tHeight);
    post.setExif(exif);
    post.setNum(num);
    post.setThreadNum(threadNum);
    post.setOp(op);
    post.setTitle(this.cleanSimple(title));
    post.setEmail(email);
    post.setName(this.cleanSimple(name));
    post.setTrip(trip);
    post.setDate(timeStamp);
    post.setDateExpired(timeStampExpired);
    post.setComment(this.doClean(comment));
    post.setSpoiler(spoiler);
    post.setDeleted(false);
    post.setSticky(sticky);
    post.setCapcode(capcode);
    post.setPosterHash(posterHash);
    post.setOmitted(omitted);

    return post;
  }