Example usage for org.dom4j.io OutputFormat createPrettyPrint

List of usage examples for org.dom4j.io OutputFormat createPrettyPrint

Introduction

In this page you can find the example usage for org.dom4j.io OutputFormat createPrettyPrint.

Prototype

public static OutputFormat createPrettyPrint() 

Source Link

Document

A static helper method to create the default pretty printing format.

Usage

From source file:com.ztesoft.inf.extend.xstream.io.xml.Dom4JDriver.java

License:Open Source License

public Dom4JDriver(XmlFriendlyReplacer replacer) {
    this(new DocumentFactory(), OutputFormat.createPrettyPrint(), replacer);
}

From source file:com.zuuyii.action.admin.InstallAction.java

public String save() throws URISyntaxException, IOException, DocumentException {
    if (isInstalled()) {
        return ajaxJsonErrorMessage("SHOP++?????");
    }//  www  .jav  a2  s  .c  om
    if (StringUtils.isEmpty(databaseHost)) {
        return ajaxJsonErrorMessage("?!");
    }
    if (StringUtils.isEmpty(databasePort)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(databasePassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseName)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminPassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(installStatus)) {
        Map<String, String> jsonMap = new HashMap<String, String>();
        jsonMap.put(STATUS, "requiredCheckFinish");
        return ajaxJson(jsonMap);
    }

    String jdbcUrl = "jdbc:mysql://" + databaseHost + ":" + databasePort + "/" + databaseName
            + "?useUnicode=true&characterEncoding=UTF-8";
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        // ?
        connection = DriverManager.getConnection(jdbcUrl, databaseUsername, databasePassword);
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        String[] types = { "TABLE" };
        resultSet = databaseMetaData.getTables(null, databaseName, "%", types);
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCheck")) {
            Map<String, String> jsonMap = new HashMap<String, String>();
            jsonMap.put(STATUS, "databaseCheckFinish");
            return ajaxJson(jsonMap);
        }

        // ?
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCreate")) {
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = null;
            String sqlFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
                    .getPath() + SQL_INSTALL_FILE_NAME;
            bufferedReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(sqlFilePath), "UTF-8"));
            String line = "";
            while (null != line) {
                line = bufferedReader.readLine();
                stringBuffer.append(line);
                if (null != line && line.endsWith(";")) {
                    System.out.println("[SHOP++?]SQL: " + line);
                    preparedStatement = connection.prepareStatement(stringBuffer.toString());
                    preparedStatement.executeUpdate();
                    stringBuffer = new StringBuffer();
                }
            }
            String insertAdminSql = "INSERT INTO `Admin` VALUES ('402881862bec2a21012bec2bd8de0003','2010-10-10 0:0:0','2010-10-10 0:0:0','','admin@shopxx.net',b'1',b'0',b'0',b'0',NULL,NULL,0,NULL,'?','"
                    + DigestUtils.md5Hex(adminPassword) + "','" + adminUsername + "');";
            String insertAdminRoleSql = "INSERT INTO `Admin_Role` VALUES ('402881862bec2a21012bec2bd8de0003','402881862bec2a21012bec2b70510002');";
            preparedStatement = connection.prepareStatement(insertAdminSql);
            preparedStatement.executeUpdate();
            preparedStatement = connection.prepareStatement(insertAdminRoleSql);
            preparedStatement.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return ajaxJsonErrorMessage("???!");
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (preparedStatement != null) {
                preparedStatement.close();
                preparedStatement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // ???
    String configFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()
            + JDBC_CONFIG_FILE_NAME;
    Properties properties = new Properties();
    properties.put("jdbc.driver", "com.mysql.jdbc.Driver");
    properties.put("jdbc.url", jdbcUrl);
    properties.put("jdbc.username", databaseUsername);
    properties.put("jdbc.password", databasePassword);
    properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    properties.put("hibernate.show_sql", "false");
    properties.put("hibernate.format_sql", "false");
    OutputStream outputStream = new FileOutputStream(configFilePath);
    properties.store(outputStream, JDBC_CONFIG_FILE_DESCRIPTION);
    outputStream.close();

    // ??
    /*String backupWebConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_WEB_CONFIG_FILE_NAME;
    String backupApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupCompassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupSecurityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
            
    String webConfigFilePath = new File(Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()).getParent() + "/" + WEB_CONFIG_FILE_NAME;
    String applicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String compassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String securityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
            
    FileUtils.copyFile(new File(backupWebConfigFilePath), new File(webConfigFilePath));
    FileUtils.copyFile(new File(backupApplicationContextConfigFilePath), new File(applicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupCompassApplicationContextConfigFilePath), new File(compassApplicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupSecurityApplicationContextConfigFilePath), new File(securityApplicationContextConfigFilePath));
    */
    // ??
    String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
            .getPath() + SystemConfigUtil.CONFIG_FILE_NAME;
    File systemConfigFile = new File(systemConfigFilePath);
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(systemConfigFile);
    Element rootElement = document.getRootElement();
    Element systemConfigElement = rootElement.element("systemConfig");
    Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled");
    if (isInstalledNode == null) {
        isInstalledNode = systemConfigElement.addElement("isInstalled");
    }
    isInstalledNode.setText("true");
    try {
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
        outputFormat.setEncoding("UTF-8");// XML?
        outputFormat.setIndent(true);// ?
        outputFormat.setIndent("   ");// TAB?
        outputFormat.setNewlines(true);// ??
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(systemConfigFile), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ajaxJsonSuccessMessage("SHOP++?????");
}

From source file:condorclient.utilities.XMLHandler.java

public String createName_IdXML() {
    String strXML = null;/*from   www. jav  a2s .  c  om*/
    Document document = DocumentHelper.createDocument();
    // document.
    Element root = document.addElement("root");

    Element info = root.addElement("info");

    Element job = info.addElement("job");
    job.addAttribute("name", "test");
    job.addAttribute("id", "0");

    StringWriter strWtr = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter xmlWriter = new XMLWriter(strWtr, format);
    try {
        xmlWriter.write(document);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    strXML = strWtr.toString();
    //--------

    //-------
    //strXML=document.asXML();
    //------
    //-------------
    File file = new File("niInfo.xml");
    if (file.exists()) {
        file.delete();
    }
    try {
        file.createNewFile();
        XMLWriter out = new XMLWriter(new FileWriter(file));
        out.write(document);
        out.flush();
        out.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //--------------

    return strXML;
}

From source file:condorclient.utilities.XMLHandler.java

public String createXML() {
    String strXML = null;//from w  ww.  j a  va2 s.co  m
    Document document = DocumentHelper.createDocument();
    // document.
    Element root = document.addElement("root");

    Element job = root.addElement("Job");

    Element jobDescFile = job.addElement("item");
    jobDescFile.addAttribute("about", "descfile");
    Element file_name = jobDescFile.addElement("name");
    file_name.addText("submit.txt");
    Element filer_path = jobDescFile.addElement("path");
    filer_path.addText("D:\\HTCondor\\test\\2");

    StringWriter strWtr = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter xmlWriter = new XMLWriter(strWtr, format);
    try {
        xmlWriter.write(document);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    strXML = strWtr.toString();
    //--------

    //-------
    //strXML=document.asXML();
    //------
    //-------------
    File file = new File("condorclient.xml");
    if (file.exists()) {
        file.delete();
    }
    try {
        file.createNewFile();
        XMLWriter out = new XMLWriter(new FileWriter(file));
        out.write(document);
        out.flush();
        out.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //--------------

    return strXML;
}

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;// www .  j  a  v  a  2 s .  com
    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: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();//  ww w  .j  a  va 2 s.  c  o  m
    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());
        }//  w  w  w. j  a  v  a 2s . co 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:cparser.CParser.java

License:GNU General Public License

public static void main(final String argv[]) {
    System.loadLibrary("cparser");
    init();//w ww. j a v  a2  s .c  o  m

    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.muni.stanse.utils.xmlpatterns.XMLAlgo.java

License:GNU General Public License

/**
 * Pretty-print XML node to a stream//from  ww w . j av  a2 s  .  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();
    }
}

From source file:cz.mzk.editor.server.fedora.utils.DocumentSaver.java

License:Open Source License

private static OutputFormat chooseOutputFormat(PrintType printType) {
    switch (printType) {
    case COMPACT:
        return OutputFormat.createCompactFormat();
    case PRETTY://www . j a va2s . c  om
        return OutputFormat.createPrettyPrint();
    default:
        return OutputFormat.createCompactFormat();
    }
}