forked from JasonMOliver/Java_Parsers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLCompTable.java
More file actions
125 lines (118 loc) · 4.29 KB
/
Copy pathXMLCompTable.java
File metadata and controls
125 lines (118 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLCompTable {
public static void main(String args[]) throws IOException, ParserConfigurationException,
org.xml.sax.SAXException {
try {
ArrayList<String> hostSet = new ArrayList<String>();
ArrayList<String> testSet = new ArrayList<String>();
ArrayList<String> resultSet = new ArrayList<String>();
ArrayList<String> hostSetIndex = new ArrayList<String>();
ArrayList<String> testSetIndex = new ArrayList<String>();
String host = null;
int n = 0;
for (int a = 0; a < args.length; a++)
{
File file = new File(args[a]);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("ReportHost");
for (int s = 0; s < nodeLst.getLength(); s++)
{
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE)
{
Element fstElmnt = (Element) fstNode;
host = fstElmnt.getAttributes().getNamedItem("name").getNodeValue();
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("ReportItem");
for (int i=0; i < fstNmElmntLst.getLength(); i++)
{
Element fstNmElmnt = (Element) fstNmElmntLst.item(i);
if (fstNmElmnt.getAttributes().getNamedItem("pluginID").getNodeValue().compareTo("21156")==0||fstNmElmnt.getAttributes().getNamedItem("pluginID").getNodeValue().compareTo("21157")==0)
{
if(fstNmElmnt.hasChildNodes())
{
NodeList riBody = fstNmElmnt.getChildNodes();
for (int x=0; x < riBody.getLength(); x++)
{
if((riBody.item(x)).hasChildNodes())
{
if (riBody.item(x).getNodeName()=="description")
{
String data = riBody.item(x).getFirstChild().getNodeValue().replaceAll("\\r|\\n", " ");
String[] testResultStr = data.split("\\[");
hostSet.add(host);
if (hostSetIndex.contains(host)==false)
{
hostSetIndex.add(host);
}
testSet.add(testResultStr[0].replaceAll("\"|: ", ""));
if (testSetIndex.contains(testResultStr[0].replaceAll("\"|: ", ""))==false)
{
testSetIndex.add(testResultStr[0].replaceAll("\"|: ", ""));
}
String[] resultStr = testResultStr[1].split("\\]");
resultSet.add(resultStr[0]);
}
}
}
}
n++;
}
}
}
}
}
System.out.println("<table>");
System.out.println("<tr>");
System.out.println("<th bgcolor=gray>TEST NAME</th>");
for (int i = 0; i < hostSetIndex.size(); i++)
{
System.out.println("<th bgcolor=gray>" + hostSetIndex.get(i) + "</th>");
}
System.out.println("</tr>");
for (int i = 0; i < testSetIndex.size(); i++)
{
System.out.println("<tr>");
System.out.println("<td>" + testSetIndex.get(i) + "</td>");
for (int x = 0; x < hostSetIndex.size(); x++)
{
for (int y = 0; y < resultSet.size(); y++)
{
if (hostSet.get(y).compareTo(hostSetIndex.get(x))==0 && testSet.get(y).compareTo(testSetIndex.get(i))==0)
{
//Need to develop an answer for tests with duplicate names. For now making them null
if (testSet.get(y).compareTo("CPE Platform Check")==0||testSet.get(y).compareTo("Xccdf_Scan_Check")==0||testSet.get(y).compareTo("Group Check")==0)
{
System.out.println("<td>" + "" + "</td>");
} else if (resultSet.get(y).compareTo("PASSED")==0)
{
System.out.println("<td align=center bgcolor=green>Passed</td>");
} else if (resultSet.get(y).compareTo("FAILED")==0)
{
System.out.println("<td align=center bgcolor=red>Failed</td>");
} else
{
System.out.println("<td align=center bgcolor=yellow>No Data</td>");
}
}
}
}
System.out.println("</tr>");
}
System.out.println("</table>");
} catch (Exception e) {
e.printStackTrace();
}
}
}