-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlWriter.java
More file actions
105 lines (93 loc) · 3.76 KB
/
Copy pathXmlWriter.java
File metadata and controls
105 lines (93 loc) · 3.76 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
package ToArrayExcel;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.OutputKeys;
import java.io.*;
import java.util.*;
/**
*
* @author Administrator
*/
public class XmlWriter {
private String saveFile;
private Document doc;
private DocumentBuilderFactory docFactory;
private DocumentBuilder builder;
private Element element;
private Writer writer;
private StreamResult result;
public XmlWriter(String saveFile) {
this.saveFile = saveFile;
try {
writer = new StringWriter();
result = new StreamResult(writer);
this.docFactory = DocumentBuilderFactory.newInstance();
this.builder = this.docFactory.newDocumentBuilder();
this.doc = this.builder.newDocument();
this.element = this.doc.createElement("sarp");
this.doc.appendChild(element);
} catch (Exception e) {
e.printStackTrace();
}
}
public void writeXml() {
try {
StringWriter sw = new StringWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer trans = tFactory.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.ENCODING, "utf-8");
trans.transform(new DOMSource(doc), new StreamResult(new FileWriter(this.saveFile)));
} catch (Exception e) {
e.printStackTrace();
}
}
public void saveNssPath(String nssPath) {
Element tmp = this.doc.createElement("nss");
tmp.setAttribute("path", nssPath);
this.element.appendChild(tmp);
}
public void saveThroughput(ArrayList<ThroughputArraySet> throughput) {
for (int i = 0; i < throughput.size(); i++) {
Element tmp = this.doc.createElement("throughput");
ThroughputArraySet tps = (ThroughputArraySet)throughput.get(i);
tmp.setAttribute("transaction", String.valueOf(tps.transaction));
tmp.setAttribute("value", String.valueOf(tps.throughput));
this.element.appendChild(tmp);
}
}
public void saveParent(ArrayList<ParentArraySet> parentSet){
for(int i = 0; i < parentSet.size(); i++){
ParentArraySet pas = (ParentArraySet)parentSet.get(i);
for(int j = 0; j < pas.size(); j++){
Element tmp = this.doc.createElement("parent");
tmp.setAttribute("transaction", String.valueOf(pas.getTransaction()));
tmp.setAttribute("source", String.valueOf(pas.getSource(j)));
tmp.setAttribute("target", String.valueOf(pas.getTarget(j)));
this.element.appendChild(tmp);
}
}
}
public void saveTrust(ArrayList<TrustArraySet> trust) {
for (int i = 0; i < trust.size(); i++) {
Element tmp = this.doc.createElement("trust");
TrustArraySet tas = (TrustArraySet)trust.get(i);
tmp.setAttribute("transaction", String.valueOf(tas.transaction));
tmp.setAttribute("time", String.valueOf(tas.time));
tmp.setAttribute("source", String.valueOf(tas.source));
tmp.setAttribute("target", String.valueOf(tas.target));
tmp.setAttribute("trustFP", String.valueOf(tas.trustFP));
tmp.setAttribute("trustPR", String.valueOf(tas.trustPR));
tmp.setAttribute("overall", String.valueOf(tas.overall));
this.element.appendChild(tmp);
}
}
}