Example usage for java.text ParseException ParseException

List of usage examples for java.text ParseException ParseException

Introduction

In this page you can find the example usage for java.text ParseException ParseException.

Prototype

public ParseException(String s, int errorOffset) 

Source Link

Document

Constructs a ParseException with the specified detail message and offset.

Usage

From source file:org.unitedinternet.cosmo.calendar.query.TimeRangeFilter.java

/**
 * Construct a TimeRangeFilter object from a DOM Element
 * @param element The DOM Element.//from  ww  w  .  jav  a  2  s. co  m
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException {
    // Get start (must be present)
    String start = DomUtil.getAttribute(element, ATTR_CALDAV_START, null);
    if (start == null) {
        throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1);
    }

    DateTime trstart = new DateTime(start);
    if (!trstart.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1);
    }

    // Get end (must be present)
    String end = DomUtil.getAttribute(element, ATTR_CALDAV_END, null);
    DateTime trend = end != null ? new DateTime(end) : addOneYearToDateStart(trstart);

    if (!trend.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
    }

    setPeriod(new Period(trstart, trend));
    setTimezone(timezone);
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

public static <T extends Enum<T>> EnumDistribution<T> // Immutable
        create(Class<T> token, String sourceFile) throws IOException {
    if (token == null)
        throw new NullArgumentException();
    if (!token.isEnum())
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum.");
    if (token.getEnumConstants().length == 0)
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum.");
    EnumDistribution<T> result = new EnumDistribution<T>();
    result.values = token.getEnumConstants();
    result.probabilities = new EnumMap<T, Double>(token);
    Map<String, T> converter = new HashMap<String, T>();
    final int numberOfValues = result.values.length;
    int[] valueIndices = new int[numberOfValues];
    double[] valueProbabilities = new double[numberOfValues];
    BitSet valueIsComitted = new BitSet(numberOfValues);
    {//from   w ww.  ja v a  2s.  co  m
        int counter = 0;
        for (T value : result.values) {
            valueIndices[counter] = counter++;
            result.probabilities.put(value, 0.);
            converter.put(value.name(), value);
        }
    }
    BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
    try {
        String newLine;
        while ((newLine = reader.readLine()) != null) {
            if (newLine.isEmpty())
                continue;
            StringTokenizer tokenizer = new StringTokenizer(newLine);
            final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t");
            if (tokenizer.hasMoreTokens())
                throw new ParseException(
                        "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0);
            final double p = Double.parseDouble(pStr);
            if (p < 0. || p > 1.)
                throw new IOException(pStr + " is not a valid probability for the value " + name);
            result.probabilities.put(converter.get(name), p);
            final int ordinal = converter.get(name).ordinal();
            if (valueIsComitted.get(ordinal))
                throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0);
            valueProbabilities[converter.get(name).ordinal()] = p;
            valueIsComitted.set(ordinal, true);
        }
        { // Check sum of probabilities
            double sum = 0.;
            for (double p : valueProbabilities)
                sum += p;
            if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.))
                throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting "
                        + "probaility sum (value " + sum + ") is not equal to 1.");
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    } finally {
        reader.close();
    }
    result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities);
    return result;
}

From source file:com.marklogic.contentpump.utilities.JSONDocBuilder.java

@Override
public void put(String key, String value) throws Exception {
    try {//from  w ww  .java2  s.c  o m
        Object valueObj = datatypeMap.get(key).parse(value);
        generator.writeObjectField(key, valueObj);
    } catch (ParseException e) {
        throw new ParseException("Value " + value + " is not type " + datatypeMap.get(key).name(), 0);
    } catch (Exception e) {
        String msg = e.getMessage();
        if (!msg.contains("missing value")) {
            throw new Exception(msg);
        }
    }

}

From source file:org.xlcloud.openstack.model.climate.json.OpenStackDateDeserializer.java

private Date parseDate(String input, String[] datePatterns) throws ParseException {
    SimpleDateFormat parser = new SimpleDateFormat();
    parser.setLenient(true);/*from   w  w w  .  j  av  a 2  s. c o  m*/
    parser.setTimeZone(DateUtils.UTC_TIME_ZONE);
    ParsePosition position = new ParsePosition(0);
    for (String datePattern : datePatterns) {
        parser.applyPattern(datePattern);
        Date date = parser.parse(input, position);
        if (date != null && position.getIndex() == input.length()) {
            return date;
        }
    }
    throw new ParseException("Unable to parse the date: " + input, -1);
}

From source file:org.apache.hadoop.chukwa.rest.bean.ViewBean.java

