List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:com.unboundid.scim2.server.utils.SchemaChecker.java
/** * Check an attribute value to see if it has the right type. * * @param prefix The issue prefix./*from ww w . j a v a2 s.c o m*/ * @param node The attribute value. * @param path The attribute path. * @param attribute The attribute definition. * @param results The schema check results. * @param currentObjectNode The current resource. * @param isPartialReplace Whether this is a partial replace. * @param isPartialAdd Whether this is a partial add. * @throws ScimException If an error occurs. */ private void checkAttributeValue(final String prefix, final JsonNode node, final Path path, final AttributeDefinition attribute, final Results results, final ObjectNode currentObjectNode, final boolean isPartialReplace, final boolean isPartialAdd) throws ScimException { if (node.isNull()) { return; } // Check the node type. switch (attribute.getType()) { case STRING: case DATETIME: case BINARY: case REFERENCE: if (!node.isTextual()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON string"); return; } break; case BOOLEAN: if (!node.isBoolean()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON boolean"); return; } break; case DECIMAL: case INTEGER: if (!node.isNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON number"); return; } break; case COMPLEX: if (!node.isObject()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON object"); return; } break; default: throw new RuntimeException("Unexpected attribute type " + attribute.getType()); } // If the node type checks out, check the actual value. switch (attribute.getType()) { case DATETIME: try { ISO8601Utils.parse(node.textValue(), new ParsePosition(0)); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid ISO8601 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid ISO8601 formatted string"); } break; case BINARY: try { Base64Variants.getDefaultVariant().decode(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid base64 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid base64 encoded string"); } break; case REFERENCE: try { new URI(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid URI string during schema checking", e); results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not a valid URI string"); } break; case INTEGER: if (!node.isIntegralNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not an integral number"); } break; case COMPLEX: checkObjectNode(prefix, path, attribute.getSubAttributes(), (ObjectNode) node, results, currentObjectNode, isPartialReplace, isPartialAdd, false); break; case STRING: // Check for canonical values if (attribute.getCanonicalValues() != null) { boolean found = false; for (String canonicalValue : attribute.getCanonicalValues()) { if (attribute.isCaseExact() ? canonicalValue.equals(node.textValue()) : StaticUtils.toLowerCase(canonicalValue) .equals(StaticUtils.toLowerCase(node.textValue()))) { found = true; break; } } if (!found) { results.syntaxIssues.add(prefix + "Value " + node.textValue() + " is not valid for attribute " + path + " because it " + "is not one of the canonical types: " + StaticUtils.collectionToString(attribute.getCanonicalValues(), ", ")); } } } // Special checking of the schemas attribute to ensure that // no undefined schemas are listed. if (attribute.equals(SchemaUtils.SCHEMAS_ATTRIBUTE_DEFINITION) && path.size() == 1) { boolean found = false; for (SchemaResource schemaExtension : resourceType.getSchemaExtensions().keySet()) { if (node.textValue().equals(schemaExtension.getId())) { found = true; break; } } if (!found) { found = node.textValue().equals(resourceType.getCoreSchema().getId()); } if (!found && !enabledOptions.contains(Option.ALLOW_UNDEFINED_ATTRIBUTES)) { results.syntaxIssues.add(prefix + "Schema URI " + node.textValue() + " is not a valid value for attribute " + path + " because it is " + "undefined as a core or schema extension for this resource type"); } } }
From source file:com.novartis.opensource.yada.util.QueryUtils.java
/** * Calls the appropriate setter method for {@code type} in the {@code pstmt}, * performing the appropriate type conversion or syntax change as needed * (e.g., for {@link java.sql.Date}s)/*from w ww . j ava 2 s. co m*/ * * @param pstmt * the statement to which to assign the parameter values * @param index * the position of the parameter * @param type * the data type of the parameter * @param val * the value to assign */ @SuppressWarnings("static-method") private void setQueryParameter(PreparedStatement pstmt, int index, char type, String val) { String idx = (index < 10) ? " " + String.valueOf(index) : String.valueOf(index); l.debug("Setting param [" + idx + "] of type [" + String.valueOf(type) + "] to: " + val); try { switch (type) { case DATE: try { if ("".equals(val) || val == null) { pstmt.setNull(index, java.sql.Types.DATE); } else { SimpleDateFormat sdf = new SimpleDateFormat(STANDARD_DATE_FMT); ParsePosition pp = new ParsePosition(0); Date dateVal = sdf.parse(val, pp); if (dateVal == null) { sdf = new SimpleDateFormat(ORACLE_DATE_FMT); dateVal = sdf.parse(val, pp); } if (dateVal != null) { long t = dateVal.getTime(); java.sql.Date sqlDateVal = new java.sql.Date(t); pstmt.setDate(index, sqlDateVal); } } } catch (Exception e) { l.error("Error: " + e.getMessage()); } break; case INTEGER: try { int ival = Integer.parseInt(val); pstmt.setInt(index, ival); } catch (NumberFormatException nfe) { l.error("Error: " + nfe.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: null"); pstmt.setNull(index, java.sql.Types.INTEGER); } catch (NullPointerException npe) { l.error("Error: " + npe.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: null"); pstmt.setNull(index, java.sql.Types.INTEGER); } catch (Exception sqle) { l.error("Error: " + sqle.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: 0"); pstmt.setNull(index, java.sql.Types.INTEGER); } break; case NUMBER: try { float fval = Float.parseFloat(val); pstmt.setFloat(index, fval); } catch (NumberFormatException nfe) { l.error("Error: " + nfe.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: null"); pstmt.setNull(index, java.sql.Types.INTEGER); } catch (NullPointerException npe) { l.error("Error: " + npe.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: null"); pstmt.setNull(index, java.sql.Types.INTEGER); } catch (Exception sqle) { l.error("Error: " + sqle.getMessage()); l.debug("Setting param [" + String.valueOf(index) + "] of type [" + String.valueOf(type) + "] to: null"); pstmt.setNull(index, java.sql.Types.INTEGER); } break; case OUTPARAM_DATE: ((CallableStatement) pstmt).registerOutParameter(index, java.sql.Types.DATE); break; case OUTPARAM_INTEGER: ((CallableStatement) pstmt).registerOutParameter(index, java.sql.Types.INTEGER); break; case OUTPARAM_NUMBER: ((CallableStatement) pstmt).registerOutParameter(index, java.sql.Types.FLOAT); break; case OUTPARAM_VARCHAR: ((CallableStatement) pstmt).registerOutParameter(index, java.sql.Types.VARCHAR); break; default: // VARCHAR2 pstmt.setString(index, val); break; } } catch (SQLException e) { e.printStackTrace(); l.error(e.getMessage()); } }
From source file:org.catechis.Stats.java
private void compareWordDates(String str_date) { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = null;// www . ja v a2s. c om ParsePosition pp = new ParsePosition(0); date = sdf.parse(str_date, pp); long this_time = date.getTime(); if (this_time > words_last_test_time) { words_last_test_time = this_time; words_last_test_date = str_date; } else { if (words_last_test_date == null) { words_last_test_time = this_time; words_last_test_date = str_date; } else { // last_time should already be set } } }
From source file:org.pentaho.di.job.entries.zipfile.JobEntryZipFile.java
private int determineDepth(String depthString) throws KettleException { DecimalFormat df = new DecimalFormat("0"); ParsePosition pp = new ParsePosition(0); df.setParseIntegerOnly(true);//ww w . j a v a 2 s. c o m try { Number n = df.parse(depthString, pp); if (n == null) { return 1; // default } if (pp.getErrorIndex() == 0) { throw new KettleException("Unable to convert stored depth '" + depthString + "' to depth at position " + pp.getErrorIndex()); } return n.intValue(); } catch (Exception e) { throw new KettleException("Unable to convert stored depth '" + depthString + "' to depth", e); } }
From source file:org.catechis.Stats.java
private void compareReadingWordTestDates(String str_date, String level, Word word) { if (Integer.parseInt(level) > (allowed_number_of_levels - 1)) { level = Integer.toString((allowed_number_of_levels - 1)); }/*from ww w. jav a 2 s. c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = null; ParsePosition pp = new ParsePosition(0); date = sdf.parse(str_date, pp); long this_time = date.getTime(); if (this_time > words_last_test_reading_time) { words_last_test_reading_time = this_time; words_last_test_reading_date = str_date; words_last_test_reading_level = level; } else { if (words_last_test_date == null) { words_last_test_reading_time = this_time; words_last_test_reading_date = str_date; words_last_test_reading_level = level; } else { // last_time should already be set } } }
From source file:org.catechis.Stats.java
private void compareWritingWordTestDates(String str_date, String level, Word word) { if (Integer.parseInt(level) > (allowed_number_of_levels - 1)) { level = Integer.toString((allowed_number_of_levels - 1)); }//from w w w .j av a2 s . c o m SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = null; ParsePosition pp = new ParsePosition(0); date = sdf.parse(str_date, pp); long this_time = date.getTime(); if (this_time > words_last_test_writing_time) { words_last_test_writing_time = this_time; words_last_test_writing_date = str_date; words_last_test_writing_level = level; } else { if (words_last_test_date == null) { words_last_test_writing_time = this_time; words_last_test_writing_date = str_date; words_last_test_writing_level = level; } else { // last_time should already be set } } }
From source file:com.amaze.filemanager.utils.Futils.java
public BaseFile parseName(String line) { boolean linked = false; String name = "", link = "", size = "-1", date = ""; String[] array = line.split(" "); if (array.length < 6) return null; for (int i = 0; i < array.length; i++) { if (array[i].contains("->") && array[0].startsWith("l")) { linked = true;// w ww.jav a2 s . co m } } int p = getColonPosition(array); if (p != -1) { date = array[p - 1] + " | " + array[p]; size = array[p - 2]; } if (!linked) { for (int i = p + 1; i < array.length; i++) { name = name + " " + array[i]; } name = name.trim(); } else { int q = getLinkPosition(array); for (int i = p + 1; i < q; i++) { name = name + " " + array[i]; } name = name.trim(); for (int i = q + 1; i < array.length; i++) { link = link + " " + array[i]; } } long Size = (size == null || size.trim().length() == 0) ? -1 : Long.parseLong(size); if (date.trim().length() > 0) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd | HH:mm"); Date stringDate = simpledateformat.parse(date, pos); BaseFile baseFile = new BaseFile(name, array[0], stringDate.getTime(), Size, true); baseFile.setLink(link); return baseFile; } else { BaseFile baseFile = new BaseFile(name, array[0], new File("/").lastModified(), Size, true); baseFile.setLink(link); return baseFile; } }
From source file:com.filemanager.free.utils.Futils.java
public BaseFile parseName(String line) { boolean linked = false; String name = "", link = "", size = "-1", date = ""; String[] array = line.split(" "); if (array.length < 6) return null; for (String anArray : array) { if (anArray.contains("->") && array[0].startsWith("l")) { linked = true;//from w w w .j av a2s.co m } } int p = getColonPosition(array); if (p != -1) { date = array[p - 1] + " | " + array[p]; size = array[p - 2]; } if (!linked) { for (int i = p + 1; i < array.length; i++) { name = name + " " + array[i]; } name = name.trim(); } else { int q = getLinkPosition(array); for (int i = p + 1; i < q; i++) { name = name + " " + array[i]; } name = name.trim(); for (int i = q + 1; i < array.length; i++) { link = link + " " + array[i]; } } long Size = (size == null || size.trim().length() == 0) ? -1 : Long.parseLong(size); if (date.trim().length() > 0) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd | HH:mm"); Date stringDate = simpledateformat.parse(date, pos); BaseFile baseFile = new BaseFile(name, array[0], stringDate.getTime(), Size, true); baseFile.setLink(link); return baseFile; } else { BaseFile baseFile = new BaseFile(name, array[0], new File("/").lastModified(), Size, true); baseFile.setLink(link); return baseFile; } }
From source file:com.runwaysdk.dataaccess.database.general.Oracle.java
/** * Formats an SQL value to a java value. * * @param value//from w w w. j av a 2s. c o m * @param dataType * @param ignoreCase * @return */ public String formatSQLToJavaTime(String value) { SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); java.util.Date date = sdf.parse(value, new ParsePosition(0)); sdf = new SimpleDateFormat(Constants.TIME_FORMAT); return sdf.format(date); }
From source file:com.runwaysdk.dataaccess.database.general.Oracle.java
/** * Formats an SQL date value to a Java String. * * @param value//from ww w .j a va2s. co m * @param dataType * @param ignoreCase * @return */ public String formatSQLToJavaDate(String value) { SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); java.util.Date date = sdf.parse(value, new ParsePosition(0)); sdf = new SimpleDateFormat(Constants.DATE_FORMAT); return sdf.format(date); }