import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class GenerateCodeCenterDashboard {
private static void usage() {
System.out.println("Input Parameters:" );
System.out.println("Folder path\\name - Location and folder name where all Code Center xml files are stored\n" +
"File path\\name - location and filename to store the dashboard summary html report ");
System.out.println("");
}
/**********************************************************************************
*
* @param xml file generated by GetAssociateAndValidateResult script
* @return HTML String
*********************************************************************************/
public String getCodeCenterResult(File file) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
//System.out.println("Exists: " + file.getName() + " " + file.exists());
if (file.exists()) {
Document doc = db.parse(file);
NodeList appList = doc.getElementsByTagName("Application");
Node appName = appList.item(0);
Element appElement = (Element) appName;
NodeList validList = doc.getElementsByTagName("ValidationStatus");
Node validNode = validList.item(0);
Element validElement = (Element) validNode;
NodeList approveList = doc.getElementsByTagName("ApprovedStatus");
Node approveNode = approveList.item(0);
Element approveElement = (Element) approveNode;
String prj_str = "
| " + appElement.getTextContent() + " | ";
if (validElement.getTextContent().equals("PASSED"))
prj_str = prj_str + "" + validElement.getTextContent() + " | ";
else
prj_str = prj_str + " " + validElement.getTextContent() + " | ";
if (approveElement.getTextContent().equals("APPROVED"))
prj_str = prj_str + "" + approveElement.getTextContent() + " |
";
else
prj_str = prj_str + " " + approveElement.getTextContent() + " | ";
return prj_str;
}
} catch (Exception e) {
System.out.println(e);
}
return "Error!! Parsing XML reports";
}
/***********************************************************************************
* main()
* @param args
***********************************************************************************/
public static void main(String[] args)
{
if (args.length < 2) {
System.err.println("Not enough parameters!");
usage();
System.exit(-1);
}
GenerateCodeCenterDashboard parser = new GenerateCodeCenterDashboard();
String filename;
File folder = new File( args[0] );
File[] listOfFiles = folder.listFiles();
String html_content = "";
String OSName = null;
String delimiter = null;
OSName = System.getProperty("os.name");
if (OSName.contains("Windows")) delimiter = "\\";
else delimiter = "/";
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
filename = folder.getPath() + delimiter + listOfFiles[i].getName();
//System.out.println("File: " + filename);
if (filename.endsWith(".xml") || filename.endsWith(".XML"))
{
File filehandle = new File(filename);
String prj_str = parser.getCodeCenterResult( filehandle );
html_content = html_content + prj_str;
}
}
}
File f = new File(args[1]);
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write( ""
+ " Code Center Summary
"
+ ""
+ ""
+ "| Code Center Application | "
+ " Validation Status | "
+ " Approval Status | "
+ "
"
+ html_content + "
" ) ;
bw.close();
} catch (Exception e) {
System.out.println(e);
}
}
}