List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:org.lnicholls.galleon.togo.ToGo.java
public void getvideoDetails(HttpClient client, Video video, String url) { GetMethod get = null;// w ww. ja va 2 s. c o m try { // System.out.println(httpget.getResponseBodyAsString()); get = new GetMethod(url); client.executeMethod(get); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(get.getResponseBodyAsStream()); // Get the root element Element root = document.getRootElement(); // <TiVoContainer> Element showing = root.element("showing"); if (showing != null) { Element element = showing; if (element != null) { Element node = element.element("partCount"); if (node != null) try { video.setPartCount(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part count", ex); } node = element.element("partIndex"); if (node != null) try { video.setPartIndex(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part index", ex); } Element program = element.element("program"); if (program != null) { node = program.element("vActor"); if (node != null) video.setActors(getElements(node)); node = program.element("vAdvisory"); if (node != null) video.setAdvisories(getElements(node)); node = program.element("vChoreographer"); if (node != null) video.setChoreographers(getElements(node)); node = program.element("vChoreographer"); if (node != null) video.setChoreographers(getElements(node)); node = program.element("colorCode"); if (node != null) { video.setColor(node.getText()); try { video.setColorCode(Integer.parseInt(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set color code", ex); } } node = program.element("description"); if (node != null) video.setDescription(node.getTextTrim()); node = program.element("vDirector"); if (node != null) video.setDirectors(getElements(node)); node = program.element("episodeNumber"); if (node != null) try { video.setEpisodeNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not episode number", ex); } node = program.element("episodeTitle"); if (node != null) video.setEpisodeTitle(node.getTextTrim()); node = program.element("vExecProducer"); if (node != null) video.setExecProducers(getElements(node)); node = program.element("vProgramGenre"); if (node != null) video.setProgramGenre(getElements(node)); node = program.element("vGuestStar"); if (node != null) video.setGuestStars(getElements(node)); node = program.element("vHost"); if (node != null) video.setHosts(getElements(node)); node = program.element("isEpisode"); if (node != null) video.setEpisodic(Boolean.valueOf(node.getTextTrim())); node = program.element("originalAirDate"); if (node != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(node.getTextTrim(), pos); if (date == null) date = new Date(0); video.setOriginalAirDate(date); // 2000-03-25T00:00:00Z } node = program.element("vProducer"); if (node != null) video.setProducers(getElements(node)); Element series = program.element("series"); if (series != null) { node = series.element("vSeriesGenre"); if (node != null) video.setSeriesGenre(getElements(node)); node = series.element("seriesTitle"); if (node != null) video.setSeriesTitle(node.getTextTrim()); } node = program.element("showType"); if (node != null) { video.setShowType(node.getTextTrim()); try { video.setShowTypeValue(new Integer(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set showtype value", ex); } } node = program.element("title"); if (node != null) video.setTitle(node.getTextTrim()); node = program.element("vWriter"); if (node != null) video.setWriters(getElements(node)); } Element channel = element.element("channel"); if (channel != null) { node = channel.element("displayMajorNumber"); if (node != null) try { video.setChannelMajorNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not set channel major number", ex); } node = channel.element("displayMinorNumber"); if (node != null) try { video.setChannelMinorNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not set channel minor number", ex); } node = channel.element("callsign"); if (node != null) video.setCallsign(node.getTextTrim()); } Element rating = element.element("tvRating"); if (rating != null) { video.setRating(rating.getTextTrim()); try { video.setRatingValue(new Integer(rating.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } } } showing = root.element("vActualShowing"); if (showing != null) { Iterator iterator = showing.elementIterator("element"); while (iterator.hasNext()) { Element element = (Element) iterator.next(); Element node = null; Element channel = element.element("channel"); if (channel != null) { node = channel.element("displayMajorNumber"); if (node != null) try { int value = Integer.parseInt(node.getTextTrim()); if (value != video.getChannelMajorNumber()) break; video.setChannelMajorNumber(value); } catch (Exception ex) { log.error("Could not set channel major number", ex); } node = channel.element("displayMinorNumber"); if (node != null) try { int value = Integer.parseInt(node.getTextTrim()); if (value != video.getChannelMinorNumber()) break; video.setChannelMinorNumber(value); } catch (Exception ex) { log.error("Could not set channel minor number", ex); } node = channel.element("callsign"); if (node != null && video.getCallsign() == null) video.setCallsign(node.getTextTrim()); } node = element.element("partCount"); if (node != null && video.getPartCount() == null) try { video.setPartCount(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part count", ex); } node = element.element("partIndex"); if (node != null && video.getPartIndex() == null) try { video.setPartIndex(new Integer(node.getText())); } catch (Exception ex) { log.error("Could not set part index", ex); } Element program = element.element("program"); if (program != null) { node = program.element("vActor"); if (node != null && video.getActors() == null) video.setActors(getElements(node)); node = program.element("vAdvisory"); if (node != null && video.getAdvisories() == null) video.setAdvisories(getElements(node)); node = program.element("vChoreographer"); if (node != null && video.getChoreographers() == null) video.setChoreographers(getElements(node)); node = program.element("vChoreographer"); if (node != null && video.getChoreographers() == null) video.setChoreographers(getElements(node)); node = program.element("colorCode"); if (node != null && video.getColor() == null) { video.setColor(node.getText()); try { video.setColorCode(Integer.parseInt(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set color code", ex); } } node = program.element("description"); if (node != null && video.getDescription() == null) video.setDescription(node.getTextTrim()); node = program.element("vDirector"); if (node != null && video.getDirectors() == null) video.setDirectors(getElements(node)); node = program.element("episodeNumber"); if (node != null && video.getEpisodeNumber() != 0) try { video.setEpisodeNumber(Integer.parseInt(node.getTextTrim())); } catch (Exception ex) { log.error("Could not episode number", ex); } node = program.element("episodeTitle"); if (node != null && video.getEpisodeTitle() == null) video.setEpisodeTitle(node.getTextTrim()); node = program.element("vExecProducer"); if (node != null && video.getExecProducers() == null) video.setExecProducers(getElements(node)); node = program.element("vProgramGenre"); if (node != null && video.getProgramGenre() == null) video.setProgramGenre(getElements(node)); node = program.element("vGuestStar"); if (node != null && video.getGuestStars() == null) video.setGuestStars(getElements(node)); node = program.element("vHost"); if (node != null && video.getHosts() == null) video.setHosts(getElements(node)); node = program.element("isEpisode"); if (node != null && video.getEpisodic() == null) video.setEpisodic(Boolean.valueOf(node.getTextTrim())); node = program.element("originalAirDate"); if (node != null && video.getOriginalAirDate() == null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(node.getTextTrim(), pos); if (date == null) date = new Date(0); video.setOriginalAirDate(date); // 2000-03-25T00:00:00Z } node = program.element("vProducer"); if (node != null && video.getProducers() == null) video.setProducers(getElements(node)); Element series = program.element("series"); if (series != null && video.getSeriesGenre() == null) { node = series.element("vSeriesGenre"); if (node != null) video.setSeriesGenre(getElements(node)); node = series.element("seriesTitle"); if (node != null) video.setSeriesTitle(node.getTextTrim()); } node = program.element("showType"); if (node != null && video.getShowType() == null) { video.setShowType(node.getTextTrim()); try { video.setShowTypeValue(new Integer(node.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set showtype value", ex); } } node = program.element("title"); if (node != null && video.getTitle() == null) video.setTitle(node.getTextTrim()); node = program.element("vWriter"); if (node != null && video.getWriters() == null) video.setWriters(getElements(node)); } Element rating = element.element("tvRating"); if (rating != null && video.getRating() == null) { video.setRating(rating.getTextTrim()); try { video.setRatingValue(new Integer(rating.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } } } Element node = root.element("vBookmark"); if (node != null) { /* * <vBookmark> <element> <time>PT4M42.137000000S </time> * </element> </vBookmark> * */ StringBuffer buffer = new StringBuffer(); int counter = 0; for (Iterator iterator = node.elementIterator("element"); iterator.hasNext();) { Element bookmarkElement = (Element) iterator.next(); if (counter++ > 0) buffer.append(";"); buffer.append(Tools.getAttribute(bookmarkElement, "time")); } video.setBookmarks(buffer.toString()); } Element quality = root.element("recordingQuality"); if (quality != null) { video.setRecordingQuality(quality.getTextTrim()); try { video.setRecordingQualityValue(new Integer(quality.attribute("value").getText())); } catch (Exception ex) { log.error("Could not set rating value", ex); } } Element time = root.element("startTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setStartTime(date); // 2005-02-23T11:59:58Z } time = root.element("stopTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setStopTime(date); // 2005-02-23T11:59:58Z } time = root.element("expirationTime"); if (time != null) { ParsePosition pos = new ParsePosition(0); Date date = mTimeDateFormat.parse(time.getTextTrim(), pos); if (date == null) date = new Date(0); video.setExpirationTime(date); // 2005-02-23T11:59:58Z } } catch (Exception ex) { Tools.logException(ToGo.class, ex); } finally { if (get != null) { get.releaseConnection(); get = null; } } }
From source file:com.nridge.core.base.field.Field.java
/** * Returns a <i>Date</i> representation of the field value * string based on the FORMAT_DATETIME_DEFAULT format mask * property.// w ww. ja va2 s .c o m * * @param aValue Date/Time string value. * * @return Converted value. */ public static Date createDate(String aValue) { if (StringUtils.isNotEmpty(aValue)) { if (aValue.equals(Field.VALUE_DATETIME_TODAY)) return new Date(); else { ParsePosition parsePosition = new ParsePosition(0); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Field.FORMAT_DATETIME_DEFAULT); return simpleDateFormat.parse(aValue, parsePosition); } } else return new Date(); }
From source file:com.flexive.shared.FxFormatUtils.java
/** * Convert a String to Long//from w w w . java2 s. c o m * * @param value value to convert * @return Long */ public static Long toLong(String value) { if (StringUtils.isBlank(value)) return null; final ParsePosition pos = new ParsePosition(0); final String _value = value.trim(); try { final Number parse = FxValueRendererFactory.getNumberFormatInstance().parse(unquote(_value), pos); if (pos.getErrorIndex() >= 0 || pos.getIndex() != _value.length() || parse.doubleValue() != (double) parse.longValue() /*truncation*/) throw new FxConversionException("ex.conversion.value.error", FxLargeNumber.class.getCanonicalName(), value, "Failed to parse " + value).asRuntimeException(); return parse.longValue(); } catch (NumberFormatException e) { throw new FxConversionException("ex.conversion.value.error", FxLargeNumber.class.getCanonicalName(), value, "Failed to parse [" + value + "] using dec.sep. [" + FxContext.get().getDecimalSeparator() + "] and grouping sep. [" + FxContext.get().getDecimalSeparator() + "]") .asRuntimeException(); } }
From source file:com.servoy.j2db.util.Utils.java
/** * Create a Date (time) from a String, returns null on failure<br> * Example: Timestamp t = Utils.parseDate("23-06-1975 6:08 AM", "dd-MM-yyyy hh:mm a"); <br> * * @param datetime the date as formatted string * @param format the format to be used/*w w w . j a v a 2s. co m*/ * @return the Timestamp object * @see java.text.SimpleDateFormat */ public static Timestamp parseDate(String datetime, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); Date d = sdf.parse(datetime, new ParsePosition(0)); return new Timestamp(d.getTime()); }
From source file:com.flexive.shared.FxFormatUtils.java
/** * Convert a String to Double//from w ww. ja va 2 s . c o m * * @param value value to convert * @return Double */ public static Double toDouble(String value) { if (StringUtils.isBlank(value)) return null; final ParsePosition pos = new ParsePosition(0); final String _value = value.trim(); try { Double res = FxValueRendererFactory.getNumberFormatInstance().parse(unquote(_value), pos).doubleValue(); if (pos.getErrorIndex() >= 0 || pos.getIndex() != _value.length()) throw new FxConversionException("ex.conversion.value.error", FxDouble.class.getCanonicalName(), value, "Failed to parse " + value).asRuntimeException(); return res; } catch (NumberFormatException e) { throw new FxConversionException("ex.conversion.value.error", FxLargeNumber.class.getCanonicalName(), value, "Failed to parse [" + value + "] using dec.sep. [" + FxContext.get().getDecimalSeparator() + "] and grouping sep. [" + FxContext.get().getDecimalSeparator() + "]") .asRuntimeException(); } }
From source file:nattable.ColorNatInstance.java
/** * Format: String date value using a SimpleDateFormat *///from w w w . ja va 2 s . c o m private static IDisplayConverter getDateFormatter() { return new DisplayConverter() { private final SimpleDateFormat dateFormatter = new SimpleDateFormat("MM-dd-yy"); public Object canonicalToDisplayValue(Object canonicalValue) { return dateFormatter.format((Date) canonicalValue); } public Object displayToCanonicalValue(Object displayValue) { return dateFormatter.parse(displayValue.toString(), new ParsePosition(0)); } }; }
From source file:nattable.ColorNatInstance.java
/** * Format: Number as millions (with commas). Convert to int. *///from ww w. j a v a 2 s .c o m private static IDisplayConverter getMillionsDisplayConverter() { return new DisplayConverter() { NumberFormat numberFormatter = new DecimalFormat("###,###,###"); public Object canonicalToDisplayValue(Object canonicalValue) { if (canonicalValue == null) { return null; } return numberFormatter.format(Integer.valueOf(canonicalValue.toString())); } public Object displayToCanonicalValue(Object displayValue) { return (numberFormatter.parse(displayValue.toString(), new ParsePosition(0))).intValue(); } }; }
From source file:com.flexive.shared.FxFormatUtils.java
/** * Convert a String to Float// w w w.j a v a2 s . c o m * * @param value value to convert * @return Float */ public static Float toFloat(String value) { if (StringUtils.isBlank(value)) return null; final ParsePosition pos = new ParsePosition(0); final String _value = value.trim(); try { Float res = FxValueRendererFactory.getNumberFormatInstance().parse(unquote(_value), pos).floatValue(); if (pos.getErrorIndex() >= 0 || pos.getIndex() != _value.length()) throw new FxConversionException("ex.conversion.value.error", FxFloat.class.getCanonicalName(), value, "Failed to parse " + value).asRuntimeException(); return res; } catch (NumberFormatException e) { throw new FxConversionException("ex.conversion.value.error", FxLargeNumber.class.getCanonicalName(), value, "Failed to parse [" + value + "] using dec.sep. [" + FxContext.get().getDecimalSeparator() + "] and grouping sep. [" + FxContext.get().getDecimalSeparator() + "]") .asRuntimeException(); } }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testParseOffset() { final DateParser parser = getInstance(YMD_SLASH); final Date date = parser.parse("Today is 2015/07/04", new ParsePosition(9)); final Calendar cal = Calendar.getInstance(); cal.clear();//w w w.ja v a2 s. c o m cal.set(2015, Calendar.JULY, 4); Assert.assertEquals(cal.getTime(), date); }
From source file:com.unboundid.scim2.common.utils.JsonUtils.java
/** * Try to parse out a date from a JSON text node. * * @param node The JSON node to parse.// www . j av a 2 s .com * * @return A parsed date instance or {@code null} if the text is not an * ISO8601 formatted date and time string. */ private static Date dateValue(final JsonNode node) { String text = node.textValue().trim(); if (text.length() >= 19 && Character.isDigit(text.charAt(0)) && Character.isDigit(text.charAt(1)) && Character.isDigit(text.charAt(2)) && Character.isDigit(text.charAt(3)) && text.charAt(4) == '-') { try { return ISO8601Utils.parse(text, new ParsePosition(0)); } catch (ParseException e) { // This is not a date after all. } } return null; }