Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

From source file:eu.scape_project.planning.xml.ProjectExporter.java

License:Apache License

/**
 * Creates a dom4j document template to add plans.
 * //from  w w w.  j a  v  a  2s.c o m
 * @return the dom4j document
 */
public Document createProjectDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("plans");

    root.add(XSI_NAMESPACE);
    root.add(PLATO_NAMESPACE);
    root.addAttribute(XSI_NAMESPACE.getPrefix() + ":schemaLocation",
            PlanXMLConstants.PLATO_NS + " " + PlanXMLConstants.PLATO_SCHEMA);
    root.add(new Namespace("fits", "http://hul.harvard.edu/ois/xml/ns/fits/fits_output"));

    // set version of corresponding schema
    root.addAttribute("version", PlanXMLConstants.PLATO_SCHEMA_VERSION);

    return doc;
}

From source file:eu.scape_project.planning.xml.ProjectExporter.java

License:Apache License

/**
 * Creates a template document./*from   w ww. jav a2s.  c  o m*/
 * 
 * @return the dom4j-document
 */
public Document createTemplateDoc() {
    Document doc = DocumentHelper.createDocument();

    Element root = doc.addElement("templates");

    root.add(XSI_NAMESPACE);

    return doc;
}

From source file:eu.scape_project.planning.xml.ProjectExporter.java

License:Apache License

public String exportTreeToFreemind(TreeNode treeRoot) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);/* w  ww  . jav  a2 s .  c o  m*/
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");
    addSubTreeFreemind(root, treeRoot);

    String xml = doc.asXML();
    // PlatoLogger.getLogger(ProjectExporter.class).debug(arg0)
    return xml;
}

From source file:eu.sisob.uma.crawler.ResearcherXMLFileSplitter.java

License:Open Source License

/**
 * Reader folder of one researcher and takes the uri of clean file for to make infoblock. 
 * @param elementResearcher// w  w  w . j  av  a2 s. c o  m
 * @param path
 * @param sInstitutionName
 * @param sWebAddress
 * @param sUnitOfAssessment_Description
 * @param sResearchGroupDescription
 * @param sResearchName
 * @param sResearchInitials
 * @param sStaffIndentifier
 */
@Override
protected boolean actionsInInstitutionNode(org.dom4j.Element elementInstitution, String path,
        String sInstitutionName, String sWebAddress) {
    Document split_doc = DocumentHelper.createDocument();
    Element split_root = split_doc.addElement("root");
    split_root.add((Element) elementInstitution.clone());
    File split_file = new File(work_dir, prefix_file + sInstitutionName.replaceAll("\\W+", "").toLowerCase());
    try {
        FileUtils.write(split_file, split_doc.asXML(), "UTF-8");
    } catch (IOException ex) {
        Logger.getLogger("roor").error("Cannot create xml file for " + split_file.getPath());
    }

    return true;
}

From source file:eu.sisob.uma.crawlerWorks.WebPagesOfUniversities.Format.FileFormatConversor.java

License:Open Source License

