HtmlRenderer { public void generateFileList(final String entity, final File sourceFolder, final File targetFolder) throws CommanderException { File generatedFileList = new File( targetFolder.getAbsolutePath() + "/" + entity + ".xml"); DocumentBuilderFactory docFactory = DocumentBuilderFactory .newInstance(); docFactory.setNamespaceAware(true); try { DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("Files"); rootElement.setAttributeNS("http: "http: doc.appendChild(rootElement); Element entityElement = doc.createElement("entity"); entityElement.appendChild(doc.createTextNode(entity)); entityElement.setAttributeNS("http: "xmlns", "http: rootElement.appendChild(entityElement); File[] fileList = sourceFolder.listFiles(new XmlFileNameFilter()); Arrays.sort(fileList); for (File actFile : fileList) { Element newFileElement = doc.createElement("file"); newFileElement.appendChild(doc.createTextNode(actFile.getName() .substring(0, actFile.getName().lastIndexOf(".")))); newFileElement.setAttributeNS("http: "xmlns", "http: rootElement.appendChild(newFileElement); } TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(doc), new StreamResult(generatedFileList)); } catch (ParserConfigurationException e) { throw new CommanderException( "Could not configure document builder for " + generatedFileList.getAbsolutePath(), e); } catch (TransformerException e) { new CommanderException("Could not transform xml-result into file " + generatedFileList.getAbsolutePath(), e); } } HtmlRenderer(String aSystemName, String aRenderPath); void generateOutput(); final void render(final File xslFile, final File xmlFile,
            final File htmlFile); void mergeFiles(String entity, File sourceFolder); void generateFileList(final String entity, final File sourceFolder,
            final File targetFolder);  }
@Test public void generateFileListTest() throws CommanderException, SAXException, IOException, ParserConfigurationException { File resourceFolder = new File("src/test/resources/roles"); File targetFolder = new File("src/test/resources/lists"); targetFolder.mkdirs(); HtmlRenderer renderer = new HtmlRenderer("", ""); renderer.generateFileList("roles", resourceFolder, targetFolder); File generatedFileList = new File("src/test/resources/lists/roles.xml"); Assert.assertTrue(generatedFileList.exists()); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(generatedFileList); Element rootElement = doc.getDocumentElement(); Assert.assertEquals("Files", rootElement.getNodeName()); Assert.assertEquals("http: rootElement.getNamespaceURI()); NodeList files = rootElement.getElementsByTagName("file"); Assert.assertEquals(2, files.getLength()); generatedFileList.delete(); targetFolder.delete(); Assert.assertFalse(targetFolder.exists()); }