List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:eu.crisis_economics.configuration.TypeDeclarationExpression.java
static TypeDeclarationExpression tryCreate(String expression, FromFileConfigurationContext context) throws ParseException { List<String> expressions = TypeDeclarationExpression.isExpressionOfType(expression, context); if (expressions == null) throw new ParseException(expression, 0); String literalTypename = expressions.get(0); if (expressions.size() == 1) { return new TypeDeclarationExpression(literalTypename, context); } else {//from w w w .j a v a 2 s .c o m String indexExpression = expressions.get(1); if (IntegerPrimitiveExpression.isExpressionOfType(expressions.get(1), context) != null) { IntegerPrimitiveExpression primitiveIndexExpression = IntegerPrimitiveExpression .tryCreate(indexExpression, context); return new TypeDeclarationExpression(literalTypename, primitiveIndexExpression, context); } else { NameDeclarationExpression nameDeclExpression = NameDeclarationExpression.tryCreate(indexExpression, context); return new TypeDeclarationExpression(literalTypename, nameDeclExpression, context); } } }
From source file:org.osaf.cosmo.model.text.BaseXhtmlFormat.java
protected void handleException(String message, Location location) throws ParseException { int offset = location != null ? location.getCharacterOffset() : -1; throw new ParseException(message, offset); }
From source file:com.playonlinux.domain.ScriptRecent.java
@Override public String extractSignature() throws ParseException, IOException { BufferedReader bufferReader = new BufferedReader(new FileReader(this.getScriptFile())); StringBuilder signatureBuilder = new StringBuilder(); String readLine;/*from w w w . j a v a 2s . c o m*/ Boolean insideSignature = false; do { readLine = bufferReader.readLine(); if (readLine == null) { break; } if (readLine.contains("-----BEGIN PGP PUBLIC KEY BLOCK-----") && readLine.startsWith("#")) { insideSignature = true; } if (insideSignature) { if (readLine.startsWith("#")) { signatureBuilder.append(readLine.substring(1, readLine.length()).trim()); } signatureBuilder.append("\n"); } if (readLine.contains("-----END PGP PUBLIC KEY BLOCK-----") && readLine.startsWith("#")) { insideSignature = false; } } while (true); String signature = signatureBuilder.toString().trim(); if (StringUtils.isBlank(signature)) { throw new ParseException("The script has no valid signature!", 0); } return signature; }
From source file:org.musicrecital.util.DateUtil.java
/** * This method generates a string representation of a date/time * in the format you specify on input//from w w w. j av a 2 s . c o m * * @param aMask the date pattern the string is in * @param strDate a string representation of a date * @return a converted Date object * @throws ParseException when String doesn't match the expected format * @see java.text.SimpleDateFormat */ public static Date convertStringToDate(String aMask, String strDate) throws ParseException { SimpleDateFormat df; Date date; df = new SimpleDateFormat(aMask); if (log.isDebugEnabled()) { log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'"); } try { date = df.parse(strDate); } catch (ParseException pe) { //log.error("ParseException: " + pe); throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }
From source file:org.apache.hawq.pxf.plugins.ignite.IgniteResolver.java
/** * Transform a {@link JsonArray} stored in {@link OneRow} into a list of {@link OneField} * * @throws ParseException if the response could not be correctly parsed * @throws UnsupportedOperationException if the type of some field is not supported *///from www. j a v a 2s.c o m @Override public List<OneField> getFields(OneRow row) throws ParseException, UnsupportedOperationException { JsonArray result = JsonArray.class.cast(row.getData()); LinkedList<OneField> fields = new LinkedList<OneField>(); if (result.size() != columns.size()) { throw new ParseException( "getFields(): Failed (a tuple received from Ignite contains more or less fields than requested). Raw tuple: '" + result.toString() + "'", 0); } for (int i = 0; i < columns.size(); i++) { Object value = null; OneField oneField = new OneField(columns.get(i).columnTypeCode(), null); // Handle null values if (result.get(i).isJsonNull()) { fields.add(oneField); continue; } switch (DataType.get(oneField.type)) { case INTEGER: value = result.get(i).getAsInt(); break; case FLOAT8: value = result.get(i).getAsDouble(); break; case REAL: value = result.get(i).getAsFloat(); break; case BIGINT: value = result.get(i).getAsLong(); break; case SMALLINT: value = result.get(i).getAsShort(); break; case BOOLEAN: value = result.get(i).getAsBoolean(); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: value = result.get(i).getAsString(); break; case BYTEA: value = Base64.decodeBase64(result.get(i).getAsString()); break; case TIMESTAMP: boolean isConversionSuccessful = false; for (SimpleDateFormat sdf : getTimestampSDFs.get()) { try { value = sdf.parse(result.get(i).getAsString()); isConversionSuccessful = true; break; } catch (ParseException e) { // pass } } if (!isConversionSuccessful) { throw new ParseException(result.get(i).getAsString(), 0); } break; case DATE: value = getDateSDF.parse(result.get(i).getAsString()); break; default: throw new UnsupportedOperationException("Field type not supported: " + DataType.get(oneField.type).toString() + ", Column: " + columns.get(i).columnName()); } oneField.val = value; fields.add(oneField); } return fields; }
From source file:org.nishkarma.petclinic.controller.PetTypeFormatter.java
@Override public Types parse(String text, Locale locale) throws ParseException { try {/* w w w . ja v a2 s . c om*/ Collection<Types> findPetTypes = this.clinicService.findPetTypes(); for (Types type : findPetTypes) { if (type.getName().equals(text)) { return type; } } } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); throw new NishkarmaException( NishkarmaMessageSource.getMessage("exception_message", NishkarmaLocaleUtil.resolveLocale())); } throw new ParseException("type not found: " + text, 0); }
From source file:com.anrisoftware.globalpom.format.latlong.LatitudeFormatLogger.java
void checkLatitude(String source, ParsePosition pos) throws ParseException { if (WORD_PATTERN.matcher(source).matches() && !containsAny(source, SOUTH, NORTH)) { ParseException ex = new ParseException(format(latitude_error.toString(), source), pos.getErrorIndex()); throw logException(ex, latitude_error_message, source); }/*from www . j a v a2 s. c o m*/ }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
private static Boolean parseBoolean(String value) throws ParseException { if ("true".equals(value)) { return Boolean.TRUE; } else if ("false".equals(value)) { return Boolean.FALSE; } else {//from w w w .j a va2 s. c o m throw new ParseException("Cannot parse '" + value + "' as boolean", 0); } }
From source file:com.anrisoftware.globalpom.format.latlong.LongitudeFormatLogger.java
void checkLongitude(String source, ParsePosition pos) throws ParseException { if (WORD_PATTERN.matcher(source).matches() && !containsAny(source, EAST, WEST)) { ParseException ex = new ParseException(format(longitude_error.toString(), source), pos.getErrorIndex()); throw logException(ex, longitude_error_message, source); }/*w ww. j ava 2s . c o m*/ }
From source file:de.codesourcery.utils.xml.XmlHelper.java
public static Element getElement(Document doc, String tagName, boolean isRequired) throws ParseException { NodeList list = doc.getElementsByTagName(tagName); if (list.getLength() == 0 && isRequired) { log.error("getElement(): XML is lacking required tag <" + tagName + ">"); throw new ParseException("XML is lacking required tag <" + tagName + ">", -1); }/*from ww w.j ava 2 s .com*/ if (list.getLength() > 1) { log.error("getElement(): XML is contains multiple <" + tagName + "> tags, expected only one"); throw new ParseException("XML is contains multiple <" + tagName + "> tags, expected only one", -1); } Node n = list.item(0); if (!(n instanceof Element)) { log.error("getElement(): Internal error, expected Element but got Node"); throw new ParseException("Internal error, expected Element but got Node", -1); } return (Element) n; }