Search in sources :

Example 71 with XPathParseException

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DateTime(org.joda.time.DateTime) NavException(com.ximpleware.NavException) ParseException(java.text.ParseException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException)

Aggregations

XPathParseException (com.ximpleware.XPathParseException)71 NavException (com.ximpleware.NavException)66 XPathEvalException (com.ximpleware.XPathEvalException)66 AutoPilot (com.ximpleware.AutoPilot)65 VTDNav (com.ximpleware.VTDNav)46 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)36 ModifyException (com.ximpleware.ModifyException)17 ArrayList (java.util.ArrayList)17 XMLModifier (com.ximpleware.XMLModifier)15 IOException (java.io.IOException)15 VTDGen (com.ximpleware.VTDGen)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 HashMap (java.util.HashMap)9 ParseException (com.ximpleware.ParseException)8 TranscodeException (com.ximpleware.TranscodeException)7 FileNotFoundException (java.io.FileNotFoundException)7 FileOutputStream (java.io.FileOutputStream)6 EOFException (com.ximpleware.EOFException)5 EncodingException (com.ximpleware.EncodingException)5 EntityException (com.ximpleware.EntityException)5