List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:edu.amc.sakai.user.SimpleLdapAttributeMapper.java
/** * A delegate of {@link #mapLdapAttributeOntoUserData(LDAPAttribute, LdapUserData, Collection)} * that allows for discrete handling of each logical attribute name associated with * the given {@link LDAPAttribute}/* w w w . j a v a 2s .co m*/ * * @param attribute * @param userData * @param logicalAttrName */ protected void mapLdapAttributeOntoUserData(LDAPAttribute attribute, LdapUserData userData, String logicalAttrName) { String attrValue = attribute.getStringValue(); MessageFormat format = valueMappings.get(logicalAttrName); if (format != null && attrValue != null) { format = (MessageFormat) format.clone(); if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData(): value mapper [attrValue = " + attrValue + "; format=" + format.toString() + "]"); } attrValue = (String) (format.parse(attrValue, new ParsePosition(0))[0]); } if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() preparing to map: [logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } if (logicalAttrName.equals(AttributeMappingConstants.LOGIN_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.eid: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setEid(attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.FIRST_NAME_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.firstName: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setFirstName(attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.PREFERRED_FIRST_NAME_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.firstNamePreferred: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setPreferredFirstName(attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.LAST_NAME_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.lastName: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setLastName(attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.EMAIL_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User.email: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setEmail(attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.DISPLAY_ID_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User display Id: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setProperty(JLDAPDirectoryProvider.DISPLAY_ID_PROPERTY, attrValue); } else if (logicalAttrName.equals(AttributeMappingConstants.DISPLAY_NAME_ATTR_MAPPING_KEY)) { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to User display name: " + "[logical attr name = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setProperty(JLDAPDirectoryProvider.DISPLAY_NAME_PROPERTY, attrValue); } else { if (M_log.isDebugEnabled()) { M_log.debug("mapLdapAttributeOntoUserData() mapping attribute to a User property: " + "[logical attr name (and property name) = " + logicalAttrName + "][physical attr name = " + attribute.getName() + "][value = " + attrValue + "]"); } userData.setProperty(logicalAttrName, attrValue); } }
From source file:org.eclipse.dirigible.runtime.registry.RegistryServlet.java
private Date parseDate(String modifiedSinceHeader) { final Calendar calendar = Calendar.getInstance(); if ((modifiedSinceHeader.length() > 1) && modifiedSinceHeader.startsWith(SINGLE_QUOTE) && modifiedSinceHeader.endsWith(SINGLE_QUOTE)) { modifiedSinceHeader = modifiedSinceHeader.substring(1, modifiedSinceHeader.length() - 1); }// www . jav a 2 s . c om for (String format : DATE_FORMATS) { SimpleDateFormat dateParser = new SimpleDateFormat(format); dateParser.set2DigitYearStart(calendar.getTime()); final ParsePosition pos = new ParsePosition(0); final Date result = dateParser.parse(modifiedSinceHeader, pos); if (pos.getIndex() != 0) { return result; } } return null; }
From source file:org.catechis.Domartin.java
public static long getMillisecondsFromShortDate(String str_date) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); Date date = null;//from w ww . j a va 2 s .c om ParsePosition pp = new ParsePosition(0); long time = 0; try { date = sdf.parse(str_date, pp); time = date.getTime(); } catch (java.lang.NullPointerException npe) { } return time; }
From source file:com.s3d.webapps.util.time.DateUtils.java
/** * <p>Parses a string representing a date by trying a variety of different parsers.</p> * /*from w ww . j a v a 2 s. c om*/ * <p>The parse will try each parse pattern in turn. * A parse is only deemed successful if it parses the whole of the input string. * If no parse patterns match, a ParseException is thrown.</p> * * @param str the date to parse, not null * @param parsePatterns the date format patterns to use, see SimpleDateFormat, not null * @param lenient Specify whether or not date/time parsing is to be lenient. * @return the parsed date * @throws IllegalArgumentException if the date string or pattern array is null * @throws ParseException if none of the date patterns were suitable * @see java.util.Calender#isLenient() */ private static Date parseDateWithLeniency(String str, String[] parsePatterns, boolean lenient) throws ParseException { if (str == null || parsePatterns == null) { throw new IllegalArgumentException("Date and Patterns must not be null"); } SimpleDateFormat parser = new SimpleDateFormat(); parser.setLenient(lenient); ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { String pattern = parsePatterns[i]; // LANG-530 - need to make sure 'ZZ' output doesn't get passed to SimpleDateFormat if (parsePatterns[i].endsWith("ZZ")) { pattern = pattern.substring(0, pattern.length() - 1); } parser.applyPattern(pattern); pos.setIndex(0); String str2 = str; // LANG-530 - need to make sure 'ZZ' output doesn't hit SimpleDateFormat as it will ParseException if (parsePatterns[i].endsWith("ZZ")) { int signIdx = indexOfSignChars(str2, 0); while (signIdx >= 0) { str2 = reformatTimezone(str2, signIdx); signIdx = indexOfSignChars(str2, ++signIdx); } } Date date = parser.parse(str2, pos); if (date != null && pos.getIndex() == str2.length()) { return date; } } throw new ParseException("Unable to parse the date: " + str, -1); }
From source file:Unsigned.java
/** * Parse a binary number into a Number object. If up to 8 bits are parsed, * returns a Byte. If more than 8 and up to 16 bits are parsed, return a * Short. If more than 16 and up to 32 bits are parsed, return an Integer. * If more than 32 and up to 64 bits are parsed, return a Long. * //from w w w . j a va 2 s . c o m * @param source * a binary number * @return return an integer form of Number object if parse is successful * @exception ParseException * thrown if source is cannot be converted to a Byte, Short, * Int, or Long. * * @since 1.0 */ public Number parse(String source) throws ParseException { int startIndex = 0; Number result; ParsePosition parsePosition = new ParsePosition(startIndex); result = parse(source, parsePosition); if (result == null) { throw new ParseException("Unable to parse " + source + " using BinaryFormat", parsePosition.getIndex()); } return (result); }
From source file:com.zimbra.cs.util.SoapCLI.java
public static Date parseDatetime(String str) { for (String formatStr : DATETIME_FORMATS) { SimpleDateFormat fmt = new SimpleDateFormat(formatStr); fmt.setLenient(false);// ww w.j a v a 2s. c o m ParsePosition pp = new ParsePosition(0); Date d = fmt.parse(str, pp); if (d != null && pp.getIndex() == str.length()) return d; } return null; }
From source file:org.catechis.Domartin.java
public static String getCurrentFormattedDate() { SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = new Date(); String str_date = date.toString(); ParsePosition pp = new ParsePosition(0); long time = 0; try {//from w w w . j a v a2 s . c o m date = sdf.parse(str_date, pp); } catch (java.lang.NullPointerException npe) { } str_date = date.toString(); return str_date; }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParser.java
@Override public Date parse(final String source) throws ParseException { final ParsePosition pp = new ParsePosition(0); final Date date = parse(source, pp); if (date == null) { // Add a note re supported date range if (locale.equals(JAPANESE_IMPERIAL)) { throw new ParseException("(The " + locale + " locale does not support dates before 1868 AD)\n" + "Unparseable date: \"" + source, pp.getErrorIndex()); }/*from ww w. j a v a 2 s .c om*/ throw new ParseException("Unparseable date: " + source, pp.getErrorIndex()); } return date; }
From source file:util.android.util.DateUtils.java
/** * Parse an Atom date String into Date object. This is a fairly lenient parse and does not require the date String * to conform exactly./*from w ww .ja v a 2s . c o m*/ * * @param dateString * @return Date * @throws IllegalArgumentException */ @SuppressLint("SimpleDateFormat") public static Date parseAtomDate(String dateString, TimeZone timezone) throws IllegalArgumentException { Date d = null; for (int n = 0; n < atomMasks.length; n++) { try { atomFormats[n].setTimeZone(timezone); atomFormats[n].setLenient(true); d = atomFormats[n].parse(dateString, new ParsePosition(0)); if (d != null) break; } catch (Exception ignored) { } } if (d == null) { Log.e("DateUtils", "Cannot parse: " + dateString); throw new IllegalArgumentException(); } return d; }
From source file:org.kepler.io.DirectoryListing.java
private long getUTC(String month, String day, String timeORyear) { String dateStr;//from w ww . j a v a2 s . c om if (timeORyear.indexOf(':') > -1) { // this is hh:mm dateStr = month + " " + day + " " + currentYear + " " + timeORyear; } else { // this is yyyy year dateStr = month + " " + day + " " + timeORyear + " 00:00"; } ParsePosition pp = new ParsePosition(0); Date d = sdf.parse(dateStr, pp); // System.out.println(" Parsed " + dateStr + " to " + d); long utc = d.getTime() / 1000; return utc; }