public static void appendCatalogNode(MutableTreeNode parentNode, DefaultTreeModel treeModel, InvCatalogRef catalogRef) { final DefaultMutableTreeNode catalogNode = new DefaultMutableTreeNode(catalogRef.getName()); final String catalogPath = catalogRef.getURI().toASCIIString(); final CatalogNode opendapNode = new CatalogNode(catalogPath, catalogRef); opendapNode.setCatalogUri(catalogPath); catalogNode.add(new DefaultMutableTreeNode(opendapNode)); treeModel.insertNodeInto(catalogNode, parentNode, parentNode.getChildCount()); }
public static List<InvDataset> getCatalogDatasets(DefaultMutableTreeNode node) throws IOException { Object userObject = node.getUserObject(); if (!(userObject instanceof CatalogNode)) { return Collections.emptyList(); } final CatalogNode catalogNode = (CatalogNode) userObject; final URL catalogUrl; InputStream inputStream = null; try { catalogUrl = new URL(catalogNode.getCatalogUri()); URLConnection urlConnection = catalogUrl.openConnection(); inputStream = urlConnection.getInputStream(); return getCatalogDatasets(inputStream, catalogUrl.toURI()); } catch (URISyntaxException e) { throw new IOException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ignore) { // ok } } } } }
@Test public void testThatOpendapLeafWhichIsCatalogRefIsResolvedToTrue() { final CatalogNode opendapLeaf = new CatalogNode("any", null); final DefaultMutableTreeNode notDapNode = new DefaultMutableTreeNode(opendapLeaf); assertEquals(true, CatalogTreeUtils.isCatalogReferenceNode(notDapNode)); } }
@Test public void testAppendCatalogNodeToParent() throws URISyntaxException { //preparation final URI whatever = null; final InvCatalogRef catalogReference = new InvCatalogRef(null, "catalogRefName", "http://a.b"); catalogReference.setCatalog(new InvCatalogImpl("whatever", "1.0", whatever)); //execution CatalogTreeUtils.appendCatalogNode(parentNode, getDefaultTreeModel(), catalogReference); //verification assertEquals(1, parentNode.getChildCount()); assertEquals(1, parentNode.getChildAt(0).getChildCount()); final DefaultMutableTreeNode child1 = (DefaultMutableTreeNode) parentNode.getChildAt(0); assertEquals(true, child1.getUserObject() instanceof String); assertEquals("catalogRefName", child1.getUserObject()); final DefaultMutableTreeNode child2 = (DefaultMutableTreeNode) parentNode.getChildAt(0).getChildAt(0); assertEquals(true, child2.getUserObject() instanceof CatalogNode); final CatalogNode catalogNode = (CatalogNode) child2.getUserObject(); assertEquals("http://a.b", catalogNode.getCatalogUri()); }