XmlWriter.java 3.01 KB
/*
 * 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;
    }
}