Ejemplo n.º 1
0
  public static boolean getBoolean(String field, Map data, boolean required)
      throws GeneralException {

    Object o = null;

    if (required) {

      o = TypeEncoder.checkTypeAndNotNull(field, data, Boolean.class);

    } else {

      o = data.get(field);

      if (o == null) {

        return false;
      }

      if (!Boolean.class.isAssignableFrom(o.getClass())) {

        throw new GeneralException(
            "Expected type for: "
                + field
                + " to be: "
                + Number.class.getName()
                + ", is: "
                + o.getClass().getName());
      }
    }

    return (Boolean) o;
  }
Ejemplo n.º 2
0
  public static Date getDate(String field, Map data, boolean required) throws GeneralException {

    Object o = null;

    if (required) {

      o = TypeEncoder.checkTypeAndNotNull(field, data, Number.class);

    } else {

      o = data.get(field);

      if (o == null) {

        return null;
      }

      if (!Number.class.isAssignableFrom(o.getClass())) {

        throw new GeneralException(
            "Expected type for: "
                + field
                + " to be: "
                + Number.class.getName()
                + ", is: "
                + o.getClass().getName());
      }
    }

    return new Date(((Number) o).longValue());
  }
Ejemplo n.º 3
0
  public static Chapter decodeToChapter(Map m) throws GeneralException {

    String cid = TypeEncoder.getString(MessageFieldNames.chapterid, m);
    String cname = TypeEncoder.getString(MessageFieldNames.name, m);
    String ctext = TypeEncoder.getString(MessageFieldNames.text, m, false);
    String cver = TypeEncoder.getString(MessageFieldNames.version, m);
    String cm = TypeEncoder.getString(MessageFieldNames.markup, m, false);

    Chapter c = new Chapter();
    c.setId(cid);
    c.setName(cname);
    c.setText(ctext);

    c.setMarkup(cm);
    c.setVersion(cver);

    return c;
  }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
0
  public static boolean getBoolean(String field, Map data) throws GeneralException {

    return TypeEncoder.getBoolean(field, data, true);
  }
Ejemplo n.º 6
0
  public static Date getDate(String field, Map data) throws GeneralException {

    return TypeEncoder.getDate(field, data, true);
  }
Ejemplo n.º 7
0
  public static int getInt(String field, Map data) throws GeneralException {

    return TypeEncoder.getInt(field, data, true);
  }