public ViewBean(JSONObject json) throws ParseException {
    try {//w  w  w . j a v  a 2 s  . c om
        if (json.has("description")) {
            this.description = json.getString("description");
        } else {
            this.description = "";
        }
        this.owner = json.getString("owner");
        this.name = json.getString("name");
        this.permissionType = json.getString("permissionType");
        int size = json.getJSONArray("pages").length();
        PagesBean[] pages = new PagesBean[size];
        for (int i = 0; i < size; i++) {
            pages[i] = new PagesBean(json.getJSONArray("pages").getJSONObject(i));
        }
        this.pages = pages;
    } catch (JSONException e) {
        log.error(ExceptionUtil.getStackTrace(e));
        throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
    }
}

From source file:edu.lternet.pasta.client.SubscriptionUtility.java

/**
 * Constructs a new QualityReportUtility object from the quality report XML.
 * /*from  w w  w. j av  a 2s. c o m*/
 * @param qr
 *          The quality report XML as a String object.
 * 
 * @throws ParseException
 */
public SubscriptionUtility(String subscription) throws ParseException {

    if (subscription == null || subscription.isEmpty()) {
        throw new ParseException("Subscription is empty", 0);
    }

    this.subscription = subscription;

}

From source file:org.apache.hadoop.chukwa.rest.bean.PagesBean.java

public PagesBean(JSONObject json) throws ParseException {
    try {//from  w  ww  .j ava2s.  c om
        title = json.getString("title");
        columns = json.getInt("columns");
        JSONArray layout = json.getJSONArray("layout");
        this.layout = new ColumnBean[layout.length()];
        for (int i = 0; i < layout.length(); i++) {
            ColumnBean c = new ColumnBean(layout.getJSONArray(i));
            this.layout[i] = c;
        }
        if (json.has("colSize")) {
            JSONArray ja = json.getJSONArray("colSize");
            columnSizes = new int[ja.length()];
            for (int i = 0; i < ja.length(); i++) {
                columnSizes[i] = ja.getInt(i);
            }
        }
    } catch (JSONException e) {
        log.error(ExceptionUtil.getStackTrace(e));
        throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
    }
}

From source file:org.kalypso.wspwin.core.RunOffEventBean.java

/** Reads a qwt or wsf file */
public static RunOffEventBean[] read(final File qwtFile) throws ParseException, IOException {
    // the qwt and wsf files may not exist; return empty list of beans
    if (!qwtFile.exists())
        return new RunOffEventBean[] {};

    final List<RunOffEventBean> beans = new ArrayList<>(10);

    LineIterator lineIt = null;// ww  w  . ja  v  a2s.co  m
    try {
        int count = 0;
        for (lineIt = FileUtils.lineIterator(qwtFile, null); lineIt.hasNext();) {
            final String nextLine = lineIt.nextLine().trim();
            count++;

            if (nextLine.isEmpty())
                continue;

            final StringTokenizer tokenizer = new StringTokenizer(nextLine);
            if (tokenizer.countTokens() != 2)
                throw new ParseException(
                        Messages.getString("org.kalypso.wspwin.core.RunOffEventBean.0") + nextLine, count); //$NON-NLS-1$

            final String eventName = tokenizer.nextToken();

            final RunOffEventBean bean = new RunOffEventBean(eventName);

            final int eventLength = Integer.parseInt(tokenizer.nextToken());

            // read block: station -> value
            for (int i = 0; i < eventLength; i++) {
                if (!lineIt.hasNext())
                    throw new ParseException(
                            Messages.getString("org.kalypso.wspwin.core.RunOffEventBean.1") + eventName, count); //$NON-NLS-1$

                final String line = lineIt.nextLine();
                count++;
                final StringTokenizer tz = new StringTokenizer(line);
                if (tz.countTokens() != 2)
                    throw new ParseException(
                            Messages.getString("org.kalypso.wspwin.core.RunOffEventBean.2") + nextLine, count); //$NON-NLS-1$

                final double station = Double.parseDouble(tz.nextToken());
                final double value = Double.parseDouble(tz.nextToken());
                bean.addEntry(BigDecimal.valueOf(station), BigDecimal.valueOf(value));
            }

            beans.add(bean);
        }

        return beans.toArray(new RunOffEventBean[beans.size()]);
    } finally {
        LineIterator.closeQuietly(lineIt);
    }
}

From source file:com.anrisoftware.globalpom.format.latlong.LatitudeFormatLogger.java

ParseException errorParseLatitude(String source, ParsePosition pos) {
    ParseException ex = new ParseException(format(parse_error.toString(), source), pos.getErrorIndex());
    return logException(ex, parse_error_message, source);
}

From source file:org.osaf.cosmo.eim.schema.text.DurationFormat.java

public Object parseObject(String source, ParsePosition pos) {
    if (pos.getIndex() > 0)
        return null;

    if (!PATTERN.matcher(source).matches()) {
        parseException = new ParseException("Invalid duration " + source, 0);
        pos.setErrorIndex(0);//from ww  w. j a v a  2s  .  c o  m
        return null;
    }

    Dur dur = new Dur(source);

    pos.setIndex(source.length());

    return dur;
}