List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:edu.ku.brc.util.DateConverter.java
/** * @param dateStr/* w ww. j a v a 2s.c o m*/ * @return the precision of dateStr * @throws ParseException */ public UIFieldFormatterIFace.PartialDateEnum getDatePrecision(String dateStr) throws ParseException { if (StringUtils.isBlank(dateStr)) { return UIFieldFormatterIFace.PartialDateEnum.None; } DateFormats format = match(dateStr); if (format != null) { return format.getPrecision(dateStr); } throw new ParseException("unrecognized date format", 0); }
From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java
/**Extracts a block (data enclosed within delimeters) ignoring escape * sequences. Throws ParseException if an incomplete block is found else * returns null.//from www .java2s. co m * @param str * split address to find * @param open * if the split is open * @param close * if the split is close * @param index * block write index. * @return blocks has got */ private static String getBlock(String str, char open, char close, IntWritable index) throws ParseException { StringBuilder split = new StringBuilder(); int next = StringUtils.findNext(str, open, StringUtils.ESCAPE_CHAR, index.get(), split); split.setLength(0); // clear the buffer if (next >= 0) { ++next; // move over '(' next = StringUtils.findNext(str, close, StringUtils.ESCAPE_CHAR, next, split); if (next >= 0) { ++next; // move over ')' index.set(next); return split.toString(); // found a block } else { throw new ParseException("Unexpected end of block", next); } } return null; // found nothing }
From source file:edu.ku.brc.util.DateConverter.java
/** * @param dateStr/*from w w w. ja v a 2 s. co m*/ * @return a String defining a valid Calendar object according to precision of dateStr * @throws ParseException */ public String adjustForPrecision(String dateStr) throws ParseException { if (StringUtils.isBlank(dateStr)) { return dateStr; } DateFormats format = match(dateStr); if (format != null) { UIFieldFormatterIFace.PartialDateEnum prec = format.getPrecision(dateStr); return format.adjustForPrecision(dateStr, prec); } throw new ParseException("unrecognized date format", 0); }
From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java
public Integer convertToInteger(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) { if (clientApplicationLocale == null) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final String defaultMessage = new StringBuilder( "The parameter '" + parameterName + "' requires a 'locale' parameter to be passed with it.") .toString();/*from w ww. j a va 2 s.co m*/ final ApiParameterError error = ApiParameterError .parameterError("validation.msg.missing.locale.parameter", defaultMessage, parameterName); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } try { Integer number = null; if (StringUtils.isNotBlank(numericalValueFormatted)) { String source = numericalValueFormatted.trim(); final NumberFormat format = NumberFormat.getInstance(clientApplicationLocale); final DecimalFormat df = (DecimalFormat) format; final DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); df.setParseBigDecimal(true); // http://bugs.sun.com/view_bug.do?bug_id=4510618 final char groupingSeparator = symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') { source = source.replaceAll(" ", Character.toString('\u00a0')); } final Number parsedNumber = df.parse(source); final double parsedNumberDouble = parsedNumber.doubleValue(); final int parsedNumberInteger = parsedNumber.intValue(); if (source.contains(Character.toString(symbols.getDecimalSeparator()))) { throw new ParseException(source, 0); } if (!Double.valueOf(parsedNumberDouble) .equals(Double.valueOf(Integer.valueOf(parsedNumberInteger)))) { throw new ParseException(source, 0); } number = parsedNumber.intValue(); } return number; } catch (final ParseException e) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError( "validation.msg.invalid.integer.format", "The parameter " + parameterName + " has value: " + numericalValueFormatted + " which is invalid integer value for provided locale of [" + clientApplicationLocale.toString() + "].", parameterName, numericalValueFormatted, clientApplicationLocale); error.setValue(numericalValueFormatted); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } }
From source file:net.oddsoftware.android.feedscribe.data.FeedManager.java
public static Date parseRFC822Date(String str) throws ParseException { for (SimpleDateFormat dateFormat : rfc822DateFormats) { try {/* ww w.ja v a 2 s.c o m*/ return dateFormat.parse(str); } catch (ParseException exc) { } } throw new ParseException("unable to match any rfc822 date to:" + str, 0); }
From source file:com.kactech.otj.Utils.java
public static Signed parseSigned(BasicSigned signed, String content) throws ParseException { if (signed == null) signed = new BasicSigned(); signed.setRaw(content);//from www. j av a 2s . c o m BufferedReader r = new BufferedReader(new StringReader(content), BUFFERED_READER_SIZE); String line; BasicOTSignature sign = null; StringBuilder bSign = new StringBuilder(); StringBuilder bContent = new StringBuilder(); boolean mSign = false;//signature mode boolean mContent = false; boolean mEnteredContent = false; int lineN = 0; try { while ((line = r.readLine()) != null) { lineN++; if (line.length() < 2) { if (mSign) continue; } else if (line.charAt(0) == '-') { if (mSign) { mSign = false; sign.setValue(bSign.toString().trim()); continue; } if (!mEnteredContent) { if (line.length() > 3 && line.startsWith("----") && line.contains("BEGIN")) { mEnteredContent = true; mContent = true; continue; } else continue; } else if (line.length() > 3 && line.startsWith("----") && line.contains("SIGNATURE")) { mSign = true; mContent = false; bSign = new StringBuilder(); signed.getSignatures().add(sign = new BasicOTSignature()); continue; } else if (line.length() < 3 || line.charAt(1) != ' ' || line.charAt(2) != '-') throw new ParseException(line, lineN); else ; } else { if (mEnteredContent) { if (mSign) { if (line.length() < 2) continue; else if (line.startsWith("Version:")) { sign.setVersion(line.substring("Version:".length()).trim()); continue; } else if (line.startsWith("Comment:")) { sign.setComment(line.substring("Comment:".length()).trim()); continue; } else if (line.startsWith("Meta:")) { if (line.length() != 13) throw new ParseException("incorrect meta length", lineN); sign.setMeta(line.substring(9, 13)); continue; } } if (mContent) { if (line.startsWith("Hash:")) { signed.setHashType(line.substring("Hash: ".length()).trim().toUpperCase()); r.readLine(); continue; } } } } if (mSign) bSign.append(line); else if (mContent) bContent.append(line).append('\n'); } r.close(); } catch (IOException e) { //not normal with reader throw new RuntimeException(e); } signed.setUnsigned(bContent.toString()); if (mSign) throw new IllegalStateException("still in signature mode"); if (mContent) throw new IllegalStateException("still in content mode"); if (!mEnteredContent) throw new IllegalStateException("never entered content mode"); return signed; }
From source file:org.sakaiproject.reports.tool.ReportsTool.java
public void validateTriggerExpression(FacesContext context, UIComponent component, Object value) { if (value != null) { try {//ww w .java 2s.c om String expression = (String) value; CronTrigger trigger = new CronTrigger(); trigger.setCronExpression(expression); // additional checks // quartz does not check for more than 7 tokens in expression String[] arr = expression.split("\\s"); if (arr.length > 7) { throw new ParseException("Expression has more than 7 tokens", 7); } //(check that last 2 entries are not both * or ? String trimmed_expression = expression.replaceAll("\\s", ""); // remove whitespace if (trimmed_expression.endsWith(CRON_CHECK_ASTERISK) || trimmed_expression.endsWith(CRON_CHECK_QUESTION_MARK)) { throw new ParseException("Cannot End in * * or ? ?", 1); } } catch (ParseException e) { // not giving a detailed message to prevent line wraps FacesMessage message = new FacesMessage("Parse Exception"); message.setSeverity(FacesMessage.SEVERITY_WARN); throw new ValidatorException(message); } } }
From source file:com.zimbra.perf.chart.ChartUtil.java
private Date readTS(CsvReader r, String ctx) throws ParseException { Date ts = null;//from w w w . j a v a2 s .c o m String tstamp = r.getValue(PlotSettings.TSTAMP_COLUMN); if (tstamp == null) { throw new ParseException(ctx + ": no timestamp found.", 0); } // Try all date parsers until one succeeds ParseException lastException = null; for (int i = 0; i < sDateFormats.length && ts == null; i++) { try { synchronized (sDateFormats[i]) { ts = sDateFormats[i].parse(tstamp); } } catch (ParseException e) { lastException = e; } if (lastException != null) { throw lastException; } } return ts; }
From source file:com.ottogroup.bi.streaming.operator.json.JsonProcessingUtils.java
/** * Extracts from a {@link JSONObject} the value of the field referenced by the provided path. The received content is treated as * {@link Boolean} value. If the value is a plain {@link Boolean} value it is returned right away. Boolean values contained inside {@link String} * instances are parsed out by {@link Boolean#parseBoolean(String)}. * @param jsonObject//from w ww .j ava2 s . c om * The {@link JSONObject} to read the value from (null is not permitted as input) * @param fieldPath * Path inside the {@link JSONObject} pointing towards the value of interest (null is not permitted as input) * @param required * Field is required to exist at the end of the given path * @return * Value found at the end of the provided path. An empty path simply returns the input * @throws JSONException * Thrown in case extracting values from the {@link JSONObject} fails for any reason * @throws IllegalArgumentException * Thrown in case a provided parameter does not comply with the restrictions * @throws NoSuchElementException * Thrown in case an element referenced inside the path does not exist at the expected location inside the {@link JSONObject} * @throws ParseException * Thrown in case parsing out an {@link ZonedDateTime} from the retrieved field value fails for any format related reason */ public Boolean getBooleanFieldValue(final JSONObject jsonObject, final String[] fieldPath, final boolean required) throws JSONException, IllegalArgumentException, NoSuchElementException, ParseException { Object value = getFieldValue(jsonObject, fieldPath); if (value == null && !required) return null; if (value instanceof Boolean) return (Boolean) value; else if (value instanceof String) return StringUtils.equalsIgnoreCase((String) value, "true"); throw new ParseException("Types of " + (value != null ? value.getClass().getName() : "null") + " cannot be parsed into a valid boolean representation", 0); }
From source file:ORG.oclc.os.SRW.Utilities.java
public static Object xmlToObj(String xml) throws ParseException { log.debug(xml);//from ww w . j ava 2s. c o m Object obj; String leader, soapMessage; while (xml.startsWith("<?")) { // contains processing instruction. Strip that off int i = xml.indexOf('<', 2); if (i < 0) { log.error(xml); throw new ParseException("XML starts with processing instruction but contains no elements", 0); } xml = xml.substring(i); } soapMessage = xml; // use it as it is leader = xml.substring(0, 20); if (!leader.contains("Envelope")) soapMessage = EnvelopeStart + soapMessage + EnvelopeEnd; DeserializationContext dser = new DeserializationContext(new InputSource(new StringReader(soapMessage)), new MessageContext(new AxisServer()), org.apache.axis.Message.RESPONSE); try { dser.parse(); SOAPEnvelope env = dser.getEnvelope(); RPCElement rpcElem = (RPCElement) env.getFirstBody(); String objectType = rpcElem.getLocalName(); if (objectType.equals("searchRetrieveRequest")) obj = rpcElem.getObjectValue(SearchRetrieveRequestType.class); else if (objectType.equals("searchRetrieveResponse")) obj = rpcElem.getObjectValue(SearchRetrieveResponseType.class); else if (objectType.equals("scanRequest")) obj = rpcElem.getObjectValue(ScanRequestType.class); else if (objectType.equals("scanResponse")) obj = rpcElem.getObjectValue(ScanResponseType.class); else throw new ParseException("Unrecognized XML object: " + objectType, 0); } catch (Exception e) { log.error(e, e); throw new ParseException(e.getMessage(), 0); } return obj; }