List of usage examples for org.jdom2 Document setRootElement
public Document setRootElement(Element rootElement)
Element
for the Document
. From source file:warningfix.treemap.JTreeMapWarningsFIX.java
License:Apache License
public void StrategiesQuantitiesofWarningsforProgram() throws SQLException, ClassNotFoundException { File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/warnings/" + program_analyzed + "_warnings.xml"); if (f.exists()) { setXmlFile(f.getAbsolutePath()); } else {/*from www.j ava2 s .co m*/ Conexao.open(); Document doc = new Document(); Element root = new Element("root"); Element label = new Element("label"); label.addContent("" + program_analyzed); root.addContent(label); String sql0 = "select distinct nomepacote from arquivo where nomeprograma='" + program_analyzed + "' AND nomepacote IS NOT NULL group by nomepacote"; Statement stmt0 = Conexao.cn.createStatement(); ResultSet rs0 = stmt0.executeQuery(sql0); // armazenar nome dos pacotes while (rs0.next()) { String namepacote = rs0.getString(1); String sql1 = "select sum(quant_warnings) from quantity_warnings_for_package where nomepacote='" + namepacote + "'"; 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("" + namepacote); leaf.addContent(label3); weight = new Element("weight"); weight.addContent("" + rs4.getString(1)); value = new Element("value"); value.addContent("" + rs4.getString(1)); leaf.addContent(weight); leaf.addContent(value); branch.addContent(leaf); root.addContent(branch); } } 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 StrategiesQuantitiesofWarningsforProgram_Means() throws SQLException, ClassNotFoundException { File f = new File("programs_analyzeds/" + program_analyzed + "/treemap/warnings/" + program_analyzed + "_means_warnings.xml"); Conexao.open();/*from w w w . ja va2 s .c om*/ if (f.exists()) { setXmlFile(f.getAbsolutePath()); } else { Document doc = new Document(); Element root = new Element("root"); Element label = new Element("label"); label.addContent("" + program_analyzed); root.addContent(label); String sql0 = "select distinct nomepacote from arquivo where nomeprograma='" + program_analyzed + "' AND nomepacote IS NOT NULL group by nomepacote"; Statement stmt4; stmt4 = Conexao.cn.createStatement(); ResultSet rs4 = stmt4.executeQuery(sql0); Statement stmt5; stmt5 = Conexao.cn.createStatement(); // armazenar nome dos pacotes while (rs4.next()) { String namepacote = rs4.getString(1); String sql1 = "select nomepacote, sum(quant_warnings)/count(*) from quantity_warnings_for_package where nomepacote='" + namepacote + "' group by nomepacote"; ResultSet rs5 = stmt5.executeQuery(sql1); // all_packages_xml = new JTreeMapWarningsFIX(program_analyzed, // namepacote, ""); // all_packages_xml // .StrategiesQuantitiesofWarningsforPackage_Means(); while (rs5.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"); weight.addContent("" + rs5.getString(2)); value = new Element("value"); value.addContent("" + rs5.getString(2)); leaf.addContent(weight); leaf.addContent(value); branch.addContent(leaf); root.addContent(branch); } rs5.close(); } rs4.close(); stmt4.close(); stmt5.close(); 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 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 w w . j a v a 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, 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 ww w.ja va 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 w ww . j a va 2s .c om*/ 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 {/*from ww w. ja v a 2s . com*/ 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); } }