List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.op4j.functions.FnCalendar.java
protected static Calendar fromInts(final Integer year, final Integer month, final Integer day, final Integer hour, final Integer minute, final Integer second, final Integer milli) throws Exception { /*/*from w ww . j a v a 2 s. c o m*/ * None of the Integers can be null */ Validate.notNull(year); Validate.notNull(month); Validate.notNull(day); Validate.notNull(hour); Validate.notNull(minute); Validate.notNull(second); Validate.notNull(milli); Integer safeYear = year; String yearAsString = year.toString(); if ((safeYear.intValue() >= 0) && (yearAsString.length() <= 2)) { final SimpleDateFormat sdf = new SimpleDateFormat("yy"); final Calendar calendar = Calendar.getInstance(); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Date date = sdf.parse(yearAsString, pp); if (pp.getIndex() != yearAsString.length()) { throw new ParseException("The whole input String does not represent a valid Date", pp.getIndex()); } calendar.setTime(date); safeYear = Integer.valueOf(calendar.get(Calendar.YEAR)); } final Calendar result = Calendar.getInstance(); result.set(Calendar.YEAR, safeYear.intValue()); result.set(Calendar.MONTH, month.intValue() - 1); result.set(Calendar.DAY_OF_MONTH, day.intValue()); result.set(Calendar.HOUR_OF_DAY, hour.intValue()); result.set(Calendar.MINUTE, minute.intValue()); result.set(Calendar.SECOND, second.intValue()); result.set(Calendar.MILLISECOND, milli.intValue()); return result; }
From source file:org.op4j.functions.FnDate.java
protected static Date fromInts(final Integer year, final Integer month, final Integer day, final Integer hour, final Integer minute, final Integer second, final Integer milli) throws Exception { /*/* w ww . jav a 2s. c om*/ * None of the Integers can be null */ Validate.notNull(year); Validate.notNull(month); Validate.notNull(day); Validate.notNull(hour); Validate.notNull(minute); Validate.notNull(second); Validate.notNull(milli); Integer safeYear = year; String yearAsString = year.toString(); if ((safeYear.intValue() >= 0) && (yearAsString.length() <= 2)) { final SimpleDateFormat sdf = new SimpleDateFormat("yy"); final Calendar calendar = Calendar.getInstance(); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Date date = sdf.parse(yearAsString, pp); if (pp.getIndex() != yearAsString.length()) { throw new ParseException("The whole input String does not represent a valid Date", pp.getIndex()); } calendar.setTime(date); safeYear = Integer.valueOf(calendar.get(Calendar.YEAR)); } final Calendar result = Calendar.getInstance(); result.set(Calendar.YEAR, safeYear.intValue()); result.set(Calendar.MONTH, month.intValue() - 1); result.set(Calendar.DAY_OF_MONTH, day.intValue()); result.set(Calendar.HOUR_OF_DAY, hour.intValue()); result.set(Calendar.MINUTE, minute.intValue()); result.set(Calendar.SECOND, second.intValue()); result.set(Calendar.MILLISECOND, milli.intValue()); return result.getTime(); }
From source file:nl.nn.adapterframework.parameters.Parameter.java
private String format(ParameterValueList alreadyResolvedParameters, ParameterResolutionContext prc) throws ParameterException { int startNdx = -1; int endNdx = 0; // replace the named parameter with numbered parameters StringBuffer formatPattern = new StringBuffer(); List<Object> params = new ArrayList<Object>(); int paramPosition = 0; while (endNdx != -1) { // get name of parameter in pattern to be substituted startNdx = pattern.indexOf("{", endNdx); if (startNdx == -1) { formatPattern.append(pattern.substring(endNdx)); break; } else if (endNdx != -1) { formatPattern.append(pattern.substring(endNdx, startNdx)); }/* w w w . j a v a 2 s .com*/ int tmpEndNdx = pattern.indexOf("}", startNdx); endNdx = pattern.indexOf(",", startNdx); if (endNdx == -1 || endNdx > tmpEndNdx) { endNdx = tmpEndNdx; } if (endNdx == -1) { throw new ParameterException(new ParseException("Bracket is not closed", startNdx)); } String substitutionName = pattern.substring(startNdx + 1, endNdx); // get value Object substitutionValue = getValueForFormatting(alreadyResolvedParameters, prc, substitutionName); params.add(substitutionValue); formatPattern.append('{').append(paramPosition++); } return MessageFormat.format(formatPattern.toString(), params.toArray()); }
From source file:com.adito.core.CoreUtil.java
/** * @param parameterList//from w ww . j a v a 2s . c o m * @return Properties * @throws ParseException */ public static Properties parseActionParameter(String parameterList) throws ParseException { Properties p = new Properties(); String[] properties = parameterList.split(","); for (int i = 0; i < properties.length; i++) { String n = properties[i]; int idx = n.indexOf('='); if (idx == -1) { throw new ParseException("Parameter list in incorrect format. [<name>=<value>[,<name>=<value>] ..]", 0); } String v = n.substring(idx + 1); n = n.substring(0, idx); p.setProperty(n, v); } return p; }
From source file:gov.nasa.arc.spife.core.plan.advisor.resources.ProfileConstraintPlanAdvisor.java
private Object parseValue(Profile profile, String valueLiteral) throws ParseException { Object value = null;/* www . ja v a 2 s . c o m*/ if (valueLiteral == null) { return null; } else { EDataType dataType = profile.getDataType(); try { if (dataType != null) { EPackage ePackage = dataType.getEPackage(); EFactory eFactory = ePackage.getEFactoryInstance(); value = eFactory.createFromString(dataType, valueLiteral); } } catch (Exception x) { if (EcorePackage.Literals.EINT == dataType || EcorePackage.Literals.EINTEGER_OBJECT == dataType) { try { Double doubleValue = Double.parseDouble(valueLiteral); int intValue = doubleValue.intValue(); if (doubleValue == intValue) { return intValue; } } catch (Exception e) { // tried to parse double as an integer } } } if (value == null) { throw new ParseException("Cannot parse " + valueLiteral, 0); } } return value; }
From source file:org.lockss.daemon.OpenUrlResolver.java
/** * Resolve serials article based on the SICI descriptor. For an article * "Who are These Independent Information Brokers?", Bulletin of the * American Society for Information Science, Feb-Mar 1995, Vol. 21, no 3, * page 12, the SICI would be: 0095-4403(199502/03)21:3<12:WATIIB>2.0.TX;2-J * /*from w w w .j a v a 2 s. co m*/ * @param sici a string representing the serials article SICI * @return the article url or <code>null</code> if not resolved * @throws ParseException if error parsing SICI */ public OpenUrlInfo resolveFromSici(String sici) throws ParseException { int i = sici.indexOf('('); if (i < 0) { // did not find end of date section throw new ParseException("Missing start of date section", 0); } // validate ISSN after normalizing to remove punctuation String issn = sici.substring(0, i).replaceFirst("-", ""); if (!MetadataUtil.isIssn(issn)) { // ISSN is 8 characters throw new ParseException("Malformed ISSN", 0); } // skip over date section (199502/03) int j = sici.indexOf(')', i + 1); if (j < 0) { // did not find end of date section throw new ParseException("Missing end of date section", i + 1); } // get volume and issue between end of // date section and start of article section i = j + 1; // advance to start of volume j = sici.indexOf('<', i); if (j < 0) { // did not find start of issue section throw new ParseException("Missing start of issue section", i); } // get volume delimiter int k = sici.indexOf(':', i); if ((k < 0) || (k >= j)) { // no volume delimiter before start of issue section throw new ParseException("Missing volume delimiter", i); } String volume = sici.substring(i, k); String issue = sici.substring(k + 1, j); // get end of issue section i = j + 1; k = sici.indexOf('>', i + 1); if (k < 0) { // did not find end of issue section throw new ParseException("Missing end of issue section", i + 1); } j = sici.indexOf(':', i + 1); if ((j < 0) || (j >= k)) { throw new ParseException("Missing page delimiter", i + 1); } String spage = sici.substring(i, j); // get the cached URL from the parsed paramaters // note: no publisher with sici OpenUrlInfo resolved = resolveFromIssn(issn, null, null, volume, issue, spage, null, null, null); if ((resolved.resolvedTo != OpenUrlInfo.ResolvedTo.NONE) && log.isDebug()) { // report on the found article Tdb tdb = ConfigManager.getCurrentConfig().getTdb(); String jTitle = null; if (tdb != null) { TdbTitle title = tdb.getTdbTitleByIssn(issn); if (title != null) { jTitle = title.getName(); } } if (log.isDebug3()) { String s = "Located cachedURL " + ((resolved.resolvedUrl == null) ? "" : resolved.resolvedUrl) + " for ISSN " + issn + ", volume: " + volume + ", issue: " + issue + ", start page: " + spage; if (jTitle != null) { s += ", journal title \"" + jTitle + "\""; } log.debug3(s); } } return noOpenUrlInfo; }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java
/** * @param criteriaEntry - String of comma-delimited entries * @return Array of formatted criteria//from w w w. ja v a2 s. co m * @throws ParseException */ protected Object[] parseCriteria(final String origCriteriaEntry) throws ParseException { String[] raw; UIFieldFormatterIFace formatter = fieldQRI.getFormatter(); boolean isNumericCatNum = (formatter instanceof CatalogNumberUIFieldFormatter && ((CatalogNumberUIFieldFormatter) formatter).isNumeric()); String criteriaEntry = origCriteriaEntry; if (isNumericCatNum) { criteriaEntry = CatalogNumberFormatter.preParseNumericCatalogNumbersWithSeries(origCriteriaEntry, formatter); } if (operatorCBX.getSelectedItem() == SpQueryField.OperatorType.BETWEEN || operatorCBX.getSelectedItem() == SpQueryField.OperatorType.IN || formatter instanceof CatalogNumberUIFieldFormatter) //',' in numeric catnums cause stack traces, and they are invalid in string catnums so don't allow them) { raw = criteriaEntry.split(","); } else { raw = new String[1]; raw[0] = criteriaEntry; } if (operatorCBX.getSelectedItem() == SpQueryField.OperatorType.BETWEEN) { if (raw.length != 2) { throw new ParseException(getLabel() + " - " + UIRegistry.getResourceString("QB_INVALID_CRITERIA"), -1); } } else if (operatorCBX.getSelectedItem() != SpQueryField.OperatorType.IN) { if (raw.length != 1) { throw new ParseException(getLabel() + " - " + UIRegistry.getResourceString("QB_INVALID_CRITERIA"), -1); } } Object[] result = new Object[raw.length]; for (int e = 0; e < raw.length; e++) { try { if (isNumericCatNum) { Pair<String, String> series = getSerStartEnd(raw[e].trim()); formatter.formatFromUI(series.getFirst()); formatter.formatFromUI(series.getSecond()); if (!series.getSecond().equals(raw[e].trim())) { result[e] = series; } else { result[e] = series.getFirst(); } } else { result[e] = formatter != null ? formatter.formatFromUI(raw[e].trim()) : raw[e].trim(); } } catch (Exception ex) { throw new ParseException(getLabel() + " - " + String.format(UIRegistry.getResourceString("QB_PARSE_ERROR"), ex.getLocalizedMessage()), -1); } } return result; }
From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java
private static void readExtraData(Reader reader) throws IOException, ParseException { char dquote = '"'; StreamTokenizer tokenizer = new StreamTokenizer(reader); tokenizer.resetSyntax();/*w ww . j a v a 2 s . c om*/ tokenizer.wordChars(32, 126); tokenizer.whitespaceChars(' ', ' '); tokenizer.whitespaceChars('\t', '\t'); tokenizer.whitespaceChars(0, 20); tokenizer.commentChar('#'); tokenizer.quoteChar(dquote); tokenizer.eolIsSignificant(true); List<String> tokenList = new ArrayList<String>(); LineType lineType = LineType.UNKNOWN; boolean atLineStart = true; int ttype; int prevTtype = StreamTokenizer.TT_EOL; // used for empty line detection while ((ttype = tokenizer.nextToken()) != StreamTokenizer.TT_EOF) { int lineNum = tokenizer.lineno(); if (ttype == StreamTokenizer.TT_WORD || ttype == dquote) { String token = tokenizer.sval; if (atLineStart) { lineType = LineType.lookUp(token); if (LineType.UNKNOWN.equals(lineType)) throw new ParseException("Invalid line type", lineNum); } else { tokenList.add(token); } atLineStart = false; } else if (ttype == StreamTokenizer.TT_EOL) { if (prevTtype == StreamTokenizer.TT_EOL) { prevTtype = ttype; continue; } atLineStart = true; switch (lineType) { case PRIMARYZONE: if (tokenList.size() < 1) throw new ParseException("Not enough fields in a PrimaryZone line", lineNum); String primaryTZID = tokenList.get(0); sPrimaryTZIDs.add(primaryTZID); break; case ZONEMATCHSCORE: if (tokenList.size() < 2) throw new ParseException("Not enough fields in a ZoneMatchScore line", lineNum); String zoneName = tokenList.get(0); String zoneMatchScoreStr = tokenList.get(1); int zoneMatchScore = 0; try { zoneMatchScore = Integer.parseInt(zoneMatchScoreStr); } catch (NumberFormatException e) { throw new ParseException("Zone match score must be an integer: " + zoneMatchScoreStr, lineNum); } sMatchScores.put(zoneName, zoneMatchScore); break; } if (atLineStart) { tokenList.clear(); lineType = LineType.UNKNOWN; } } else if (ttype == StreamTokenizer.TT_NUMBER) { // shouldn't happen throw new ParseException("Invalid parser state: TT_NUMBER found", lineNum); } prevTtype = ttype; } }
From source file:com.zimbra.perf.chart.ChartUtil.java
private void validateChartSettings(List<ChartSettings> allSettings) throws ParseException { // Make sure we're not writing the same chart twice Set<String> usedFilenames = new HashSet<String>(); for (ChartSettings cs : allSettings) { String filename = cs.getOutfile(); if (usedFilenames.contains(filename)) { throw new ParseException("Found two charts that write " + filename, 0); }//from w w w.j a v a 2s . c om usedFilenames.add(filename); } }
From source file:org.lockss.daemon.OpenUrlResolver.java
/** * Resolve a book chapter based on the BICI descriptor. For an item "English * as a World Language", Chapter 10, in "The English Language: A Historical * Introduction", 1993, pp. 234-261, ISBN 0-521-41620-5, the BICI would be * 0521416205(1993)(10;EAAWL;234-261)2.2.TX;1-1 * /*from www . j a va 2 s . c o m*/ * @param bici a string representing the book chapter BICI * @return the article url or <code>null</code> if not resolved * @throws ParseException if error parsing BICI */ public OpenUrlInfo resolveFromBici(String bici) throws ParseException { int i = bici.indexOf('('); if (i < 0) { // did not find end of date section throw new ParseException("Missing start of date section", 0); } String isbn = bici.substring(0, i).replaceAll("-", ""); // match ISBN-10 or ISBN-13 with 0-9 or X checksum character if (!MetadataUtil.isIsbn(isbn, false)) { // ISSB is 10 or 13 characters throw new ParseException("Malformed ISBN", 0); } // skip over date section (1993) int j = bici.indexOf(')', i + 1); if (j < 0) { // did not find end of date section throw new ParseException("Missing end of date section", i + 5); } String date = bici.substring(i + 1, j); // get volume and issue between end of // date section and start of article section if (bici.charAt(j + 1) != '(') { // did not find start of chapter section throw new ParseException("Missing start of chapter section", j + 1); } i = j + 2; // advance to start of chapter j = bici.indexOf(')', i); if (j < 0) { // did not find end of chapter section throw new ParseException("Missing end of chapter section", i); } // get chapter number delimiter int k = bici.indexOf(';', i); if ((k < 0) || (k >= j)) { // no chapter number delimiter before end of chapter section throw new ParseException("Missing chapter number delimiter", i); } String chapter = bici.substring(i, k); // get end of chapter section i = k + 1; k = bici.indexOf(';', i + 1); if ((k < 0) || (k >= j)) { // no chapter abbreviation delimiter before end of chapter section throw new ParseException("Missing chapter abbreviation delimiter", i); } // extract the start page String spage = bici.substring(k + 1, j); if (spage.indexOf('-') > 0) { spage = spage.substring(0, spage.indexOf('-')); } // (isbn, date, volume, edition, chapter, spage, author, title) // note: no publisher specified with bici OpenUrlInfo resolved = resolveFromIsbn(isbn, null, date, null, null, chapter, spage, null, null); if ((resolved.resolvedTo != OpenUrlInfo.ResolvedTo.NONE) && log.isDebug()) { Tdb tdb = ConfigManager.getCurrentConfig().getTdb(); String bTitle = null; if (tdb != null) { Collection<TdbAu> tdbAus = tdb.getTdbAusByIsbn(isbn); if (!tdbAus.isEmpty()) { bTitle = tdbAus.iterator().next().getPublicationTitle(); } } if (log.isDebug3()) { String s = "Located cachedURL " + ((resolved.resolvedUrl == null) ? "" : resolved.resolvedUrl) + " for ISBN " + isbn + ", year: " + date + ", chapter: " + chapter + ", start page: " + spage; if (bTitle != null) { s += ", book title \"" + bTitle + "\""; } log.debug3(s); } } return noOpenUrlInfo; }