List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.kalypso.wspwin.core.WspWinZustand.java
private static ZustandSegmentBean[] readZustandSegments(final LineNumberReader reader, final int segmentCount, final String filename) throws ParseException, IOException { final List<ZustandSegmentBean> beans = new ArrayList<>(20); int readSegments = 0; while (reader.ready()) { final String line = reader.readLine(); /* Skip empty lines; we have WspWin projects with and without a separating empty line */ if (StringUtils.isBlank(line)) continue; final StringTokenizer tokenizer = new StringTokenizer(line); if (tokenizer.countTokens() != 7) throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.2", filename, //$NON-NLS-1$ reader.getLineNumber()), reader.getLineNumber()); try {//from w w w .j ava 2 s . co m final BigDecimal stationFrom = new BigDecimal(tokenizer.nextToken()); final BigDecimal stationTo = new BigDecimal(tokenizer.nextToken()); final double distanceVL = Double.parseDouble(tokenizer.nextToken()); final double distanceHF = Double.parseDouble(tokenizer.nextToken()); final double distanceVR = Double.parseDouble(tokenizer.nextToken()); final String fileNameFrom = tokenizer.nextToken(); final String fileNameTo = tokenizer.nextToken(); final ZustandSegmentBean bean = new ZustandSegmentBean(stationFrom, stationTo, fileNameFrom, fileNameTo, distanceVL, distanceHF, distanceVR); beans.add(bean); readSegments++; } catch (final NumberFormatException e) { e.printStackTrace(); throw new ParseException(Messages.getString("org.kalypso.wspwin.core.WspWinZustand.3", filename, //$NON-NLS-1$ reader.getLineNumber()), reader.getLineNumber()); } } if (readSegments != segmentCount) throw new ParseException( Messages.getString("org.kalypso.wspwin.core.WspWinZustand.1", filename, reader.getLineNumber()), //$NON-NLS-1$ reader.getLineNumber()); return beans.toArray(new ZustandSegmentBean[beans.size()]); }
From source file:org.polymap.rhei.field.NumberValidator.java
public M transform2Model(String fieldValue) throws Exception { if (fieldValue == null) { return null; } else if (fieldValue instanceof String) { ParsePosition pp = new ParsePosition(0); Number result = nf.parse((String) fieldValue, pp); if (pp.getErrorIndex() > -1 || pp.getIndex() < ((String) fieldValue).length()) { throw new ParseException("field value: " + fieldValue, pp.getErrorIndex()); }//from ww w . ja va 2s .co m log.debug("value: " + fieldValue + " -> " + result.doubleValue()); // XXX check max digits if (Float.class.isAssignableFrom(targetClass)) { return (M) Float.valueOf(result.floatValue()); } else if (Double.class.isAssignableFrom(targetClass)) { return (M) Double.valueOf(result.floatValue()); } else if (Integer.class.isAssignableFrom(targetClass)) { return (M) Integer.valueOf(result.intValue()); } else if (Long.class.isAssignableFrom(targetClass)) { return (M) Long.valueOf(result.longValue()); } else { throw new RuntimeException("Unsupported target type: " + targetClass); } } else { throw new RuntimeException("Unhandled field value type: " + fieldValue); } }
From source file:RegexFormatter.java
/** * Parses text returning an arbitrary Object. Some formatters * may return null.//from ww w. j a va 2 s. c o m * * If a Pattern has been specified and the text completely * matches the regular expression this will invoke setMatcher. * * @throws ParseException * if there is an error in the conversion * @param text * String to convert * @return Object representation of text */ public Object stringToValue(String text) throws ParseException { Pattern pattern = getPattern(); if (pattern != null) { Matcher matcher = pattern.matcher(text); if (matcher.matches()) { setMatcher(matcher); return super.stringToValue(text); } throw new ParseException("Pattern did not match", 0); } return text; }
From source file:de.codesourcery.utils.xml.XmlHelper.java
public static String getElementValue(Element parent, String tagName, boolean isRequired) throws ParseException { Element element = getElement(parent, tagName, isRequired); String result = null;/* w w w . j a v a 2 s . c o m*/ if (element != null) { result = getNodeValue(element, null, isRequired); } if (StringUtils.isBlank(result) && isRequired) { final String msg = "Required child tag <" + tagName + " of parent <" + parent.getNodeName() + " to have non-blank value"; log.error("getElement(): " + msg); throw new ParseException(msg, -1); } return result; }
From source file:eionet.cr.util.sql.VirtuosoFullTextQuery.java
/** * @throws ParseException//from w w w.j a v a 2s . com * */ private void parse() throws ParseException { if (query == null) { return; } query = query.trim(); if (query.length() == 0) { return; } // parse phrases first int unclosedQuotes = -1; int len = query.length(); for (int i = 0; i < len; i++) { if (query.charAt(i) == '"') { if (unclosedQuotes != -1) { String phrase = query.substring(unclosedQuotes + 1, i); if (phrase.trim().length() >= MIN_WORD_LENGTH) { if (StringUtils.containsAny(phrase, " \t\r\n\f")) { phrases.add(query.substring(unclosedQuotes + 1, i)); } } unclosedQuotes = -1; } else { unclosedQuotes = i; } } } // remove phrases from expression if (phrases != null) { for (String phrase : phrases) { query = query.replaceAll("\"" + phrase + "\"", ""); } } // there must be no unclosed quotes left if (unclosedQuotes != -1) { throw new ParseException("Unclosed quotes at index " + unclosedQuotes, unclosedQuotes); } String prevToken = null; StringTokenizer st = new StringTokenizer(query, " \t\r\n\f\""); // remove any redundant logical operands and too short words from the beginning of query query = removeOperands(st); st = new StringTokenizer(query, " \t\r\n\f\""); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.equals("&")) token = "AND"; if (token.equals("|")) token = "OR"; // If this token is a VirtuosoSQL full-text query's boolean operator // then append it to the parsed query only if the previous token // was not null and wasn't already a boolean operator itself. // // However, if this token is NOT a a VirtuosoSQL full-text query's boolean operator, // then append it to the parsed query, but first make sure that the previous // token was a boolean operator. If it wasn't then append the default operator. boolean appendThisToken = false; if (isBooleanOperator(token)) { if (prevToken != null && !isBooleanOperator(prevToken)) { appendThisToken = true; } } else { if (token.length() >= MIN_WORD_LENGTH) { appendThisToken = true; if (prevToken != null && !isBooleanOperator(prevToken)) { parsedQuery.append(" ").append(DEFAULT_BOOLEAN_OPERATOR); } } } if (appendThisToken) { if (parsedQuery.length() > 0) { parsedQuery.append(" "); } if (isBooleanOperator(token)) parsedQuery.append(token); else parsedQuery.append("'").append(token).append("'"); prevToken = token; } } // add phrases to query if (phrases != null && phrases.size() > 0) { for (String phrase : phrases) { if (parsedQuery != null && parsedQuery.length() > 0) parsedQuery.append(" and "); parsedQuery.append("'").append(phrase).append("'"); } } }
From source file:org.kalypso.ogc.gml.gui.XsdDecimalGuiTypeHandler.java
@Override public Object parseText(final String text, final String formatHint) throws ParseException { final String normalizedText = XsdFloatGuiTypeHandler.normalizeDecimalText(text); if (StringUtils.isBlank(normalizedText)) return null; try {/*from w w w . j av a2 s .c o m*/ return new BigDecimal(normalizedText); } catch (final NumberFormatException e) { throw new ParseException(e.getLocalizedMessage(), 0); } }
From source file:com.playonlinux.bash.ScriptLegacy.java
private String extract(boolean extractSignature) throws IOException, ParseException { final BufferedReader bufferReader = new BufferedReader(new StringReader(this.getScriptContent())); final StringBuilder signatureBuilder = new StringBuilder(); final String separator = FileAnalyser.identifyLineDelimiter(this.getScriptContent()); Boolean insideSignature = false; for (String readLine = bufferReader.readLine(); readLine != null; readLine = bufferReader.readLine()) { if (readLine.contains(BEGIN_PGP_KEY_BLOCK_LINE)) { insideSignature = true;// www.j a va 2 s. co m } if (extractSignature == insideSignature) { signatureBuilder.append(readLine); signatureBuilder.append(separator); } if (readLine.contains(END_PGP_KEY_BLOCK_LINE)) { insideSignature = false; } } final String extractedContent = signatureBuilder.toString(); if (StringUtils.isBlank(extractedContent)) { if (extractSignature) { throw new ParseException("The script has no valid signature!", 0); } else { throw new ParseException("The script has no valid content", 0); } } return extractedContent; }
From source file:de.qaware.chronix.lucene.client.stream.date.DateQueryParser.java
/** * Converts the given date term into a numeric representation * * @param dateTerm the date term, e.g, start:NOW+30DAYS * @return the long representation of the date term * @throws ParseException if the date term could not be evaluated *///from w ww . ja v a 2s . co m private long getNumberRepresentation(String dateTerm) throws ParseException { long numberRepresentation; if (StringUtils.isNumeric(dateTerm)) { numberRepresentation = Long.valueOf(dateTerm); } else if (solrDateMathPattern.matcher(dateTerm).matches()) { numberRepresentation = parseDateTerm(dateTerm); } else if (instantDatePattern.matcher(dateTerm).matches()) { numberRepresentation = Instant.parse(dateTerm).toEpochMilli(); } else { throw new ParseException("Could not parse date representation '" + dateTerm + "'", 0); } return numberRepresentation; }
From source file:org.osaf.cosmo.eim.schema.text.TriageStatusFormat.java
public Object parseObject(String source, ParsePosition pos) { if (pos.getIndex() > 0) return null; int index = 0; String[] chunks = source.split(" ", 3); if (chunks.length != 3) { parseException = new ParseException("Incorrect number of chunks: " + chunks.length, 0); pos.setErrorIndex(index);//from w w w .j a v a 2 s.c o m return null; } TriageStatus ts = entityFactory.createTriageStatus(); try { pos.setIndex(index); Integer code = new Integer(chunks[0]); // validate the code as being known TriageStatusUtil.label(code); ts.setCode(code); index += chunks[0].length() + 1; } catch (Exception e) { parseException = new ParseException(e.getMessage(), 0); pos.setErrorIndex(index); return null; } try { pos.setIndex(index); BigDecimal rank = new BigDecimal(chunks[1]); if (rank.scale() != 2) throw new NumberFormatException("Invalid rank value " + chunks[1]); ts.setRank(rank); index += chunks[1].length() + 1; } catch (NumberFormatException e) { parseException = new ParseException(e.getMessage(), 0); pos.setErrorIndex(index); return null; } if (chunks[2].equals(AUTOTRIAGE_ON)) ts.setAutoTriage(Boolean.TRUE); else if (chunks[2].equals(AUTOTRIAGE_OFF)) ts.setAutoTriage(Boolean.FALSE); else { parseException = new ParseException("Invalid autotriage value " + chunks[2], 0); pos.setErrorIndex(index); return null; } index += chunks[2].length(); pos.setIndex(index); return ts; }
From source file:com.couchbase.client.protocol.views.DesignDocFetcherOperationImpl.java
private DesignDocument parseDesignDocument(String ddn, String json) throws ParseException { DesignDocument design = new DesignDocument(ddn); try {//from w ww.j ava 2 s .com JSONObject base = new JSONObject(json); if (base.has("error")) { return null; } if (base.has("views")) { JSONObject views = base.getJSONObject("views"); Iterator iterator = views.keys(); while (iterator.hasNext()) { ViewDesign view; String name = (String) iterator.next(); String map = (String) views.getJSONObject(name).get("map"); if (views.getJSONObject(name).has("reduce")) { String reduce = (String) views.getJSONObject(name).get("reduce"); view = new ViewDesign(name, map, reduce); } else { view = new ViewDesign(name, map); } design.setView(view); } } if (base.has("spatial")) { JSONObject views = base.getJSONObject("spatial"); Iterator iterator = views.keys(); while (iterator.hasNext()) { String name = (String) iterator.next(); String map = (String) views.get(name); SpatialViewDesign view = new SpatialViewDesign(name, map); design.setSpatialView(view); } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } return design; }