public static boolean createResearchersXMLFileFromCSV(File filePathCSV, File filePathXml)
        throws FileNotFoundException, IOException {
    boolean sucess = false;

    CSVReader reader = new CSVReader(new FileReader(filePathCSV), ';');
    String[] nextLine;/* ww w .  j  av a 2  s . c om*/
    int idStaffIdentifier = -1;
    int idName = -1;
    int idFirstName = -1;
    int idLastName = -1;
    int idInitials = -1;
    int idUnitOfAssessment_Description = -1;
    int idInstitutionName = -1;
    int idWebAddress = -1;
    int idResearchGroupDescription = -1;
    int idResearcherWebAddress = -1;
    int idResearcherWebAddressType = -1;
    int idResearcherWebAddressExt = -1;
    if ((nextLine = reader.readNext()) != null) {
        //Locate indexes            
        //Locate indexes                        
        for (int i = 0; i < nextLine.length; i++) {
            String column_name = nextLine[i];
            if (column_name.equals(CSV_COL_ID))
                idStaffIdentifier = i;
            else if (column_name.equals(CSV_COL_NAME))
                idName = i;
            else if (column_name.equals(CSV_COL_FIRSTNAME))
                idFirstName = i;
            else if (column_name.equals(CSV_COL_LASTNAME))
                idLastName = i;
            else if (column_name.equals(CSV_COL_INITIALS))
                idInitials = i;
            else if (column_name.equals(CSV_COL_SUBJECT))
                idUnitOfAssessment_Description = i;
            else if (column_name.equals(CSV_COL_INSTITUTION_NAME))
                idInstitutionName = i;
            else if (column_name.equals(CSV_COL_INSTITUTION_URL))
                idWebAddress = i;
            else if (column_name.equals(CSV_COL_RESEARCHER_PAGE_URL))
                idResearcherWebAddress = i;
            else if (column_name.equals(CSV_COL_RESEARCHER_PAGE_TYPE))
                idResearcherWebAddressType = i;
            else if (column_name.equals(CSV_COL_RESEARCHER_PAGE_EXT))
                idResearcherWebAddressExt = i;
        }
    }

    if (idLastName != -1 && idInitials != -1 && idStaffIdentifier != -1 && idWebAddress != -1
            && idInstitutionName != -1 && idUnitOfAssessment_Description != -1) {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("root");

        while ((nextLine = reader.readNext()) != null) {
            for (int k = 0; k < nextLine.length; k++) {
                nextLine[k] = nextLine[k].replace("'", "");
            }

            Node n = root.selectSingleNode(XMLTags.INSTITUTION + "/" + XMLTags.INSTITUTION_NAME + "[text()='"
                    + nextLine[idInstitutionName] + "']");
            Element eInstitution = null;
            if (n == null) {
                eInstitution = root.addElement(XMLTags.INSTITUTION);
                eInstitution.addElement(XMLTags.INSTITUTION_NAME).addCDATA(nextLine[idInstitutionName]);
                eInstitution.addElement(XMLTags.INSTITUTION_WEBADDRESS)
                        .addCDATA(idWebAddress == -1 ? "" : nextLine[idWebAddress]);
            } else {
                eInstitution = n.getParent();
            }
            {
                n = eInstitution.selectSingleNode(
                        XMLTags.UNIT_OF_ASSESSMENT + "/" + XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION + "[text()='"
                                + nextLine[idUnitOfAssessment_Description] + "']");
                Element eUnitOfAssessment = null;
                if (n == null) {
                    eUnitOfAssessment = eInstitution.addElement(XMLTags.UNIT_OF_ASSESSMENT);
                    eUnitOfAssessment.addElement(XMLTags.UNIT_OF_ASSESSMENT_DESCRIPTION)
                            .addCDATA(nextLine[idUnitOfAssessment_Description]);
                    //eUnitOfAssessment.addElement("DepartamentWebAddress").addCDATA("");                        
                } else {
                    eUnitOfAssessment = n.getParent();
                }
                {
                    String researchGroupDescription = "";
                    if (idResearchGroupDescription != -1) {
                        researchGroupDescription = nextLine[idResearchGroupDescription];
                    }
                    n = eUnitOfAssessment
                            .selectSingleNode(XMLTags.RESEARCHGROUP + "/" + XMLTags.RESEARCHGROUP_DESCRIPTION
                                    + "[text()='" + researchGroupDescription + "']");
                    Element eResearchGroup = null;
                    if (n == null) {
                        eResearchGroup = eUnitOfAssessment.addElement(XMLTags.RESEARCHGROUP);
                        eResearchGroup.addElement(XMLTags.RESEARCHGROUP_DESCRIPTION)
                                .addCDATA(researchGroupDescription);
                    } else {
                        eResearchGroup = n.getParent();
                    }
                    {
                        Element eResearcher = eResearchGroup.addElement(XMLTags.RESEARCHER);
                        eResearcher.addElement(XMLTags.RESEARCHER_STAFFIDENTIFIER)
                                .addCDATA(nextLine[idStaffIdentifier]);
                        if (idName != -1) {
                            eResearcher.addElement(XMLTags.RESEARCHER_NAME).addCDATA(nextLine[idName]);
                        }

                        if (idFirstName != -1) {
                            eResearcher.addElement(XMLTags.RESEARCHER_FIRSTNAME)
                                    .addCDATA(nextLine[idFirstName]);
                        }

                        eResearcher.addElement(XMLTags.RESEARCHER_LASTNAME).addCDATA(nextLine[idLastName]);
                        eResearcher.addElement(XMLTags.RESEARCHER_INITIALS).addCDATA(nextLine[idInitials]);

                        if (idResearcherWebAddress != -1) {
                            String researcherWebAddress = "";
                            String researcherWebAddressType = "";
                            String researcherWebAddressExt = "";

                            researcherWebAddress = nextLine[idResearcherWebAddress].trim();

                            if (!researcherWebAddress.equals("")) {

                                if (idResearcherWebAddressType != -1)
                                    researcherWebAddressType = nextLine[idResearcherWebAddressType];
                                else
                                    researcherWebAddressType = XMLTags.RESEARCHER_WEB_ADDRESS_ATTR_TYPE_VALUE_DEFAULT_CV;

                                if (idResearcherWebAddressExt != -1)
                                    researcherWebAddressExt = nextLine[idResearcherWebAddressExt];
                                else
                                    researcherWebAddressExt = XMLTags.RESEARCHER_WEB_ADDRESS_ATTR_EXT_VALUE_DEFAULT_HTML;

                                eResearcher.addElement(XMLTags.RESEARCHER_WEB_ADDRESS)
                                        .addAttribute(XMLTags.RESEARCHER_WEB_ADDRESS_ATTR_TYPE,
                                                researcherWebAddressType)
                                        .addAttribute(XMLTags.RESEARCHER_WEB_ADDRESS_ATTR_EXT,
                                                researcherWebAddressExt)
                                        .addCDATA(researcherWebAddress);
                            }
                        }
                    }
                }
            }
        }

        reader.close();

        FileOutputStream fileOS = new java.io.FileOutputStream(filePathXml, false);
        OutputStreamWriter writer = new java.io.OutputStreamWriter(fileOS, "UTF-8");
        BufferedWriter bw = new java.io.BufferedWriter(writer);
        String sOut = document.asXML();
        bw.write(sOut);
        bw.close();
        writer.close();
        fileOS.close();

        sucess = true;
    } else {
        sucess = false;
    }

    return sucess;

}

