List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:wptools.lib.Misc.java
/** * Parse an ISO8601 date/time string//from w ww . j a v a2s. co m * @param unparsed String containing date/time expression. * @param zone Time zone suffix to strip, if present. * @return Date parsed into a java.util.Date object. Note * that the Date is only suitable for setting * post_date_gmt, not post_date. */ public static Date parseDate(String unparsed, String zone) throws ParseException { String munged = unparsed.toUpperCase(); if (munged.endsWith(zone)) munged = munged.substring(0, munged.length() - zone.length()); for (SimpleDateFormat fmt : DATE_FORMATS) { ParsePosition pos = new ParsePosition(0); Date ret = fmt.parse(munged, pos); if (ret != null) { return ret; } } throw new ParseException("Unparseable date: " + unparsed, 0); }
From source file:org.pentaho.reporting.libraries.formula.typing.DefaultTypeRegistry.java
private static Number parse(final NumberFormat format, final String source) { final ParsePosition parsePosition = new ParsePosition(0); final Number result = format.parse(source, parsePosition); if (parsePosition.getIndex() == 0 || parsePosition.getIndex() != source.length()) { return null; }//from w ww . j a va 2s .c o m return result; }
From source file:org.jboss.forge.roaster.model.impl.PropertyImpl.java
@Override public PropertySource<O> setName(final String name) { if (StringUtils.isBlank(name)) { throw new IllegalStateException("Property name cannot be null/empty/blank"); }// ww w . ja va2s . c o m if (hasField()) { getField().setName(name); } final String oldName = this.name; final boolean visitDocTags = true; final ASTVisitor renameVisitor = new ASTVisitor(visitDocTags) { @Override public boolean visit(SimpleName node) { if (Objects.equals(oldName, node.getIdentifier())) { node.setIdentifier(name); } return super.visit(node); } @Override public boolean visit(TextElement node) { final String text = node.getText(); if (!text.contains(oldName)) { return super.visit(node); } final int matchLength = oldName.length(); final int textLength = text.length(); final StringBuilder buf = new StringBuilder(text.length()); final ParsePosition pos = new ParsePosition(0); while (pos.getIndex() < textLength) { final int index = pos.getIndex(); final char c = text.charAt(index); if (Character.isJavaIdentifierStart(c)) { final int next = index + matchLength; if (next <= textLength && Objects.equals(oldName, text.substring(index, next))) { buf.append(name); pos.setIndex(next); continue; } } buf.append(c); pos.setIndex(index + 1); } node.setText(buf.toString()); return super.visit(node); } }; if (isAccessible()) { final MethodSource<O> accessor = getAccessor(); final String prefix = accessor.getReturnType().isType(boolean.class) ? "is" : "get"; accessor.setName(methodName(prefix, name)); ((MethodDeclaration) accessor.getInternal()).accept(renameVisitor); } if (isMutable()) { final MethodSource<O> mutator = getMutator(); mutator.setName(methodName("set", name)); ((MethodDeclaration) mutator.getInternal()).accept(renameVisitor); } this.name = name; return this; }
From source file:org.apache.roller.weblogger.ui.core.tags.calendar.WeblogCalendarModel.java
public void setDay(String month) throws Exception { SimpleDateFormat fmt = DateUtil.get8charDateFormat(); fmt.setCalendar(getCalendar());/*from w w w.ja va 2 s . c o m*/ ParsePosition pos = new ParsePosition(0); initDay(fmt.parse(month, pos)); }
From source file:org.noorganization.instalistsynch.controller.synch.impl.RecipeSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }/*from w w w .j av a 2 s.c o m*/ Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (logCursor.getCount() == 0) { logCursor.close(); return; } try { while (logCursor.moveToNext()) { // fetch the action type int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mRecipeMappingController.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mRecipeMappingController.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mRecipeMappingController.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mRecipeMappingController.update(modelMapping); break; default: } } } catch (Exception e) { logCursor.close(); } }
From source file:org.pentaho.reporting.libraries.formula.typing.DefaultTypeRegistry.java
private static Date parse(final DateFormat format, final String source) { final ParsePosition parsePosition = new ParsePosition(0); final Date result = format.parse(source, parsePosition); if (parsePosition.getIndex() == 0 || parsePosition.getIndex() != source.length()) { return null; }//w ww. j a v a2 s.com return result; }
From source file:org.noorganization.instalistsynch.controller.synch.impl.TagSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }/*from ww w . jav a 2s .c o m*/ Cursor tagLogCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (tagLogCursor.getCount() == 0) { tagLogCursor.close(); return; } try { while (tagLogCursor.moveToNext()) { // fetch the action type int actionId = tagLogCursor.getInt(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mTagModelMappingController.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = tagLogCursor .getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mTagModelMappingController.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = tagLogCursor .getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mTagModelMappingController.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mTagModelMappingController.update(modelMapping); break; default: } } } catch (Exception e) { tagLogCursor.close(); } }
From source file:com.novartis.opensource.yada.adaptor.OracleAdaptor.java
/** * Enables checking for {@link JDBCAdaptor#ORACLE_DATE_FMT} if {@code val} does not conform to {@link JDBCAdaptor#STANDARD_DATE_FMT} * @since 5.1.1/*from ww w . ja v a 2 s . com*/ */ @Override protected void setDateParameter(PreparedStatement pstmt, int index, char type, String val) throws SQLException { if (EMPTY.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); pp = new ParsePosition(0); 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); } } }
From source file:org.noorganization.instalistsynch.controller.synch.impl.ProductSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }//from w ww . j a va 2 s. c o m Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (logCursor.getCount() == 0) { logCursor.close(); return; } try { while (logCursor.moveToNext()) { // fetch the action type int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mProductModelMapping.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mProductModelMapping.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mProductModelMapping.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mProductModelMapping.update(modelMapping); break; default: } } } catch (Exception e) { logCursor.close(); } }
From source file:org.ossmeter.platform.communicationchannel.nntp.local.NntpUtil.java
public static Date parseDate(String dateString) { for (SimpleDateFormat sdf : sdfList) { ParsePosition ps = new ParsePosition(0); Date result = sdf.parse(dateString, ps); if (ps.getIndex() != 0) return result; }//from w ww . j a v a 2 s . co m System.err.println("\t\t" + dateString + " cannot be parsed!\n"); return null; }