XmlWriter.java
3.01 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gerador;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
/**
*
* @author felipel
*/
public class XmlWriter {
String taEntrada = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
String geradorAberto = "<gerador>";
String geradorFechado = "</gerador>";
String porOut, ip;
public void writer(String pid, String resolucao, String posicoes, String versaoDic, String pidCC, String portaIn, String tipo, String tipoEntrada, String portaOut, String ipp) throws FileNotFoundException {
portaOut = porOut;
ipp = ip;
int CC = 0, flag = 0, i = 1;
String DPH = "", DPV = "", DFW = "", DFH = "";
while (!posicoes.substring(i, i + 1).equals(",")) {
DPH += posicoes.substring(i, i + 1);
i++;
}
i += 1;
while (!posicoes.substring(i, i + 1).equals(")")) {
DPV += posicoes.substring(i, i + 1);
i++;
}
i += 3;
while (!posicoes.substring(i, i + 1).equals(",")) {
DFW += posicoes.substring(i, i + 1);
i++;
}
i += 1;
while (!posicoes.substring(i, i + 1).equals(")")) {
DFH += posicoes.substring(i, i + 1);
i++;
}
File arq = new File("data/configuracoes.xml");
CC = Integer.parseInt(pidCC);
PrintWriter outStream = new PrintWriter(arq);
outStream.print(taEntrada);
outStream.println(geradorAberto);
outStream.print("\t<pid>" + pid + "</pid>\n");
outStream.print("\t<resolucao>" + resolucao + "</resolucao>\n");
outStream.print("\t<posicoes>\n");
outStream.print("\t\t<DPH>" + DPH + "</DPH>\n");
outStream.print("\t\t<DPV>" + DPV + "</DPV>\n");
outStream.print("\t\t<DFW>" + DFW + "</DFW>\n");
outStream.print("\t\t<DFH>" + DFH + "</DFH>\n");
outStream.print("\t</posicoes>\n");
outStream.print("\t<versao>" + versaoDic + "</versao>\n");
if (CC > 0) {
outStream.print("\t<pidCC>" + pidCC + "</pidCC>\n");
}
if (tipo.equals("IP") || tipo.equals("ASI")) {
outStream.print("\t<entrada tipo=\"" + tipoEntrada + "\">\n");
outStream.print("\t\t<porta input=\"" + tipo + "\">" + portaIn + "</porta>\n");
outStream.print("\t</entrada>\n");
}
if(tipo.equals("Arquivo")) {
outStream.print("\t<entrada tipo=\"" + tipoEntrada + "\">" + tipo + "</entrada>\n");
}
outStream.print("\t<saida tipo=\"" + "IP" + "\">\n");
outStream.print("\t\t<ip>" + ipp + "</ip>\n");
outStream.print("\t\t<porta>" + portaOut + "</porta>\n");
outStream.print("\t</saida>\n");
outStream.print(geradorFechado);
outStream.close();
}
public void setPortaOut(String out) {
porOut = out;
}
public void setIpOut(String i) {
ip = i;
}
}