All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.swconsultoria.mdfe.ValidarMDFe Maven / Gradle / Ivy

The newest version!
package br.com.swconsultoria.mdfe;

import br.com.swconsultoria.mdfe.dom.ConfiguracoesMDFeInterface;
import br.com.swconsultoria.mdfe.exception.MdfeException;
import br.com.swconsultoria.mdfe.util.ConstantesMDFe;
import br.com.swconsultoria.mdfe.util.Valida;

import java.io.File;

/**
 * @author Samuel Oliveira
 * @author john
 */
class ValidarMDFe extends Valida {

    static String validaXml(ConfiguracoesMDFeInterface configuracoes, String xml, String tipo) throws MdfeException {
        String errosValidacao;

        switch (tipo) {
            case ConstantesMDFe.SERVICOS.STATUS_SERVICO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.STATUS_SERVICO;
                break;
            case ConstantesMDFe.SERVICOS.ENVIO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.ENVIO_MDFE;
                break;
            case ConstantesMDFe.SERVICOS.EVENTO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.EVENTO;
                break;
            case ConstantesMDFe.SERVICOS.CANCELAR:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.CANCELAR;
                break;
            case ConstantesMDFe.SERVICOS.ENCERRAR:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.ENCERRAR;
                break;
            case ConstantesMDFe.SERVICOS.INCLUIR_CONDUTOR:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.INCLUIR_CONDUTOR;
                break;

            case ConstantesMDFe.SERVICOS.CONSULTA_NAO_ENCERRADO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.CONSULTA_NAO_ENCERRADO;
                break;

            case ConstantesMDFe.SERVICOS.CONSULTA_PROTOCOLO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.CONSULTA_PROTOCOLO;
                break;
            case ConstantesMDFe.SERVICOS.CONSULTA_RECIBO:
                xsd = configuracoes.getPastaSchemas() + "/" + ConstantesMDFe.XSD.CONSULTA_RECIBO;
                break;

            default:
                throw new MdfeException("Não Encontrado XSD para:" + tipo);
        }

        xsd += ".xsd";

        if (!new File(xsd).exists()) {
            throw new MdfeException("Schema Nfe não Localizado: " + xsd);
        }

        ValidarMDFe validar = new ValidarMDFe();

        errosValidacao = validar.validateXml(xml, xsd);

        return errosValidacao;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy