List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:com.maydesk.base.util.PDUtil.java
public static int[] htmlColorToIntRGBArray(String str) throws ParseException { if (str == null) { throw new NullPointerException("str == null"); }/*from w ww . ja v a 2 s .c om*/ str = str.trim(); if (str.length() != 7) { throw new ParseException("str.length() != 7", 0); } if (!str.startsWith("#")) { throw new ParseException("!str.startsWith(\"#\")", 0); } int[] ret = new int[3]; ret[0] = Integer.parseInt(str.substring(1, 3), 16); ret[1] = Integer.parseInt(str.substring(3, 5), 16); ret[2] = Integer.parseInt(str.substring(5, 7), 16); return ret; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityJsonParser.java
@Override protected ActivityContext prepareItem(TNTInputStream<?, ?> stream, Object data) throws ParseException { DocumentContext jsonDoc;/* w ww . j av a2 s . c o m*/ String jsonString = null; try { if (data instanceof DocumentContext) { jsonDoc = (DocumentContext) data; } else if (data instanceof InputStream) { jsonDoc = JsonPath.parse((InputStream) data); } else { jsonString = getNextActivityString(data); if (StringUtils.isEmpty(jsonString)) { return null; } jsonDoc = JsonPath.parse(jsonString); } } catch (Exception e) { ParseException pe = new ParseException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityJsonParser.jsonDocument.parse.error"), 0); pe.initCause(e); throw pe; } if (jsonString == null) { jsonString = jsonDoc.jsonString(); } ActivityContext cData = new ActivityContext(stream, data, jsonDoc); cData.setMessage(jsonString); return cData; }
From source file:it.geosolutions.opensdi2.mvc.SessionController.java
/** Transform ISO 8601 string to Calendar. */ public static Calendar toCalendar(final String iso8601string) throws ParseException { Calendar calendar = GregorianCalendar.getInstance(); String s = iso8601string.replace("Z", "+00:00"); try {//w ww . j a v a2s . c o m s = s.substring(0, 22) + s.substring(23); // to get rid of the ":" } catch (IndexOutOfBoundsException e) { throw new ParseException("Invalid length", 0); } Date date = expireParser.parse(s); calendar.setTime(date); return calendar; }
From source file:com.arcao.geocaching.api.data.coordinates.CoordinatesParser.java
protected static ParseResult parse(String coordinate, CoordinateType coordinateType) throws ParseException { Pattern pattern;//from w ww .j a v a 2 s . c om switch (coordinateType) { case LAT_UNSAFE: pattern = LATITUDE_PATTERN_UNSAFE; break; case LON_UNSAFE: pattern = LONGITUDE_PATTERN_UNSAFE; break; case LON: pattern = LONGITUDE_PATTERN; break; case LAT: default: pattern = LATITUDE_PATTERN; break; } final Matcher matcher = pattern.matcher(coordinate); if (matcher.find()) { double sign = matcher.group(1).equalsIgnoreCase("S") || matcher.group(1).equalsIgnoreCase("W") ? -1.0 : 1.0; double degree = Double.parseDouble(matcher.group(2)); if (degree < 0) { sign = -1; degree = Math.abs(degree); } double minutes = 0.0; double seconds = 0.0; if (matcher.group(3) != null) { minutes = Double.parseDouble(matcher.group(3)); if (matcher.group(4) != null) { seconds = Double.parseDouble("0." + matcher.group(4)) * 60.0; } else if (matcher.group(5) != null) { seconds = Double.parseDouble(matcher.group(5).replace(",", ".")); } } double result = sign * (degree + minutes / 60.0 + seconds / 3600.0); // normalize result switch (coordinateType) { case LON_UNSAFE: case LON: result = normalize(result, -180, 180); break; case LAT_UNSAFE: case LAT: default: result = normalize(result, -90, 90); break; } return new ParseResult(result, matcher.start(), matcher.group().length()); } else { // Nothing found with "N 52...", try to match string as decimaldegree try { final String[] items = StringUtils.split(coordinate.trim()); if (items.length > 0) { final int index = (coordinateType == CoordinateType.LON ? items.length - 1 : 0); final int pos = (coordinateType == CoordinateType.LON ? coordinate.lastIndexOf(items[index]) : coordinate.indexOf(items[index])); return new ParseResult(Double.parseDouble(items[index]), pos, items[index].length()); } } catch (NumberFormatException e) { logger.error(e.getMessage(), e); } } throw new ParseException("Could not parse coordinate: \"" + coordinate + "\"", 0); }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityStringParser.java
/** * Gets field raw data value resolved by locator. * * @param locator// w ww . jav a2 s . c om * activity field locator * @param cData * activity data carrier object * @param formattingNeeded * flag to set if value formatting is not needed * @return substring value resolved by locator, or {@code null} if value is not resolved */ @Override protected Object resolveLocatorValue(ActivityFieldLocator locator, ActivityContext cData, AtomicBoolean formattingNeeded) throws ParseException { Object val = null; String locStr = locator.getLocator(); try { IntRange range = IntRange.getRange(locStr, true); val = StringUtils.substring(cData.getData(), range.getFrom(), range.getTo()); } catch (Exception exc) { ParseException pe = new ParseException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityStringParser.range.exception"), 0); pe.initCause(exc); throw pe; } return val; }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlTimestampConverter.java
private Date parseDate(String str, String[] parsePatterns, Locale locale) throws ParseException { if ((str == null) || (parsePatterns == null)) { throw new IllegalArgumentException("Date and Patterns must not be null"); }/*from www. j a v a 2 s . c om*/ SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { parser = new SimpleDateFormat(parsePatterns[0], locale); } else { parser.applyPattern(parsePatterns[i]); } pos.setIndex(0); Date date = parser.parse(str, pos); if ((date != null) && (pos.getIndex() == str.length())) { return date; } } throw new ParseException("Unable to parse the date: " + str, -1); }
From source file:com.freiheit.fuava.sftp.util.FilenameUtil.java
/** * Cuts the date from a filename and returns it as a string: * YYYYMMDD_hhmmss.//from w w w. ja v a2 s . c o m */ @CheckForNull private static String getDateFromFilenameWithDelimiter(final String filename) throws ParseException { final String[] split = filename.replace(".ok", "").replace(".zip", "").replace(".csv", "") .split(FILENAME_DELIMITER); // the assumption is, that the date and time is the second last and last part of the filename. try { return split[split.length - 2] + FILENAME_DELIMITER + split[split.length - 1]; } catch (final IndexOutOfBoundsException e) { LOG.error("Could not extract date and time from line: " + filename); throw new ParseException("Could not extract date and time from line: " + filename, 0); } }
From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java
private List<LevelRevisionInfo> parseLevelLines(List<String> levelLines) throws ParseException { List<LevelRevisionInfo> infos = new ArrayList<LevelRevisionInfo>(); for (String line : levelLines) { Matcher m = LEVEL_INFO_PATTERN.matcher(line); if (m.matches()) { String name = m.group(1).trim(); String release = m.group(2).trim(); String revision = m.group(3).trim(); infos.add(new LevelRevisionInfo(name, release, revision)); } else {/* ww w. j av a 2 s.com*/ throw new ParseException("Failed to parse the revision info in '" + line + "'", 0); } } return infos; }
From source file:org.manalith.ircbot.plugin.keyseqconv.DubeolAutomataEngine.java
@Override public String parseKeySequenceToKorean(String keySequence) throws ParseException, IllegalArgumentException { String result = ""; LetterState stateFlag = LetterState.Null; String tICon = ""; String tIConLookahead = ""; String tIConLookaheadCombination = ""; String tVow = ""; String tVowLookahead = ""; String tVowLookaheadCombination = ""; String tFCon = ""; String tFConLookahead = ""; String tFConLookaheadCombination = ""; LetterObject syl = new LetterObject(KeyboardLayout.Dubeol); if (isEnableParsingExceptionSyntax() && StringUtils.countMatches(keySequence, "\\") % 2 == 1) throw new ParseException("Back slashes do not match", keySequence.lastIndexOf("\\", 0)); for (int i = 0; i < keySequence.length(); i++) { if (stateFlag.equals(LetterState.Null) || stateFlag.equals(LetterState.Finish)) { stateFlag = LetterState.IConsonant; }//from w w w . j a va2 s . c om if (!CharUtils.isAsciiAlpha(keySequence.charAt(i))) { if (keySequence.charAt(i) == '\\' && isEnableParsingExceptionSyntax()) { if (i < keySequence.length() - 1) if (keySequence.charAt(i + 1) == '\\') { result += "\\"; continue; } i++; while (true) { if (i + 1 <= keySequence.length() - 1) { if (keySequence.charAt(i) == '\\') { if (keySequence.charAt(i + 1) == '\\') { i++; result += '\\'; } else break; } else { result += keySequence.charAt(i); } } else { if (keySequence.charAt(i) == '\\') { break; } else { result += keySequence.charAt(i); } } i++; } } else { result += keySequence.charAt(i); } continue; } // (??, ???) if (stateFlag.equals(LetterState.IConsonant)) { // ? tIConLookahead = tIConLookaheadCombination = ""; // ?? ? ? ? ? tICon = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { // ?? ? ? ? ? tIConLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tIConLookaheadCombination = tICon + tIConLookahead; } // ??? ??? ?, ? ?. // ( , ? ) if (isFConsonant(tIConLookaheadCombination)) { // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i + 2)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); // ?? ? , ?? ? ?, , ? if (isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep) || !CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { result += getSingleChar(getSingleCharVal(tIConLookaheadCombination)); i++; } // ?? ? ? else if (isVowel(lookOverTwoStep)) { // ??? ? ? result += getSingleChar(getSingleCharVal(tICon)); continue; } } // ? ? () ?? ? else { result += getSingleChar(getSingleCharVal(tIConLookaheadCombination)); stateFlag = LetterState.Null; break; } } // ???, ??? ( () ?? ) else { // ??? ? ? if (isISingleConsonant(tICon) || isIDoubleConsonant(tICon)) { syl.setIConsonant(tICon); // init = DubeolSymbol.DubeolIConsonant.valueOf(tICon); } // ?? ??? ? ? else if (isVowel(tICon)) { stateFlag = LetterState.Vowel; i--; continue; } // ? ? ? ?? ? if (i == keySequence.length() - 1) { result += getSingleChar(getSingleCharVal(tICon)); syl.initLetter(); stateFlag = LetterState.Null; break; } // ??? ? ? ?? ?? ? ? if (isVowel(tIConLookahead)) { stateFlag = LetterState.Vowel; continue; } // ??? ? else { result += getSingleChar(getSingleCharVal(tICon)); syl.initLetter(); } } } // (?) else if (stateFlag.equals(LetterState.Vowel)) { // ? tVowLookahead = tVowLookaheadCombination = ""; // ?? ? ? ? ? tVow = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { // ?? ? ? ? ? tVowLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tVowLookaheadCombination = tVow + tVowLookahead; } // ?? ? if (isVowel(tVowLookaheadCombination)) { syl.setVowel(tVowLookaheadCombination); // vow = // DubeolSymbol.DubeolVowel.valueOf(tVowLookaheadCombination); // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { // ?? ? ? ? ? String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i + 2)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); i++; // ?? ?? ? ? ? , ? ?? ??? . // ?? ??? ? ? ? ? if (isVowel(lookOverTwoStep) || ((isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep)) && !isFConsonant(lookOverTwoStep))) { stateFlag = LetterState.Finish; } // ?? ? ? ? ? , ex: else if (isFConsonant(lookOverTwoStep)) { if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); stateFlag = LetterState.Null; } else { stateFlag = LetterState.FConsonant; continue; } } // ? ? else if (!CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); syl.initLetter(); stateFlag = LetterState.Null; } else stateFlag = LetterState.Finish; } } // ? ? ? ? (? ) else { // ??? ? ? ? if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); syl.initLetter(); i++; stateFlag = LetterState.Null; } else { stateFlag = LetterState.Finish; } // ?? ? ? if (i == keySequence.length() - 1) break; } } // ?? , ? ? else { // ?? if (isVowel(tVow)) { // ?? ? . if (!syl.isCompleteSyllable()) syl.setVowel(tVow); // ? ?? if (i == keySequence.length() - 1) { // ??? ? ? if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); stateFlag = LetterState.Null; } // ??? ? ? else { stateFlag = LetterState.Finish; } break; } // 2? ? ??? ?? // ?? ? ? ? delimiter // ? , ?, ? ? . if (!CharUtils.isAsciiAlpha(tVowLookahead.charAt(0))) { // ? ? ? . if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); stateFlag = LetterState.IConsonant; continue; } else stateFlag = LetterState.Finish; } // *// ? ? ?. ? // ??? ? ? if (!syl.isCompleteSyllable()) { // ? ? result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); // ?? ??? ?? if (isISingleConsonant(tVowLookahead) || isIDoubleConsonant(tVowLookahead)) stateFlag = LetterState.IConsonant; // ?? ? else if (isVowel(tVowLookahead)) stateFlag = LetterState.Vowel; continue; } else { // ?? + ? + : good! if (isFConsonant(tVowLookahead)) stateFlag = LetterState.FConsonant; // ??? ?? ? ? ? , : // ? ??? ? . else stateFlag = LetterState.Finish; } } } } // else if (stateFlag.equals(LetterState.FConsonant)) { // ? tFConLookahead = tFConLookaheadCombination = ""; // ?? ? ? ? ? tFCon = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { tFConLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tFConLookaheadCombination = tFCon + tFConLookahead; } stateFlag = LetterState.Finish; // ? ? ? ??. // ???? if (isFConsonant(tFConLookaheadCombination)) { // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); // () ??? ??? ? if (isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep) || !CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { // ? ? . ??? syl.setFConsonant(tFConLookaheadCombination); i++; // ?? ? ? . , ?? + ? } else if (isVowel(lookOverTwoStep)) syl.setFConsonant(tFCon); } else { // ? ?? ?? ? ??. if (isFConsonant(tFConLookaheadCombination)) { syl.setFConsonant(tFConLookaheadCombination); } break; } } else { // ?? ? ??? ? ? . if (isFConsonant(tFCon)) syl.setFConsonant(tFCon); // ? ???? ??. if (i == keySequence.length() - 1) break; // ? ? ?? backtracking. // ? ? if (isVowel(tFConLookahead)) { syl.setFConsonant("nul"); stateFlag = LetterState.Finish; i--; } } } // ? ? ? ? ?? if (stateFlag == LetterState.Finish) { result += syl.getLetter(); syl.initLetter(); } } // . if (stateFlag == LetterState.Finish) result += syl.getLetter(); return result; }
From source file:org.apache.solr.handler.extraction.ExtractionDateUtil.java
/** * Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDate * <p>//w w w . ja va2 s . c o m * Parses the date value using the given date formats. * * @param dateValue the date value to parse * @param dateFormats the date formats to use * @param startDate During parsing, two digit years will be placed in the range * <code>startDate</code> to <code>startDate + 100 years</code>. This value may * be <code>null</code>. When <code>null</code> is given as a parameter, year * <code>2000</code> will be used. * @return the parsed date * @throws ParseException if none of the dataFormats could parse the dateValue */ public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) throws ParseException { if (dateValue == null) { throw new IllegalArgumentException("dateValue is null"); } if (dateFormats == null) { dateFormats = DEFAULT_HTTP_CLIENT_PATTERNS; } if (startDate == null) { startDate = DEFAULT_TWO_DIGIT_YEAR_START; } // trim single quotes around date if present // see issue #5279 if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) { dateValue = dateValue.substring(1, dateValue.length() - 1); } //TODO upgrade to Java 8 DateTimeFormatter. But how to deal with the GMT as a default? SimpleDateFormat dateParser = null; Iterator formatIter = dateFormats.iterator(); while (formatIter.hasNext()) { String format = (String) formatIter.next(); if (dateParser == null) { dateParser = new SimpleDateFormat(format, Locale.ENGLISH); dateParser.setTimeZone(GMT); dateParser.set2DigitYearStart(startDate); } else { dateParser.applyPattern(format); } try { return dateParser.parse(dateValue); } catch (ParseException pe) { // ignore this exception, we will try the next format } } // we were unable to parse the date throw new ParseException("Unable to parse the date " + dateValue, 0); }