RemoteMapCatalog { public void parseXML(List<Workspace> workspaces,XMLStreamReader parser) throws XMLStreamException { List<String> hierarchy = new ArrayList<String>(); StringBuilder characters = new StringBuilder(); for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { switch(event) { case XMLStreamConstants.START_ELEMENT: hierarchy.add(parser.getLocalName()); break; case XMLStreamConstants.END_ELEMENT: if(RemoteCommons.endsWith(hierarchy,"workspaces","workspace","name")) { workspaces.add(new Workspace(cParams,characters.toString().trim())); } hierarchy.remove(hierarchy.size()-1); characters = new StringBuilder(); break; case XMLStreamConstants.CHARACTERS: characters.append(StringEscapeUtils.unescapeHtml4(parser.getText())); break; } } } RemoteMapCatalog(ConnectionProperties connectionProperties); void parseXML(List<Workspace> workspaces,XMLStreamReader parser); List<Workspace> getWorkspaces();  }
@Test public void testParseXML() throws Exception { URL apiUrl = new URL("http: FileReader inFile = new FileReader(new File(RemoteMapCatalogTest.class.getResource("workspaces.xml").toURI())); BufferedReader in = new BufferedReader(inFile); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser; parser = factory.createXMLStreamReader(in); RemoteMapCatalog mapCatalog = new RemoteMapCatalog( new ConnectionProperties(apiUrl, null, new File("target/maps"))); List<Workspace> workspaces = new ArrayList<Workspace>(); mapCatalog.parseXML(workspaces, parser); parser.close(); assertEquals(workspaces.size(), 4); List<String> workspacesNames = new ArrayList<String>(); for(Workspace workspace : workspaces) { workspacesNames.add(workspace.getWorkspaceName()); } assertTrue(workspacesNames.containsAll( Arrays.asList("default","toto","titi","tata"))); }