Example usage for org.dom4j.io XMLWriter XMLWriter

List of usage examples for org.dom4j.io XMLWriter XMLWriter

Introduction

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

Prototype

public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException 

Source Link

Usage

From source file:gov.nih.nci.rembrandt.web.helper.ReportGeneratorHelper.java

License:BSD License

/**
 * This static method will render a query report of the passed reportXML, in
 * HTML using the XSLT whose name has been passed, to the jsp whose 
 * jspWriter has been passed. The request is used to acquire any filter 
 * params that may have been added to the request and that may be applicable
 * to the XSLT.//w w  w. j  av a 2  s .c om
 *  
 * @param request --the request that will contain any parameters you want applied
 * to the XSLT that you specify
 * @param reportXML -- this is the XML that you want transformed to HTML
 * @param xsltFilename --this the XSLT that you want to use
 * @param out --the JSPWriter you want the transformed document to go to...
 */
public static void renderReport(HttpServletRequest request, Document reportXML, String xsltFilename,
        JspWriter out, String isIGV) {
    File styleSheet = new File(RembrandtContextListener.getContextPath() + "/XSL/" + xsltFilename);
    // load the transformer using JAX
    logger.debug("Applying XSLT " + xsltFilename);

    Transformer transformer;
    try {

        // if the xsltFiname is pathway xlst, then do this
        if ((xsltFilename.equals(RembrandtConstants.DEFAULT_PATHWAY_XSLT_FILENAME))
                || (xsltFilename.equals(RembrandtConstants.DEFAULT_PATHWAY_DESC_XSLT_FILENAME))
                || (xsltFilename.equals(RembrandtConstants.DEFAULT_GENE_XSLT_FILENAME))) {
            transformer = new Transformer(styleSheet);
        }
        // otherwise do this

        else {
            transformer = new Transformer(styleSheet,
                    (HashMap) request.getAttribute(RembrandtConstants.FILTER_PARAM_MAP));
        }

        Document transformedDoc = transformer.transform(reportXML);

        /*
         * right now this assumes that we will only have one XSL for CSV
         * and it checks for that as we do not want to "pretty print" the CSV, we
         * only want to spit it out as a string, or formatting gets messed up
         * we will of course want to pretty print the XHTML for the graphical reports
         * later we can change this to handle mult XSL CSVs
         * RCL
         */
        if (!xsltFilename.equals(RembrandtConstants.DEFAULT_XSLT_CSV_FILENAME)) {
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter writer;
            writer = new XMLWriter(out, format);
            writer.write(transformedDoc);
            if (!xsltFilename.equals(RembrandtConstants.DEFAULT_PATHWAY_DESC_XSLT_FILENAME)) {
                //writer.close();
            }
        } else {
            String csv = transformedDoc.getStringValue();
            csv.trim();
            if (isIGV != null && isIGV.equals("true")) {
                csv = csv.replaceAll(",\\s+", "\t");
            }
            out.println(csv);
        }
    } catch (UnsupportedEncodingException uee) {
        logger.error("UnsupportedEncodingException");
        logger.error(uee);
    } catch (IOException ioe) {
        logger.error("IOException");
        logger.error(ioe);
    }
}

From source file:gov.nih.nci.rembrandt.web.helper.ReportGeneratorHelper.java

License:BSD License

/**
 * Render report with paging params/* ww w . ja va  2s  . c  o m*/
 * @param request
 * @param reportXMLParam
 * @param xsltFilename
 * @param out
 * @param params
 */
