XmlReader.java
3.88 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gerador;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
*
* @author felipel
*/
public class XmlReader {
String portIn = null, portOut = null, pid = null, resolution = null,
dph = null, dpv = null, dfw = null, dfh = null, version = null,
pidcc = null, ip = null, tipo = null, input = null;
int flag = 0;
public XmlReader(String nomeXml) throws JDOMException, IOException {
// cria uma nova instância
SAXBuilder saxBuilder = new SAXBuilder();
Document document = null;
// o saxBuilder constroe um documento em árvore usando o SAX
try {
document = (Document) saxBuilder.build(nomeXml);
} catch (Exception e) {
e.printStackTrace();
}
// obtem o elemento raiz da árvore.
Element root = document.getRootElement();
this.percorrerArvore(root);
}
private void percorrerArvore(Element element) {
String nome;
Element child;
Iterator iterator;
List children;
nome = element.getName();
//System.out.println("Nome: " + nome);
if (nome.equals("pid")) {
pid = element.getTextNormalize();
}
if (nome.equals("resolucao")) {
resolution = element.getTextNormalize();
}
if (nome.equals("DPH")) {
dph = element.getTextNormalize();
}
if (nome.equals("DPV")) {
dpv = element.getTextNormalize();
}
if (nome.equals("DFW")) {
dfw = element.getTextNormalize();
}
if (nome.equals("DFH")) {
dfh = element.getTextNormalize();
}
if (nome.equals("versao")) {
version = element.getTextNormalize();
}
if (nome.equals("pidCC")) {
pidcc = element.getTextNormalize();
}
if (nome.equals("entrada")) {
tipo = element.getAttributeValue("tipo");
if (tipo.equals("MPEG-2 TS") || tipo.equals("RAW")) {
flag = 1;
}
if(tipo.equals("Texto")) {
input = element.getTextNormalize();
}
}
if (nome.equals("porta") && flag == 1) {
input = element.getAttributeValue("input");
portIn = element.getTextNormalize();
}
if (nome.equals("saida")) {
flag = 2;
}
if (nome.equals("ip")) {
ip = element.getTextNormalize();
}
if (nome.equals("porta") && flag == 2) {
portOut = element.getTextNormalize();
}
children = element.getChildren();
// Percorre os filhos deste elemento
iterator = children.iterator();
while (iterator.hasNext()) {
child = (Element) iterator.next();
// busca os filhos deste elemento
percorrerArvore(child);
}
}
public String getTipo() {
return tipo;
}
public String getInput() {
return input;
}
public String getPid() {
return pid;
}
public String getresolucao() {
return resolution;
}
public String getDph() {
return dph;
}
public String getDpv() {
return dpv;
}
public String getDfw() {
return dfw;
}
public String getDfh() {
return dfh;
}
public String getVersao() {
return version;
}
public String getPidCC() {
return pidcc;
}
public String getPortaIn() {
return portIn;
}
public String getPortaOut() {
return portOut;
}
public String getIp() {
return ip;
}
}