Search in sources :

Example 1 with MSBibDatabase

use of org.jabref.logic.msbib.MSBibDatabase in project jabref by JabRef.

the class MSBibExportFormat method performExport.

@Override
public void performExport(final BibDatabaseContext databaseContext, final String file, final Charset encoding, List<BibEntry> entries) throws SaveException {
    Objects.requireNonNull(databaseContext);
    Objects.requireNonNull(entries);
    if (entries.isEmpty()) {
        return;
    }
    // forcing to use UTF8 output format for some problems with xml export in other encodings
    SaveSession session = new FileSaveSession(StandardCharsets.UTF_8, false);
    MSBibDatabase msBibDatabase = new MSBibDatabase(databaseContext.getDatabase(), entries);
    try (VerifyingWriter ps = session.getWriter()) {
        try {
            DOMSource source = new DOMSource(msBibDatabase.getDomForExport());
            StreamResult result = new StreamResult(ps);
            Transformer trans = TransformerFactory.newInstance().newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");
            trans.transform(source, result);
        } catch (TransformerException | IllegalArgumentException | TransformerFactoryConfigurationError e) {
            throw new Error(e);
        }
        finalizeSaveSession(session, Paths.get(file));
    } catch (IOException ex) {
        throw new SaveException(ex);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) IOException(java.io.IOException) MSBibDatabase(org.jabref.logic.msbib.MSBibDatabase) TransformerException(javax.xml.transform.TransformerException)

Example 2 with MSBibDatabase

use of org.jabref.logic.msbib.MSBibDatabase in project jabref by JabRef.

the class MsBibImporter method importDatabase.

@Override
public ParserResult importDatabase(BufferedReader reader) throws IOException {
    Objects.requireNonNull(reader);
    MSBibDatabase dbase = new MSBibDatabase();
    return new ParserResult(dbase.importEntriesFromXml(reader));
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) MSBibDatabase(org.jabref.logic.msbib.MSBibDatabase)

Aggregations

MSBibDatabase (org.jabref.logic.msbib.MSBibDatabase)2 IOException (java.io.IOException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 ParserResult (org.jabref.logic.importer.ParserResult)1