예제 #1
0
  public static Note decodeToNote(Map m) throws GeneralException {

    String chid = TypeEncoder.getString(MessageFieldNames.chapterid, m);
    String chver = TypeEncoder.getString(MessageFieldNames.chapterversion, m);

    String cname = TypeEncoder.getString(MessageFieldNames.chaptername, m, false);

    // Create a fake chapter to hold the id/version.
    Chapter c = new Chapter();
    c.setId(chid);
    c.setVersion(chver);
    c.setName(cname);

    String cid = TypeEncoder.getString(MessageFieldNames.commentid, m);

    String text = TypeEncoder.getString(MessageFieldNames.text, m);

    Note n = new Note();

    n.setChapter(c);
    n.setDescription(text);

    // Need to also setup the summary.
    n.setSummaryFromDescription();

    n.setId(cid);

    n.setDealtWith(TypeEncoder.getDate(MessageFieldNames.date, m, false));
    n.setPosition(TypeEncoder.getInt(MessageFieldNames.start, m));

    int end = TypeEncoder.getInt(MessageFieldNames.end, m, false);

    if (end > -1) {

      n.setEndPosition(end);
    }

    return n;
  }
예제 #2
0
  public static Map encode(Note n) {

    if (n.getChapter() == null) {

      throw new IllegalArgumentException("No chapter for note: " + n);
    }

    if ((n.getDescription() == null) || (n.getDescription().trim().length() == 0)) {

      throw new IllegalArgumentException("No text for note: " + n);
    }

    Map cdata = new HashMap();
    cdata.put(MessageFieldNames.commentid, n.getId());
    cdata.put(MessageFieldNames.chapterid, n.getChapter().getId());
    cdata.put(MessageFieldNames.chapterversion, n.getChapter().getVersion());
    cdata.put(MessageFieldNames.chaptername, n.getChapter().getName());
    cdata.put(MessageFieldNames.text, n.getDescription());
    cdata.put(MessageFieldNames.start, n.getStartPosition());

    if (n.getDealtWith() != null) {

      cdata.put(MessageFieldNames.date, n.getDealtWith().getTime());
    }

    if ((n.getEndPosition() > 0) && (n.getEndPosition() > n.getStartPosition())) {

      cdata.put(MessageFieldNames.end, n.getEndPosition());
    }

    return cdata;
  }