public void setFecha(String val) {
   try {
     fecha.setDate(sdf.parse(val));
   } catch (Exception e) {
     omoikane.sistema.Dialogos.lanzarDialogoError(
         null,
         "Error en el registro: Fecha inválida",
         omoikane.sistema.Herramientas.getStackTraceString(e));
   }
 }
  /**
   * isValidDate tests a string to see whether it is a valid date.
   *
   * @param date
   * @return true if valid date, false if not valid
   */
  public static boolean isValidDate(String date) {

    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
    Date testDate = null;

    try {
      testDate = sdf.parse(date);
    } catch (ParseException e) {
      return false;
    }

    if (!sdf.format(testDate).equals(date)) {
      return false;
    }

    return true;
  }
Example #3
0
  /*==========================================================
   * public methods
   *==========================================================*/
  public Vector parse(Object entry) throws ParseException {
    String logEntry = (String) entry;
    // parsing the log Entry and return segments
    // Debug.println("LogDataModel: DefaultLogParser: parse() -" +logEntry);
    int x = logEntry.indexOf("[");
    if (x == -1) throw new ParseException(logEntry, 0);
    String temp = logEntry.substring(x + 1);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);

    String dateStr = temp.substring(0, x);
    // Debug.println("LogDataModel: DefaultLogParser: parse() -"+dateStr+" "+temp);
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = format.parse(dateStr);
    String dateColumn = DateFormat.getDateInstance().format(date);
    String timeColumn = DateFormat.getTimeInstance().format(date);

    // Debug.println("LogDataModel: DefaultLogParser: parse() -"+dateColumn+" "+timeColumn);
    temp = temp.substring(x + 2);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);
    String source = temp.substring(1, x);
    temp = temp.substring(x + 2);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);
    String level = temp.substring(1, x);
    temp = temp.substring(x + 2);
    Vector row = new Vector();
    row.addElement(getSourceString(source));
    row.addElement(getLevelString(level));
    row.addElement(dateColumn);
    row.addElement(timeColumn);
    JLabel detail = new JLabel(temp);
    detail.setToolTipText(temp);
    row.addElement(detail);
    return row;
  }