List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java
License:Open Source License
private void init() { factory = DocumentFactory.getInstance(); outputFormat = options.getOutputFormat(); outputFormat.setExpandEmptyElements(true); //expand elements into form <a></a> instead of <a/>; TBD: expose processedTypes = new ArrayList<>(); recursiveCount = new HashMap<>(); schemaStack = new Stack<>(); initNSMap();/*from w ww. j av a2 s . c om*/ }
From source file:com.sun.tools.xjc.reader.dtd.bindinfo.BIUserConversion.java
License:Open Source License
/** Adds all built-in conversions into the given map. */ static void addBuiltinConversions(BindInfo bi, Map m) { DocumentFactory f = DocumentFactory.getInstance(); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "boolean") .addAttribute("type", "java.lang.Boolean").addAttribute("parse", "getBoolean"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "byte") .addAttribute("type", "java.lang.Byte").addAttribute("parse", "parseByte"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "short") .addAttribute("type", "java.lang.Short").addAttribute("parse", "parseShort"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "int") .addAttribute("type", "java.lang.Integer").addAttribute("parse", "parseInt"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "long") .addAttribute("type", "java.lang.Long").addAttribute("parse", "parseLong"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "float") .addAttribute("type", "java.lang.Float").addAttribute("parse", "parseFloat"))); add(m, new BIUserConversion(bi, f.createElement("conversion").addAttribute("name", "double") .addAttribute("type", "java.lang.Double").addAttribute("parse", "parseDouble"))); }
From source file:com.sun.tools.xjc.reader.dtd.bindinfo.SAXContentHandlerEx.java
License:Open Source License
private SAXContentHandlerEx(Locator[] loc) { super(DocumentFactory.getInstance(), new MyElementHandler(loc)); this.loc = loc; }
From source file:com.taobao.osceola.demo.acount.persist.service.impl.AccountPersistServiceImpl.java
License:Open Source License
private Document readDocument() throws AccountPersistException { File dataFile = new File(file); if (!dataFile.exists()) { dataFile.getParentFile().mkdirs(); Document doc = DocumentFactory.getInstance().createDocument(); Element rootEle = doc.addElement(ELEMENT_ROOT); rootEle.addElement(ELEMENT_ACCOUNTS); writeDocment(doc);// w w w. j a v a 2 s . c o m } try { return reader.read(new File(file)); } catch (DocumentException e) { throw new AccountPersistException("", e); } }
From source file:com.thoughtworks.cruise.utils.DomUtil.java
License:Apache License
private static void registerNamespace() { HashMap<String, String> map = new HashMap<String, String>(); map.put("atom", "http://www.w3.org/2005/Atom"); DocumentFactory instance = DocumentFactory.getInstance(); instance.setXPathNamespaceURIs(map); }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public boolean save(File outPutFile, Element rootElement, boolean lineAble) { final Document document = DocumentFactory.getInstance().createDocument(rootElement.createCopy()); return save(outPutFile, document, lineAble); }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
private void writeDocument(final OutputStream out, Element rootElement) { final Document document = DocumentFactory.getInstance().createDocument(rootElement.createCopy()); writeDocument(out, document);/*w w w .j a v a2 s . co m*/ }
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 . j a v a 2 s . com 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.java 2 s . c om } 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:cz.muni.stanse.checker.CheckerError.java
License:GNU General Public License
public Element xmlDump() { Element result = DocumentFactory.getInstance().createElement("error"); result.addElement("short_desc").addText(getShortDesc()); result.addElement("full_desc").addText(getFullDesc()); result.addElement("importance").addText(Integer.toString(getImportance())); result.addElement("checker_name").addText(getCheckerName()); Element eTraces = result.addElement("traces").addText(getCheckerName()); for (final CheckerErrorTrace trace : getTraces()) eTraces.add(trace.xmlDump());//from w ww . ja va 2 s.c om return result; }