Example usage for org.jdom2.output XMLOutputter XMLOutputter

List of usage examples for org.jdom2.output XMLOutputter XMLOutputter

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter XMLOutputter.

Prototype

public XMLOutputter() 

Source Link

Document

This will create an XMLOutputter with a default Format and XMLOutputProcessor .

Usage

From source file:ddf.catalog.source.opensearch.impl.OpenSearchSource.java

License:Open Source License

private List<Metacard> processAdditionalForeignMarkups(Element element, String id) {
    List<Metacard> metacards = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(markUpSet) && markUpSet.contains(element.getName())) {
        XMLOutputter xmlOutputter = new XMLOutputter();
        Metacard metacard = parseContent(xmlOutputter.outputString(element), id);
        metacards.add(metacard);/*from  w ww  .j a v a 2s. c  o  m*/
    }
    return metacards;
}

From source file:de.bund.bfr.knime.pmm.common.PmmXmlDoc.java

License:Open Source License

public String toXmlString() {
    Document doc = toXmlDocument();
    XMLOutputter xmlo = new XMLOutputter();
    return xmlo.outputString(doc);
}

From source file:de.danielluedecke.zettelkasten.database.Settings.java

License:Open Source License

/**
 * Saves the settings file// w w  w .j a va2 s  .com
 * 
 * @return 
 */
public boolean saveSettings() {
    // initial value
    boolean saveok = true;
    try {
        // open the outputstream
        ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(filepath));
        // I first wanted to use a pretty output format, so advanced users who
        // extract the data file can better watch the xml-files. but somehow, this
        // lead to an error within the method "retrieveElement" in the class "CDaten.java",
        // saying the a org.jdom.text cannot be converted to org.jdom.element?!?
        // XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        XMLOutputter out = new XMLOutputter();
        // save settings
        zip.putNextEntry(new ZipEntry(Constants.settingsFileName));
        out.output(settingsFile, zip);
        // save settings
        // here we retrieve the acceleratorkey-file for the mainwindow
        zip.putNextEntry(new ZipEntry(Constants.acceleratorKeysMainName));
        out.output(acceleratorKeys.getDocument(AcceleratorKeys.MAINKEYS), zip);
        // save settings
        // here we retrieve the acceleratorkey-file for the new-entry-window
        zip.putNextEntry(new ZipEntry(Constants.acceleratorKeysNewEntryName));
        out.output(acceleratorKeys.getDocument(AcceleratorKeys.NEWENTRYKEYS), zip);
        // save settings
        // here we retrieve the acceleratorkey-file for the desktop-window
        zip.putNextEntry(new ZipEntry(Constants.acceleratorKeysDesktopName));
        out.output(acceleratorKeys.getDocument(AcceleratorKeys.DESKTOPKEYS), zip);
        // save settings
        // here we retrieve the acceleratorkey-file for the search-results-window
        zip.putNextEntry(new ZipEntry(Constants.acceleratorKeysSearchResultsName));
        out.output(acceleratorKeys.getDocument(AcceleratorKeys.SEARCHRESULTSKEYS), zip);
        // close zipfile
        zip.close();
    } catch (IOException e) {
        // log error
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // change return value
        saveok = false;
    }
    // first, create temporary backup of data-file
    // therefor, create tmp-file-path
    File tmpdatafp = new File(datafilepath.toString() + ".tmp");
    // check whether we have any saved data at all
    if (datafilepath.exists()) {
        try {
            // check whether we already have a temporary file. if so, delete it
            if (tmpdatafp.exists()) {
                try {
                    tmpdatafp.delete();
                } catch (SecurityException e) {
                    Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
                }
            }
            // and now copy the datafile
            FileOperationsUtil.copyFile(datafilepath, tmpdatafp, 1024);
        } catch (IOException e) {
            Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        }
    }
    // save original data-file. in case we get an error here, we can copy
    // back the temporary saved file...
    try {
        // open the outputstream
        ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(datafilepath));
        // I first wanted to use a pretty output format, so advanced users who
        // extract the data file can better watch the xml-files. but somehow, this
        // lead to an error within the method "retrieveElement" in the class "CDaten.java",
        // saying the a org.jdom.text cannot be converted to org.jdom.element?!?
        // XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        XMLOutputter out = new XMLOutputter();
        // save foreign words
        zip.putNextEntry(new ZipEntry(Constants.foreignWordsName));
        out.output(foreignWordsFile, zip);
        // save settings
        zip.putNextEntry(new ZipEntry(Constants.synonymsFileName));
        out.output(synonyms.getDocument(), zip);
        // save settings
        zip.putNextEntry(new ZipEntry(Constants.stenoFileName));
        out.output(steno.getDocument(), zip);
        // save auto-correction
        zip.putNextEntry(new ZipEntry(Constants.autoKorrekturFileName));
        out.output(autoKorrekt.getDocument(), zip);
        // close zip-file
        zip.close();
    } catch (IOException e) {
        // log error message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // change return value
        saveok = false;
        // first, create basic backup-file
        File checkbackup = FileOperationsUtil.getBackupFilePath(datafilepath);
        // rename temporary file as backup-file
        tmpdatafp.renameTo(checkbackup);
        // log path.
        Constants.zknlogger.log(Level.INFO, "A backup of the meta-data was saved to {0}",
                checkbackup.toString());
        // tell user that an error occured
        JOptionPane.showMessageDialog(null,
                resourceMap.getString("metadataSaveErrMsg", "\"" + checkbackup.getName() + "\""),
                resourceMap.getString("metadataSaveErrTitle"), JOptionPane.PLAIN_MESSAGE);
    } catch (SecurityException e) {
        // log error message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // change return value
        saveok = false;
        // first, create basic backup-file
        File checkbackup = FileOperationsUtil.getBackupFilePath(datafilepath);
        // rename temporary file as backup-file
        tmpdatafp.renameTo(checkbackup);
        // log path.
        Constants.zknlogger.log(Level.INFO, "A backup of the meta-data was saved to {0}",
                checkbackup.toString());
        // tell user that an error occured
        JOptionPane.showMessageDialog(null,
                resourceMap.getString("metadataSaveErrMsg", "\"" + checkbackup.getName() + "\""),
                resourceMap.getString("metadataSaveErrTitle"), JOptionPane.PLAIN_MESSAGE);
    }
    // finally, delete temp-file
    tmpdatafp = new File(datafilepath.toString() + ".tmp");
    // check whether we already have a temporary file. if so, delete it
    if (tmpdatafp.exists()) {
        try {
            tmpdatafp.delete();
        } catch (SecurityException e) {
            Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
        }
    }
    // return result
    return saveok;
}

