• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wmixvideo / nfe / #7324

18 Nov 2025 12:44PM UTC coverage: 52.488%. Remained the same
#7324

push

web-flow
Merge 5aad707ce into 2d4409cab

272 of 387 new or added lines in 14 files covered. (70.28%)

704 existing lines in 45 files now uncovered.

14639 of 27890 relevant lines covered (52.49%)

0.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.09
/src/main/java/com/fincatto/documentofiscal/validadores/DFXMLValidador.java
1
package com.fincatto.documentofiscal.validadores;
2

3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.net.URISyntaxException;
6
import java.net.URL;
7
import javax.xml.transform.stream.StreamSource;
8
import javax.xml.validation.Schema;
9
import javax.xml.validation.SchemaFactory;
10
import org.xml.sax.SAXException;
11

12
public final class DFXMLValidador {
×
13

14
    private static boolean valida(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
15
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_008i2/%s", xsd));
×
16
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
17
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
18
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
19
        return true;
×
20
    }
21

22
    public static boolean validaLote(final String arquivoXML) throws Exception {
23
        return DFXMLValidador.valida(arquivoXML, "enviNFe_v3.10.xsd");
×
24
    }
25

26
    public static boolean validaNota(final String arquivoXML) throws Exception {
27
        return DFXMLValidador.valida(arquivoXML, "nfe_v3.10.xsd");
×
28
    }
29

30
    public static boolean valida400(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
31
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_010b_NT2025_002_v1.20/%s", xsd));
×
32
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
33
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
34
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
35
        return true;
×
36
    }
37

38
    public static boolean validaLote400(final String arquivoXML) throws Exception {
39
        return DFXMLValidador.valida400(arquivoXML, "enviNFe_v4.00.xsd");
×
40
    }
41

42
    public static boolean validaNota400(final String arquivoXML) throws Exception {
43
        return DFXMLValidador.valida400(arquivoXML, "nfe_v4.00.xsd");
×
44
    }
45

46
    /**
47
     * Valida MDFe. Para evitar "org.xml.sax.SAXParseException", message:
48
     * "Current configuration of the parser doesn't allow a maxOccurs attribute
49
     * value to be set greater than the value 5.000", foi adicionado a linha
50
     * System.setProperty("jdk.xml.maxOccurLimit", "10000");
51
     *
52
     * @param xml
53
     * @param xsd
54
     * @return
55
     * @throws IOException
56
     * @throws SAXException
57
     * @throws URISyntaxException
58
     */
59
    private static boolean validaMDF(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
60
        System.setProperty("jdk.xml.maxOccurLimit", "20000");
1✔
61
        /*
62
         * Para o jdk 11, falhava o teste com  DFXMLValidador.class.getClassLoader()
63
         * */
64
        final URL xsdPath = Thread.currentThread().getContextClassLoader().getResource(String.format("schemas/PL_MDFe_300b_NT022024/%s", xsd));        
1✔
65
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
1✔
66
        StreamSource streamSource = new StreamSource(xsdPath.toURI().toString());
1✔
67
                final Schema schema = schemaFactory.newSchema(streamSource);
1✔
68
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
1✔
69
        return true;
1✔
70
    }
71

72
    public static boolean validaLoteMDFe(final String arquivoXML) throws Exception {
UNCOV
73
        return DFXMLValidador.validaMDF(arquivoXML, "enviMDFe_v3.00.xsd");
×
74
    }
75

76
    public static boolean validaMDFe(final String arquivoXML) throws Exception {
77
        return DFXMLValidador.validaMDF(arquivoXML, "mdfe_v3.00.xsd");
×
78
    }
79
    
80
    public static boolean validaMDFeProcessado(final String xml) throws Exception {
81
        return DFXMLValidador.validaMDF(xml, "procMDFe_v3.00.xsd");
1✔
82
    }
83

84
    public static boolean validaEventoMDFe(final String xml) throws Exception {
UNCOV
85
        return DFXMLValidador.validaMDF(xml, "eventoMDFe_v3.00.xsd");
×
86
    }
87

88
    public static boolean validaEventoPagamentoOperacaoMDFe(final String xml) throws Exception {
89
        return DFXMLValidador.validaMDF(xml, "evPagtoOperMDFe_v3.00.xsd");
×
90
    }
91

92
    private static boolean validaCTe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
93
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTe_300a_NT2022.001/%s", xsd));
×
UNCOV
94
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
95
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
96
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
97
        return true;
×
98
    }
