Package java.text

Examples of java.text.ParseException


    this.set(date);
  }
 
  public long parseISO8601(final String s) throws ParseException {
      if(s == null || s.length() < 1) {
        throw new ParseException("parseISO8601 - empty string, nothing to parse", 0);
      }
      SimpleDateFormat dateformat;
      StringBuilder date = new StringBuilder(s);
      if(s.length()==10)
        dateformat = new SimpleDateFormat("yyyy-MM-dd");
View Full Code Here


       
        // split 2007-12-19T10:20:30.789+0500 into its parts
        // correct: yyyy['-'MM['-'dd['T'HH':'MM[':'ss['.'SSS]]('Z'|ZZZZZ)]]]
        final StringTokenizer t = new StringTokenizer(s, "-T:.Z+", true);
        if (s == null || t.countTokens() == 0)
            throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
       
        try {
            // year
            cal.set(Calendar.YEAR, Integer.parseInt(t.nextToken()));
            // month
            if (t.nextToken().equals("-")) {
                cal.set(Calendar.MONTH, Integer.parseInt(t.nextToken()) - 1);
            } else {
                return cal.getTime();
            }
            // day
            if (t.nextToken().equals("-")) {
                cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(t.nextToken()));
            } else {
                return cal.getTime();
            }
            // The standard says:
            // if there is an hour there has to be a minute and a timezone token, too.
            if (t.nextToken().equals("T")) {
                final int hour = Integer.parseInt(t.nextToken());
                // no error, got hours
                int min = 0;
                int sec = 0;
                int msec = 0;
                if (t.nextToken().equals(":")) {
                    min = Integer.parseInt(t.nextToken());
                    // no error, got minutes
                    // need TZ or seconds
                    String token = t.nextToken();
                    if (token.equals(":")) {
                        sec = Integer.parseInt(t.nextToken());
                        // need millisecs or TZ
                        token = t.nextToken();
                        if (token.equals(".")) {
                            msec = Integer.parseInt(t.nextToken());
                            // need TZ
                            token = t.nextToken();
                        }
                    }
                   
                    // check for TZ data
                    int offset;
                    if (token.equals("Z")) {
                        offset = 0;
                    } else {
                        int sign = 0;
                        if (token.equals("+")) {
                            sign = 1;
                        } else if (token.equals("-")) {
                            sign = -1;
                        } else {
                            // no legal TZ offset found
                            return cal.getTime();
                        }
                        offset = sign * Integer.parseInt(t.nextToken()) * 10 * 3600;
                    }
                    cal.set(Calendar.ZONE_OFFSET, offset);
                }
                cal.set(Calendar.HOUR_OF_DAY, hour);
                cal.set(Calendar.MINUTE, min);
                cal.set(Calendar.SECOND, sec);
                cal.set(Calendar.MILLISECOND, msec);
            }
        } catch (final NoSuchElementException e) {
            // ignore this as it is perfectly fine to have non-complete date in this format
        } catch (final Exception e) {
            // catch all Exceptions and return what we parsed so far
            //serverLog.logInfo("SERVER", "parseISO8601: DATE ERROR with: '" + s + "' got so far: '" + cal.toString());
        }
       
        // in case we couldn't even parse a year
        if (!cal.isSet(Calendar.YEAR))
            throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
        Date d = cal.getTime();
        return d;
    }
View Full Code Here

          log_.debug("fillGapsInColumnHeaders: isNextweek("+previousWeek+","+currWeek+"): false");
          String additionalWeek = nextWeek(previousWeek);
          if (columnHeaders.contains(additionalWeek)) {
            // oups, then we have a bug in our algorithm or what?
            log_.warn("fillGapsInColumnHeaders: throwing a ParseException, can't add "+additionalWeek+" to "+columnHeaders);
            throw new ParseException("Can't add "+additionalWeek+" to the list of weeks - it is already there", 0);
          }
          if (sdf_.parse(additionalWeek).compareTo(sdf_.parse(currWeek))>0) {
            // then we're overshooting
            continue;
          }
View Full Code Here

        } else if (w>=53) {
          return (year+1)+"-"+0;
        }
      } catch(NumberFormatException nfe) {
        log_.warn("nextWeek: Got a NumberFormatException: "+nfe, nfe);
        throw new ParseException("Got a NumberFormatException, rethrowing", 0);
      }
    } else if (result.equals(week)) {
      // daylight saving
      d = new Date(d.getTime() + 1*60*60*1000);
      result = sdf_.format(d);
View Full Code Here

      } else if (result instanceof Integer) {
        return ((Integer) result).floatValue();
      } else throw new ArgumentParseException("Parse exception: expected Double or Integer, but got:"
          + (result == null ? "no object(null)" : result.getClass().getName()));
    } catch (XExpression xe) {
      throw new ParseException("Parse exception for calculation: " + calculation + ". " + xe.getMessage(), xe.getPosition());
    }
  }
View Full Code Here

        return (((Double) result).doubleValue() == 1.0) ? true : false;
      } else if (result instanceof Integer) {
        return (((Integer) result).intValue() == 1) ? true : false;
      } else return false;
    } catch (XExpression xe) {
      throw new ParseException("Parse exception for condition: " + condition + ". " + xe.getMessage(), xe.getPosition());
    }
  }
View Full Code Here

        return (((Double) result).doubleValue() == 1.0) ? true : false;
      } else if (result instanceof Integer) {
        return (((Integer) result).intValue() == 1) ? true : false;
      } else return false;
    } catch (XExpression xe) {
      throw new ParseException("Parse exception" + xe.getMessage(), xe.getPosition());
    }
  }
View Full Code Here

    }
    try {
      return new Long(formatter.parsePeriod(source).toDurationFrom(
          new Instant(0)).getMillis());
    } catch (Throwable t) {
      throw new ParseException(t.getMessage(), 0);
    }
  }
View Full Code Here

      while (li >= 0)
      {
        count++;
        int ri = infos.indexOf(')', li);
        if (ri < 0)
          throw new ParseException(infos, li);

        sb.append("<tr class=\"" + (index++ % 2 == 0 ? "even" : "odd") + "\">\n");
        if (first)
        {
          sb.append("<td rowspan=\"${rowSpan}\">" + method + "</td>");
View Full Code Here

      int li = infos.indexOf('(');
      while (li >= 0)
      {
        int ri = infos.indexOf(')', li);
        if (ri < 0)
          throw new ParseException(infos, li);

        String info = infos.substring(li + 1, ri);
 
        li = infos.indexOf('(', ri);
        InfoIterator it = new InfoIterator(info);
View Full Code Here

TOP

Related Classes of java.text.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.