Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

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

Prototype

public Document() 

Source Link

Document

Creates a new empty document.

Usage

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofWarningsforPackage_Means() {

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

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {/*from  w  ww .  j  a v  a 2s . c o m*/
        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, sum(quantidade_warning)/count(*) from quantity_tool_and_warnings_for_line 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 stmt6;
            stmt6 = Conexao.cn.createStatement();
            ResultSet rs6 = stmt6.executeQuery(sql1);

            while (rs6.next()) {
                Element branch = new Element("branch");
                Element leaf = new Element("leaf");
                Element label3 = null, weight = null, value = null;
                label3 = new Element("label");
                label3.addContent("" + rs6.getString(1));
                leaf.addContent(label3);
                weight = new Element("weight");
                weight.addContent("" + rs6.getString(2));
                value = new Element("value");
                value.addContent("" + rs6.getString(2));
                leaf.addContent(weight);
                leaf.addContent(value);
                branch.addContent(leaf);
                root.addContent(branch);
            }
            rs6.close();
            stmt6.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());
    }
}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofToolsforPackage() {

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

    if (f.exists()) {
        setXmlFile(f.getAbsolutePath());
    } else {//from w w  w.j av a 2 s.co  m
        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(distinct tool) 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 stmt10;
            stmt10 = Conexao.cn.createStatement();
            ResultSet rs3 = stmt10.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");

                all_class_xml = new JTreeMapWarningsFIX(program_analyzed, package_analyzed, rs3.getString(1));
                all_class_xml.StrategiesQuantitiesofToolsforClass();
                all_class_xml.StrategiesQuantitiesofSuspectionRateforClass();

                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();
            stmt10.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());
    }

}

From source file:warningfix.treemap.JTreeMapWarningsFIX.java

License:Apache License

public void StrategiesQuantitiesofToolsforProgram() throws SQLException, ClassNotFoundException {

    File f = new File(
            "programs_analyzeds/" + program_analyzed + "/treemap/tools/" + program_analyzed + "_tools.xml");

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

        Document doc = new Document();
        Element root = new Element("root");
        Element label = new Element("label");
        label.addContent("" + program_analyzed);
        root.addContent(label);
        Conexao.open();
        String sql0 = "select distinct nomepacote from arquivo where nomeprograma='" + program_analyzed
                + "' AND nomepacote is NOT NULL group by nomepacote";
        Statement stmt9;
        stmt9 = Conexao.cn.createStatement();
        ResultSet rs1 = stmt9.executeQuery(sql0);
        Statement stmt8;
        stmt8 = Conexao.cn.createStatement();
        // armazenar nome dos pacotes

        while (rs1.next()) {
            String namepacote = rs1.getString(1);
            String sql1 = "select MAX(quant_tools) from quantity_tools_for_package where nomepacote='"
                    + namepacote + "' group by nomepacote";

            ResultSet rs2 = stmt8.executeQuery(sql1);

            // all_packages_xml = new JTreeMapWarningsFIX(program_analyzed,
            // namepacote, "");
            // all_packages_xml.StrategiesQuantitiesofToolsforPackage();
            // all_packages_xml
            // .StrategiesQuantitiesofSuspectionRateforPackage();

            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("" + namepacote);
                leaf.addContent(label3);
                weight = new Element("weight");
                System.out.println(rs2.getString(1) + "\n");
                weight.addContent("" + rs2.getString(1));
                value = new Element("value");
                value.addContent("" + rs2.getString(1));
                leaf.addContent(weight);
                leaf.addContent(value);
                branch.addContent(leaf);
                root.addContent(branch);
            }

            rs2.close();
        }

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

        rs1.close();
        stmt9.close();
        stmt8.close();
        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());
    }
}

From source file:XML.JXML.java

public void CreateXML() {

    try {/* w ww.  j av a  2 s  . c  om*/
        Element root = new Element("DriveLessons");
        Document doc = new Document();

        Element stdnt = new Element("Student");
        stdnt.addContent(new Element("StudentName").addContent(studentName));
        stdnt.addContent(new Element("PermitNumber").addContent(studentPermitNumber));
        stdnt.addContent(new Element("DateOfBirth").addContent(studentDOB));

        Element instr = new Element("Instructor");
        instr.addContent(new Element("InstructorName").addContent(instructorName));
        instr.addContent(new Element("InstructorID").addContent(instructorID));

        Element eval = new Element("Evaluation");
        eval.addContent(new Element("EvaluationDate").addContent(evaluationDate));
        eval.addContent(new Element("Pass").addContent(getFinalGrade()));

        root.addContent(stdnt);
        root.addContent(instr);
        root.addContent(eval);

        doc.setRootElement(root);

        XMLOutputter outter = new XMLOutputter();
        outter.setFormat(Format.getPrettyFormat());
        outter.output(doc, new FileWriter(new File("C:\\temp\\myxml.xml")));
    } catch (IOException ex) {
        Logger.getLogger(JXML.class.getName()).log(Level.SEVERE, null, ex);
    }
}