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:com.playonlinux.domain.ScriptLegacy.java

@Override
public String extractSignature() throws ParseException, IOException {
    BufferedReader bufferReader = new BufferedReader(new FileReader(this.getScriptFile()));
    StringBuilder signatureBuilder = new StringBuilder();

    String readLine;//from w ww.  j av  a  2  s  .com
    Boolean insideSignature = false;
    do {
        readLine = bufferReader.readLine();
        if (BEGIN_PGP_KEY_BLOCK_LINE.equals(readLine)) {
            insideSignature = true;
        }

        if (insideSignature) {
            signatureBuilder.append(readLine);
            signatureBuilder.append("\n");
        }

        if (END_PGP_KEY_BLOCK_LINE.equals(readLine)) {
            insideSignature = false;
        }
    } while (readLine != null);

    String signature = signatureBuilder.toString().trim();

    if (StringUtils.isBlank(signature)) {
        throw new ParseException("The script has no valid signature!", 0);
    }
    return signature;
}

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

/**
 * Construct a ParamFilter object from a DOM Element
 * @param element The element.//from w  ww .  ja  v a  2  s . c  o  m
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public ParamFilter(Element element) throws ParseException {
    // Get name which must be present
    name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null);

    if (name == null) {
        throw new ParseException(
                "CALDAV:param-filter a property parameter name (e.g., \"PARTSTAT\") is required", -1);
    }

    // Can only have a single ext-match element
    ElementIterator i = DomUtil.getChildren(element);

    if (i.hasNext()) {

        Element child = i.nextElement();

        if (i.hasNext()) {
            throw new ParseException(
                    "CALDAV:param-filter only a single text-match or is-not-defined element is allowed", -1);
        }

        if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) {
            textMatchFilter = new TextMatchFilter(child);

        } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) {

            isNotDefinedFilter = new IsNotDefinedFilter();
        } else {
            throw new ParseException("CALDAV:param-filter an invalid element name found", -1);
        }
    }
}

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

public WidgetBean(JSONObject json) throws ParseException {
    try {//w ww. jav  a 2s.c  om
        this.id = json.getString("id");
        this.title = json.getString("title");
        this.version = json.getString("version");
        this.categories = json.getString("categories");
        this.url = json.getString("url");
        this.description = json.getString("description");
        this.refresh = json.getInt("refresh");
        try {
            int size = json.getJSONArray("parameters").length();
            ParametersBean[] list = new ParametersBean[size];
            for (int i = 0; i < size; i++) {
                list[i] = new ParametersBean(json.getJSONArray("parameters").getJSONObject(i));
            }
            this.parameters = list;
        } catch (JSONException e) {
            this.parameters = null;
        }
    } catch (JSONException e) {
        log.error(ExceptionUtil.getStackTrace(e));
        throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
    }
}

From source file:org.kalypso.model.wspm.ewawi.data.reader.AbstractEwawiReader.java

private void readLine(final String line) throws ParseException {
    try {//w w  w. ja  v  a  2  s .com
        final String[] tabs = StringUtils.splitPreserveAllTokens(line, '\t'); //$NON-NLS-1$
        readTabs(tabs);
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        throw new ParseException(line, 0);
    }
}

From source file:org.osaf.cosmo.calendar.query.ComponentFilter.java

/**
 * Construct a ComponentFilter object from a DOM Element
 * @param element//from   w  w w  . j  a v a  2 s  . c om
 * @throws ParseException
 */
public ComponentFilter(Element element, VTimeZone timezone) throws ParseException {
    // Name must be present
    name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null);

    if (name == null) {
        throw new ParseException("CALDAV:comp-filter a calendar component name  (e.g., \"VEVENT\") is required",
                -1);
    }

    if (!(name.equals(Calendar.VCALENDAR) || CalendarUtils.isSupportedComponent(name)
            || name.equals(Component.VALARM) || name.equals(Component.VTIMEZONE)))
        throw new ParseException(name + " is not a supported iCalendar component", -1);

    ElementIterator i = DomUtil.getChildren(element);
    int childCount = 0;

    while (i.hasNext()) {
        Element child = i.nextElement();
        childCount++;

        // if is-not-defined is present, then nothing else can be present
        if (childCount > 1 && isNotDefinedFilter != null)
            throw new ParseException("CALDAV:is-not-defined cannnot be present with other child elements", -1);

        if (ELEMENT_CALDAV_TIME_RANGE.equals(child.getLocalName())) {

            // Can only have one time-range element in a comp-filter
            if (timeRangeFilter != null) {
                throw new ParseException("CALDAV:comp-filter only one time-range element permitted", -1);
            }

            timeRangeFilter = new TimeRangeFilter(child, timezone);
        } else if (ELEMENT_CALDAV_COMP_FILTER.equals(child.getLocalName())) {

            // Add to list
            componentFilters.add(new ComponentFilter(child, timezone));

        } else if (ELEMENT_CALDAV_PROP_FILTER.equals(child.getLocalName())) {

            // Add to list
            propFilters.add(new PropertyFilter(child, timezone));

        } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) {
            if (childCount > 1)
                throw new ParseException("CALDAV:is-not-defined cannnot be present with other child elements",
                        -1);
            isNotDefinedFilter = new IsNotDefinedFilter();
        } else if (ELEMENT_CALDAV_IS_DEFINED.equals(child.getLocalName())) {
            // XXX provided for backwards compatibility with
            // Evolution 2.6, which does not implement
            // is-not-defined;
            if (childCount > 1)
                throw new ParseException("CALDAV:is-defined cannnot be present with other child elements", -1);
            log.warn("old style 'is-defined' ignored from (outdated) client!");
        } else
            throw new ParseException("CALDAV:comp-filter an invalid element name found", -1);

    }
}

From source file:net.spy.memcached.protocol.couch.ReducedOperationImpl.java

protected ViewResponseReduced parseResult(String json) throws ParseException {
    final Collection<ViewRow> rows = new LinkedList<ViewRow>();
    final Collection<RowError> errors = new LinkedList<RowError>();
    if (json != null) {
        try {/*from ww w.  j a  v a  2 s  . c om*/
            JSONObject base = new JSONObject(json);
            if (base.has("rows")) {
                JSONArray ids = base.getJSONArray("rows");
                for (int i = 0; i < ids.length(); i++) {
                    JSONObject elem = ids.getJSONObject(i);
                    String key = elem.getString("key");
                    String value = elem.getString("value");
                    rows.add(new ViewRowReduced(key, value));
                }
            }
            if (base.has("errors")) {
                JSONArray ids = base.getJSONArray("errors");
                for (int i = 0; i < ids.length(); i++) {
                    JSONObject elem = ids.getJSONObject(i);
                    String from = elem.getString("from");
                    String reason = elem.getString("reason");
                    errors.add(new RowError(from, reason));
                }
            }
        } catch (JSONException e) {
            throw new ParseException("Cannot read json: " + json, 0);
        }
    }
    return new ViewResponseReduced(rows, errors);
}

From source file:com.qcadoo.localization.api.utils.DateUtils.java

/**
 * Parse string into date, with autocomplete missing month, day, hour, minute and second.
 * /*from  w w w.  j  av a 2  s.co m*/
 * Examples with up-complete:
 * 
 * <ul>
 * <li>2010: 2010-12-31 23:59:59</li>
 * <li>2010-03: 2010-03-31 23:59:59</li>
 * <li>2010-03-06: 2010-03-06 23:59:59</li>
 * <li>2010-03-06 19: 2010-03-06 19:59:59</li>
 * <li>2010-03-06 19:30: 2010-03-06 19:30:59</li>
 * <li>2010-03-06 19:30:20: 2010-03-06 19:30:20</li>
 * </ul>
 * 
 * Examples with down-complete:
 * 
 * <ul>
 * <li>2010: 2010-01-01 00:00:00</li>
 * <li>2010-03: 2010-03-01 00:00:00</li>
 * <li>2010-03-06: 2010-03-06 00:00:00</li>
 * <li>2010-03-06 19: 2010-03-06 19:00:00</li>
 * <li>2010-03-06 19:30: 2010-03-06 19:30:00</li>
 * <li>2010-03-06 19:30:20: 2010-03-06 19:30:20</li>
 * </ul>
 * 
 * @param dateExpression
 *            string with date expression
 * @param upComplete
 *            true if up-complete, otherwise down-complete
 * @return parsed date
 * @throws ParseException
 *             if year, month, day, hour, minute or second is invalid or when year is &lt; 1500 or &gt; 2500
 */
