Created
July 1, 2018 05:17
-
-
Save masud-technope/5c6df6f9f95d1e8b94d34cd41ad1d1c2 to your computer and use it in GitHub Desktop.
XML creation for BugLocator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DocumentBuilderFactory docFactory = DocumentBuilderFactory | |
.newInstance(); | |
DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); | |
// root elements | |
Document doc = docBuilder.newDocument(); | |
Element rootElement = doc.createElement("bugrepository"); | |
rootElement.setAttribute("name", repoName); | |
doc.appendChild(rootElement); | |
for (BugEntry bentry : entries) { | |
Element bugElement = doc.createElement("bug"); | |
//if(bentry.bugID!=48784)continue; | |
bugElement.setAttribute("id", bentry.bugID + ""); | |
// adding the dates | |
bugElement.setAttribute("opendate", | |
this.openDateMap.get(bentry.bugID)); | |
bugElement.setAttribute("fixdate", | |
this.fixDateMap.get(bentry.bugID)); | |
Element bugInfo = doc.createElement("buginformation"); | |
// adding the summary | |
Element summary = doc.createElement("summary"); | |
summary.setTextContent(bentry.summary); | |
bugInfo.appendChild(summary); | |
// adding the description | |
Element description = doc.createElement("description"); | |
String refinedDesc = bentry.description.replace('\n', ' '); | |
description.setTextContent(refinedDesc); | |
bugInfo.appendChild(description); | |
Element fixedFiles = doc.createElement("fixedFiles"); | |
for (String changedFile : bentry.fixedFiles) { | |
if (changedFile.endsWith(".java") | |
|| changedFile.endsWith(".JAVA")) { | |
boolean existed = fileExists(changedFile); | |
if (existed) { | |
String canonicalName = changedFile | |
.replace('/', '.'); | |
canonicalName = makeItBLFriendly(canonicalName); | |
if (!canonicalName.trim().isEmpty()) { | |
Element file = doc.createElement("file"); | |
file.setTextContent(canonicalName); | |
fixedFiles.appendChild(file); | |
System.out.println(changedFile); | |
} | |
} else { | |
System.err.println(changedFile); | |
} | |
} | |
// adding the fixed files | |
bugElement.appendChild(bugInfo); | |
if(fixedFiles.hasChildNodes()){ | |
bugElement.appendChild(fixedFiles); | |
rootElement.appendChild(bugElement); | |
} | |
} | |
} | |
TransformerFactory transformerFactory = TransformerFactory | |
.newInstance(); | |
Transformer transformer = transformerFactory.newTransformer(); | |
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); | |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | |
transformer.setOutputProperty( | |
"{http://xml.apache.org/xslt}indent-amount", "2"); | |
DOMSource source = new DOMSource(doc); | |
StreamResult result = new StreamResult(new File(this.bugRepoXML)); | |
transformer.transform(source, result); | |
System.out.println("Bug reports saved successfully: " + repoName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment