List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.freedesktop.desktopentry.DesktopEntry.java
protected void initFromProperties(INIFile iniFile, Properties properties) throws IOException, ParseException { String typeName = properties.getProperty(TYPE, "").trim(); if (typeName.equals("")) { throw new ParseException("Type field is required.", 0); }//from www . java2s.co m type = Type.valueOf(typeName.toLowerCase()); if (type == null) { throw new ParseException("Invalid Type.", 0); } version = properties.getProperty(VERSION, "pre-standard").trim(); encoding = properties.getProperty(ENCODING, "").trim(); if (!encoding.equals("") && !encoding.equalsIgnoreCase("utf-8") && !encoding.equals("legacy-mixed")) { Log.warn(String.format("Invalid encoding, %s, defaulting to UTF-8", encoding)); encoding = "UTF-8"; } noDisplay = "true".equalsIgnoreCase(Util.emptyOrTrimmed(properties.getProperty(NO_DISPLAY))); hidden = "true".equalsIgnoreCase(Util.emptyOrTrimmed(properties.getProperty(HIDDEN))); filePattern = Util.splitList(properties.getProperty(FILE_PATTERN, "")); tryExec = Util.trimmedNonEmptyOrNull(properties.getProperty(TRY_EXEC)); exec = Util.trimmedNonEmptyOrNull(properties.getProperty(EXEC)); path = Util.trimmedNonEmptyOrNull(properties.getProperty(PATH)); terminal = "true".equalsIgnoreCase(Util.emptyOrTrimmed(properties.getProperty(TERMINAL))); swallowExec = Util.trimmedNonEmptyOrNull(properties.getProperty(SWALLOW_EXEC)); actions = Util.splitList(properties.getProperty(ACTIONS, "")); mimeType = Util.splitList(properties.getProperty(MIME_TYPE, "")); sortOrder = Util.trimmedNonEmptyOrNull(properties.getProperty(SORT_ORDER)); dev = Util.trimmedNonEmptyOrNull(properties.getProperty(DEV)); fSType = Util.trimmedNonEmptyOrNull(properties.getProperty(FS_TYPE)); mountPoint = Util.trimmedNonEmptyOrNull(properties.getProperty(MOUNT_POINT)); readOnly = "true".equalsIgnoreCase(Util.emptyOrTrimmed(properties.getProperty(READ_ONLY))); String url = Util.trimmedNonEmptyOrNull(properties.getProperty(URL)); if (url != null) { try { this.url = new URI(url); } catch (URISyntaxException e) { throw new ParseException(e.getMessage(), 0); } } categories = Util.splitList(properties.getProperty(CATEGORIES, "")); onlyShowIn = Util.splitList(properties.getProperty(ONLY_SHOW_IN, "")); notShowIn = Util.splitList(properties.getProperty(NOT_SHOW_IN, "")); if (onlyShowIn.size() > 0 && notShowIn.size() > 0) { throw new ParseException("Only OnlyShowIn or NotShowIn may be specified, not both.", 0); } startupNotify = "true".equalsIgnoreCase(Util.emptyOrTrimmed(properties.getProperty(STARTUP_NOTIFY))); startupWMClass = Util.trimmedNonEmptyOrNull(properties.getProperty(STARTUP_WM_CLASS)); }
From source file:org.kuali.rice.kew.rule.web.WebRuleBaseValues.java
private Timestamp decodeTimestamp(String dateValue) throws ParseException { if (org.apache.commons.lang.StringUtils.isEmpty(dateValue)) { return null; }/* w w w . j av a2 s. c om*/ /* Not the best solution below but does allow our forcing of the 4 digit year * until KEW and use the KNS for it's date entry/validation */ String convertedDate = SQLUtils.getEntryFormattedDate(dateValue); if (convertedDate == null) { throw new ParseException("Date entered as '" + dateValue + "' is in invalid format", 0); } Date date = RiceConstants.getDefaultDateFormat().parse(convertedDate); return new Timestamp(date.getTime()); }
From source file:com.examples.with.different.packagename.concolic.MathRuntimeException.java
/** * Constructs a new <code>ParseException</code> with specified * formatted detail message.//from w w w. j ava 2 s .c o m * Message formatting is delegated to {@link java.text.MessageFormat}. * @param offset offset at which error occurred * @param pattern format specifier * @param arguments format arguments * @return built exception */ public static ParseException createParseException(final int offset, final String pattern, final Object... arguments) { return new ParseException(buildMessage(Locale.US, pattern, arguments), offset) { /** Serializable version identifier. */ private static final long serialVersionUID = -1103502177342465975L; /** {@inheritDoc} */ @Override public String getLocalizedMessage() { return buildMessage(Locale.getDefault(), pattern, arguments); } }; }
From source file:de.betterform.xml.xforms.ui.AbstractFormControl.java
private BigDecimal strictParse(String value, Locale locale) throws ParseException { DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.setParseBigDecimal(true);//from www. j av a2s . c o m value = value.trim(); ParsePosition pos = new ParsePosition(0); BigDecimal number = (BigDecimal) format.parse(value, pos); boolean okay = pos.getIndex() == value.length() && pos.getErrorIndex() == -1; if (!okay) throw new ParseException("Could not parse '" + value + "' as a number", pos.getErrorIndex()); return number; }
From source file:hk.idv.kenson.jrconsole.Console.java
/** * Parsing the string into the specified value (with right data-type) * @param arg/*from ww w . jav a 2 s . co m*/ * @return * @throws java.text.ParseException */ public static Object parseVal(String arg, Map<String, Object> params) throws java.text.ParseException { try { if (arg == null) return null; if (arg.startsWith("boolean:")) return Boolean.valueOf(arg.substring(8)); if (arg.startsWith("int:")) return Integer.valueOf(arg.substring(4)); if (arg.startsWith("long:")) return Long.valueOf(arg.substring(5)); if (arg.startsWith("double:")) return Double.valueOf(arg.substring(7)); if (arg.startsWith("url:")) return new URL(arg.substring(4)); if (arg.startsWith("date:")) return getDateFormat().parse(arg.substring(5)); if (arg.startsWith("decimal:")) return getDecimalFormat().parse(arg.substring(8)); if (arg.startsWith("stream:")) return new URL(arg.substring(7)).openStream(); if (arg.startsWith("string:")) return arg.substring(7); if (arg.startsWith("locale:")) return getLocale(arg.substring(7)); if (arg.startsWith("properties:")) return getProperties(arg.substring(11)); if (arg.startsWith("bundle:")) { Object locale = params.get(PARAM_LOCALE); if (locale == null) locale = Locale.getDefault(); if (!(locale instanceof Locale)) throw new IllegalArgumentException( "parameter[" + PARAM_LOCALE + "] is reserved for the locale specification. "); return getBundle(arg.substring(7), (Locale) locale); } return arg; } catch (MalformedURLException e) { throw new ParseException("Cannot create the url: " + arg.substring(4), 0); } catch (IOException e) { throw new ParseException("Cannot open the stream: " + arg.substring(7), 0); } }
From source file:graphene.util.StringUtils.java
public static String[] splitKeyValue(final String aLine) throws ParseException { final String line = clean(aLine); if (line == null) { return null; }// w w w .j a va2 s .c o m String[] split = line.split(" ", 2); if (split.length != 2) { // fallback to checking for an equals sign split = line.split("=", 2); if (split.length != 2) { final String msg = "Unable to determine Key/Value pair from line [" + line + "]. There is no space from " + "which the split location could be determined."; throw new ParseException(msg, 0); } } split[0] = clean(split[0]); split[1] = clean(split[1]); if (split[1].startsWith("=")) { // they used spaces followed by an equals followed by zero or more // spaces to split the key/value pair, so // remove the equals sign to result in only the key and values in // the split[1] = clean(split[1].substring(1)); } if (split[0] == null) { final String msg = "No valid key could be found in line [" + line + "] to form a key/value pair."; throw new ParseException(msg, 0); } if (split[1] == null) { final String msg = "No corresponding value could be found in line [" + line + "] for key [" + split[0] + "]"; throw new ParseException(msg, 0); } return split; }
From source file:org.archive.wayback.accesscontrol.ui.AdministrativeExclusionServlet.java
private void handleRuleCreate(AdministrativeExclusionAuthority auth, Map<String, String[]> queryMap) throws ParseException, URIException, DatabaseException { AdministrativeExclusionRule rule = new AdministrativeExclusionRule(); String start = getRequiredMapParam(queryMap, MODIFY_FORM_START); String startDateStr = Timestamp.padStartDateStr(start); if (!startDateStr.equals(start)) { throw new ParseException("invalid value: " + MODIFY_FORM_START, 0); }/*from www . j av a 2 s .co m*/ String end = getRequiredMapParam(queryMap, MODIFY_FORM_END); String endDateStr = Timestamp.padEndDateStr(end); if (!endDateStr.equals(end)) { throw new ParseException("invalid value: " + MODIFY_FORM_END, 0); } String type = getRequiredMapParam(queryMap, MODIFY_FORM_TYPE); if (type.equals(MODIFY_FORM_TYPE_EXCLUDE_VALUE)) { rule.setExclude(); } else if (type.equals(MODIFY_FORM_TYPE_INCLUDE_VALUE)) { rule.setInclude(); } else if (type.equals(MODIFY_FORM_TYPE_ROBOTS_VALUE)) { rule.setRobots(); } else if (type.equals(MODIFY_FORM_TYPE_NOROBOTS_VALUE)) { rule.setNoRobots(); } else { throw new ParseException("invalid value: " + MODIFY_FORM_TYPE, 0); } String mod = getRequiredMapParam(queryMap, MODIFY_FORM_MOD); if (mod.equals(MODIFY_FORM_MOD_ADD_VALUE)) { rule.setAdd(); } else if (mod.equals(MODIFY_FORM_MOD_DELETE_VALUE)) { rule.setDelete(); } else { throw new ParseException("invalid value: " + MODIFY_FORM_MOD, 0); } String who = getRequiredMapParam(queryMap, MODIFY_FORM_WHO); String why = getRequiredMapParam(queryMap, MODIFY_FORM_WHY); String url = getMapParam(queryMap, MODIFY_FORM_URL); String surt = getMapParam(queryMap, MODIFY_FORM_SURT); if (surt == null) { if (url == null) { throw new ParseException("Missing argument " + MODIFY_FORM_URL, 0); } String prefix = getMapParam(queryMap, MODIFY_FORM_PREFIX); if (prefix == null || !prefix.equals(MODIFY_FORM_PREFIX_YES_VALUE)) { surt = SURTTokenizer.exactKey(url); } else { surt = SURTTokenizer.prefixKey(url); } } rule.setWho(who); rule.setWhy(why); rule.setWhen(new Date().getTime()); rule.setStartDateStr(startDateStr); rule.setEndDateStr(endDateStr); auth.addRuleFor(surt, rule); }
From source file:com.orange.clara.cloud.servicedbdumper.service.DbDumperServiceInstanceService.java
protected Date parseDate(String date) throws ParseException { SimpleDateFormat simpleDateFormat; Date createdAt = null;//from ww w . j a va2 s . c o m for (String validDateFormat : VALID_DATES_FORMAT) { simpleDateFormat = new SimpleDateFormat(validDateFormat); try { createdAt = simpleDateFormat.parse(date); break; } catch (ParseException e) { createdAt = null; } } if (createdAt == null) { throw new ParseException("Cannot parse date", 0); } return createdAt; }
From source file:uk.ac.ucl.excites.sapelli.storage.model.columns.StringColumn.java
/** * If {@code undelimited} is {@code false} the given {@code valueString} is expected to be wrapped/escaped using {@link #serialisationDelimiter}s. * /*from w w w . java 2 s. c o m*/ * @see uk.ac.ucl.excites.sapelli.storage.model.ListLikeColumn#parse(java.lang.String, boolean) * @see #toString(String, boolean) */ @Override public String parse(String valueString, boolean undelimited) throws ParseException, IllegalArgumentException, NullPointerException { if (!undelimited) { // Perform delimiter checks: if (valueString.length() < 2) throw new ParseException("String is not delimited by " + serialisationDelimiter + "s", 0); if (valueString.charAt(0) != serialisationDelimiter) throw new ParseException("String does not begin with " + serialisationDelimiter, 0); if (valueString.charAt(valueString.length() - 1) != serialisationDelimiter) throw new ParseException("String does not end with " + serialisationDelimiter, valueString.length() - 1); // Remove serialisationDelimiters: return StringUtils.deescapeByDoublingAndWrapping(valueString, serialisationDelimiter); } else return valueString; }
From source file:org.apache.openejb.math.MathRuntimeException.java
/** * Constructs a new <code>ParseException</code> with specified * formatted detail message./*ww w .jav a 2 s. c o m*/ * Message formatting is delegated to {@link MessageFormat}. * * @param offset offset at which error occurred * @param pattern format specifier * @param arguments format arguments * @return built exception */ public static ParseException createParseException(final int offset, final String pattern, final Object... arguments) { return new ParseException(null, offset) { /** Serializable version identifier. */ private static final long serialVersionUID = -1103502177342465975L; /** {@inheritDoc} */ @Override public String getMessage() { return buildMessage(Locale.US, pattern, arguments); } /** {@inheritDoc} */ @Override public String getLocalizedMessage() { return buildMessage(Locale.getDefault(), pattern, arguments); } }; }