class WebPageDateEvaluator {

    public static ExtractedDate getBestPubDateHtml5(Document document) {
        Validate.notNull(document, "document must not be null");

        List<Node> articleNodes = XPathHelper.getXhtmlNodes(document, "//article");
        
        // determine the longest article node.
        Node nodeToCheck = null;
        int longest = -1;
        for (Node articleNode : articleNodes) {
            int articleLength = HtmlHelper.getInnerXml(articleNode).length();
            if (articleLength > longest) {
                nodeToCheck = articleNode;
                longest = articleLength;
            }
        }
        
        // we couldn't identify a document node, consider the whole document
        if (nodeToCheck == null) {
            nodeToCheck = document;
        }

        if (nodeToCheck != null) {
            List<Node> timeNodes = XPathHelper.getXhtmlNodes(nodeToCheck, ".//time");
            for (Node timeNode : timeNodes) {
                NamedNodeMap attributes = timeNode.getAttributes();
                if (attributes.getNamedItem("pubdate") != null) {
                    Node dateTime = attributes.getNamedItem("datetime");
                    if (dateTime != null) {
                        return DateParser.findDate(dateTime.getTextContent());
                    }
                }
            }
        }
        return null;
    }

    private  WebPageDateEvaluator();

}