List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:net.spy.memcached.protocol.couch.DocsOperationImpl.java
protected ViewResponseWithDocs parseResult(String json) throws ParseException { final Collection<ViewRow> rows = new LinkedList<ViewRow>(); final Collection<RowError> errors = new LinkedList<RowError>(); if (json != null) { try {/*from w ww .j av a2 s. co m*/ JSONObject base = new JSONObject(json); if (base.has("rows")) { JSONArray ids = base.getJSONArray("rows"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String id = elem.getString("id"); String key = elem.getString("key"); String value = elem.getString("value"); rows.add(new ViewRowWithDocs(id, key, value, null)); } } if (base.has("errors")) { JSONArray ids = base.getJSONArray("errors"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String from = elem.getString("from"); String reason = elem.getString("reason"); errors.add(new RowError(from, reason)); } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } } return new ViewResponseWithDocs(rows, errors); }
From source file:edu.lternet.pasta.client.ResultSetUtility.java
/** * Constructs a new ResultSetUtility object from search results XML, * specifying whether the search results represent saved data packages * or regular search results.//w ww . j a v a 2 s .c o m * * @param xml * The search results XML as a String object. * * @throws ParseException */ public ResultSetUtility(String xml, String sort, SavedData savedData, boolean isSavedDataPage) throws ParseException { if (xml == null || xml.isEmpty()) { throw new ParseException("Result Set is empty", 0); } this.resultSet = xml; this.sort = sort; this.savedData = savedData; this.isSavedDataPage = isSavedDataPage; parseResultSet(xml); pageControl = new PageControl(numFound, start, rows, sort, isSavedDataPage); pageHeaderHTML = pageControl.composePageHeader(); pageBodyHTML = pageControl.composePageBody(); mapButtonHTML = composeMapButtonHTML(); relevanceHTML = composeRelevanceHTML(); }
From source file:com.haulmont.chile.core.datatypes.impl.LongDatatype.java
@Override protected Number parse(String value, NumberFormat format) throws ParseException { format.setParseIntegerOnly(true);/*from w ww. j a v a 2 s. c om*/ Number result = super.parse(value, format); if (!hasValidLongRange(result)) { throw new ParseException(String.format("Integer range exceeded: \"%s\"", value), 0); } return result; }
From source file:com.playonlinux.wine.registry.RegistryParser.java
private void parseValueLine(RegistryKey lastNode, String currentLine, int lineNumber) throws ParseException { if (!currentLine.startsWith("\"")) { throw new ParseException(String.format("Invalid registry file. Error found line %s", lineNumber), 0); }/* w ww .j av a 2s . c o m*/ ParseState parseState = ParseState.INITIAL; StringBuilder nameBuilder = new StringBuilder(); StringBuilder valueBuilder = new StringBuilder(); Boolean ignoreNextQuote = false; for (int i = 0; i < currentLine.length(); i++) { char currentChar = currentLine.charAt(i); if (parseState == ParseState.INITIAL) { if (currentChar == QUOTE) { parseState = ParseState.READING_NAME; } } else if (parseState == ParseState.READING_NAME) { if (currentChar == '"' && !ignoreNextQuote) { parseState = ParseState.SEPARATOR; } else if (currentChar == '\\' && !ignoreNextQuote) { ignoreNextQuote = true; } else { nameBuilder.append(currentChar); ignoreNextQuote = false; } } else if (parseState == ParseState.SEPARATOR) { if (currentChar != '=') { throw new ParseException( String.format("Invalid registry file. Error found line %s", lineNumber), 0); } else { parseState = ParseState.READING_VALUE; } } else if (parseState == ParseState.READING_VALUE) { valueBuilder.append(currentChar); } } String name = nameBuilder.toString(); try { RegistryValue value = RegistryValue.fromString(name, valueBuilder.toString()); lastNode.addChild(value); } catch (IllegalArgumentException e) { throw new ParseException(String.format("Error on line %s: %s", lineNumber, e), 0); } }
From source file:org.apache.hadoop.chukwa.rest.bean.UserBean.java
public void setProperty(String key, String value) throws ParseException { try {/* w ww . j a v a 2s . c o m*/ this.properties.put(key, value); } catch (Exception e) { log.error(ExceptionUtil.getStackTrace(e)); throw new ParseException("Error parsing user object.", 0); } }
From source file:org.freedesktop.AbstractFreedesktopEntity.java
public void load(InputStream in) throws IOException, ParseException { INIFile iniFile = new INIFile(); iniFile.load(in);/* w ww . j ava2s . c o m*/ entityProperties = iniFile.get(entityTypeName); if (entityProperties == null) { throw new ParseException("No '" + entityTypeName + "' section.", 0); } initFromProperties(iniFile, entityProperties); }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
private static Character parseCharacter(String value) throws ParseException { if (value.length() != 1) { throw new ParseException("Cannot parse '" + value + "' as character", value.length()); }/*from www . jav a 2s . c o m*/ return new Character(value.charAt(0)); }
From source file:org.jmqtt.auth.impl.FileAuthenticator.java
private void parse(Reader reader) throws ParseException { if (reader == null) { return;/*from w w w.j a v a 2 s . com*/ } BufferedReader br = new BufferedReader(reader); String line; try { while ((line = br.readLine()) != null) { int commentMarker = line.indexOf('#'); if (commentMarker != -1) { if (commentMarker == 0) { //skip its a comment continue; } else { //it's a malformed comment throw new ParseException(line, commentMarker); } } else { if (line.isEmpty() || line.matches("^\\s*$")) { //skip it's a black line continue; } //split till the first space int delimiterIdx = line.indexOf(':'); String username = line.substring(0, delimiterIdx).trim(); String password = line.substring(delimiterIdx + 1).trim(); identities.put(username, password); } } } catch (IOException ex) { throw new ParseException("Failed to read", 1); } }
From source file:io.moquette.spi.impl.security.FileAuthenticator.java
private void parse(Reader reader) throws ParseException { if (reader == null) { return;//from w ww. jav a2 s . c o m } BufferedReader br = new BufferedReader(reader); String line; try { while ((line = br.readLine()) != null) { int commentMarker = line.indexOf('#'); if (commentMarker != -1) { if (commentMarker == 0) { //skip its a comment continue; } else { //it's a malformed comment throw new ParseException(line, commentMarker); } } else { if (line.isEmpty() || line.matches("^\\s*$")) { //skip it's a black line continue; } //split till the first space int delimiterIdx = line.indexOf(':'); String username = line.substring(0, delimiterIdx).trim(); String password = line.substring(delimiterIdx + 1).trim(); m_identities.put(username, password); } } } catch (IOException ex) { throw new ParseException("Failed to read", 1); } }
From source file:org.osaf.cosmo.calendar.query.PropertyFilter.java
/** * Construct a PropertyFilter object from a DOM Element * @param element/*w w w . j a v a 2s . co m*/ * @throws ParseException */ public PropertyFilter(Element element, VTimeZone timezone) throws ParseException { // Name must be present name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException("CALDAV:prop-filter a calendar property name (e.g., \"ATTENDEE\") is required", -1); } ElementIterator i = DomUtil.getChildren(element); int childCount = 0; while (i.hasNext()) { Element child = i.nextElement(); childCount++; // if is-not-defined is present, then nothing else can be present if (childCount > 1 && isNotDefinedFilter != null) throw new ParseException("CALDAV:is-not-defined cannnot be present with other child elements", -1); if (ELEMENT_CALDAV_TIME_RANGE.equals(child.getLocalName())) { // Can only have one time-range or text-match if (timeRangeFilter != null) throw new ParseException( "CALDAV:prop-filter only one time-range or text-match element permitted", -1); timeRangeFilter = new TimeRangeFilter(child, timezone); } else if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) { // Can only have one time-range or text-match if (textMatchFilter != null) { throw new ParseException( "CALDAV:prop-filter only one time-range or text-match element permitted", -1); } textMatchFilter = new TextMatchFilter(child); } else if (ELEMENT_CALDAV_PARAM_FILTER.equals(child.getLocalName())) { // Add to list paramFilters.add(new ParamFilter(child)); } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) { if (childCount > 1) throw new ParseException("CALDAV:is-not-defined cannnot be present with other child elements", -1); isNotDefinedFilter = new IsNotDefinedFilter(); } else throw new ParseException("CALDAV:prop-filter an invalid element name found", -1); } }