use of com.ximpleware.XPathParseException in project opennms by OpenNMS.
the class AbstractVTDXmlCollectionHandler method getTimeStamp.
/**
* Gets the time stamp.
*
* @param document the document
* @param group the group
* @return the time stamp
* @throws XPathParseException the x-path parse exception
*/
protected Date getTimeStamp(VTDNav document, XmlGroup group) throws XPathParseException {
if (group.getTimestampXpath() == null) {
return null;
}
String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern);
document.push();
AutoPilot ap = new AutoPilot();
ap.bind(document);
ap.selectXPath(group.getTimestampXpath());
String value = ap.evalXPathToString();
document.pop();
if (value == null || value.isEmpty()) {
LOG.warn("getTimeStamp: can't find the custom timestamp using XPATH {}", group.getTimestampXpath());
return null;
}
Date date = null;
try {
DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
DateTime dateTime = dtf.parseDateTime(value);
date = dateTime.toDate();
} catch (Exception e) {
LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern);
date = DateTime.now().toDate();
}
return date;
}
Aggregations