Example usage for org.dom4j DocumentFactory createCDATA

List of usage examples for org.dom4j DocumentFactory createCDATA

Introduction

In this page you can find the example usage for org.dom4j DocumentFactory createCDATA.

Prototype

public CDATA createCDATA(String text) 

Source Link

Usage

From source file:nl.ru.cmbi.vase.parse.VASEXMLParser.java

License:Apache License

public static void write(VASEDataObject data, OutputStream xmlOut) throws IOException {

    DocumentFactory df = DocumentFactory.getInstance();

    Document doc = df.createDocument();

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

    if (data.getTitle() != null) {

        Element title = root.addElement("title");
        title.setText(data.getTitle());//w w  w.  j  a va2s . co m
    }

    Element fasta = root.addElement("fasta");
    ByteArrayOutputStream fastaStream = new ByteArrayOutputStream();
    FastaParser.toFasta(data.getAlignment().getMap(), fastaStream);

    fasta.add(df.createCDATA(new String(fastaStream.toByteArray(), StandardCharsets.UTF_8)));

    Element pdb = root.addElement("pdb");
    pdb.addAttribute("pdbid", data.getPdbID());

    table2xml(data.getTable(), root);

    if (data.getPlots().size() > 0) {
        Element plots = root.addElement("plots");
        for (PlotDescription pd : data.getPlots()) {

            Element plot = plots.addElement("plot");
            plot.addElement("x").setText(pd.getXAxisColumnID());
            plot.addElement("y").setText(pd.getYAxisColumnID());
            plot.addAttribute("title", pd.getPlotTitle());
        }
    }

    XMLWriter writer = new XMLWriter(xmlOut);
    writer.write(doc);
    writer.close();
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

/**
 * Write the properties to simple CDATA tags
 * @param writer//from w  w  w  . j  av  a  2s . c  om
 * @param tags
 * @throws IOException
 */
private static void addCdataPropertyTags(XMLWriter writer, Properties tags) throws IOException {
    DocumentFactory factory = getDocumentFactory();
    for (String tag : tags.stringPropertyNames()) {
        Element el = factory.createElement(tag);
        el.add(factory.createCDATA(tags.getProperty(tag)));
        writer.write(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addIssueFields(XMLWriter writer, List<IssueField> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;//from w w w.  j ava2 s.c  o m
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_ISSUE_FIELDS);
        writer.writeOpen(el);
        for (IssueField c : entities) {
            elTmp = factory.createElement(TAG_ISSUE_FIELD);
            elTmp.addAttribute(ATTR_ID, TAG_CUSTOM_FIELD + c.getId());
            elTmp.add(factory.createCDATA(c.getValue(EXPORT_LOCALE)));
            writer.write(elTmp);
        }
        writer.writeClose(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addIssueHistory(XMLWriter writer, List<IssueHistory> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;/*  w  ww. j  a  v  a 2s. c o  m*/
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_ISSUE_HISTORY);
        writer.writeOpen(el);
        for (IssueHistory c : entities) {
            elTmp = factory.createElement(TAG_HISTORY_ENTRY);
            elTmp.addAttribute(ATTR_CREATOR_ID, TAG_USER + c.getUser().getId());
            elTmp.addAttribute(ATTR_DATE, DATE_FORMATTER.format(c.getCreateDate()));
            elTmp.addAttribute(ATTR_STATUS, String.valueOf(c.getStatus()));

            writer.writeOpen(elTmp);
            writer.write(factory.createCDATA(ITrackerResources.escapeUnicodeString(c.getDescription(), false)));
            writer.writeClose(elTmp);
        }
        writer.writeClose(el);
    }
}