List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:controllers.core.TimesheetController.java
/** * Get the timesheet report of an actor for a given string date. * // www .ja v a 2 s .co m * if the string date is empty: the start date corresponds to the first day * (monday) of the current week<br/> * else: the start date corresponds to the first day (monday) of the week * including the given date * * Note: if the report doesn't exist, the system creates it. * * @param stringDate * a date in the format yyyy-MM-dd: the system gets the weekly * report including this date, if empty it uses the current date. * @param actor * the actor of the timesheet */ public static TimesheetReport getTimesheetReport(String stringDate, Actor actor) { // get the date: either given as a parameter or the current Date date = null; if (!stringDate.equals("")) { try { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); date = formatter.parse(stringDate); } catch (ParseException e) { log.error(e.getMessage()); return null; } } else { date = new Date(); } // get the first day of the week including the date // we consider the first day as Monday Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startDate = cal.getTime(); TimesheetReport report = TimesheetDao.getTimesheetReportByActorAndStartDate(actor.id, startDate); if (report == null) { report = new TimesheetReport(); report.actor = actor; report.orgUnit = actor.orgUnit; report.type = TimesheetReport.Type.WEEKLY; report.startDate = startDate; report.status = TimesheetReport.Status.OPEN; report.save(); } return report; }
From source file:org.archive.access.nutch.Nutchwax.java
public static long getDate(String d) throws IOException { long date = 0; try {/*from www .j a v a 2 s.c om*/ date = ArchiveUtils.getDate(d).getTime(); } catch (final java.text.ParseException e) { throw new IOException("Failed parse of date: " + d + ": " + e.getMessage()); } // Date can be < 0 if pre-1970 (Seen in some old ARCs). return date >= 0 ? date : 0; }
From source file:com.zimbra.qa.unittest.TestJaxb.java
private static long ymdStringToDate(String ymdString) { SimpleDateFormat formatter = new SimpleDateFormat(YMD_PATTERN, Locale.US); formatter.setTimeZone(GMT);//from w ww.j ava 2 s . c o m Date date; try { date = formatter.parse(ymdString); return date.getTime(); } catch (ParseException e) { Assert.fail( String.format("Failed to convert string %s to long - exception %s", ymdString, e.getMessage())); } return 0; }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "remove" command./* ww w. ja v a 2 s . c o m*/ * * @param commandLine CommandLine. */ private static void removeCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; ModuleVersion moduleVersion; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length < 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } for (int i = 1; i < args.length; i++) { try { moduleVersion = ModuleVersion.parse(args[i]); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } if (!RootManager.containsModuleVersion(moduleVersion)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_NOT_IN_LIST_OF_ROOTS), moduleVersion)); } else { RootManager.removeModuleVersion(moduleVersion); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_REMOVED_FROM_LIST_OF_ROOTS), moduleVersion)); } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "add-reference-path-matcher" command. * * @param commandLine CommandLine.//from w w w .j a va2 s .c o m */ private static void addReferencePathMatcherCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; ReferencePathMatcherOr referencePathMatcherOr; ReferencePathMatcherByElement referencePathMatcherByElement; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length < 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } for (int i = 1; i < args.length; i++) { referencePathMatcherOr = RootManager.getReferencePathMatcherOr(); try { referencePathMatcherByElement = ReferencePathMatcherByElement.parse(args[i], ExecContextHolder.get().getModel()); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } if (referencePathMatcherOr.getListReferencePathMatcher().contains(referencePathMatcherByElement)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_ALREADY_IN_LIST), referencePathMatcherByElement)); } else { referencePathMatcherOr.addReferencePathMatcher(referencePathMatcherByElement); RootManager.saveReferencePathMatcherOr(); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_ADDED_TO_LIST), referencePathMatcherByElement)); } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "remove-reference-path-matcher" command. * * @param commandLine CommandLine.//from w w w. j a va 2 s . co m */ private static void removeReferencePathMatcherCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; ReferencePathMatcherOr referencePathMatcherOr; ReferencePathMatcherByElement referencePathMatcherByElement; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length < 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } for (int i = 1; i < args.length; i++) { referencePathMatcherOr = RootManager.getReferencePathMatcherOr(); try { referencePathMatcherByElement = ReferencePathMatcherByElement.parse(args[i], ExecContextHolder.get().getModel()); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } if (!referencePathMatcherOr.getListReferencePathMatcher().contains(referencePathMatcherByElement)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_NOT_IN_LIST), referencePathMatcherByElement)); } else { referencePathMatcherOr.getListReferencePathMatcher().remove(referencePathMatcherByElement); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_REFERENCE_PATH_MATCHER_REMOVED_FROM_LIST), referencePathMatcherByElement)); RootManager.saveReferencePathMatcherOr(); } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "add" command.// ww w .j a v a 2s . c o m * * @param commandLine CommandLine. */ private static void addCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; boolean indAllowDuplicateModule; ModuleVersion moduleVersion; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length < 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } indAllowDuplicateModule = commandLine.hasOption("ind-allow-duplicate-modules"); for (int i = 1; i < args.length; i++) { try { moduleVersion = ModuleVersion.parse(args[i]); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } if (RootManager.containsModuleVersion(moduleVersion)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ALREADY_IN_LIST_OF_ROOTS), moduleVersion)); } else { if (indAllowDuplicateModule) { RootManager.addModuleVersion(moduleVersion, true); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } else { ModuleVersion moduleVersionOrg; moduleVersionOrg = RootManager.getModuleVersion(moduleVersion.getNodePath()); if (moduleVersionOrg != null) { RootManager.replaceModuleVersion(moduleVersionOrg, moduleVersion); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_REPLACED_IN_LIST_OF_ROOTS), moduleVersionOrg, moduleVersion)); } else { RootManager.addModuleVersion(moduleVersion, false); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } } } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "add-from-file" command. * * @param commandLine CommandLine.// ww w. j a v a 2 s .c o m */ private static void addFromFileCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; boolean indAllowDuplicateModule; BufferedReader bufferedReaderArtifacts; String stringModuleVersion; ModuleVersion moduleVersion; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length != 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } indAllowDuplicateModule = commandLine.hasOption("ind-allow-duplicate-modules"); bufferedReaderArtifacts = null; try { bufferedReaderArtifacts = new BufferedReader(new FileReader(args[1])); while ((stringModuleVersion = bufferedReaderArtifacts.readLine()) != null) { try { moduleVersion = ModuleVersion.parse(stringModuleVersion); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } if (RootManager.containsModuleVersion(moduleVersion)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ALREADY_IN_LIST_OF_ROOTS), moduleVersion)); } else { if (indAllowDuplicateModule) { RootManager.addModuleVersion(moduleVersion, true); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } else { ModuleVersion moduleVersionOrg; moduleVersionOrg = RootManager.getModuleVersion(moduleVersion.getNodePath()); if (moduleVersionOrg != null) { RootManager.replaceModuleVersion(moduleVersionOrg, moduleVersion); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_REPLACED_IN_LIST_OF_ROOTS), moduleVersionOrg, moduleVersion)); } else { RootManager.addModuleVersion(moduleVersion, false); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } } } } } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { if (bufferedReaderArtifacts != null) { try { bufferedReaderArtifacts.close(); } catch (IOException ioe) { } } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "add-artifact" command. * * @param commandLine CommandLine.//from w ww.jav a2 s.c om */ private static void addArtifactCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; boolean indAllowDuplicateModule; ArtifactGroupIdVersion artifactGroupIdVersion; ExecContext execContext; Model model; Module module; ArtifactVersionMapperPlugin artifactVersionMapperPlugin; Version version; ModuleVersion moduleVersion; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length < 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } indAllowDuplicateModule = commandLine.hasOption("ind-allow-duplicate-modules"); for (int i = 1; i < args.length; i++) { // First, convert the ArtifactGroupIdVersion to a ModuleVersion. try { artifactGroupIdVersion = ArtifactGroupIdVersion.parse(args[i]); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } execContext = ExecContextHolder.get(); model = execContext.getModel(); module = model.findModuleByArtifactGroupId(artifactGroupIdVersion.getArtifactGroupId()); if (module == null) { // We expect the handling of the tool exit status to be done by // model.findModuleByArtifactGroupId called above. If we get here with a null // module, it means we are expected to silently continue and ignore artifact. continue; } if (!module.isNodePluginExists(ArtifactVersionMapperPlugin.class, null)) { throw new RuntimeExceptionUserError(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_ARTIFACT_VERSION_CANNOT_MAP_TO_VERSION), artifactGroupIdVersion.getArtifactVersion(), module.getNodePath())); } artifactVersionMapperPlugin = module.getNodePlugin(ArtifactVersionMapperPlugin.class, null); version = artifactVersionMapperPlugin .mapArtifactVersionToVersion(artifactGroupIdVersion.getArtifactVersion()); moduleVersion = new ModuleVersion(module.getNodePath(), version); // Second, do the same as for the add command. if (RootManager.containsModuleVersion(moduleVersion)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle .getString(RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ALREADY_IN_LIST_OF_ROOTS), moduleVersion)); } else { if (indAllowDuplicateModule) { RootManager.addModuleVersion(moduleVersion, true); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } else { ModuleVersion moduleVersionOrg; moduleVersionOrg = RootManager.getModuleVersion(moduleVersion.getNodePath()); if (moduleVersionOrg != null) { RootManager.replaceModuleVersion(moduleVersionOrg, moduleVersion); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_REPLACED_IN_LIST_OF_ROOTS), moduleVersionOrg, moduleVersion)); } else { RootManager.addModuleVersion(moduleVersion, false); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } } } } }
From source file:org.azyva.dragom.tool.RootManagerTool.java
/** * Implements the "add-artifact-from-file" command. * * @param commandLine CommandLine./*from www. j a v a 2s. co m*/ */ private static void addArtifactFromFileCommand(CommandLine commandLine) { UserInteractionCallbackPlugin userInteractionCallbackPlugin; String[] args; boolean indAllowDuplicateModule; BufferedReader bufferedReaderArtifacts; String artifact; ArtifactGroupIdVersion artifactGroupIdVersion; ExecContext execContext; Model model; Module module; ArtifactVersionMapperPlugin artifactVersionMapperPlugin; Version version; ModuleVersion moduleVersion; userInteractionCallbackPlugin = ExecContextHolder.get() .getExecContextPlugin(UserInteractionCallbackPlugin.class); args = commandLine.getArgs(); if (args.length != 2) { throw new RuntimeExceptionUserError(MessageFormat.format( CliUtil.getLocalizedMsgPattern(CliUtil.MSG_PATTERN_KEY_INVALID_ARGUMENT_COUNT), CliUtil.getHelpCommandLineOption())); } indAllowDuplicateModule = commandLine.hasOption("ind-allow-duplicate-modules"); bufferedReaderArtifacts = null; try { bufferedReaderArtifacts = new BufferedReader(new FileReader(args[1])); while ((artifact = bufferedReaderArtifacts.readLine()) != null) { // First, convert the ArtifactGroupIdVersion to a ModuleVersion. try { artifactGroupIdVersion = ArtifactGroupIdVersion.parse(artifact); } catch (ParseException pe) { throw new RuntimeExceptionUserError(pe.getMessage()); } execContext = ExecContextHolder.get(); model = execContext.getModel(); module = model.findModuleByArtifactGroupId(artifactGroupIdVersion.getArtifactGroupId()); if (module == null) { // We expect the handling of the tool exit status to be done by // model.findModuleByArtifactGroupId called above. If we get here with a null // module, it means we are expected to silently continue and ignore artifact. continue; } if (!module.isNodePluginExists(ArtifactVersionMapperPlugin.class, null)) { throw new RuntimeExceptionUserError(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_ARTIFACT_VERSION_CANNOT_MAP_TO_VERSION), artifactGroupIdVersion.getArtifactVersion(), module.getNodePath())); } artifactVersionMapperPlugin = module.getNodePlugin(ArtifactVersionMapperPlugin.class, null); version = artifactVersionMapperPlugin .mapArtifactVersionToVersion(artifactGroupIdVersion.getArtifactVersion()); moduleVersion = new ModuleVersion(module.getNodePath(), version); // Second, do the same as for the add command. if (RootManager.containsModuleVersion(moduleVersion)) { userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ALREADY_IN_LIST_OF_ROOTS), moduleVersion)); } else { if (indAllowDuplicateModule) { RootManager.addModuleVersion(moduleVersion, true); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } else { ModuleVersion moduleVersionOrg; moduleVersionOrg = RootManager.getModuleVersion(moduleVersion.getNodePath()); if (moduleVersionOrg != null) { RootManager.replaceModuleVersion(moduleVersionOrg, moduleVersion); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_REPLACED_IN_LIST_OF_ROOTS), moduleVersionOrg, moduleVersion)); } else { RootManager.addModuleVersion(moduleVersion, false); userInteractionCallbackPlugin.provideInfo(MessageFormat.format( RootManagerTool.resourceBundle.getString( RootManagerTool.MSG_PATTERN_KEY_MODULE_VERSION_ADDED_TO_LIST_OF_ROOTS), moduleVersion)); } } } } } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { if (bufferedReaderArtifacts != null) { try { bufferedReaderArtifacts.close(); } catch (IOException ioe) { } } } }