LastModifiedHelper { static long getLastModified(Source source) { if (source instanceof DOMSource) { Document document = TraxUtils.getDocument((DOMSource) source); return document != null ? getLastModified(document.getDocumentURI()) : -1; } else { return getLastModified(source.getSystemId()); } } private  LastModifiedHelper();   }
@Test public void testSaxSource() throws Exception { long result = LastModifiedHelper.getLastModified(new ResourceSource(resource)); Assert.assertEquals("Invalid last modified", expected, result); }
@Test public void testDomSource() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(resource.getFile()); long result = LastModifiedHelper.getLastModified(new DOMSource(document)); Assert.assertEquals("Invalid last modified", expected, result); }
@Test public void testStreamSource() throws Exception { long result = LastModifiedHelper.getLastModified(new StreamSource(resource.getFile())); Assert.assertEquals("Invalid last modified", expected, result); }