99

100
    public static boolean validaLoteCTe300(final String arquivoXML) throws Exception {
101
        return DFXMLValidador.validaCTe(arquivoXML, "enviCTe_v3.00.xsd");
×
102
    }
103

104
    public static boolean validaCTeOS300(final String arquivoXML) throws Exception {
105
        return DFXMLValidador.validaCTe(arquivoXML, "cteOS_v3.00.xsd");
×
106
    }
107

108
    public static boolean validaNotaCte(final String arquivoXML) throws Exception {
109
        return DFXMLValidador.validaCTe(arquivoXML, "cte_v3.00.xsd");
×
110
    }
111

112
    public static boolean validaEventoCTe300(final String arquivoXML) throws Exception {
113
        return DFXMLValidador.validaCTe(arquivoXML, "eventoCTe_v3.00.xsd");
×
114
    }
115

116
    public static boolean validaEventoCancelamentoCTe300(final String arquivoXML) throws Exception {
117
        return DFXMLValidador.validaCTe(arquivoXML, "evCancCTe_v3.00.xsd");
×
118
    }
119

120
    public static boolean validaEventoCancelamentoComprovanteEntregaCTe300(final String arquivoXML) throws Exception {
121
        return DFXMLValidador.validaCTe(arquivoXML, "evCancCECTe_v3.00.xsd");
×
122
    }
123

124
    public static boolean validaEventoCartaCorrecaoCTe300(final String arquivoXML) throws Exception {
125
        return DFXMLValidador.validaCTe(arquivoXML, "evCCeCTe_v3.00.xsd");
×
126
    }
127

128
    public static boolean validaEventoComprovanteEntregaCTe300(final String arquivoXML) throws Exception {
129
        return DFXMLValidador.validaCTe(arquivoXML, "evCECTe_v3.00.xsd");
×
130
    }
131

132
    public static boolean validaEventoEpecCTe300(final String arquivoXML) throws Exception {
133
        return DFXMLValidador.validaCTe(arquivoXML, "evEPECCTe_v3.00.xsd");
×
134
    }
135

136
    public static boolean validaEventoGtvCTe300(final String arquivoXML) throws Exception {
137
        return DFXMLValidador.validaCTe(arquivoXML, "evGTV_v3.00.xsd");
×
138
    }
139

140
    public static boolean validaEventoPrestacaoEmDesacordoCTe300(final String arquivoXML) throws Exception {
141
        return DFXMLValidador.validaCTe(arquivoXML, "evPrestDesacordo_v3.00.xsd");
×
142
    }
143

144
    public static boolean validaEventoRegistroMultimodalCTe300(final String arquivoXML) throws Exception {
145
        return DFXMLValidador.validaCTe(arquivoXML, "evRegMultimodal_v3.00.xsd");
×
146
    }
147

148
    private static boolean validaCTe400(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
149
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTe_400_NT2025.001_RTC_1.05/%s", xsd));
×
UNCOV
150
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
151
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
152
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
153
        return true;
×
154
    }
155

156
    public static boolean validaNotaCte400(final String arquivoXML) throws Exception {
157
        return DFXMLValidador.validaCTe400(arquivoXML, "cte_v4.00.xsd");
×
158
    }
159

160
    public static boolean validaNotaCTeOS400(final String arquivoXML) throws Exception {
161
        return DFXMLValidador.validaCTe400(arquivoXML, "cteOS_v4.00.xsd");
×
162
    }
163

164
    public static boolean validaEventoCTe400(final String arquivoXML) throws Exception {
165
        return DFXMLValidador.validaCTe400(arquivoXML, "eventoCTe_v4.00.xsd");
×
166
    }
167

168
    public static boolean validaEventoCancelamentoCTe400(final String arquivoXML) throws Exception {
169
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancCTe_v4.00.xsd");
×
170
    }
171

172
    public static boolean validaEventoCancelamentoComprovanteEntregaCTe400(final String arquivoXML) throws Exception {
173
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancCECTe_v4.00.xsd");
×
174
    }
175

176
    public static boolean validaEventoCartaCorrecaoCTe400(final String arquivoXML) throws Exception {
177
        return DFXMLValidador.validaCTe400(arquivoXML, "evCCeCTe_v4.00.xsd");
×
178
    }