From source file:de.danielluedecke.zettelkasten.DesktopFrame.java

License:Open Source License

/**
 * This method archives the currently active desktop to a zipped xml-file. This method saves the
 * current desktop-data, the related notes for this desktop and possible modified entries.<br><br>
 * Archive files can be imported as well (see {@link #importArchivedDesktop() importArchivedDesktop()}).
 *//*from   w w w. j av a2 s  . c  om*/
@Action
public void archiveDesktop() {
    // retrieve data-filepath
    File datafp = settingsObj.getFilePath();
    // convert to string, and cut off filename by creating a substring that cuts off
    // everything after the last separator char
    String datafilepath = (datafp != null)
            ? datafp.getPath().substring(0, datafp.toString().lastIndexOf(java.io.File.separator) + 1)
            : "";
    // ... to cut off extension
    if (!datafilepath.isEmpty())
        datafilepath = datafilepath + desktopObj.getCurrentDesktopName()
                + resourceMap.getString("archiveDesktopSuffix");
    // create new path
    File exportdir = new File(datafilepath);
    // here we open a swing filechooser, in case the os ist no mac aqua
    File filepath = FileOperationsUtil.chooseFile(this,
            (settingsObj.isMacAqua()) ? FileDialog.SAVE : JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY,
            exportdir.getPath(), exportdir.getName(), resourceMap.getString("fileDialogTitleSave"),
            new String[] { ".zip" }, "Zip", settingsObj);
    if (filepath != null) {
        // add fileextenstion, if necessay
        if (!filepath.getName().endsWith(".zip")) {
            filepath = new File(filepath.toString() + ".zip");
        }
        // check whether file already exists
        if (filepath.exists()) {
            // file exists, ask user to overwrite it...
            int optionDocExists = JOptionPane.showConfirmDialog(null,
                    resourceMap.getString("askForOverwriteFileMsg", filepath.getName()),
                    resourceMap.getString("askForOverwriteFileTitle"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.PLAIN_MESSAGE);
            // if the user does *not* choose to overwrite, quit...
            if (optionDocExists != JOptionPane.YES_OPTION) {
                // don't show "export was OK" message in main frame
                return;
            }
        }
        // create desktop-archive-XML-document
        Document archiveddesktop = desktopObj.archiveDesktop(desktopObj.getCurrentDesktopName());
        // check whether an error occured
        if (null == archiveddesktop) {
            // tell user about error
            JOptionPane.showMessageDialog(this, resourceMap.getString("archiveErrMsg"),
                    resourceMap.getString("archiveErrTitle"), JOptionPane.PLAIN_MESSAGE);
            zknframe.showErrorIcon();
            return;
        }
        // export and zip file
        try {
            // open the outputstream
            ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(filepath));
            // I first wanted to use a pretty output format, so advanced users who
            // extract the data file can better watch the xml-files. but somehow, this
            // lead to an error within the method "retrieveElement" in the class "CDaten.java",
            // saying the a org.jdom.text cannot be converted to org.jdom.element?!?
            // XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
            XMLOutputter out = new XMLOutputter();
            // save archived desktop
            zip.putNextEntry(new ZipEntry(Constants.archivedDesktopFileName));
            out.output(archiveddesktop, zip);
            zip.close();
        } catch (IOException e) {
            Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
            JOptionPane.showMessageDialog(this, resourceMap.getString("archiveErrMsg"),
                    resourceMap.getString("archiveErrTitle"), JOptionPane.PLAIN_MESSAGE);
            zknframe.showErrorIcon();
            return;
        } catch (SecurityException e) {
            Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
            JOptionPane.showMessageDialog(this, resourceMap.getString("archiveErrMsg"),
                    resourceMap.getString("archiveErrTitle"), JOptionPane.PLAIN_MESSAGE);
            zknframe.showErrorIcon();
            return;
        }
        JOptionPane.showMessageDialog(this, resourceMap.getString("archiveOkMsg"),
                resourceMap.getString("archiveOkTitle"), JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:de.danielluedecke.zettelkasten.tasks.export.ExportToZknTask.java

License:Open Source License

@Override
protected Object doInBackground() {
    // Your Task's code here.  This method runs
    // on a background thread, so don't reference
    // the Swing GUI from here.
    // prevent task from processing when the file path is incorrect

    // if no file exists, exit task
    if (null == filepath) {
        showOkMessage = false;/*from w  w w .  ja va 2  s  .  c om*/
        return null;
    }
    // check whether file already exists
    if (filepath.exists()) {
        // file exists, ask user to overwrite it...
        int optionDocExists = JOptionPane.showConfirmDialog(null,
                resourceMap.getString("askForOverwriteFileMsg", "", filepath.getName()),
                resourceMap.getString("askForOverwriteFileTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        // if the user does *not* choose to overwrite, quit...
        if (optionDocExists != JOptionPane.YES_OPTION) {
            // don't show "export was OK" message in main frame
            showOkMessage = false;
            return null;
        }
    }
    // yet everything is ok...
    exportOk = true;
    // create list with all export entries...
    ArrayList<Integer> entrylist = new ArrayList<Integer>();
    // go through all elements of the data file
    for (int cnt = 0; cnt < exportentries.size(); cnt++) {
        try {
            // retrieve zettelnumber
            int zettelnummer = Integer.parseInt(exportentries.get(cnt).toString());
            // and add it to list.
            entrylist.add(zettelnummer);
        } catch (NumberFormatException e) {
        }
    }
    // sort array
    Collections.sort(entrylist);
    // create document for exporting the entries
    dataObj.createExportEntries(entrylist);
    // create export-XML-file for bookmarks
    Document bookmarks = new Document(new Element("bookmarks"));
    // iterate all bookmarks
    for (int cnt = 0; cnt < bookmarksObj.getCount(); cnt++) {
        // retrieve each bookmarked entry number
        int bookmarkpos = bookmarksObj.getBookmarkEntry(cnt);
        // check whether bookmarked entry is in export list
        if (entrylist.contains(bookmarkpos)) {
            // create new bookmark element
            Element bookmark = new Element("bookmark");
            // add zettel-id as attribute
            bookmark.setAttribute("id", dataObj.getZettelID(bookmarkpos));
            // add bookmark-category as attribute
            bookmark.setAttribute("cat", bookmarksObj.getBookmarkCategoryAsString(cnt));
            // add comment as text
            bookmark.setText(bookmarksObj.getComment(cnt));
            // add element to XML file
            bookmarks.getRootElement().addContent(bookmark);
        }
    }

    // TODO suchergebnisse nummern in id's umwandeln und mitexportieren
    // TODO schreibtisch-Daten: zettel-nummern in id's umwandeln und mitexportieren

    // export data to zkn3-file
    try {
        // open the outputstream
        ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(filepath));
        // I first wanted to use a pretty output format, so advanced users who
        // extract the data file can better watch the xml-files. but somehow, this
        // lead to an error within the method "retrieveElement" in the class "CDaten.java",
        // saying the a org.jdom.text cannot be converted to org.jdom.element?!?
        // XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        XMLOutputter out = new XMLOutputter();
        // show status text
        msgLabel.setText(resourceMap.getString("msg2"));
        // save metainformation
        zip.putNextEntry(new ZipEntry(Constants.metainfFileName));
        out.output(dataObj.getMetaInformationData(), zip);
        // save main data.
        zip.putNextEntry(new ZipEntry(Constants.zknFileName));
        out.output(dataObj.retrieveExportDocument(), zip);
        // save authors
        zip.putNextEntry(new ZipEntry(Constants.authorFileName));
        out.output(dataObj.getAuthorData(), zip);
        // save keywords
        zip.putNextEntry(new ZipEntry(Constants.keywordFileName));
        out.output(dataObj.getKeywordData(), zip);
        // save bookmarks
        zip.putNextEntry(new ZipEntry(Constants.bookmarksFileName));
        out.output(bookmarks, zip);
        // close zip-stream
        zip.close();
    } catch (IOException e) {
        // log error-message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // change error-indicator
        exportOk = false;
    } catch (SecurityException e) {
        // log error-message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // change error-indicator
        exportOk = false;
    }
    // if the user requested a bibtex-export, do this now
    if (exportbibtex) {
        // show status text
        msgLabel.setText(resourceMap.getString("msgBibtextExport"));
        // write bibtex file
        ExportTools.writeBibTexFile(dataObj, bibtexObj, exportentries, filepath, resourceMap);
    }

    return null; // return your result
}

From source file:de.danielluedecke.zettelkasten.tasks.SaveFileTask.java

License:Open Source License

@Override
protected Object doInBackground() {
    // Your Task's code here.  This method runs
    // on a background thread, so don't reference
    // the Swing GUI from here.
    // prevent task from processing when the file path is incorrect
    File fp = settingsObj.getFilePath();
    // if no file exists, exit task
    if (null == fp) {
        // log error
        Constants.zknlogger.log(Level.WARNING, "Filepath is null!");
        saveOk = false;/* ww  w  . j ava2  s.com*/
        return null;
    }
    // check whether file is write protected
    if (!fp.canWrite()) {
        // ask whether write protection should be removed
        int option = JOptionPane.showConfirmDialog(null, resourceMap.getString("removeWriteProtectMsg"),
                resourceMap.getString("removeWriteProtectTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
        // user cancelled dialog
        if (JOptionPane.CANCEL_OPTION == option || JOptionPane.CLOSED_OPTION == option
                || JOptionPane.NO_OPTION == option) {
            saveOk = false;
            return null;
        }
        // check return result
        if (JOptionPane.YES_OPTION == option) {
            try {
                // try to remove write protection
                fp.setWritable(true);
            } catch (SecurityException ex) {
                // log error-message
                Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage());
                Constants.zknlogger.log(Level.SEVERE,
                        "File is write-protected. Write protection could not be removed!");
                saveOk = false;
                return null;
            }
        }
    }
    try {
        // log file path
        Constants.zknlogger.log(Level.INFO, "Saving file to {0}", fp.toString());
        // open the outputstream
        ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(fp));
        // I first wanted to use a pretty output format, so advanced users who
        // extract the data file can better watch the xml-files. but somehow, this
        // lead to an error within the method "retrieveElement" in the class "Daten.java",
        // saying the a org.jdom.text cannot be converted to org.jdom.element?!?
        // XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        XMLOutputter out = new XMLOutputter();
        // show status text
        msgLabel.setText(resourceMap.getString("msg1"));
        // save metainformation
        zip.putNextEntry(new ZipEntry(Constants.metainfFileName));
        out.output(dataObj.getMetaInformationData(), zip);
        // save main data.
        zip.putNextEntry(new ZipEntry(Constants.zknFileName));
        out.output(dataObj.getZknData(), zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg2"));
        // save authors
        zip.putNextEntry(new ZipEntry(Constants.authorFileName));
        out.output(dataObj.getAuthorData(), zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg3"));
        // save keywords
        zip.putNextEntry(new ZipEntry(Constants.keywordFileName));
        out.output(dataObj.getKeywordData(), zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg4"));
        // save keywords
        zip.putNextEntry(new ZipEntry(Constants.bookmarksFileName));
        out.output(bookmarkObj.getBookmarkData(), zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg5"));
        // save keywords
        zip.putNextEntry(new ZipEntry(Constants.searchrequestsFileName));
        out.output(searchrequestsObj.getSearchData(), zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg6"));
        // save synonyms
        zip.putNextEntry(new ZipEntry(Constants.synonymsFileName));
        out.output(synonymsObj.getDocument(), zip);
        // save bibtex file
        zip.putNextEntry(new ZipEntry(Constants.bibTexFileName));
        ByteArrayOutputStream bout = bibtexObj.saveFile();
        bout.writeTo(zip);
        // show status text
        msgLabel.setText(resourceMap.getString("msg6"));
        // save desktops
        zip.putNextEntry(new ZipEntry(Constants.desktopFileName));
        out.output(desktopObj.getDesktopData(), zip);
        zip.putNextEntry(new ZipEntry(Constants.desktopModifiedEntriesFileName));
        out.output(desktopObj.getDesktopModifiedEntriesData(), zip);
        zip.putNextEntry(new ZipEntry(Constants.desktopNotesFileName));
        out.output(desktopObj.getDesktopNotesData(), zip);
        // close zip-stream
        zip.close();
        bout.close();
    } catch (IOException e) {
        // log error-message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // check whether file is write protected
        if (!fp.canWrite()) {
            // log error-message
            Constants.zknlogger.log(Level.SEVERE, "Save failed. The file is write-protected.");
            // show error message
            JOptionPane.showMessageDialog(null, resourceMap.getString("errorSavingWriteProtectedMsg"),
                    resourceMap.getString("errorSavingTitle"), JOptionPane.PLAIN_MESSAGE);
        } else {
            // show error message
            JOptionPane.showMessageDialog(null, resourceMap.getString("errorSavingMsg"),
                    resourceMap.getString("errorSavingTitle"), JOptionPane.PLAIN_MESSAGE);
        }
        // change error-indicator
        saveOk = false;
    } catch (SecurityException e) {
        // log error-message
        Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage());
        // show error message
        JOptionPane.showMessageDialog(null, resourceMap.getString("errorNoAccessMsg"),
                resourceMap.getString("errorNoAccessTitle"), JOptionPane.PLAIN_MESSAGE);
        // change error-indicator
        saveOk = false;
    }
    return null; // return your result
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

License:Creative Commons License

private static void write(EObject instance, Resource resource, OutputStream os,
        NonContainmentReferenceHandling refOption, Map<String, Object> saveOptions) throws IOException {
    if (refOption == null) {
        refOption = NonContainmentReferenceHandling.KEEP_ORIGINAL_LOCATION;
    }//w  ww.  ja va  2s .c o  m
    HashSet<EObject> alreadyVisited = new HashSet<EObject>();
    List<EObject> rootList = new ArrayList<EObject>();

    if (refOption == NonContainmentReferenceHandling.ADD_TO_RESOURCE) {
        instance = EmfUtils.clone(instance);
        resource.getContents().add(instance);
        collectObjectsWithoutResource(instance, alreadyVisited, rootList, refOption);
        resource.getContents().addAll(rootList);
        write(resource, os, saveOptions);
    } else if (refOption == NonContainmentReferenceHandling.KEEP_ORIGINAL_LOCATION) {
        instance = EcoreUtil.copy(instance);
        resource.getContents().add(instance);
        collectObjectsWithoutResource(instance, alreadyVisited, rootList, refOption);

        Resource resourceTemp = new XMLResourceFactoryImpl().createResource(URI.createURI(""));
        resourceTemp.getContents().addAll(rootList);
        write(resource, os, saveOptions);
    } else if (refOption == NonContainmentReferenceHandling.INLINE) {
        instance = EmfUtils.clone(instance);

        resource.getContents().add(instance);
        // Reads to DOM and injects dependencies(replaces href nodes)

        Document d;
        Map<String, Namespace> namespaces = new HashMap<String, Namespace>();
        try {
            d = createDocFromEObject(instance, namespaces);
            Set<EObject> alreadyHandled = new HashSet<EObject>();
            dfs(instance, d.getRootElement(), alreadyHandled, namespaces);
            for (String prefix : namespaces.keySet()) {
                Namespace namespace = d.getRootElement().getNamespace(prefix);
                if (namespace == null)
                    d.getRootElement().addNamespaceDeclaration(namespaces.get(prefix));
            }
            XMLOutputter out = new XMLOutputter();
            out.setFormat(Format.getPrettyFormat());
            out.output(d, os);
        } catch (Exception e) {
            logger.error("An error occured while serializing an object:\n" + e.getLocalizedMessage());
            e.printStackTrace();
        }
    }
}

From source file:de.herm_detlef.java.application.io.Export.java

License:Apache License

public static Document exportExerciseItemListToFile(CommonData commonData, File file) {

    commonData.markSelectedAnswerPartItems();

    final Document doc = createJdomDocument(commonData.getExerciseItemListMaster());
    assert doc != null;

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());

    try {/*from w  ww.  ja  v a2  s .co  m*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1_000_000);
        xmlOutput.output(doc, outputStream);
        ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
        validateDocument(inputStream);

        xmlOutput.output(doc, new FileWriter(file.getCanonicalPath()));

        commonData.savedExerciseItemListMaster();
        commonData.setRecentlySavedFile(file);
        commonData.setRecentlyOpenedFile(file);

        commonData.getExerciseItemListInitialMaster().clear();
        commonData.getExerciseItemListInitialMaster().addAll(commonData.getExerciseItemListMaster());

    } catch (IOException | JDOMException e) {
        Utilities.showErrorMessage(e.getClass().getSimpleName(), e.getMessage());
        // e.printStackTrace();
        return null;
    }

    return doc;
}

From source file:de.herm_detlef.java.application.io.Export.java

License:Apache License

public static boolean validateCurrentExerciseItem(CommonData commonData, boolean showErrorMessageJDOM) {

    final ObservableList<ExerciseItem> exerciseItemList = FXCollections.observableArrayList();

    exerciseItemList.add(commonData.getCurrentExerciseItem());

    Document doc = createJdomDocument(exerciseItemList);

    XMLOutputter xmlOutput = new XMLOutputter();

    try {//from  w ww. ja v  a  2s  . c  o m

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1_000_000);

        xmlOutput.output(doc, outputStream);

        ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

        validateDocument(inputStream);

    } catch (JDOMException e) {

        if (!showErrorMessageJDOM)
            return false;

        Utilities.showErrorMessage(e.getClass().getSimpleName(), e.getMessage());
        //e.printStackTrace();
        return false;

    } catch (IOException e) {

        Utilities.showErrorMessage(e.getClass().getSimpleName(), e.getMessage());
        //e.printStackTrace();
        return false;
    }

    return true;
}

From source file:de.kay_muench.reqif10.reqifparser.ToolExRemover.java

License:Open Source License

private void output(final Document document, final File tmp) throws IOException {
    DOMBuilder domBuilder = new DOMBuilder();
    org.jdom2.Document doc = domBuilder.build(document);
    XMLOutputter out = new XMLOutputter();

    Writer w = new OutputStreamWriter(new FileOutputStream(tmp), "UTF8");
    BufferedWriter writer = new BufferedWriter(w);
    out.output(doc, writer);//  w w  w .ja  va  2  s.c om
    writer.close();
}