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:cz.muni.fi.editor.webapp.formatters.OrganizationFormatter.java

@Override
public OrganizationForm parse(String s, Locale locale) throws ParseException {
    if (StringUtils.isEmpty(s)) {
        throw new ParseException("Passed empty text", 0);
    } else {/*from   w ww . ja va2s.c om*/
        OrganizationForm of = new OrganizationForm();
        of.setId(Long.valueOf(s));

        return of;
    }
}

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

public ColumnBean(JSONArray json) throws ParseException {
    try {//from  w ww .j a  va2s. co  m
        widgets = new WidgetBean[json.length()];
        for (int i = 0; i < json.length(); i++) {
            widgets[i] = new WidgetBean(json.getJSONObject(i));
        }
    } catch (JSONException e) {
        log.error(ExceptionUtil.getStackTrace(e));
        throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
    }
}

From source file:org.osaf.cosmo.model.text.XhtmlTicketFormat.java

public Ticket parse(String source, EntityFactory entityFactory) throws ParseException {

    String key = null;/*from ww  w. j a va  2  s  .  c  om*/
    TicketType type = null;
    Integer timeout = null;
    try {
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inTicket = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "ticket")) {
                if (log.isDebugEnabled())
                    log.debug("found ticket element");
                inTicket = true;
                continue;
            }

            if (inTicket && hasClass(reader, "key")) {
                if (log.isDebugEnabled())
                    log.debug("found key element");

                key = reader.getElementText();
                if (StringUtils.isBlank(key))
                    handleParseException("Key element must not be empty", reader);

                continue;
            }

            if (inTicket && hasClass(reader, "type")) {
                if (log.isDebugEnabled())
                    log.debug("found type element");

                String typeId = reader.getAttributeValue(null, "title");
                if (StringUtils.isBlank(typeId))
                    handleParseException("Ticket type title must not be empty", reader);
                type = TicketType.createInstance(typeId);

                continue;
            }
            if (inTicket && hasClass(reader, "timeout")) {
                if (log.isDebugEnabled())
                    log.debug("found timeout element");

                String timeoutString = reader.getAttributeValue(null, "title");
                if (StringUtils.isBlank(timeoutString))
                    timeout = null;
                else
                    timeout = Integer.getInteger(timeoutString);

                continue;
            }
        }
        if (type == null || key == null)
            handleParseException("Ticket must have type and key", reader);
        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    Ticket ticket = entityFactory.createTicket(type);
    ticket.setKey(key);
    if (timeout == null)
        ticket.setTimeout(Ticket.TIMEOUT_INFINITE);
    else
        ticket.setTimeout(timeout);

    return ticket;
}

From source file:org.unitedinternet.cosmo.model.text.XhtmlPreferenceFormat.java

public Preference parse(String source, EntityFactory entityFactory) throws ParseException {
    Preference pref = entityFactory.createPreference();

    try {//  w  w  w .  ja  va  2s.c o  m
        if (source == null) {
            throw new ParseException("Source has no XML data", -1);
        }
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inPreference = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement()) {
                continue;
            }

            if (hasClass(reader, "preference")) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("found preference element");
                }
                inPreference = true;
                continue;
            }

            if (inPreference && hasClass(reader, "key")) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("found key element");
                }

                String key = reader.getElementText();
                if (StringUtils.isBlank(key)) {
                    handleParseException("Key element must not be empty", reader);
                }
                pref.setKey(key);

                continue;
            }

            if (inPreference && hasClass(reader, "value")) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("found value element");
                }

                String value = reader.getElementText();
                if (StringUtils.isBlank(value)) {
                    value = "";
                }
                pref.setValue(value);

                continue;
            }
        }

        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    return pref;
}

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

static CommaListExpression tryCreate(String expression, FromFileConfigurationContext context)
        throws ParseException {
    try {//w  ww  .j  a v  a 2 s  .com
        return ArrayMemberDefinitionExpression.tryCreate(expression, context);
    } catch (Exception e) {
    }
    try {
        return ConstructionDefinitionExpression.tryCreate(expression, context);
    } catch (Exception e) {
    }
    throw new ParseException(expression, 0);
}

From source file:com.whizzosoftware.hobson.davisvantage.api.command.LoopResponse.java

public LoopResponse(byte[] data) throws ParseException {
    if (data.length == 99 && data[0] == 'L' && data[1] == 'O' && data[2] == 'O') {
        if (data[3] != 'P') {
            barTrend = (int) data[3];
        }//from w  w  w . j  a  v  a  2  s  . co  m
        type = (data[4] == 1) ? Type.LOOP : Type.LOOP2;
        barometer = convertTwoBytesToUnsignedInt(data[8], data[7]);
        insideTemp = convertTwoBytesToUnsignedInt(data[10], data[9]);
        insideHumidity = (int) data[11];
        outsideTemp = convertTwoBytesToUnsignedInt(data[13], data[12]);
        outsideHumidity = (int) data[33];
        windSpeed = (int) data[14];
        windDirection = convertTwoBytesToUnsignedInt(data[17], data[16]);
        dewPoint = convertTwoBytesToSignedInt(data[31], data[30]);
    } else {
        throw new ParseException(new String(data), 0);
    }
}

From source file:org.kuali.rice.kew.rule.KRAMetaRuleEngine.java

public KRAMetaRuleEngine(String expression) throws ParseException {
    this.expression = expression;
    statements = expression.split("\\s*[;\r\n]\\s*");

    if (statements.length == 0) {
        throw new ParseException("No statements parsed in expression: " + expression, 0);
    }//from w  ww.jav a  2  s .c  om
}

From source file:org.osaf.cosmo.model.text.XhtmlCollectionFormat.java

public CollectionItem parse(String source, EntityFactory entityFactory) throws ParseException {
    CollectionItem collection = entityFactory.createCollection();

    try {// w ww .j av  a 2s . c  o m
        if (source == null)
            throw new ParseException("Source has no XML data", -1);
        StringReader sr = new StringReader(source);
        XMLStreamReader reader = createXmlReader(sr);

        boolean inCollection = false;
        while (reader.hasNext()) {
            reader.next();
            if (!reader.isStartElement())
                continue;

            if (hasClass(reader, "collection")) {
                if (log.isDebugEnabled())
                    log.debug("found collection element");
                inCollection = true;
                continue;
            }

            if (inCollection && hasClass(reader, "name")) {
                if (log.isDebugEnabled())
                    log.debug("found name element");

                String name = reader.getElementText();
                if (StringUtils.isBlank(name))
                    throw new ParseException("Empty name not allowed",
                            reader.getLocation().getCharacterOffset());
                collection.setDisplayName(name);

                continue;
            }

            if (inCollection && hasClass(reader, "uuid")) {
                if (log.isDebugEnabled())
                    log.debug("found uuid element");

                String uuid = reader.getElementText();
                if (StringUtils.isBlank(uuid))
                    throw new ParseException("Empty uuid not allowed",
                            reader.getLocation().getCharacterOffset());
                collection.setUid(uuid);

                continue;
            }
        }

        reader.close();
    } catch (XMLStreamException e) {
        handleXmlException("Error reading XML", e);
    }

    return collection;
}

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

/**
 * Construct a CalendarFilter object from a DOM Element
 * @param element/*from w  w w  .j  a v a2  s .c  o  m*/
 * @throws ParseException
 */
public CalendarFilter(Element element, VTimeZone timezone) throws ParseException {
    // Can only have a single comp-filter element
    ElementIterator i = DomUtil.getChildren(element, ELEMENT_CALDAV_COMP_FILTER, NAMESPACE_CALDAV);
    if (!i.hasNext()) {
        throw new ParseException("CALDAV:filter must contain a comp-filter", -1);
    }

    Element child = i.nextElement();

    if (i.hasNext()) {
        throw new ParseException("CALDAV:filter can contain only one comp-filter", -1);
    }

    // Create new component filter and have it parse the element
    filter = new ComponentFilter(child, timezone);
}

From source file:com.teamsun.framework.util.DateUtil.java

/**
 * This method generates a string representation of a date/time
 * in the format you specify on input//w ww .  j  a v a2 s .  c o  m
 *
 * @param aMask the date pattern the string is in
 * @param strDate a string representation of a date
 * @return a converted Date object
 * @see java.text.SimpleDateFormat
 * @throws ParseException
 */
public static final Date convertStringToDate(String aMask, String strDate) throws ParseException {
    SimpleDateFormat df = null;
    Date date = null;
    df = new SimpleDateFormat(aMask);

    if (log.isDebugEnabled()) {
        log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'");
    }

    try {
        date = df.parse(strDate);
    } catch (ParseException pe) {
        //log.error("ParseException: " + pe);
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());
    }

    return (date);
}