179

180
    public static boolean validaEventoComprovanteEntregaCTe400(final String arquivoXML) throws Exception {
181
        return DFXMLValidador.validaCTe400(arquivoXML, "evCECTe_v4.00.xsd");
×
182
    }
183

184
    public static boolean validaEventoEpecCTe400(final String arquivoXML) throws Exception {
185
        return DFXMLValidador.validaCTe400(arquivoXML, "evEPECCTe_v4.00.xsd");
×
186
    }
187

188
    public static boolean validaEventoGtvCTe400(final String arquivoXML) throws Exception {
189
        return DFXMLValidador.validaCTe400(arquivoXML, "evGTV_v4.00.xsd");
×
190
    }
191

192
    public static boolean validaEventoPrestacaoEmDesacordoCTe400(final String arquivoXML) throws Exception {
193
        return DFXMLValidador.validaCTe400(arquivoXML, "evPrestDesacordo_v4.00.xsd");
×
194
    }
195

196
    public static boolean validaEventoRegistroMultimodalCTe400(final String arquivoXML) throws Exception {
197
        return DFXMLValidador.validaCTe400(arquivoXML, "evRegMultimodal_v4.00.xsd");
×
198
    }
199

200
    public static boolean validaEventoCancelamentoPrestacaoEmDesacordoCTe400(final String arquivoXML) throws Exception {
201
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancPrestDesacordo_v4.00.xsd");
×
202
    }
203

204
    public static boolean validaEventoCancelamentoInsucessoEntregaCTe400(final String arquivoXML) throws Exception {
205
        return DFXMLValidador.validaCTe400(arquivoXML, "evCancIECTe_v4.00.xsd");
×
206
    }
207

208
    public static boolean validaEventoInsucessoEntregaCTe400(final String arquivoXML) throws Exception {
209
        return DFXMLValidador.validaCTe400(arquivoXML, "evIECTe_v4.00.xsd");
×
210
    }
211

212
    private static boolean validaDfe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
213
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_NFeDistDFe_102/%s", xsd));
×
UNCOV
214
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
215
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
216
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
217
        return true;
×
218
    }
219
    private static boolean validaDistribuicaoCTe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
220
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_CTeDistDFe_100/%s", xsd));
×
221
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
222
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
223
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
224
        return true;
×
225
    }
226
    public static boolean validaDistribuicaoCTe(final String arquivoXML) throws IOException, SAXException, URISyntaxException {
227
        return DFXMLValidador.validaDistribuicaoCTe(arquivoXML, "distDFeInt_v1.00.xsd");
×
228
    }
229

230
    private static boolean validaDistribuicaoMDFe(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
231
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/PL_MDFeDistDFe_100/%s", xsd));
×
UNCOV
232
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
233
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
234
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
235
        return true;
×
236
    }
237
    public static boolean validaDistribuicaoMDFe(final String arquivoXML) throws IOException, SAXException, URISyntaxException {
238
        return DFXMLValidador.validaDistribuicaoMDFe(arquivoXML, "distDFeInt_v1.00.xsd");
×
239
    }
240
    
241
    public static boolean validaConsultaDfe(final String arquivoXML) throws Exception {
242
        return DFXMLValidador.validaDfe(arquivoXML, "distDFeInt_v1.01.xsd");
×
243
    }
244

245
    private static boolean validaEpec(final String xml, final String xsd) throws IOException, SAXException, URISyntaxException {
246
        final URL xsdPath = DFXMLValidador.class.getClassLoader().getResource(String.format("schemas/Evento_EPEC_PL_v1.01/%s", xsd));
×
UNCOV
247
        final SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
×
UNCOV
248
        final Schema schema = schemaFactory.newSchema(new StreamSource(xsdPath.toURI().toString()));
×
UNCOV
249
        schema.newValidator().validate(new StreamSource(new StringReader(xml)));
×
250
        return true;
×
251
    }
252

253
    public static boolean validaEpec(final String arquivoXML) throws Exception {
254
        return DFXMLValidador.validaEpec(arquivoXML, "envEPEC_v1.00.xsd");
×
255
    }
256

257
    public static boolean validaEventoEpec(final String arquivoXML) throws Exception {
258
        return DFXMLValidador.validaEpec(arquivoXML, "EPEC_v1.00.xsd");
×
259
    }
260
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc