Example usage for org.jdom2 Document setRootElement

List of usage examples for org.jdom2 Document setRootElement

Introduction

In this page you can find the example usage for org.jdom2 Document setRootElement.

Prototype

public Document setRootElement(Element rootElement) 

Source Link

Document

This sets the root Element for the Document.

Usage

From source file:prueba.Prueba.java

public static void write() throws IOException {
    //Se crea un numero documento
    Document document = new Document();
    //Se abre el buffer para la lectura por consola
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Ingrese el nombre del elemento raiz(root):");
    String raiz = br.readLine();/*from ww  w. j  a v  a2  s .  c om*/
    //Se asigna el elemento raiz
    Element root = new Element(raiz);
    System.out.print("Numero de atributos a crear en su archivo XML:");
    int numeroElementos = Integer.parseInt(br.readLine());
    //Creacion del vector que contendra los elementos del xml 
    String[] elementos = new String[numeroElementos];
    //Creacion del vector que contendra los contenidos del xml
    String[] contenidos = new String[numeroElementos];
    for (int i = 0; i < numeroElementos; i++) {
        System.out.print("Nombre del atributo (" + (i + 1) + "):");
        elementos[i] = br.readLine();
    }
    for (int i = 0; i < numeroElementos; i++) {
        System.out.print("Digite el contenido del elemento(" + elementos[i] + "):");
        contenidos[i] = br.readLine();
    }
    for (int i = 0; i < numeroElementos; i++) {
        Element element = new Element(elementos[i]);
        element.setText(contenidos[i]);
        root.addContent(element);
    }
    document.setRootElement(root);
    XMLOutputter outputter = new XMLOutputter();
    outputter.output(document, new FileOutputStream(new File("src/file.xml")));
}

From source file:se.miun.itm.input.util.xml.SAXUtil.java

License:Open Source License

private static se.miun.itm.input.model.Document getWrapper(Document document) {
    DocType dt = document.getDocType();//  w w  w .ja v a 2s .  c o  m
    document.setDocType(null);
    Element root = document.getRootElement();
    // a new root is just added to change the context.
    document.setRootElement(new Element(Q.SEED));
    return new se.miun.itm.input.model.Document(root, dt, document.getBaseURI());
}

From source file:Servico.ArgoUMLtoAstahXML.java

public void ToXmi(UmlModel model) throws InterruptedException, IOException {
    Document doc = new Document();
    Element Emodel = new Element(model.getClass().getName());
    Emodel.setAttribute("id", model.getId() + "");
    Emodel.setAttribute("name", model.getName() + "");
    doc.setRootElement(Emodel);
    for (UmlDiagram diagram : model.getDiagrams()) {
        Element EDiagram = new Element(diagram.getClass().getName());
        EDiagram.setAttribute("id", diagram.getId() + "");
        EDiagram.setAttribute("name", diagram.getName() + "");

        for (UmlBase umlObject : diagram.getUmlObjects()) {
            //verificar o conteudo para a tag tdaction e substituir
            String action = umlObject.getTaggedValues().get("TDACTION");
            if (action != null) {
                action = action.replaceAll("%", "%25");
                umlObject.getTaggedValues().put("TDACTION", action);
            }/*  w  ww  .j av  a  2 s.  c o m*/

            Element EUmlObject = getElement(umlObject);
            EDiagram.addContent(EUmlObject);

        }
        Emodel.addContent(EDiagram);
        //doc.setRootElement(EDiagram);
    }

    //Imprimindo o XML
    File out = File.createTempFile("IntermediateFile", ".xml");//, new File(Configuration.getInstance().getProperty("workspacepath")));

    try (FileWriter arquivo = new FileWriter(out)) {
        XMLOutputter xout = new XMLOutputter();
        xout.output(doc, arquivo);
    } catch (Exception e) {
        throw new IllegalAccessError("No foi possivel escrever o arquivo xml.");
    }
}

From source file:view.MobilePartnerView.java

public boolean createXML(String url, String user, String driver, String password) throws Exception {
    Element root = new Element("dbconf");
    Document doc = new Document();

    Element child1 = new Element("url");
    // child1.addContent("jdbc:mysql://localhost:3306/mobile_partner");
    child1.addContent(url);/* w  w w . j  a va  2s .  c om*/
    child1.setAttribute("name", "javax.persistence.jdbc.url");

    Element child2 = new Element("user");
    // child2.addContent("root");
    child2.addContent(user);
    child2.setAttribute("name", "javax.persistence.jdbc.user");

    Element child3 = new Element("driver");
    //child3.addContent("com.mysql.jdbc.Driver");
    child3.addContent(driver);
    child3.setAttribute("name", "javax.persistence.jdbc.driver");

    Element child4 = new Element("password");
    //  child4.addContent("nbuser");
    child4.addContent(password);
    child4.setAttribute("name", "javax.persistence.jdbc.password");

    root.addContent(child1);
    root.addContent(child2);
    root.addContent(child3);
    root.addContent(child4);

    doc.setRootElement(root);

    XMLOutputter outter = new XMLOutputter();
    outter.setFormat(Format.getPrettyFormat());
    outter.output(doc, new FileWriter(new File(dir + "\\dbconf.xml")));
    File xmlFile = new File(dir + "\\dbconf.xml");
    if (xmlFile.exists()) {
        return true;
    } else {
        return false;
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

/**
 * Add a splitPane with a treeview on the left and the JTreeMap on the right
 *//* w w  w  .  j a  v  a2 s . co m*/
public void StrategiesQuantitiesofWarningsforClass() {
    File f = new File(
            "programs_analyzeds/" + program_analyzed + "/treemap/warnings/" + class_analyzed + "_warnings.xml");

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {

        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + class_analyzed);
        root.addContent(label);

        try {
            Conexao.open();
            String sql1 = "select beginline, quantidade_warning from quantity_tool_and_warnings_for_line A inner join arquivo B on (A.nameprogram=B.nomeprograma AND A.nameprogram='"
                    + program_analyzed + "') AND (A.nameclass='" + class_analyzed
                    + "' AND A.nameclass=B.nomearquivo) AND nomepacote='" + package_analyzed + "'";
            Statement stmt7;
            stmt7 = Conexao.cn.createStatement();
            ResultSet rs7 = stmt7.executeQuery(sql1);
            while (rs7.next()) {
                Element branch = new Element("branch");
                Element leaf = new Element("leaf");
                Element label3 = null, weight = null, value = null;

                label3 = new Element("label");
                label3.addContent("" + rs7.getString(1));
                leaf.addContent(label3);
                weight = new Element("weight");
                weight.addContent("" + rs7.getString(2));

                value = new Element("value");
                value.addContent("" + rs7.getString(2));
                leaf.addContent(weight);
                leaf.addContent(value);

                branch.addContent(leaf);

                root.addContent(branch);

            }
            rs7.close();
            stmt7.close();
        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
            out.close();
            Conexao.cn.close();
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        setXmlFile(f.getAbsolutePath());
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofSuspectionRateforPackage()
        throws NumberFormatException, SQLException, ClassNotFoundException {

    File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/suspection_rate/" + package_analyzed
            + "_suspection.xml");
    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {//from w  ww  .j  a  va2  s.  co m
        Conexao.open();
        Statement sentenca = Conexao.cn.createStatement();
        String tamanho_matriz = "";

        ResultSet rs3 = sentenca.executeQuery(
                " SELECT count(distinct A.nameclass) FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas A inner join arquivo B on A.nameprogram=B.nomeprograma AND B.nomepacote='"
                        + package_analyzed
                        + "'  AND (A.nameclass=B.nomearquivo AND A.nameclass NOT LIKE '%.class' AND A.nameclass NOT LIKE '%jlint%' AND A.nameclass NOT LIKE '%.zip')");

        while (rs3.next()) {
            for (int i = 1; i <= 1; i++) {
                tamanho_matriz += rs3.getObject(i).toString();
                System.out.println("Tamanho da Matriz" + tamanho_matriz);

            }
        }
        rs3.close();

        double[] mean = new double[5];

        ResultSet rs4 = sentenca.executeQuery(
                " SELECT A.nameclass, sum(qnt_nv1), sum(qnt_nv2), sum(qnt_nv3), sum(qnt_nv4), sum(qnt_nv5) FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas A inner join arquivo B on A.nameprogram=B.nomeprograma AND B.nomepacote='"
                        + package_analyzed
                        + "' AND (A.nameclass=B.nomearquivo AND A.nameclass NOT LIKE '%.class' AND A.nameclass NOT LIKE '%jlint%' AND A.nameclass NOT LIKE '%.zip') group by A.nameclass");

        double[][] matriz_ = new double[Integer.parseInt(tamanho_matriz)][5];

        int j = 0;
        int soma_coluna_1 = 1;
        int soma_coluna_2 = 1;
        int soma_coluna_3 = 1;
        int soma_coluna_4 = 1;
        int soma_coluna_5 = 1;

        while (rs4.next()) {
            String part1 = "", part11[] = null;

            for (int i = 1; i <= 6; i++) {
                part1 += rs4.getObject(i) + "/";

                if (i == 6) {

                    if (matriz_[j][0] != 0) {
                        soma_coluna_1 += 1;

                    }

                    if (matriz_[j][1] != 0) {
                        soma_coluna_2 += 1;

                    }

                    if (matriz_[j][2] != 0) {
                        soma_coluna_3 += 1;

                    }

                    if (matriz_[j][3] != 0) {
                        soma_coluna_4 += 1;

                    }

                    if (matriz_[j][4] != 0) {
                        soma_coluna_5 += 1;

                    }

                    j++;
                }

            }
        }

        rs4.close();
        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + package_analyzed);
        root.addContent(label);
        String sql1 = "select A.nameclass, sum(qnt_nv1), sum(qnt_nv2), sum(qnt_nv3), sum(qnt_nv4), sum(qnt_nv5)  from quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas A inner join arquivo B on A.nameprogram=B.nomeprograma AND B.nomepacote='"
                + package_analyzed
                + "' AND (A.nameclass=B.nomearquivo AND A.nameclass NOT LIKE '%.class' AND A.nameclass NOT LIKE '%jlint%' AND A.nameclass NOT LIKE '%.zip') group by A.nameclass";
        Statement stmt2;
        stmt2 = Conexao.cn.createStatement();
        ResultSet rs = stmt2.executeQuery(sql1);
        double[] matriz_coeficientes = new double[Integer.parseInt(tamanho_matriz)];
        int i = 0;
        while (rs.next()) {
            double coeficiente = Integer.parseInt(rs.getString(2)) / soma_coluna_5 * 5
                    + Integer.parseInt(rs.getString(3)) / soma_coluna_4 * 4
                    + Integer.parseInt(rs.getString(4)) / soma_coluna_3 * 3
                    + Integer.parseInt(rs.getString(5)) / soma_coluna_2 * 2
                    + Integer.parseInt(rs.getString(6)) / soma_coluna_1 * 1;
            matriz_coeficientes[i] = coeficiente;
            System.out.println(matriz_coeficientes[i]);
            i++;
        }
        rs.close();
        stmt2.close();

        // System.out.println(selecionar_maior_coeficiente(matriz_coeficientes));

        int x = 0;
        Statement stmt;
        stmt = Conexao.cn.createStatement();
        ResultSet rs2 = stmt.executeQuery(sql1);
        double maior = selecionar_maior_coeficiente(matriz_coeficientes);
        System.out.println(maior);
        double valor;
        while (rs2.next()) {
            Element branch = new Element("branch");
            Element leaf = new Element("leaf");
            Element label3 = null, weight = null, value = null;
            label3 = new Element("label");

            label3.addContent("" + rs2.getString(1));
            leaf.addContent(label3);
            valor = matriz_coeficientes[x] / maior;
            weight = new Element("weight");
            weight.addContent("" + valor);
            value = new Element("value");
            value.addContent("" + valor);
            leaf.addContent(weight);
            leaf.addContent(value);
            branch.addContent(leaf);
            root.addContent(branch);

            x++;
        }
        rs2.close();
        stmt.close();
        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            Conexao.cn.close();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        setXmlFile(f.getAbsolutePath());
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofSuspectionRateforProgram()
        throws NumberFormatException, SQLException, ClassNotFoundException {

    File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/suspection_rate/" + program_analyzed
            + "_suspection.xml");
    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {/*from  w w w .j a  v a2s.co m*/
        Conexao.open();
        Statement sentenca = Conexao.cn.createStatement();

        String tamanho_matriz = "";

        ResultSet rs3 = sentenca
                .executeQuery("select count(distinct nomepacote)from arquivo where nomeprograma='"
                        + program_analyzed + "' AND nomepacote IS NOT NULL group by nomepacote");

        while (rs3.next()) {
            for (int i = 1; i <= 1; i++) {
                tamanho_matriz += rs3.getObject(i);
            }
        }
        rs3.close();

        ResultSet rs4 = sentenca.executeQuery(
                " SELECT B.nomepacote, sum(qnt_nv1), sum(qnt_nv2), sum(qnt_nv3), sum(qnt_nv4), sum(qnt_nv5) FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas A inner join arquivo B on (A.nameprogram='"
                        + program_analyzed
                        + "' AND A.nameprogram=B.nomeprograma) AND (nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip') AND B.nomepacote IS NOT NULL group by B.nomepacote");

        double[][] matriz_ = new double[Integer.parseInt(tamanho_matriz)][5];

        int j = 0;
        int soma_coluna_1 = 1;
        int soma_coluna_2 = 1;
        int soma_coluna_3 = 1;
        int soma_coluna_4 = 1;
        int soma_coluna_5 = 1;

        while (rs4.next()) {
            String part1 = "", part11[] = null;

            for (int i = 1; i <= 6; i++) {
                part1 += rs4.getObject(i) + "/";

                if (i == 6) {

                    // System.out.println(j);

                    if (matriz_[j][0] != 0) {
                        soma_coluna_1 += 1;

                    }

                    if (matriz_[j][1] != 0) {
                        soma_coluna_2 += 1;

                    }

                    if (matriz_[j][2] != 0) {
                        soma_coluna_3 += 1;

                    }

                    if (matriz_[j][3] != 0) {
                        soma_coluna_4 += 1;

                    }

                    if (matriz_[j][4] != 0) {
                        soma_coluna_5 += 1;

                    }

                    j++;
                }

            }

        }
        rs4.close();

        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + program_analyzed);
        root.addContent(label);
        String sql1 = "select B.nomepacote, sum(qnt_nv1), sum(qnt_nv2), sum(qnt_nv3), sum(qnt_nv4), sum(qnt_nv5)  from quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas A inner join arquivo B on (A.nameprogram='"
                + program_analyzed
                + "' AND A.nameprogram=B.nomeprograma)  AND   (nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip') group by B.nomepacote";
        Statement stmt2;
        stmt2 = Conexao.cn.createStatement();
        ResultSet rs = stmt2.executeQuery(sql1);
        double[] matriz_coeficientes = new double[Integer.parseInt(tamanho_matriz)];
        int i = 0;
        while (rs.next()) {
            double coeficiente = Integer.parseInt(rs.getString(2)) / soma_coluna_5 * 5
                    + Integer.parseInt(rs.getString(3)) / soma_coluna_4 * 4
                    + Integer.parseInt(rs.getString(4)) / soma_coluna_3 * 3
                    + Integer.parseInt(rs.getString(5)) / soma_coluna_2 * 2
                    + Integer.parseInt(rs.getString(6)) / soma_coluna_1 * 1;
            matriz_coeficientes[i] = coeficiente;
            i++;
        }
        rs.close();
        stmt2.close();
        int x = 0;
        Statement stmt;
        stmt = Conexao.cn.createStatement();
        ResultSet rs2 = stmt.executeQuery(sql1);
        Double maior = selecionar_maior_coeficiente(matriz_coeficientes);
        Double valor;
        while (rs2.next()) {
            Element branch = new Element("branch");
            Element leaf = new Element("leaf");
            Element label3 = null, weight = null, value = null;
            label3 = new Element("label");

            label3.addContent("" + rs2.getString(1));
            leaf.addContent(label3);
            weight = new Element("weight");
            valor = matriz_coeficientes[x] / maior;
            weight.addContent("" + valor);
            value = new Element("value");
            value.addContent("" + valor);
            leaf.addContent(weight);
            leaf.addContent(value);
            branch.addContent(leaf);
            root.addContent(branch);

            x++;
        }
        rs2.close();
        stmt.close();
        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            Conexao.cn.close();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        setXmlFile(f.getAbsolutePath());
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofSuspectionRateforClass()
        throws NumberFormatException, SQLException, ClassNotFoundException {

    File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/suspection_rate/" + class_analyzed
            + "_suspection.xml");

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {/*  w  w  w.  j  a  v a  2 s  .  c  o  m*/

        Conexao.open();
        Statement sentenca = Conexao.cn.createStatement();

        String tamanho_matriz = "";

        ResultSet rs0 = sentenca.executeQuery(
                " SELECT count(*) FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas where nameprogram='"
                        + program_analyzed + "'  AND ( nameclass='" + class_analyzed
                        + "' AND nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip')");

        while (rs0.next()) {
            for (int i = 1; i <= 1; i++) {
                tamanho_matriz += rs0.getObject(i);

            }
        }
        rs0.close();

        ResultSet rs1 = sentenca.executeQuery(
                " SELECT beginline, qnt_nv1, qnt_nv2, qnt_nv3, qnt_nv4, qnt_nv5 FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas where nameprogram='"
                        + program_analyzed + "' AND (nameclass='" + class_analyzed
                        + "' AND nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip')");

        double[][] matriz_ = new double[Integer.parseInt(tamanho_matriz)][5];

        int j = 0;
        int soma_coluna_1 = 1;
        int soma_coluna_2 = 1;
        int soma_coluna_3 = 1;
        int soma_coluna_4 = 1;
        int soma_coluna_5 = 1;

        while (rs1.next()) {
            String part1 = "", part11[] = null;

            for (int i = 1; i <= 6; i++) {
                part1 += rs1.getObject(i) + "/";

                if (i == 6) {

                    if (matriz_[j][0] != 0) {
                        soma_coluna_1 += 1;

                    }

                    if (matriz_[j][1] != 0) {
                        soma_coluna_2 += 1;

                    }

                    if (matriz_[j][2] != 0) {
                        soma_coluna_3 += 1;

                    }

                    if (matriz_[j][3] != 0) {
                        soma_coluna_4 += 1;

                    }

                    if (matriz_[j][4] != 0) {
                        soma_coluna_5 += 1;

                    }

                    j++;
                }
            }
        }
        rs1.close();
        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + class_analyzed);
        root.addContent(label);
        String sql1 = " SELECT beginline, qnt_nv1, qnt_nv2, qnt_nv3, qnt_nv4, qnt_nv5 FROM quantity_warnings_for_tool_for_line_eliminar_linhas_repetidas where nameprogram='"
                + program_analyzed + "' AND (nameclass='" + class_analyzed
                + "' AND nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip')";
        Statement stmt2;
        stmt2 = Conexao.cn.createStatement();
        ResultSet rs3 = stmt2.executeQuery(sql1);
        double[] matriz_coeficientes = new double[Integer.parseInt(tamanho_matriz)];
        int i = 0;
        while (rs3.next()) {
            double coeficiente = Integer.parseInt(rs3.getString(2)) / soma_coluna_5 * 5
                    + Integer.parseInt(rs3.getString(3)) / soma_coluna_4 * 4
                    + +Integer.parseInt(rs3.getString(4)) / soma_coluna_3 * 3
                    + Integer.parseInt(rs3.getString(5)) / soma_coluna_2 * 2
                    + Integer.parseInt(rs3.getString(6)) / soma_coluna_1 * 1;
            matriz_coeficientes[i] = coeficiente;
            i++;
        }
        rs3.close();
        stmt2.close();
        // System.out.println("");
        int x = 0;
        Statement stmt;
        stmt = Conexao.cn.createStatement();
        ResultSet rs4 = stmt.executeQuery(sql1);

        double maior = selecionar_maior_coeficiente(matriz_coeficientes);
        double valor;
        while (rs4.next()) {
            Element branch = new Element("branch");
            Element leaf = new Element("leaf");
            Element label3 = null, weight = null, value = null;
            label3 = new Element("label");
            label3.addContent("" + rs4.getString(1));
            leaf.addContent(label3);
            weight = new Element("weight");
            valor = matriz_coeficientes[x] / maior;
            weight.addContent("" + valor);

            // System.out.println(selecionar_maior_coeficiente(matriz_coeficientes));
            value = new Element("value");
            value.addContent("" + valor);
            leaf.addContent(weight);
            leaf.addContent(value);
            branch.addContent(leaf);
            root.addContent(branch);
            x++;
        }
        rs4.close();
        stmt.close();

        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            Conexao.cn.close();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        setXmlFile(f.getAbsolutePath());
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofToolsforClass() {
    File f = new File(
            "programs_analyzeds/" + program_analyzed + "/treemap/tools/" + class_analyzed + "_tools.xml");

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {//from  w w w. j  a v a2  s .  co  m
        Document doc = new Document();
        // DocType dt= new DocType("root SYSTEM \"TreeMap.dtd\"");
        // doc.setDocType(dt);
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + class_analyzed);
        root.addContent(label);

        try {
            Conexao.open();
            String sql1 = "select nameclass, nameprogram, beginline, quantidade_ferramentas from quantity_tool_and_warnings_for_line where nameprogram='"
                    + program_analyzed + "' AND nameclass='" + class_analyzed + "'";
            Statement stmt2;
            stmt2 = Conexao.cn.createStatement();
            ResultSet rs4 = stmt2.executeQuery(sql1);
            while (rs4.next()) {
                Element branch = new Element("branch");
                Element leaf = new Element("leaf");
                Element label3 = null, weight = null, value = null;

                label3 = new Element("label");
                label3.addContent("" + rs4.getString(3));
                leaf.addContent(label3);

                weight = new Element("weight");
                weight.addContent("" + rs4.getString(4));

                value = new Element("value");
                value.addContent("" + rs4.getString(4));
                leaf.addContent(weight);
                leaf.addContent(value);

                branch.addContent(leaf);

                root.addContent(branch);

            }
            rs4.close();
            stmt2.close();

        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
            Conexao.cn.close();
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        setXmlFile(f.getAbsolutePath());
    }

}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofWarningsforPackage() {

    File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/warnings/" + package_analyzed
            + "_warnings.xml");

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {//from ww  w  .  ja  va  2  s . c  om
        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + package_analyzed);
        root.addContent(label);
        try {
            Conexao.open();
            String sql1 = "select nameclass, count(*) from warning A inner join arquivo B on A.nameprogram=B.nomeprograma AND nomepacote='"
                    + package_analyzed
                    + "' AND (A.nameclass=B.nomearquivo AND nameclass NOT LIKE '%.class' AND nameclass NOT LIKE '%jlint%' AND nameclass NOT LIKE '%.zip') group by A.nameclass";

            Statement stmt3;
            stmt3 = Conexao.cn.createStatement();
            ResultSet rs3 = stmt3.executeQuery(sql1);

            while (rs3.next()) {
                Element branch = new Element("branch");
                Element leaf = new Element("leaf");
                Element label3 = null, weight = null, value = null;
                label3 = new Element("label");

                // cria todos xmls das classes
                if (buffer == 1) {
                    all_class_xml = new JTreeMapWarningsFIX(program_analyzed, package_analyzed,
                            rs3.getString(1));
                    all_class_xml.StrategiesQuantitiesofWarningsforClass();
                    all_class_xml.StrategiesQuantitiesofSuspectionRateforClass();
                    all_class_xml.StrategiesQuantitiesofToolsforClass();
                }

                label3.addContent("" + rs3.getString(1));
                System.out.println(rs3.getString(1) + "\n");
                leaf.addContent(label3);
                weight = new Element("weight");
                weight.addContent("" + rs3.getString(2));
                value = new Element("value");
                value.addContent("" + rs3.getString(2));
                leaf.addContent(weight);
                leaf.addContent(value);
                branch.addContent(leaf);
                root.addContent(branch);
            }
            rs3.close();
            stmt3.close();

        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        doc.setRootElement(root);
        XMLOutputter xout = new XMLOutputter();
        OutputStream out;

        try {
            out = new FileOutputStream(f);
            xout.output(doc, out);
            out.close();
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        try {
            Conexao.cn.close();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        setXmlFile(f.getAbsolutePath());
    }
}