Search in sources :

Example 1 with XMPPreferences

use of org.jabref.logic.xmp.XMPPreferences in project jabref by JabRef.

the class ImporterTest method instancesToTest.

@Parameters(name = "{index}: {0}")
public static Collection<Object[]> instancesToTest() {
    // all classes implementing {@link Importer}
    // sorted alphabetically
    ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
    XMPPreferences xmpPreferences = mock(XMPPreferences.class);
    // @formatter:off
    return Arrays.asList(new Object[] { new BiblioscapeImporter() }, new Object[] { new BibtexImporter(importFormatPreferences) }, new Object[] { new BibTeXMLImporter() }, new Object[] { new CopacImporter() }, new Object[] { new EndnoteImporter(importFormatPreferences) }, new Object[] { new FreeCiteImporter(importFormatPreferences) }, new Object[] { new InspecImporter() }, new Object[] { new IsiImporter() }, new Object[] { new MedlineImporter() }, new Object[] { new MedlinePlainImporter() }, new Object[] { new ModsImporter() }, new Object[] { new MsBibImporter() }, new Object[] { new OvidImporter() }, new Object[] { new PdfContentImporter(importFormatPreferences) }, new Object[] { new PdfXmpImporter(xmpPreferences) }, new Object[] { new RepecNepImporter(importFormatPreferences) }, new Object[] { new RisImporter() }, new Object[] { new SilverPlatterImporter() });
// @formatter:on
}
Also used : BiblioscapeImporter(org.jabref.logic.importer.fileformat.BiblioscapeImporter) IsiImporter(org.jabref.logic.importer.fileformat.IsiImporter) RisImporter(org.jabref.logic.importer.fileformat.RisImporter) MsBibImporter(org.jabref.logic.importer.fileformat.MsBibImporter) RepecNepImporter(org.jabref.logic.importer.fileformat.RepecNepImporter) EndnoteImporter(org.jabref.logic.importer.fileformat.EndnoteImporter) SilverPlatterImporter(org.jabref.logic.importer.fileformat.SilverPlatterImporter) CopacImporter(org.jabref.logic.importer.fileformat.CopacImporter) ModsImporter(org.jabref.logic.importer.fileformat.ModsImporter) OvidImporter(org.jabref.logic.importer.fileformat.OvidImporter) PdfContentImporter(org.jabref.logic.importer.fileformat.PdfContentImporter) XMPPreferences(org.jabref.logic.xmp.XMPPreferences) MedlinePlainImporter(org.jabref.logic.importer.fileformat.MedlinePlainImporter) BibTeXMLImporter(org.jabref.logic.importer.fileformat.BibTeXMLImporter) InspecImporter(org.jabref.logic.importer.fileformat.InspecImporter) BibtexImporter(org.jabref.logic.importer.fileformat.BibtexImporter) MedlineImporter(org.jabref.logic.importer.fileformat.MedlineImporter) PdfXmpImporter(org.jabref.logic.importer.fileformat.PdfXmpImporter) FreeCiteImporter(org.jabref.logic.importer.fileformat.FreeCiteImporter) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with XMPPreferences

use of org.jabref.logic.xmp.XMPPreferences in project jabref by JabRef.

the class XMPUtilMain method main.

/**
     * Command-line tool for working with XMP-data.
     *
     * Read or write XMP-metadata from or to pdf file.
     *
     * Usage:
     * <dl>
     * <dd>Read from PDF and print as bibtex:</dd>
     * <dt>xmpUtil PDF</dt>
     * <dd>Read from PDF and print raw XMP:</dd>
     * <dt>xmpUtil -x PDF</dt>
     * <dd>Write the entry in BIB given by KEY to the PDF:</dd>
     * <dt>xmpUtil KEY BIB PDF</dt>
     * <dd>Write all entries in BIB to the PDF:</dd>
     * <dt>xmpUtil BIB PDF</dt>
     * </dl>
     *
     * @param args
     *            Command line strings passed to utility.
     * @throws IOException
     *             If any of the given files could not be read or written.
     * @throws TransformerException
     *             If the given BibEntry is malformed.
     */
