List of usage examples for java.lang IllegalArgumentException getMessage
public String getMessage()
From source file:bachelorthesis.captchabuilder.builder.CaptchaBuildSequenceParser.java
/** * Creates new elementCreators from the list CaptchaElementCreatorBuilders * in the CaptchaBuilder.//from w w w . ja va 2s .c o m * * @param builder * <p/> * @throws ParseException */ public static void shortParse(CaptchaBuilder builder) throws ParseException { ArrayDeque<CaptchaElementCreatorBuilder> elementBuilders = builder.getBuilders().clone(); ArrayDeque<BuildSequenceOptions> sequence = new ArrayDeque<>(); for (String lvl1Arg : builder.getBuildSequence().split(CaptchaConstants.buildSequencelvl1Delim)) { if (!lvl1Arg.isEmpty()) { try { String[] optionArgs = lvl1Arg.split(CaptchaConstants.buildSequencelvl2Delim); sequence.offer(BuildSequenceOptions.valueOf(optionArgs[0])); } catch (IllegalArgumentException e) { throw new ParseException(e.getMessage()); } } } for (BuildSequenceOptions buildSequence : sequence) { switch (buildSequence) { case BACKGROUND: { CaptchaElementCreatorBuilder elementBuilder = elementBuilders.poll(); if (elementBuilder instanceof BackgroundProducerBuilder) { builder.addBackground((BackgroundProducer) elementBuilder.create()); } else { throw new ParseException("ShortParse Failed ... How is that possible?\n" + "Class Mismatch: Got " + elementBuilder.getClass().getSimpleName() + " and expected " + BackgroundProducerBuilder.class.getSimpleName()); } } break; case BORDER: { CaptchaElementCreatorBuilder elementBuilder = elementBuilders.poll(); if (elementBuilder instanceof BorderProducerBuilder) { builder.addBorder((BorderProducer) elementBuilder.create()); } else { throw new ParseException("ShortParse Failed ... How is that possible?\n" + "Class Mismatch: Got " + elementBuilder.getClass().getSimpleName() + " and expected " + BorderProducerBuilder.class.getSimpleName()); } } break; case GIMP: { CaptchaElementCreatorBuilder elementBuilder = elementBuilders.poll(); if (elementBuilder instanceof GimpyRendererBuilder) { builder.gimp((GimpyRenderer) elementBuilder.create()); } else { throw new ParseException("ShortParse Failed ... How is that possible?\n" + "Class Mismatch: Got " + elementBuilder.getClass().getSimpleName() + " and expected " + GimpyRendererBuilder.class.getSimpleName()); } } break; case NOISE: { CaptchaElementCreatorBuilder elementBuilder = elementBuilders.poll(); if (elementBuilder instanceof NoiseProducerBuilder) { builder.addNoise((NoiseProducer) elementBuilder.create()); } else { throw new ParseException("ShortParse Failed ... How is that possible?\n" + "Class Mismatch: Got " + elementBuilder.getClass().getSimpleName() + " and expected " + NoiseProducerBuilder.class.getSimpleName()); } } break; case TEXT: { CaptchaElementCreatorBuilder elementBuilder1 = elementBuilders.poll(); CaptchaElementCreatorBuilder elementBuilder2 = elementBuilders.poll(); if (elementBuilder1 instanceof TextProducerBuilder && elementBuilder2 instanceof WordRendererBuilder) { builder.addText((TextProducer) elementBuilder1.create(), (WordRenderer) elementBuilder2.create()); } else { throw new ParseException("ShortParse Failed ... How is that possible?\n" + "Class Mismatch: Got " + elementBuilder1.getClass().getSimpleName() + " and expected " + TextProducerBuilder.class.getSimpleName() + "\n" + "Class Mismatch: Got " + elementBuilder2.getClass().getSimpleName() + " and expected " + WordRendererBuilder.class.getSimpleName()); } } } } }
From source file:com.intel.podm.common.types.Status.java
/** * Creates Status object instance from string * @param statusString string representation of Status, e.g. "State=Enabled,Health=OK,HealthRollup=OK" * @return Status object instance//from w w w .j ava 2 s .c o m * @throws IllegalArgumentException if statusString cannot be parsed */ public static Status fromString(String statusString) { if (trimToNull(statusString) == null) { return null; } try { Map<String, String> map = splitStatusString(statusString); return fromMap(map); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(format("Cannot create Status instance for string: %s, details: %s", statusString, e.getMessage()), e); } }
From source file:org.sakaiproject.entitybroker.util.spring.ResourceFinder.java
private static List<Resource> makeResources(List<String> paths) { List<Resource> rs = new ArrayList<Resource>(); if (paths != null && !paths.isEmpty()) { for (String path : paths) { try { Resource r = makeResource(path); rs.add(r);// www . jav a 2s . com } catch (IllegalArgumentException e) { // do not add if not found, just skip System.out.println("WARN: " + e.getMessage() + ", continuing..."); } } } return rs; }
From source file:org.dspace.servicemanager.spring.ResourceFinder.java
private static List<Resource> makeResources(List<String> paths) { List<Resource> rs = new ArrayList<Resource>(); if (paths != null && !paths.isEmpty()) { for (String path : paths) { try { Resource r = makeResource(path); rs.add(r);/*from w w w.jav a 2 s. com*/ } catch (IllegalArgumentException e) { // do not add if not found, just skip log.error(e.getMessage() + ", continuing..."); } } } return rs; }
From source file:fr.free.movierenamer.utils.URIRequest.java
private static Charset getCharset(String contentType) { if (contentType != null) { // Content-Type: text/html; charset=iso-8859-1 Matcher matcher = Pattern.compile("charset=(\\p{Graph}+)").matcher(contentType); if (matcher.find()) { try { return Charset.forName(matcher.group(1)); } catch (IllegalArgumentException e) { Settings.LOGGER.log(Level.WARNING, e.getMessage()); }/* ww w. j a v a2 s. c o m*/ } // use http default encoding only for text/html if (contentType.equals("text/html")) { return Charset.forName(ISO); } } // default return Charset.forName(UTF); }
From source file:com.tuplejump.stargate.lucene.Dates.java
public static FormatDateTimeFormatter forPattern(String input, Locale locale) { if (StringUtils.isNotBlank(input)) { input = input.trim();/*w w w .j a v a2s .c o m*/ } DateTimeFormatter formatter; if (input == null || input.length() == 0) { formatter = ISODateTimeFormat.yearMonthDay(); } else if ("basicDate".equals(input) || "basic_date".equals(input)) { formatter = ISODateTimeFormat.basicDate(); } else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) { formatter = ISODateTimeFormat.basicDateTime(); } else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.basicDateTimeNoMillis(); } else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) { formatter = ISODateTimeFormat.basicOrdinalDate(); } else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) { formatter = ISODateTimeFormat.basicOrdinalDateTime(); } else if ("basicOrdinalDateTimeNoMillis".equals(input) || "basic_ordinal_date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.basicOrdinalDateTimeNoMillis(); } else if ("basicTime".equals(input) || "basic_time".equals(input)) { formatter = ISODateTimeFormat.basicTime(); } else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.basicTimeNoMillis(); } else if ("basicTTime".equals(input) || "basic_t_Time".equals(input)) { formatter = ISODateTimeFormat.basicTTime(); } else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.basicTTimeNoMillis(); } else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) { formatter = ISODateTimeFormat.basicWeekDate(); } else if ("basicWeekDateTime".equals(input) || "basic_week_date_time".equals(input)) { formatter = ISODateTimeFormat.basicWeekDateTime(); } else if ("basicWeekDateTimeNoMillis".equals(input) || "basic_week_date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.basicWeekDateTimeNoMillis(); } else if ("date".equals(input)) { formatter = ISODateTimeFormat.date(); } else if ("dateHour".equals(input) || "date_hour".equals(input)) { formatter = ISODateTimeFormat.dateHour(); } else if ("dateHourMinute".equals(input) || "date_hour_minute".equals(input)) { formatter = ISODateTimeFormat.dateHourMinute(); } else if ("dateHourMinuteSecond".equals(input) || "date_hour_minute_second".equals(input)) { formatter = ISODateTimeFormat.dateHourMinuteSecond(); } else if ("dateHourMinuteSecondFraction".equals(input) || "date_hour_minute_second_fraction".equals(input)) { formatter = ISODateTimeFormat.dateHourMinuteSecondFraction(); } else if ("dateHourMinuteSecondMillis".equals(input) || "date_hour_minute_second_millis".equals(input)) { formatter = ISODateTimeFormat.dateHourMinuteSecondMillis(); } else if ("dateOptionalTime".equals(input) || "date_optional_time".equals(input)) { // in this case, we have a separate parser and printer since the dataOptionalTimeParser can't print // this sucks we should use the root local by default and not be dependent on the node return new FormatDateTimeFormatter(input, ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC), ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale); } else if ("dateTime".equals(input) || "date_time".equals(input)) { formatter = ISODateTimeFormat.dateTime(); } else if ("dateTimeNoMillis".equals(input) || "date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.dateTimeNoMillis(); } else if ("hour".equals(input)) { formatter = ISODateTimeFormat.hour(); } else if ("hourMinute".equals(input) || "hour_minute".equals(input)) { formatter = ISODateTimeFormat.hourMinute(); } else if ("hourMinuteSecond".equals(input) || "hour_minute_second".equals(input)) { formatter = ISODateTimeFormat.hourMinuteSecond(); } else if ("hourMinuteSecondFraction".equals(input) || "hour_minute_second_fraction".equals(input)) { formatter = ISODateTimeFormat.hourMinuteSecondFraction(); } else if ("hourMinuteSecondMillis".equals(input) || "hour_minute_second_millis".equals(input)) { formatter = ISODateTimeFormat.hourMinuteSecondMillis(); } else if ("ordinalDate".equals(input) || "ordinal_date".equals(input)) { formatter = ISODateTimeFormat.ordinalDate(); } else if ("ordinalDateTime".equals(input) || "ordinal_date_time".equals(input)) { formatter = ISODateTimeFormat.ordinalDateTime(); } else if ("ordinalDateTimeNoMillis".equals(input) || "ordinal_date_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.ordinalDateTimeNoMillis(); } else if ("time".equals(input)) { formatter = ISODateTimeFormat.time(); } else if ("tTime".equals(input) || "t_time".equals(input)) { formatter = ISODateTimeFormat.tTime(); } else if ("tTimeNoMillis".equals(input) || "t_time_no_millis".equals(input)) { formatter = ISODateTimeFormat.tTimeNoMillis(); } else if ("weekDate".equals(input) || "week_date".equals(input)) { formatter = ISODateTimeFormat.weekDate(); } else if ("weekDateTime".equals(input) || "week_date_time".equals(input)) { formatter = ISODateTimeFormat.weekDateTime(); } else if ("weekyear".equals(input) || "week_year".equals(input)) { formatter = ISODateTimeFormat.weekyear(); } else if ("weekyearWeek".equals(input)) { formatter = ISODateTimeFormat.weekyearWeek(); } else if ("year".equals(input)) { formatter = ISODateTimeFormat.year(); } else if ("yearMonth".equals(input) || "year_month".equals(input)) { formatter = ISODateTimeFormat.yearMonth(); } else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) { formatter = ISODateTimeFormat.yearMonthDay(); } else if (StringUtils.isNotBlank(input) && input.contains("||")) { String[] formats = StringUtils.split(input, "||"); DateTimeParser[] parsers = new DateTimeParser[formats.length]; if (formats.length == 1) { formatter = forPattern(input, locale).parser(); } else { DateTimeFormatter dateTimeFormatter = null; for (int i = 0; i < formats.length; i++) { FormatDateTimeFormatter currentFormatter = forPattern(formats[i], locale); DateTimeFormatter currentParser = currentFormatter.parser(); if (dateTimeFormatter == null) { dateTimeFormatter = currentFormatter.printer(); } parsers[i] = currentParser.getParser(); } DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() .append(dateTimeFormatter.withZone(DateTimeZone.UTC).getPrinter(), parsers); formatter = builder.toFormatter(); } } else { try { formatter = DateTimeFormat.forPattern(input); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid format: [" + input + "]: " + e.getMessage(), e); } } return new FormatDateTimeFormatter(input, formatter.withZone(DateTimeZone.UTC), locale); }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static <T extends Enum<T>> void transformEnum(final Map<String, String> errors, final Verifiable obj, final OfferFields field, final CSVRecord record, final Class<T> enumType) { final String value = record.get(field.getField()); if ((value != null) && !value.isEmpty()) { try {//w w w . j a v a 2s . co m final T theEnum = Enum.valueOf(enumType, value.toUpperCase(DEFAULT_LOCALE)); invokeMethodOnObject(errors, obj, field, theEnum); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage(), e); errors.put(field.getField(), e.getMessage()); } } }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static <E extends Enum<E> & Descriptable<E>> void transformDescriptableEnumSet(final Map<String, String> errors, final Verifiable obj, final OfferFields field, final CSVRecord record, final Class<E> enumType) { final String value = record.get(field.getField()); if ((value != null) && !value.isEmpty()) { try {//w w w. j a v a 2 s .c o m final Set<E> set = CollectionTransformer.explodeEnumSet(enumType, value); invokeMethodOnObject(errors, obj, field, set); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage(), e); errors.put(field.getField(), e.getMessage()); } } }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static <E extends Enum<E> & Descriptable<E>> void transformDescriptableEnum(final Map<String, String> errors, final Verifiable obj, final OfferFields field, final CSVRecord record, final Class<E> enumType) { final String value = record.get(field.getField()); if ((value != null) && !value.isEmpty()) { try {/* www .j a va2 s .c om*/ final E theEnum = EnumUtil.valueOf(enumType, value); invokeMethodOnObject(errors, obj, field, theEnum); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage(), e); errors.put(field.getField(), e.getMessage()); } } }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static void transformDatePeriod(final Map<String, String> errors, final Verifiable obj, final OfferFields startField, final OfferFields endField, final CSVRecord record) { final Date from = convertDate(errors, startField, record); final Date to = convertDate(errors, endField, record); if ((from != null) && (to != null)) { try {/*w ww . ja v a 2 s . co m*/ final DatePeriod period = new DatePeriod(from, to); invokeMethodOnObject(errors, obj, startField, period); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage(), e); errors.put(startField.getField(), e.getMessage()); } } }