From source file:fr.isima.ponge.wsprotocol.xml.XmlIOManager.java

License:Open Source License

/**
 * Writes a business protocol as an XML representation to a writer.
 *
 * @param protocol The protocol.//from w w  w.java2 s .  c  o  m
 * @param writer   The writer to use.
 * @throws IOException Thrown in case an I/O error occurs.
 */
@SuppressWarnings("unchecked")
public void writeBusinessProtocol(BusinessProtocol protocol, Writer writer) throws IOException {
    // Root
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("business-protocol"); //$NON-NLS-1$

    // Protocol
    root.addElement("name").setText(protocol.getName()); //$NON-NLS-1$
    writeExtraProperties(root, protocol);

    // States
    Iterator it = protocol.getStates().iterator();
    while (it.hasNext()) {
        State s = (State) it.next();
        Element el = root.addElement("state"); //$NON-NLS-1$
        el.addElement("name").setText(s.getName()); //$NON-NLS-1$
        el.addElement("final").setText(s.isFinalState() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (s.isInitialState()) {
            el.addElement("initial-state"); //$NON-NLS-1$
        }
        writeExtraProperties(el, s);
    }

    // Operations
    it = protocol.getOperations().iterator();
    while (it.hasNext()) {
        Operation o = (Operation) it.next();
        Message m = o.getMessage();
        String pol;
        if (m.getPolarity().equals(Polarity.POSITIVE)) {
            pol = "positive"; //$NON-NLS-1$
        } else if (m.getPolarity().equals(Polarity.NEGATIVE)) {
            pol = "negative"; //$NON-NLS-1$

        } else {
            pol = "null"; //$NON-NLS-1$
        }
        Element oel = root.addElement("operation"); //$NON-NLS-1$
        Element mel = oel.addElement("message"); //$NON-NLS-1$
        mel.addElement("name").setText(m.getName()); //$NON-NLS-1$
        mel.addElement("polarity").setText(pol); //$NON-NLS-1$
        oel.addElement("name").setText(o.getName()); //$NON-NLS-1$
        oel.addElement("source").setText(o.getSourceState().getName()); //$NON-NLS-1$
        oel.addElement("target").setText(o.getTargetState().getName()); //$NON-NLS-1$
        oel.addElement("kind").setText(o.getOperationKind().toString()); //$NON-NLS-1$
        writeExtraProperties(mel, m);
        writeExtraProperties(oel, o);
    }

    // Write
    XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
    xmlWriter.write(document);
}

From source file:fullyMeshedNet.FullyMeshedNet.java

License:Open Source License

@Override
public void exportToFile(File saveFile) {
    String extension = FrevoMain.getExtension(saveFile);
    if (extension.equals("net")) {
        System.out.println("Exporting Pajek network file to " + saveFile.getName());
        try {//from   w ww .  jav a2s  .  c o m
            // Create file
            FileWriter fstream = new FileWriter(saveFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("*Vertices " + this.nodes);
            out.newLine();
            // input neurons
            for (int i = 1; i < input_nodes + 1; i++) {
                out.write(i + " \"I" + i + "\"");
                out.newLine();
            }
            for (int h = input_nodes + 1; h < nodes - output_nodes + 1; h++) {
                out.write(h + " \"H" + (h - input_nodes) + "\"");
                out.newLine();
            }
            int a = 1;
            for (int o = nodes - output_nodes + 1; o < nodes + 1; o++) {
                out.write(o + " \"O" + a + "\"");
                out.newLine();
                a++;
            }

            // Edges
            out.write("*Edges");
            out.newLine();
            for (int n = 0; n < input_nodes - 1; n++) {
                for (int p = n + 1; p < input_nodes; p++) {
                    if (n != p) {
                        out.write((n + 1) + " " + (p + 1) + " " + 0);
                        out.newLine();
                    }
                }
            }

            for (int n = input_nodes; n < nodes; n++) {
                for (int from = 0; from < nodes; from++) {
                    out.write((n + 1) + " " + (from + 1) + " " + weight[from][n]);
                    out.newLine();
                }
            }

            // Close the output stream
            out.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    } else if (extension.equals("xml")) {
        System.out.println("Saving to XML");

        Document doc = DocumentHelper.createDocument();
        doc.addDocType("CompleteNetwork", null, System.getProperty("user.dir")
                + "//Components//Representations//CompleteNetwork//src//CompleteNetwork.dtd");
        Element cnetwork = doc.addElement("CompleteNetwork");
        this.exportToXmlElement(cnetwork);

        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setLineSeparator(System.getProperty("line.separator"));

        try {
            saveFile.createNewFile();
            FileWriter out = new FileWriter(saveFile);
            BufferedWriter bw = new BufferedWriter(out);
            XMLWriter wr = new XMLWriter(bw, format);
            wr.write(doc);
            wr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:gestionecassa.backends.XmlDataBackend.java

License:Open Source License

@Override
public void saveArticlesList(ArticlesList lista) throws IOException {

    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("article_groups");
    Collection<ArticleGroup> groups = lista.getGroupsList();
    for (ArticleGroup group : groups) {
        Element tempGroup = root.addElement("group");

        tempGroup.addElement("name").addText(group.getName());
        tempGroup.addElement("id").addText(group.getId() + "");

        for (Article art : group.getList()) {
            Element tempArt = tempGroup.addElement("article");

            tempArt.addElement("name").addText(art.getName());
            tempArt.addElement("price").addText(art.getPrice() + "");
            tempArt.addElement("id").addText(art.getId() + "");

            if (art.hasOptions()) {
                tempArt.addAttribute("options", "true");
                Element tempOpzioni = tempArt.addElement("options");

                Collection<ArticleOption> options = art.getOptions();
                for (ArticleOption option : options) {
                    tempOpzioni.addElement("option").addText(option.getName());
                } //FIXME aggiungi altre parti di ArticleOption
            } else {
                tempArt.addAttribute("options", "false");
            }//w ww . j ava2  s.  c  o m
        }
    }

    // for debug purposes
    OutputFormat format = OutputFormat.createPrettyPrint();

    // lets write to a file
    XMLWriter writer = new XMLWriter(new FileWriter(ArtListFile), format);
    //XMLWriter writer = new XMLWriter(new FileWriter(fileName));
    writer.write(document);
    writer.close();
}

From source file:gestionecassa.backends.XmlDataBackend.java

License:Open Source License

@Override
public void saveAdminsList(Collection<Admin> lista) throws IOException {

    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("admins");

    for (Admin admin : lista) {
        Element tempAdmin = root.addElement("admin");
        tempAdmin.addElement("id").addText(admin.getId() + "");
        tempAdmin.addElement("username").addText(admin.getUsername());
        tempAdmin.addElement("password").addText(admin.getPassword());
    }/*from  w w  w.j  a  va 2  s  . com*/

    // for debug purposes
    OutputFormat format = OutputFormat.createPrettyPrint();

    // lets write to a file
    XMLWriter writer = new XMLWriter(new FileWriter(AdminListFile), format);
    //XMLWriter writer = new XMLWriter(new FileWriter(fileName));
    writer.write(document);
    writer.close();
}

From source file:gestionecassa.backends.XmlDataBackend.java

License:Open Source License

@Override
public void saveCassiereList(Collection<Cassiere> lista) throws IOException {

    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("cassieri");

    for (Cassiere cassiere : lista) {
        Element tempCassiere = root.addElement("cassiere");
        tempCassiere.addElement("id").addText(cassiere.getId() + "");
        tempCassiere.addElement("username").addText(cassiere.getUsername());
        tempCassiere.addElement("password").addText(cassiere.getPassword());
    }/*from   ww w.j  a va 2  s .  c  om*/

    // for debug purposes
    OutputFormat format = OutputFormat.createPrettyPrint();

    // lets write to a file
    XMLWriter writer = new XMLWriter(new FileWriter(CassiereListFile), format);
    //XMLWriter writer = new XMLWriter(new FileWriter(fileName));
    writer.write(document);
    writer.close();
}