protected List<URI> findXmlUrlReferences(final String directoryContents, final URL url) throws URISyntaxException { final List<URI> results = new ArrayList<URI>(); final List<String> urlFragments = extractHrefs(directoryContents); for (final String u : urlFragments) { if (u.endsWith(XML_EXTENSION)) { //points to xml if (u.startsWith("/")) { //absolute path need to add the protocol results.add(new URI(url.getProtocol() + ":" + u)); } else if (u.startsWith("http:")) { // full url results.add(new URI(u)); } else { // relative url stick the name on the end results.add(appendToURI(url, u)); } } } return results; }
protected List<URI> findXmlReferences(final String directoryContents, final URL url) throws URISyntaxException { if (url.getProtocol().equals(PROTOCOL_FOR_FILE)) { return findXmlFileReferences(directoryContents, url); } return findXmlUrlReferences(directoryContents, url); }
@Override public void loadDefaultCatalog(final String url) throws CatalogApiException { if (url != null) { defaultCatalog = loader.loadDefaultCatalog(url); } }
xmlURIs.add(new URI(uriString)); } else { // Assume its a directory final URL url = getURLFromString(uriString); final String directoryContents = UriAccessor.accessUriAsString(uriString); xmlURIs = findXmlReferences(directoryContents, url);
protected List<URI> findXmlFileReferences(final String directoryContents, final URL url) throws URISyntaxException { final List<URI> results = new ArrayList<URI>(); final String[] filenames = directoryContents.split("\\n"); for (final String filename : filenames) { if (filename.endsWith(XML_EXTENSION)) { results.add(appendToURI(url, filename)); } } return results; }
@Test(groups = "fast") public void testFindXmlFileReferences() throws MalformedURLException, URISyntaxException { final String page = "dg.xml\n" + "replica.foo\n" + "snv1/\n" + "viking.xml\n"; final List<URI> urls = loader.findXmlFileReferences(page, new URL("http://ning.com/")); Assert.assertEquals(urls.size(), 2); Assert.assertEquals(urls.get(0).toString(), "http://ning.com/dg.xml"); Assert.assertEquals(urls.get(1).toString(), "http://ning.com/viking.xml"); }
@Test(groups = "fast") public void testExtractHrefs() { final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" + "<html>" + " <head>" + " <title>Index of /config/trunk/xno</title>" + " </head>" + " <body>" + "<h1>Index of /config/trunk/xno</h1>" + "<ul><li><a href=\"/config/trunk/\"> Parent Directory</a></li>" + "<li><a href=\"dg.xml\"> dg.xml</a></li>" + "<li><a href=\"replica.foo\"> replica/</a></li>" + "<li><a href=\"replica2/\"> replica2/</a></li>" + "<li><a href=\"replica_dyson/\"> replica_dyson/</a></li>" + "<li><a href=\"snv1/\"> snv1/</a></li>" + "<li><a href=\"viking.xml\"> viking.xml</a></li>" + "</ul>" + "<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" + "</body></html>"; final List<String> hrefs = loader.extractHrefs(page); Assert.assertEquals(hrefs.size(), 8); Assert.assertEquals(hrefs.get(0), "/config/trunk/"); Assert.assertEquals(hrefs.get(1), "dg.xml"); }
@Test(groups = "fast") public void testFindXmlUrlReferences() throws MalformedURLException, URISyntaxException { final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" + "<html>" + " <head>" + " <title>Index of /config/trunk/xno</title>" + " </head>" + " <body>" + "<h1>Index of /config/trunk/xno</h1>" + "<ul><li><a href=\"/config/trunk/\"> Parent Directory</a></li>" + "<li><a href=\"dg.xml\"> dg.xml</a></li>" + "<li><a href=\"replica.foo\"> replica/</a></li>" + "<li><a href=\"replica2/\"> replica2/</a></li>" + "<li><a href=\"replica_dyson/\"> replica_dyson/</a></li>" + "<li><a href=\"snv1/\"> snv1/</a></li>" + "<li><a href=\"viking.xml\"> viking.xml</a></li>" + "</ul>" + "<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" + "</body></html>"; final List<URI> uris = loader.findXmlUrlReferences(page, new URL("http://ning.com/")); Assert.assertEquals(uris.size(), 2); Assert.assertEquals(uris.get(0).toString(), "http://ning.com/dg.xml"); Assert.assertEquals(uris.get(1).toString(), "http://ning.com/viking.xml"); }
@Override public Catalog loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException { return loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId); } };
@Test(groups = "fast") public void testAppendToURI() throws IOException, URISyntaxException { final URL u1 = new URL("http://www.ning.com/foo"); Assert.assertEquals(loader.appendToURI(u1, "bar").toString(), "http://www.ning.com/foo/bar"); final URL u2 = new URL("http://www.ning.com/foo/"); Assert.assertEquals(loader.appendToURI(u2, "bar").toString(), "http://www.ning.com/foo/bar"); }
@Test(groups = "fast") public void testFindXmlFileReferences() throws MalformedURLException, URISyntaxException { final String page = "dg.xml\n" + "replica.foo\n" + "snv1/\n" + "viking.xml\n"; final List<URI> urls = loader.findXmlFileReferences(page, new URL("http://ning.com/")); Assert.assertEquals(urls.size(), 2); Assert.assertEquals(urls.get(0).toString(), "http://ning.com/dg.xml"); Assert.assertEquals(urls.get(1).toString(), "http://ning.com/viking.xml"); }
@Test(groups = "fast") public void testExtractHrefs() { final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" + "<html>" + " <head>" + " <title>Index of /config/trunk/xno</title>" + " </head>" + " <body>" + "<h1>Index of /config/trunk/xno</h1>" + "<ul><li><a href=\"/config/trunk/\"> Parent Directory</a></li>" + "<li><a href=\"dg.xml\"> dg.xml</a></li>" + "<li><a href=\"replica.foo\"> replica/</a></li>" + "<li><a href=\"replica2/\"> replica2/</a></li>" + "<li><a href=\"replica_dyson/\"> replica_dyson/</a></li>" + "<li><a href=\"snv1/\"> snv1/</a></li>" + "<li><a href=\"viking.xml\"> viking.xml</a></li>" + "</ul>" + "<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" + "</body></html>"; final List<String> hrefs = loader.extractHrefs(page); Assert.assertEquals(hrefs.size(), 8); Assert.assertEquals(hrefs.get(0), "/config/trunk/"); Assert.assertEquals(hrefs.get(1), "dg.xml"); }
@Test(groups = "fast") public void testFindXmlUrlReferences() throws MalformedURLException, URISyntaxException { final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" + "<html>" + " <head>" + " <title>Index of /config/trunk/xno</title>" + " </head>" + " <body>" + "<h1>Index of /config/trunk/xno</h1>" + "<ul><li><a href=\"/config/trunk/\"> Parent Directory</a></li>" + "<li><a href=\"dg.xml\"> dg.xml</a></li>" + "<li><a href=\"replica.foo\"> replica/</a></li>" + "<li><a href=\"replica2/\"> replica2/</a></li>" + "<li><a href=\"replica_dyson/\"> replica_dyson/</a></li>" + "<li><a href=\"snv1/\"> snv1/</a></li>" + "<li><a href=\"viking.xml\"> viking.xml</a></li>" + "</ul>" + "<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" + "</body></html>"; final List<URI> uris = loader.findXmlUrlReferences(page, new URL("http://ning.com/")); Assert.assertEquals(uris.size(), 2); Assert.assertEquals(uris.get(0).toString(), "http://ning.com/dg.xml"); Assert.assertEquals(uris.get(1).toString(), "http://ning.com/viking.xml"); }
xmlURIs.add(new URI(uriString)); } else { // Assume its a directory final URL url = getURLFromString(uriString); final String directoryContents = UriAccessor.accessUriAsString(uriString); xmlURIs = findXmlReferences(directoryContents, url);
@Override public Catalog loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException { return loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId); } };
@VisibleForTesting void setDefaultCatalog() { try { // Provided in the classpath this.defaultCatalog = loader.loadDefaultCatalog("EmptyCatalog.xml"); } catch (final CatalogApiException e) { this.defaultCatalog = new DefaultVersionedCatalog(); logger.error("Exception loading EmptyCatalog - should never happen!", e); } } }
protected List<URI> findXmlReferences(final String directoryContents, final URL url) throws URISyntaxException { if (url.getProtocol().equals(PROTOCOL_FOR_FILE)) { return findXmlFileReferences(directoryContents, url); } return findXmlUrlReferences(directoryContents, url); }
protected List<URI> findXmlUrlReferences(final String directoryContents, final URL url) throws URISyntaxException { final List<URI> results = new ArrayList<URI>(); final List<String> urlFragments = extractHrefs(directoryContents); for (final String u : urlFragments) { if (u.endsWith(XML_EXTENSION)) { //points to xml if (u.startsWith("/")) { //absolute path need to add the protocol results.add(new URI(url.getProtocol() + ":" + u)); } else if (u.startsWith("http:")) { // full url results.add(new URI(u)); } else { // relative url stick the name on the end results.add(appendToURI(url, u)); } } } return results; }
protected List<URI> findXmlFileReferences(final String directoryContents, final URL url) throws URISyntaxException { final List<URI> results = new ArrayList<URI>(); final String[] filenames = directoryContents.split("\\n"); for (final String filename : filenames) { if (filename.endsWith(XML_EXTENSION)) { results.add(appendToURI(url, filename)); } } return results; }
@Test(groups = "fast", expectedExceptions = CatalogApiException.class) public void testLoadCatalogFromClasspathResourceBadFolder() throws CatalogApiException { loader.loadDefaultCatalog("SpyCarCustom.xml"); }