public static Date parseAndComplete(final String dateExpression, final boolean upComplete)
        throws ParseException {
    final String trimmedDateExpression = StringUtils.trim(dateExpression);
    DateTime parsedDate = new DateTime(org.apache.commons.lang.time.DateUtils
            .parseDateStrictly(trimmedDateExpression, SUPPORTED_PATTERNS));

    final String[] dateAndTime = trimmedDateExpression.split(" ");
    if (dateAndTime.length > 2 || parsedDate.getYear() < 1500 || parsedDate.getYear() > 2500) {
        throw new ParseException(L_WRONG_DATE, 1);
    }

    return round(parsedDate, upComplete, dateAndTime).toDate();
}

From source file:eu.crisis_economics.configuration.ObjectReferenceExpression.java

static ObjectReferenceExpression tryCreate(String expression, FromFileConfigurationContext context)
        throws ParseException {
    List<String> expressions = ObjectReferenceExpression.isExpressionOfType(expression, context);
    if (expressions == null)
        throw new ParseException(expression, 0);
    String refNameString = expressions.get(0);
    NameDeclarationExpression primeNameExpression = NameDeclarationExpression.tryCreate(refNameString, context);
    if (expressions.size() == 1) {
        return new ObjectReferenceExpression(primeNameExpression, context);
    } else {/*from w  w w  .  j  a v a2  s.c  o m*/
        String indexString = expressions.get(1);
        if (IntegerPrimitiveExpression.isExpressionOfType(indexString, context) != null) {
            IntegerPrimitiveExpression primitiveIndexExpression = IntegerPrimitiveExpression
                    .tryCreate(indexString, context);
            return new ObjectReferenceExpression(primeNameExpression, primitiveIndexExpression, context);
        } else {
            NameDeclarationExpression subPrimeNameExpression = NameDeclarationExpression.tryCreate(indexString,
                    context);
            return new ObjectReferenceExpression(primeNameExpression, subPrimeNameExpression, context);
        }
    }
}

From source file:com.haulmont.chile.core.datatypes.impl.IntegerDatatype.java

@Override
protected Number parse(String value, NumberFormat format) throws ParseException {
    format.setParseIntegerOnly(true);//from ww w. jav a2s.c o  m

    Number result = super.parse(value, format);
    if (!hasValidIntegerRange(result)) {
        throw new ParseException(String.format("Integer range exceeded: \"%s\"", value), 0);
    }
    return result;
}

From source file:net.spy.memcached.protocol.couch.NoDocsOperationImpl.java

protected ViewResponseNoDocs parseResult(String json) throws ParseException {
    final Collection<ViewRow> rows = new LinkedList<ViewRow>();
    final Collection<RowError> errors = new LinkedList<RowError>();
    if (json != null) {
        try {/*w w w . j av a  2  s.  c  o  m*/
            JSONObject base = new JSONObject(json);
            if (base.has("rows")) {
                JSONArray ids = base.getJSONArray("rows");
                for (int i = 0; i < ids.length(); i++) {
                    JSONObject elem = ids.getJSONObject(i);
                    String id = elem.getString("id");
                    String key = elem.getString("key");
                    String value = elem.getString("value");
                    rows.add(new ViewRowNoDocs(id, key, value));
                }
            }
            if (base.has("errors")) {
                JSONArray ids = base.getJSONArray("errors");
                for (int i = 0; i < ids.length(); i++) {
                    JSONObject elem = ids.getJSONObject(i);
                    String from = elem.getString("from");
                    String reason = elem.getString("reason");
                    errors.add(new RowError(from, reason));
                }
            }
        } catch (JSONException e) {
            throw new ParseException("Cannot read json: " + json, 0);
        }
    }
    return new ViewResponseNoDocs(rows, errors);
}