List of usage examples for org.dom4j.io XMLWriter write
public void write(Object object) throws IOException
From source file:condorclient.utilities.XMLHandler.java
public void removeJobs(int[] delClusterIds, int delsum) { SAXReader saxReader = new SAXReader(); Document document = null;/*from w ww . j a va2 s. c o m*/ try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job");//?job Iterator iter = list.iterator(); Element root = document.getRootElement(); Element info = root.element("info"); try { while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); for (int i = 0; i < delsum; i++) { if (id.equals("" + delClusterIds[i])) { info.remove(job); } } } } catch (Exception e) { System.out.println("???"); } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:condorclient.utilities.XMLHandler.java
void setTransfer(String clusterId) { SAXReader saxReader = new SAXReader(); Document document = null;//from w w w . j a v a 2 s.c o m try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job"); Iterator iter = list.iterator(); while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); if (id.equals(clusterId)) { job.attribute("transfer").setValue("1"); } } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:controler.ExportDataToXML.java
public ExportDataToXML() throws UnsupportedEncodingException, IOException { ArrayList<Password> data = ApplicationData.getPasswords(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("Registos"); Element registo;//from www. j av a2s .c o m int ord = 0; for (Password reg : data) { ord++; registo = root.addElement("Registo").addAttribute("num", "" + ord); registo.addElement("titulo").addText(reg.getTitle()); registo.addElement("user").addText(reg.getUser()); registo.addElement("pass").addText(reg.getPass()); registo.addElement("site").addText(reg.getSite()); registo.addElement("nota").addText(reg.getNote()); } // Pretty print the document to System.out OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer; writer = new XMLWriter(System.out, format); writer.write(document); //write to file FileOutputStream fos = new FileOutputStream("cyphDados.xml"); writer = new XMLWriter(fos, format); writer.write(document); //fos.close(); }
From source file:controller.setup.Setup.java
private void updateHibernateCfgFile(String bd, String bdHost, String bdPort, String bdName, String bdUser, String bdUserMdp) {//from w ww .j av a 2s .c o m System.out.println( "------------------------------ Creation hibernate config file -----------------------------"); try { URL resource = Thread.currentThread().getContextClassLoader().getResource("hibernate.cfg.xml"); File f = new File(resource.toURI()); SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(f); Element sessionFactory = (Element) doc.getRootElement().elements().get(0); if (sessionFactory.elements().size() != 0) for (Iterator elt = sessionFactory.elements().iterator(); elt.hasNext();) sessionFactory.remove((Element) elt.next()); if (bd.equals("mysql")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.MySQLDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:mysql://" + bdHost + ":" + bdPort + "/" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("com.mysql.jdbc.Driver"); } else if (bd.equals("pgsql")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.PostgreSQLDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:postgresql://" + bdHost + ":" + bdPort + "/" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("org.postgresql.Driver"); } else if (bd.equals("oracle")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.OracleDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:oracle:thin:@" + bdHost + ":" + bdPort + ":" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("oracle.jdbc.OracleDriver"); } else if (bd.equals("mssqlserver")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.SQLServerDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:sqlserver://" + bdHost + ":" + bdPort + ";databaseName=" + bdName + ";"); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } sessionFactory.addElement("property").addAttribute("name", "connection.username").addText(bdUser); sessionFactory.addElement("property").addAttribute("name", "connection.password").addText(bdUserMdp); sessionFactory.addElement("property").addAttribute("name", "hbm2ddl.auto").addText("update"); XMLWriter writer = new XMLWriter(new FileWriter(f)); writer.write(doc); writer.close(); System.out.println( "------------------------------ Creation hibernate config file over -----------------------------"); } catch (URISyntaxException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:controllers.FXMLScicumulusController.java
public void createScicumulusXML() throws IOException, Exception { paneGraph.requestFocus();//Altera o foco para o paneGraph this.fieldsRequired = Arrays.asList(txtTagWorkflow, txtDescriptionWorkflow, txtExecTagWorkflow, txtExpDirWorkflow, txtNameDatabase, txtServerDatabase, txtPortDatabase, txtUsernameDatabase, txtPasswordDatabase, txt_server_directory); //Monta o arquivo Scicumulus.xml // if (!isFieldEmpty()) { //Cria o diretrio de expanso this.directoryExp = dirProject.getAbsolutePath() + "/" + txtExpDirWorkflow.getText().trim(); File dir = new File(this.directoryExp); dir.mkdirs();//from w w w .ja va 2s.c om File dirPrograms = new File(this.directoryExp + "/programs"); // this.directoryPrograms = dirPrograms.getPath(); dirPrograms.mkdir(); setDataActivity(this.activity);//Utilizado para gravar a ltima activity Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("SciCumulus"); Element environment = root.addElement("environment"); environment.addAttribute("type", "LOCAL"); Element binary = root.addElement("binary"); binary.addAttribute("directory", this.directoryExp + "/bin"); binary.addAttribute("execution_version", "SCCore.jar"); Element constraint = root.addElement("constraint"); constraint.addAttribute("workflow_exectag", "montage-1"); constraint.addAttribute("cores", this.txt_cores_machines.getText()); Element workspace = root.addElement("workspace"); workspace.addAttribute("workflow_dir", this.dirProject.getAbsolutePath()); Element database = root.addElement("database"); database.addAttribute("name", txtNameDatabase.getText()); database.addAttribute("server", txtServerDatabase.getText()); database.addAttribute("port", txtPortDatabase.getText()); database.addAttribute("username", txtUsernameDatabase.getText()); database.addAttribute("password", txtPasswordDatabase.getText()); Element hydraWorkflow = root.addElement("conceptualWorkflow"); hydraWorkflow.addAttribute("tag", txtTagWorkflow.getText().replace(" ", "").trim()); hydraWorkflow.addAttribute("description", txtDescriptionWorkflow.getText()); hydraWorkflow.addAttribute("exectag", txtExecTagWorkflow.getText()); hydraWorkflow.addAttribute("expdir", this.directoryExp); Element hydraActivity; for (Activity act : this.activities) { hydraActivity = hydraWorkflow.addElement("activity"); hydraActivity.addAttribute("tag", act.getTag().replace(" ", "").trim()); hydraActivity.addAttribute("description", act.getDescription()); hydraActivity.addAttribute("type", act.getType()); hydraActivity.addAttribute("template", act.getTemplatedir()); hydraActivity.addAttribute("activation", act.getActivation()); hydraActivity.addAttribute("extractor", "./extractor.cmd"); dir = new File(this.directoryExp + "/template_" + act.getName()); dir.mkdirs(); //Criando arquivo experiment.cmd File fout = new File(dir.getPath() + "/" + "experiment.cmd"); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); for (String command : act.getCommands()) { bw.write("sleep " + chb_sleeptime.getValue().toString()); bw.newLine(); bw.write(command); bw.newLine(); } bw.close(); String input = new String(); String output = new String(); int cont = 0; for (Relation rel : this.relations) { if (act.equals(rel.nodeStart)) { if (cont == 0) { //Primeira entrada Element relation1 = hydraActivity.addElement("relation"); relation1.addAttribute("reltype", "Input"); relation1.addAttribute("name", "I" + act.getName()); // relation1.addAttribute("filename", act.getInput_filename());//Colocar o nome do arquivo } Element relation2 = hydraActivity.addElement("relation"); relation2.addAttribute("reltype", "Output"); relation2.addAttribute("name", "O" + act.getName()); // relation2.addAttribute("filename", act.getOutput_filename());//Colocar o nome do arquivo // input = "I"+act.getName(); } if (act.equals(rel.nodeEnd)) { Activity dependency = (Activity) rel.nodeStart; Element relation1 = hydraActivity.addElement("relation"); relation1.addAttribute("reltype", "Input"); relation1.addAttribute("name", "I" + act.getName()); relation1.addAttribute("filename", act.getInput_filename());//Colocar o nome do arquivo relation1.addAttribute("dependency", dependency.getTag());//Colocar o nome da dependncia se existir if (cont == this.relations.size() - 1) { //ltima sada Element relation2 = hydraActivity.addElement("relation"); relation2.addAttribute("reltype", "Output"); relation2.addAttribute("name", "O" + act.getName()); // relation2.addAttribute("filename", act.getOutput_filename());//Colocar o nome do arquivo } // output = "O"+act.getName(); } cont++; } input = "I" + act.getName(); output = "O" + act.getName(); for (Field fieldAct : act.getFields()) { Element field = hydraActivity.addElement("field"); field.addAttribute("name", fieldAct.getName()); field.addAttribute("type", fieldAct.getType()); field.addAttribute("input", input); if (!fieldAct.getType().equals("string")) { field.addAttribute("output", output); } if (fieldAct.getType().equals("float")) { field.addAttribute("decimalplaces", fieldAct.getDecimalPlaces()); } if (fieldAct.getType().equals("file")) { field.addAttribute("operation", fieldAct.getOperation()); } } // String input = new String(); // String output = new String(); // // int cont = 0; // for (Relation rel : this.relations) { // if (act.equals(rel.nodeStart)) { // if (cont == 0) { // //Primeira entrada // Element relation1 = hydraActivity.addElement("relation"); // relation1.addAttribute("reltype", "Input"); // relation1.addAttribute("name", rel.getName() + "_" + "input"); //// relation1.addAttribute("filename", act.getInput_filename());//Colocar o nome do arquivo // } // Element relation2 = hydraActivity.addElement("relation"); // relation2.addAttribute("reltype", "Output"); // relation2.addAttribute("name", rel.getName() + "_" + "output"); //// relation2.addAttribute("filename", act.getOutput_filename());//Colocar o nome do arquivo // // input = rel.getName(); // } // if (act.equals(rel.nodeEnd)) { // Activity dependency = (Activity) rel.nodeStart; // Element relation1 = hydraActivity.addElement("relation"); // relation1.addAttribute("reltype", "Input"); // relation1.addAttribute("name", rel.getName() + "_" + "input"); // relation1.addAttribute("filename", act.getInput_filename());//Colocar o nome do arquivo // relation1.addAttribute("dependency", dependency.getTag());//Colocar o nome da dependncia se existir // // if (cont == this.relations.size() - 1) { // //ltima sada // Element relation2 = hydraActivity.addElement("relation"); // relation2.addAttribute("reltype", "Output"); // relation2.addAttribute("name", rel.getName() + "_" + "output"); //// relation2.addAttribute("filename", act.getOutput_filename());//Colocar o nome do arquivo // } // output = rel.getName(); // } // cont++; // } // Element field = hydraActivity.addElement("field"); // field.addAttribute("name", "FASTA_FILE"); // field.addAttribute("type", "string"); // field.addAttribute("input", input); // field.addAttribute("output", output); Element file = hydraActivity.addElement("File"); file.addAttribute("filename", "experiment.cmd"); file.addAttribute("instrumented", "true"); } Element executionWorkflow = root.addElement("executionWorkflow"); executionWorkflow.addAttribute("tag", txtTagWorkflow.getText().replace(" ", "").trim()); executionWorkflow.addAttribute("execmodel", "DYN_FAF"); executionWorkflow.addAttribute("expdir", this.directoryExp); executionWorkflow.addAttribute("max_failure", "1"); executionWorkflow.addAttribute("user_interaction", "false"); executionWorkflow.addAttribute("redundancy", "false"); executionWorkflow.addAttribute("reliability", "0.1"); Element relationInput = executionWorkflow.addElement("relation"); // relationInput.addAttribute("name", "IListFits"); relationInput.addAttribute("name", "input_workflow"); relationInput.addAttribute("filename", this.inputFile.getName()); //Gravando arquivo FileOutputStream fos = new FileOutputStream(this.directoryExp + "/SciCumulus.xml"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.flush(); try { //Criando o arquivo machines.conf createMachinesConf(); //Criando o arquivo parameter.txt // createParameterTxt(ta_parameters.getText()); } catch (IOException ex) { Logger.getLogger(FXMLScicumulusController.class.getName()).log(Level.SEVERE, null, ex); } //Copiando arquivos para o diretrio programs Utils.copyFiles(this.dirPrograms, directoryExp + "/programs/"); Utils.copyFiles(this.inputFile, directoryExp + "/" + this.inputFile.getName()); // sendWorkflow(this.directoryExp, "/deploy/experiments"); // sendWorkflow(this.directoryExp, this.txt_server_directory.getText().trim()); // String[] dirComplete = this.directoryExp.split(this.directoryDefaultFiles)[1].split("/"); // String dirLocal = this.directoryDefaultFiles + dirComplete[0]; // sendWorkflow(dirLocal, this.txt_server_directory.getText().trim()); sendWorkflow(this.dirProject.getAbsolutePath(), this.txt_server_directory.getText().trim()); // }else{ // JOptionPane.showMessageDialog(null, "Preencha os campos obrigatrios!"); // } // if (isActivityEmpty()) { // Dialogs.create() // .owner(null) // .title("Activity Duplicate") // .masthead(null) // .message("Existe uma activity que no est conectada!") // .showInformation(); // } }
From source file:controllers.FXMLScicumulusController.java
private void saveProject(String file) throws FileNotFoundException, UnsupportedEncodingException, IOException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("SciCumulus"); root.addAttribute("nameProject", txt_name_workflow.getText().trim()); Element activities = root.addElement("activities"); activities.addAttribute("quant", Integer.toString(this.activities.size())); for (Activity act : this.activities) { Element activity = activities.addElement("activity"); activity.addAttribute("id", act.getIdObject()); activity.addAttribute("name", act.getName()); activity.addAttribute("login", act.getLogin()); activity.addAttribute("password", act.getPassword()); activity.addAttribute("tag", act.getTag()); activity.addAttribute("description", act.getDescription()); activity.addAttribute("type", act.getType()); activity.addAttribute("templatedir", act.getTemplatedir()); activity.addAttribute("activation", act.getActivation()); activity.addAttribute("input_filename", act.getInput_filename()); activity.addAttribute("output_filename", act.getOutput_filename()); activity.addAttribute("timeCommand", act.getTimeCommand().toString()); // activity.addAttribute("commands", act.getCommands().toString()); for (Field field : act.getFields()) { Element fields = activity.addElement("fields"); fields.addAttribute("name", field.getName()); fields.addAttribute("type", field.getType()); fields.addAttribute("operation", field.getOperation()); fields.addAttribute("decimalPlaces", field.getDecimalPlaces()); fields.addAttribute("input", field.getInput()); fields.addAttribute("output", field.getOutput()); }//from w ww.ja va2 s . c o m } Element relations = root.addElement("relations"); relations.addAttribute("quant", Integer.toString(this.relations.size())); for (Relation rel : this.relations) { Element relation = relations.addElement("relation"); relation.addAttribute("id", rel.getIdObject()); Activity actStart = (Activity) rel.getNodeStart(); Activity actEnd = (Activity) rel.getNodeEnd(); relation.addAttribute("name", rel.getName()); relation.addAttribute("idActStart", actStart.getIdObject()); relation.addAttribute("nameActStart", actStart.getName()); relation.addAttribute("idActEnd", actEnd.getIdObject()); relation.addAttribute("nameActEnd", actEnd.getName()); } //Gravando arquivo FileOutputStream fos = new FileOutputStream(file); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.flush(); }
From source file:controllers.ServiceController.java
License:Apache License
private boolean writeBodyToFile(String filename) { String xmlFile = filename + ".xml"; String jsonFile = filename + ".shape.json"; try {/*from w w w. j a va 2s . c om*/ BufferedReader br = request.getReader(); boolean hasJson = false; StringBuffer buf = new StringBuffer(); //Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile),"utf-8")); String inputLine; while ((inputLine = br.readLine()) != null) { if (inputLine.equals("===boundary===")) { /*?shapes*/ //writer.close(); //writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonFile),"utf-8")); SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver()); Document document = reader.read(new StringReader(buf.toString())); OutputFormat format = new OutputFormat(" ", true); XMLWriter writer = new XMLWriter( new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile), "utf-8")), format); writer.write(document); writer.flush(); writer.close(); hasJson = true; buf = new StringBuffer(); continue; } buf.append(inputLine).append("\n"); //writer.write(inputLine); //writer.write("\n"); } //writer.close(); br.close(); if (!hasJson) { Trace.write(Trace.Error, "write osworkflow: no json-shape define!"); return false; } String jsonString = buf.toString(); jsonString = formatJsonStrings(jsonString); if (jsonString == null) { Trace.write(Trace.Error, "write osworkflow[json]: " + buf.toString()); return false; } Writer jsonWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonFile), "utf-8")); jsonWriter.write(jsonString); jsonWriter.close(); return true; } catch (DocumentException de) { Trace.write(Trace.Error, de, "write osworkflow[xml]."); } catch (IOException e) { Trace.write(Trace.Error, e, "write osworkflow."); } return false; }
From source file:cparser.CParser.java
License:GNU General Public License
public static void main(final String argv[]) { System.loadLibrary("cparser"); init();//from ww w . j a v a 2 s. c om if (argv.length < 1) System.exit(1); final CParser cp = new CParser(new File(argv[0]).getAbsolutePath()); System.out.println("Parsing"); int ret = cp.parse(); if (ret != 0) System.err.println("Parsing failed with error " + ret); final Node n = cp.getRoot(); System.out.println("Computing"); n.compute(); System.out.println("Creating CFG"); n.createCFG(); System.out.println("Generating XML"); final String xml = n.toXML(); System.out.println("Writing XML text"); try { final FileWriter fw = new FileWriter("xml.text"); fw.write(xml); fw.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } System.err.println("Node:\n\tcls=" + n.getClass().getName()); System.err.println("\tstr=" + n.toString()); System.err.println("\tXML:"); try { System.out.println("Generating XML tree"); Document doc = DocumentHelper.parseText(xml); System.out.println("Writing XML"); OutputFormat format = OutputFormat.createPrettyPrint(); OutputStream os = new FileOutputStream("out.xml"); try { XMLWriter writer = new XMLWriter(os, format); writer.write(doc); writer.close(); os.close(); /* writer = new XMLWriter(System.err, format); writer.write(doc); writer.close();*/ } catch (IOException ex) { ex.printStackTrace(); } } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } fini(); }
From source file:cz.dasnet.dasik.Dasik.java
License:Open Source License
@Override protected void onConnect() { log.info("Connected on " + getServer()); auth();/*from w w w . j a v a 2s .co m*/ if (authed) { requestInvites(); } final Dasik bot = this; try { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { bot.joinChannels(); } }, 1000); TimerTask dumpTask = new TimerTask() { @Override public void run() { Document document = DocumentHelper.createDocument(); Element channelinfo = document.addElement("channelinfo"); for (String c : activeChannels.keySet()) { Element channel = channelinfo.addElement("channel"); Element name = channel.addElement("name"); name.setText(c); Element size = channel.addElement("size"); size.setText("" + getUsers(c).length); } Element updatetime = channelinfo.addElement("updatetime"); updatetime.setText(new Long(new Date().getTime() / 1000).toString()); try { XMLWriter writer = new XMLWriter(new FileWriter("channelinfo.xml")); writer.write(document); writer.close(); } catch (IOException ex) { log.error("Unable to dump channel info", ex); } } }; Timer dump = new Timer("dump", true); dump.schedule(dumpTask, 10000, 60000); } catch (Exception ex) { this.joinChannels(); log.error("Channel autojoin timer failed to schedule the task.", ex); } }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLAlgo.java
License:GNU General Public License
/** * Pretty-print XML node to a stream//from w w w. j a va 2s .c om * * @param n node to dump * @param o stream to dump to */ public static void outputXML(Node n, OutputStream o) { OutputFormat format = OutputFormat.createPrettyPrint(); try { XMLWriter writer = new XMLWriter(o, format); writer.write(n); } catch (IOException ex) { ex.printStackTrace(); } }