public static void main(String[] args) throws IOException, TransformerException {
    // Don't forget to initialize the preferences
    if (Globals.prefs == null) {
        Globals.prefs = JabRefPreferences.getInstance();
    }
    XMPPreferences xmpPreferences = Globals.prefs.getXMPPreferences();
    ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();
    switch(args.length) {
        case 0:
            usage();
            break;
        case 1:
            if (args[0].endsWith(".pdf")) {
                // Read from pdf and write as BibTex
                List<BibEntry> l = XMPUtil.readXMP(new File(args[0]), xmpPreferences);
                BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false);
                for (BibEntry entry : l) {
                    StringWriter sw = new StringWriter();
                    bibtexEntryWriter.write(entry, sw, BibDatabaseMode.BIBTEX);
                    System.out.println(sw.getBuffer());
                }
            } else if (args[0].endsWith(".bib")) {
                // Read from BIB and write as XMP
                try (FileReader fr = new FileReader(args[0])) {
                    ParserResult result = new BibtexParser(importFormatPreferences).parse(fr);
                    Collection<BibEntry> entries = result.getDatabase().getEntries();
                    if (entries.isEmpty()) {
                        System.err.println("Could not find BibEntry in " + args[0]);
                    } else {
                        System.out.println(XMPUtil.toXMP(entries, result.getDatabase(), xmpPreferences));
                    }
                }
            } else {
                usage();
            }
            break;
        case 2:
            if ("-x".equals(args[0]) && args[1].endsWith(".pdf")) {
                // Read from pdf and write as BibTex
                Optional<XMPMetadata> meta = XMPUtil.readRawXMP(new File(args[1]));
                if (meta.isPresent()) {
                    XMLUtil.save(meta.get().getXMPDocument(), System.out, StandardCharsets.UTF_8.name());
                } else {
                    System.err.println("The given pdf does not contain any XMP-metadata.");
                }
                break;
            }
            if (args[0].endsWith(".bib") && args[1].endsWith(".pdf")) {
                ParserResult result = new BibtexParser(importFormatPreferences).parse(new FileReader(args[0]));
                Collection<BibEntry> entries = result.getDatabase().getEntries();
                if (entries.isEmpty()) {
                    System.err.println("Could not find BibEntry in " + args[0]);
                } else {
                    XMPUtil.writeXMP(new File(args[1]), entries, result.getDatabase(), false, xmpPreferences);
                    System.out.println("XMP written.");
                }
                break;
            }
            usage();
            break;
        case 3:
            if (!args[1].endsWith(".bib") && !args[2].endsWith(".pdf")) {
                usage();
                break;
            }
            ParserResult result = new BibtexParser(importFormatPreferences).parse(new FileReader(args[1]));
            Optional<BibEntry> bibEntry = result.getDatabase().getEntryByKey(args[0]);
            if (bibEntry.isPresent()) {
                XMPUtil.writeXMP(new File(args[2]), bibEntry.get(), result.getDatabase(), xmpPreferences);
                System.out.println("XMP written.");
            } else {
                System.err.println("Could not find BibEntry " + args[0] + " in " + args[0]);
            }
            break;
        default:
            usage();
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) BibEntryWriter(org.jabref.logic.bibtex.BibEntryWriter) LatexFieldFormatter(org.jabref.logic.bibtex.LatexFieldFormatter) ParserResult(org.jabref.logic.importer.ParserResult) XMPPreferences(org.jabref.logic.xmp.XMPPreferences) StringWriter(java.io.StringWriter) XMPMetadata(org.apache.jempbox.xmp.XMPMetadata) ImportFormatPreferences(org.jabref.logic.importer.ImportFormatPreferences) Collection(java.util.Collection) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

XMPPreferences (org.jabref.logic.xmp.XMPPreferences)2 File (java.io.File)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 XMPMetadata (org.apache.jempbox.xmp.XMPMetadata)1 BibEntryWriter (org.jabref.logic.bibtex.BibEntryWriter)1 LatexFieldFormatter (org.jabref.logic.bibtex.LatexFieldFormatter)1 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibTeXMLImporter (org.jabref.logic.importer.fileformat.BibTeXMLImporter)1 BiblioscapeImporter (org.jabref.logic.importer.fileformat.BiblioscapeImporter)1 BibtexImporter (org.jabref.logic.importer.fileformat.BibtexImporter)1 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)1 CopacImporter (org.jabref.logic.importer.fileformat.CopacImporter)1 EndnoteImporter (org.jabref.logic.importer.fileformat.EndnoteImporter)1 FreeCiteImporter (org.jabref.logic.importer.fileformat.FreeCiteImporter)1 InspecImporter (org.jabref.logic.importer.fileformat.InspecImporter)1 IsiImporter (org.jabref.logic.importer.fileformat.IsiImporter)1 MedlineImporter (org.jabref.logic.importer.fileformat.MedlineImporter)1