public static void renderReportWithParams(HttpServletRequest request, Document reportXMLParam,
        String xsltFilename, JspWriter out, HashMap<String, String> params) {
    File styleSheet = new File(RembrandtContextListener.getContextPath() + "/XSL/" + xsltFilename);
    // load the transformer using JAX
    logger.debug("Applying XSLT with paging " + xsltFilename);
    Transformer transformer;
    Document reportXML;
    try {
        if (reportXMLParam != null)
            reportXML = reportXMLParam;
        else
            reportXML = (Document) request.getSession()
                    .getAttribute(RembrandtConstants.SESSION_ATTR_PATHWAY_XML);

        transformer = new Transformer(styleSheet, params);
        Document transformedDoc = transformer.transform(reportXML);

        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer;
        writer = new XMLWriter(out, format);
        writer.write(transformedDoc);

    } catch (UnsupportedEncodingException uee) {
        logger.error("UnsupportedEncodingException");
        logger.error(uee);
    } catch (IOException ioe) {
        logger.error("IOException");
        logger.error(ioe);
    }
}

From source file:gr.abiss.calipso.util.XmlUtils.java

License:Open Source License

/**
 * Override that accepts an XML DOM Document
 * @param document XML as DOM Document/* www  .  j  a  va  2 s .  co m*/
 */
public static String getAsPrettyXml(Document document) {
    OutputFormat format = new OutputFormat(" ", true);
    format.setSuppressDeclaration(true);
    StringWriter out = new StringWriter();
    XMLWriter writer = new XMLWriter(out, format);
    try {
        try {
            writer.write(document);
        } finally {
            writer.close();
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    return out.toString().trim();
}

From source file:gtu._work.etc.HotnoteMakerUI.java

License:Open Source License

private void initGUI() {
    try {// w  w w  . j av a  2s .  c om
        ToolTipManager.sharedInstance().setInitialDelay(0);
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("hott notes - checklist", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(612, 348));
                    {
                        checkListArea = new JTextArea();
                        jScrollPane1.setViewportView(checkListArea);
                        checkListArea.addMouseListener(new MouseAdapter() {

                            String randomColor() {
                                StringBuilder sb = new StringBuilder().append("#");
                                for (int ii = 0; ii < 6; ii++) {
                                    sb.append(RandomUtil.randomChar('a', 'b', 'c', 'd', 'f', '0', '1', '2', '3',
                                            '4', '5', '6', '7', '8', '9'));
                                }
                                return sb.toString();
                            }

                            void saveXml(Document document, File file) {
                                OutputFormat format = OutputFormat.createPrettyPrint();
                                format.setEncoding("utf-16");
                                XMLWriter writer = null;
                                try {
                                    writer = new XMLWriter(new FileWriter(file), format);
                                    writer.write(document);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                } finally {
                                    if (writer != null) {
                                        try {
                                            writer.close();
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }
                            }

                            public void mouseClicked(MouseEvent evt) {
                                if (!JMouseEventUtil.buttonLeftClick(2, evt)) {
                                    return;
                                }

                                if (StringUtils.isEmpty(checkListArea.getText())) {
                                    JCommonUtil
                                            ._jOptionPane_showMessageDialog_error("checklist area is empty!");
                                    return;
                                }

                                File file = JCommonUtil._jFileChooser_selectFileOnly_saveFile();
                                if (file == null) {
                                    JCommonUtil._jOptionPane_showMessageDialog_error("file is not correct!");
                                    return;
                                }

                                //XXX
                                StringTokenizer tok = new StringTokenizer(checkListArea.getText(), "\t\n\r\f");
                                List<String> list = new ArrayList<String>();
                                String tmp = null;
                                for (; tok.hasMoreElements();) {
                                    tmp = ((String) tok.nextElement()).trim();
                                    System.out.println(tmp);
                                    list.add(tmp);
                                }
                                //XXX

                                Document document = DocumentHelper.createDocument();
                                Element rootHot = document.addElement("hottnote");
                                rootHot.addAttribute("creationtime",
                                        new Timestamp(System.currentTimeMillis()).toString());
                                rootHot.addAttribute("lastmodified",
                                        new Timestamp(System.currentTimeMillis()).toString());
                                rootHot.addAttribute("type", "checklist");
                                //appearence
                                Element appearenceE = rootHot.addElement("appearence");
                                appearenceE.addAttribute("alpha", "204");
                                Element fontE = appearenceE.addElement("font");
                                fontE.addAttribute("face", "Default");
                                fontE.addAttribute("size", "0");
                                Element styleE = appearenceE.addElement("style");
                                styleE.addElement("bg2color").addAttribute("color", randomColor());
                                styleE.addElement("bgcolor").addAttribute("color", randomColor());
                                styleE.addElement("textcolor").addAttribute("color", randomColor());
                                styleE.addElement("titlecolor").addAttribute("color", randomColor());
                                //behavior
                                rootHot.addElement("behavior");
                                //content
                                Element contentE = rootHot.addElement("content");
                                Element checklistE = contentE.addElement("checklist");
                                for (String val : list) {
                                    checklistE.addElement("item").addCDATA(val);
                                }
                                //desktop
                                Element desktopE = rootHot.addElement("desktop");
                                desktopE.addElement("position").addAttribute("x", RandomUtil.numberStr(3))
                                        .addAttribute("y", RandomUtil.numberStr(3));
                                desktopE.addElement("size").addAttribute("height", "200").addAttribute("width",
                                        "200");
                                //title
                                Element titleE = rootHot.addElement("title");
                                titleE.addCDATA(StringUtils.defaultIfEmpty(checkListTitle.getText(),
                                        DateFormatUtils.format(System.currentTimeMillis(), "dd/MM/yyyy")));

                                if (!file.getName().toLowerCase().endsWith(".hottnote")) {
                                    file = new File(file.getParentFile(), file.getName() + ".hottnote");
                                }

                                saveXml(document, file);
                                JCommonUtil._jOptionPane_showMessageDialog_info("completed!\n" + file);
                            }
                        });
                    }
                }
                {
                    checkListTitle = new JTextField();
                    checkListTitle.setToolTipText("title");
                    jPanel1.add(checkListTitle, BorderLayout.NORTH);
                }
            }
        }
        pack();
        this.setSize(633, 415);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:hebbNet.HebbNet.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 {// ww w .  ja va2s.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.write((n+1)+" "+(from+1)+" "+plasticity[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("HebbNet", null,
                System.getProperty("user.dir") + "//Components//Representations//HebbNet//src//HebbNet.dtd");
        Element cnetwork = doc.addElement("HebbNet");
        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:hello.SampleSimpleApplication.java

License:Apache License

private void makeLargeHTML() throws IOException {
    logger.debug("Start folder : " + dirJsonStart);
    Files.walkFileTree(dirJsonStart, new SimpleFileVisitor<Path>() {

        @Override//from  w  w  w.ja v a  2s.  c o m
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            final FileVisitResult visitFile = super.visitFile(file, attrs);
            fileIdx++;

            logger.debug(fileIdx + "" + fileSeparator + filesCount + procentWorkTime() + file);
            logger.debug(fileSeparator);
            String fileStr = file.toFile().toString();
            logger.debug(fileStr);
            if (fileSeparator.equals("\\"))
                fileStr = fileStr.replace(fileSeparator, "/");
            String[] split = fileStr.split("/");
            String manufacturerName = split[split.length - 2];
            Map<String, Object> jsonMap = readJsonDbFile2map(fileStr);
            String autoName = (String) jsonMap.get("autoName");
            String autoNameWithManufacturer = split[split.length - 1].replace(".json", "");
            //            String autoNameWithManufacturer = manufacturerName+"_-_"+autoName;
            String pdfTitleAutoNameWithManufacturer = manufacturerName + " :: " + autoName;
            logger.debug(autoNameWithManufacturer + " -- BEGIN");

            String htmlOutFileName2 = dirLargeHtmlName + autoNameWithManufacturer;
            logger.debug(htmlOutFileName2);
            File f = new File(htmlOutFileName2);
            if (f.exists()) {
                logger.debug("f.exists() --  " + htmlOutFileName2);
                return visitFile;
            }
            Element autoDocBody = createAutoDocument(pdfTitleAutoNameWithManufacturer);
            autoTileNr = 0;
            bookmarkId = 0;
            debugSkip = 0;
            Element headEl = (Element) autoDocument.selectSingleNode("/html/head");
            bookmarks = headEl.addElement("bookmarks");
            //            addGroupAndRealInfo2(2,getIndexList(jsonMap));
            //buildBookmark(autoDocument);

            addGroupAndRealInfo(bookmarks, getIndexList(jsonMap));
            logger.debug(htmlOutFileName2 + " -- GOTO SAVE");

            try {
                //               String htmlOutFileName = dirLargeHtmlName+autoNameWithManufacturer+".html";
                saveHtml(autoDocument, htmlOutFileName2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            logger.debug(autoNameWithManufacturer + " -- END");
            return visitFile;
        }

        private void saveHtml(Document document, String htmlOutFileName) {
            writeToHtmlFile(document, htmlOutFileName);
        }

        private void writeToHtmlFile(Document document, String htmlOutFileName) {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(htmlOutFileName);
                //               HTMLWriter xmlWriter = new HTMLWriter(fileOutputStream, prettyPrintFormat);
                XMLWriter xmlWriter = new XMLWriter(fileOutputStream, prettyPrintFormat);
                xmlWriter.write(document);
                xmlWriter.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        OutputFormat prettyPrintFormat = OutputFormat.createPrettyPrint();

        private List<Map<String, Object>> getIndexList(Map<String, Object> jsonMap) {
            return (List<Map<String, Object>>) jsonMap.get("indexList");
        }

        private void addGroupAndRealInfo(Element bookmarkParent, List<Map<String, Object>> indexList) {
            if (indexList != null) {
                for (Map<String, Object> map : indexList) {
                    String text = (String) map.get("text");
                    Element bookmarkElement = bookmarkParent.addElement("bookmark");
                    bookmarkElement.addAttribute("name", text);
                    bookmarkElement.addAttribute("href", "#b_" + bookmarkId++);
                    String url = (String) map.get("url");
                    if (url != null) {
                        addRealInfo(url);
                    }
                    //                  if(debugSkip > 13)
                    //                     break;
                    addGroupAndRealInfo(bookmarkElement, getIndexList(map));
                }
            }
        }
    });

}

From source file:hk.hku.cecid.piazza.commons.util.PropertyTree.java

License:Open Source License

/**
 * Stores the properties to the specified url location.
 * //from   w w  w. j  ava2  s. c o  m
 * @param url the url of the properties source.
 * @throws Exception if the operation is unsuccessful. 
 * @see hk.hku.cecid.piazza.commons.module.PersistentComponent#storing(java.net.URL)
 */
protected void storing(URL url) throws Exception {
    XMLWriter writer = new XMLWriter(new FileOutputStream(Convertor.toFile(url)),
            OutputFormat.createPrettyPrint());
    writer.write(dom);
    writer.close();
}

From source file:hvv_admin4.state.HVV_StateKeeperXML.java

public void SaveState() {
    if (theApp.GetCurrentStep() < 20)
        return;//from  w  w  w .j a v  a 2s . com

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");

    try {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("SaveStateXML");

        // 
        root.addElement("CurrentStep").addText("" + theApp.GetCurrentStep());

        //?   
        root.addElement("SerialNumber").addText(theApp.GetSerial());

        //  
        root.addElement("ProcessedDeviceType").addText("" + theApp.GetProcessedDeviceType());

        // ? 
        if (theApp.GetDtmTOEnd() == null)
            root.addElement("dtmTOEnd").addText("NULL");
        else
            root.addElement("dtmTOEnd").addText(formatter.format(theApp.GetDtmTOEnd()));

        Set set = theApp.SecretSteps().entrySet();
        Iterator it = set.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();

            String strKey = (String) entry.getKey();
            Object objValue = entry.getValue();

            Element innerRoot = root.addElement("Step" + strKey);
            switch (strKey) {
            case "001":
            case "061":
            case "062":
            case "064":
            case "101":
            case "103":
            case "105":
            case "141":
            case "143":
            case "181":
                ((TechProcessStepCommon) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            case "021":
            case "022":
            case "041":
            case "042":
            case "043":
            case "044":
            case "102":
            case "104":
            case "106":
            case "142":
            case "144":
                ((TechProcessHvProcessInfo) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            case "063":
            case "121":
            case "161":
                ((TechProcessGetterInfo) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            case "081":
            case "182":
                ((TechProcessIgenIextProcessInfo) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            case "082":
            case "183":
                ((TechProcessUacProcessInfo) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            case "083":
            case "184":
                ((TechProcessCommentInfo) objValue).SaveItemXML(innerRoot,
                        theApp.GetStepNameWithNum(Integer.parseInt(strKey)));
                break;

            /*
            case "122":
            case "162":
            (( TechProcessHFInfo ) objValue).SaveItemXML( innerRoot); break;
            */
            }
        }
        OutputFormat format = OutputFormat.createPrettyPrint();

        //File fl = new File( m_strStateKeepFileName);
        //fl.createNewFile();
        XMLWriter writer = new XMLWriter(new FileWriter(m_strStateKeepFileName), format);

        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        logger.error("IOException caught while saving state!", ex);
    }
}

From source file:hvv_constructor.FrmMainWindow.java

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    Document saveFile = DocumentHelper.createDocument();
    Element program = saveFile.addElement("Program");

    Set set = theApp.m_program.entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        int nLineNumber = (int) entry.getKey();
        JProg.JProgAStatement abstractStatement = (JProg.JProgAStatement) entry.getValue();
        Element statement = program.addElement("LineNumber").addText("" + nLineNumber);
        abstractStatement.AddXMLStatement(statement);
    }/*from  w w w .  ja  v a2 s .  co  m*/

    OutputFormat format = OutputFormat.createPrettyPrint();

    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new MyXMLFilter());
    fc.setCurrentDirectory(new File(theApp.GetAMSRoot() + "/ReadyPrograms"));

    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String strFilePathName = fc.getSelectedFile().getAbsolutePath();
        if (!strFilePathName.endsWith(".xml"))
            strFilePathName += ".xml";
        File file = new File(strFilePathName);
        XMLWriter writer;
        try {
            writer = new XMLWriter(new FileWriter(file.getAbsolutePath()), format);
            writer.write(saveFile);
            writer.close();
        } catch (IOException ex) {
            logger.error("IOException: ", ex);
        }

    } else {
        logger.error(
                "   ?   ?? .");
    }

}

From source file:io.mashin.oep.model.Workflow.java

License:Open Source License

@Override
public void write(org.dom4j.Element parent) {
    Document document = parent.getDocument();
    parent.detach();//from w ww. j  a va2 s .  c  om

    Element rootElement = document.addElement("workflow-app");
    Element graphicalInfoElement = DocumentHelper.createElement("workflow");

    XMLWriteUtils.writeWorkflowSchemaVersion(getSchemaVersion(), rootElement);
    XMLWriteUtils.writeSLAVersion(this, rootElement);
    XMLWriteUtils.writeTextPropertyAsAttribute(name, rootElement, "name");
    XMLWriteUtils.writePropertiesCollection(parameters, rootElement, "parameters", "property");
    XMLWriteUtils.writeGlobalProperty(global, rootElement);
    XMLWriteUtils.writeCredentialsCollection(credentials, rootElement);

    startNode.write(rootElement);
    for (Node node : nodes) {
        if (!(node.equals(startNode) || node.equals(endNode))) {
            node.write(rootElement);
        }
        graphicalInfoElement.addElement("node").addAttribute("name", node.getName())
                .addAttribute("x", node.getPosition().x + "").addAttribute("y", node.getPosition().y + "");
    }
    endNode.write(rootElement);

    XMLWriteUtils.writeSLAProperty(this, sla, rootElement);

    Comment graphicalInfoNode = null;
    try {
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
        writer.write(graphicalInfoElement);
        writer.flush();
        graphicalInfoNode = DocumentHelper.createComment(stringWriter.toString());
    } catch (Exception e) {
        graphicalInfoNode = DocumentHelper.createComment(graphicalInfoElement.asXML());
    }
    document.add(graphicalInfoNode);
}