List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:com.indoqa.lang.util.DateRangeParser.java
private static String extractUnit(String relativeString, int pos, String part) throws ParseException { Set<String> keySet = UNIT_CONVERSIONS.keySet(); for (String key : keySet) { if (part.endsWith(key)) { return key; }//from ww w . j a v a 2s.c o m } throw new ParseException( MessageFormat.format("No unit found in relative date part >{0}< of input >{1}< at pos {2}", part, relativeString, pos), pos); }
From source file:org.ietr.preesm.cli.CLIWorkflowExecutor.java
@Override public Object start(IApplicationContext context) throws Exception { Options options = getCommandLineOptions(); try {/*w w w . ja va 2 s . c o m*/ CommandLineParser parser = new PosixParser(); String cliOpts = StringUtils .join((Object[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS), " "); CLIWorkflowLogger.traceln("Starting workflows execution"); CLIWorkflowLogger.traceln("Command line arguments: " + cliOpts); // parse the command line arguments CommandLine line = parser.parse(options, (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)); if (line.getArgs().length != 1) { throw new ParseException("Expected project name as first argument", 0); } // Get the project containing the scenarios and workflows to execute String projectName = line.getArgs()[0]; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); project = root.getProject(new Path(projectName).lastSegment()); // Handle options String workflowPath = line.getOptionValue('w'); String scenarioPath = line.getOptionValue('s'); // Set of workflows to execute Set<String> workflowPaths = new HashSet<String>(); // Set of scenarios to execute Set<String> scenarioPaths = new HashSet<String>(); // If paths to workflow and scenario are not specified using // options, find them in the project given as arguments if (workflowPath == null) { // If there is no workflow path specified, execute all the // workflows (files with workflowExt) found in workflowDir of // the project workflowPaths = getAllFilePathsIn(workflowExt, project, workflowDir); } else { // Otherwise, format the workflowPath and execute it if (!workflowPath.contains(projectName)) workflowPath = projectName + workflowDir + "/" + workflowPath; if (!workflowPath.endsWith(workflowExt)) workflowPath = workflowPath + "." + workflowExt; workflowPaths.add(workflowPath); } if (scenarioPath == null) { // If there is no scenario path specified, execute all the // scenarios (files with scenarioExt) found in scenarioDir of // the project scenarioPaths = getAllFilePathsIn(scenarioExt, project, scenarioDir); } else { // Otherwise, format the scenarioPath and execute it if (!scenarioPath.contains(projectName)) scenarioPath = projectName + scenarioDir + "/" + scenarioPath; if (!scenarioPath.endsWith(scenarioExt)) scenarioPath = scenarioPath + "." + scenarioExt; scenarioPaths.add(scenarioPath); } CLIWorkflowLogger.traceln("Launching workflows execution"); // Launch the execution of the workflos with the scenarios DFToolsWorkflowLogger.runFromCLI(); for (String wPath : workflowPaths) { for (String sPath : scenarioPaths) { CLIWorkflowLogger .traceln("Launching execution of workflow: " + wPath + " with scenario: " + sPath); execute(wPath, sPath, null); } } } catch (UnrecognizedOptionException uoe) { printUsage(options, uoe.getLocalizedMessage()); } catch (ParseException exp) { printUsage(options, exp.getLocalizedMessage()); } return IApplication.EXIT_OK; }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
/** * Parse value of specified type. The string value has to be in * standard notation for the specified type. *///from w ww.ja va 2 s .com public static Object parse(Class type, String value) throws Exception { if (value == null) { return nullValue(type); } else if (value.length() == 0) { return type == String.class ? value : nullValue(type); } type = objectType(type); if (type == BigDecimal.class) { return new BigDecimal(value); } else if (type == BigInteger.class) { return new BigInteger(value); } else if (type == Boolean.class) { return parseBoolean(value); } else if (type == Byte.class) { return Byte.valueOf(value); } else if (type == Character.class) { return parseCharacter(value); } else if (type == Date.class) { return parseDate(value); } else if (type == Double.class) { return Double.valueOf(value); } else if (type == Float.class) { return Float.valueOf(value); } else if (type == Integer.class) { return Integer.valueOf(value); } else if (type == Long.class) { return Long.valueOf(value); } else if (type == Short.class) { return Short.valueOf(value); } else if (type == String.class) { return value; } throw new ParseException("Cannot parse type " + type, 0); }
From source file:edu.cornell.mannlib.vitro.webapp.config.RevisionInfoSetup.java
private void checkValidNumberOfLines(List<String> lines) throws ParseException { if (lines.isEmpty()) { throw new ParseException("The revision info resource file contains no data.", 0); }//from www .j av a 2 s. co m }
From source file:com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype.java
protected void checkIntegerRange(String value, Number result) throws ParseException { if ((result instanceof Long || result instanceof Double) && (result.longValue() > Integer.MAX_VALUE || result.longValue() < Integer.MIN_VALUE)) throw new ParseException(String.format("Integer range exceeded: \"%s\"", value), 0); }
From source file:de.codesourcery.eve.skills.market.impl.EveMarketLogParser.java
protected static final String readColumn(String[] data, String column, Map<String, Integer> mappings) throws ParseException { final Integer idx = mappings.get(column); if (idx == null) { throw new ParseException("CSV lacks column '" + column + "'", -1); }/* w ww . j a v a 2 s .c o m*/ return data[idx]; }
From source file:org.silverpeas.core.util.EncodingUtil.java
/** * Decodes the specified text with hexadecimal values in bytes of those same values. The text is * considered to be in the UTF-8 charset. */* ww w . ja va 2 s . c o m*/ * @param hexText the text with hexadecimal-based characters. * @return the binary representation of the text. * @throws ParseException if an odd number or illegal of characters is supplied. */ public static byte[] fromHex(String hexText) throws ParseException { try { return Hex.decodeHex(hexText.toCharArray()); } catch (Exception ex) { throw new ParseException(ex.getMessage(), -1); } }
From source file:net.hasor.search.utils.DateUtil.java
/** * Slightly modified from org.apache.commons.httpclient.util.DateUtil.parseDate * <p/>/* w w w. j av a2 s . com*/ * 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); } SimpleDateFormat dateParser = null; Iterator formatIter = dateFormats.iterator(); while (formatIter.hasNext()) { String format = (String) formatIter.next(); if (dateParser == null) { dateParser = new SimpleDateFormat(format, Locale.ROOT); 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); }
From source file:org.kalypso.wspwin.core.WspWinProfProj.java
/** * Reads the file profproj.txt//from w w w.j av a2 s . c o m */ public void read(final File wspwinDir) throws IOException, ParseException { final WspWinProject wspWinProject = new WspWinProject(wspwinDir); final File profprojFile = wspWinProject.getProfProjFile(); try (LineNumberReader reader = new LineNumberReader(new FileReader(profprojFile));) { final int[] counts = readStrHeader(reader); final int profilCount = counts[0]; final int relationCount = counts[1]; if (relationCount == 0) { // ignore for now; later we may do sanity checks, if there are unused profiles } final ProfileBean[] profiles = ProfileBean.readProfiles(reader, profilCount); m_profiles.addAll(Arrays.asList(profiles)); } catch (final ParseException pe) { final String msg = Messages.getString("org.kalypso.wspwin.core.WspCfg.6") //$NON-NLS-1$ + profprojFile.getAbsolutePath() + " \n" + pe.getLocalizedMessage(); //$NON-NLS-1$ final ParseException newPe = new ParseException(msg, pe.getErrorOffset()); newPe.setStackTrace(pe.getStackTrace()); throw newPe; } }
From source file:wicket.markup.parser.filter.HtmlProblemFinder.java
/** * Handle the issue. Depending the setting either log a warning, an error, * throw an exception or ignore it.//w w w . j a v a2s . co m * * @param msg * The message * @param tag * The current tag * @throws ParseException */ private void escalateWarning(final String msg, final ComponentTag tag) throws ParseException { if (problemEscalation == ERR_LOG_WARN) { log.warn(msg + tag.toUserDebugString()); } else if (problemEscalation == ERR_LOG_ERROR) { log.error(msg + tag.toUserDebugString()); } else if (problemEscalation == ERR_INGORE) { // no action required } else // if (problemEscalation == ERR_THROW_EXCEPTION) { throw new ParseException(msg + tag.toUserDebugString(), tag.getPos()); } }