}
} else if (args[0].endsWith(".bib")) {
// Read from bib and write as XMP
ParserResult result = BibtexParser
.parse(new FileReader(args[0]));
Collection<BibtexEntry> entries = result.getDatabase()
.getEntries();
if (entries.size() == 0) {
System.err.println("Could not find BibtexEntry in "
+ args[0]);
} else {
System.out.println(XMPUtil.toXMP(entries, result
.getDatabase()));
}
} else {
usage();
}
break;
}
case 2: {
if (args[0].equals("-x") && args[1].endsWith(".pdf")) {
// Read from pdf and write as BibTex
XMPMetadata meta = XMPUtil.readRawXMP(new File(args[1]));
if (meta == null) {
System.err
.println("The given pdf does not contain any XMP-metadata.");
} else {
XMLUtil.save(meta.getXMPDocument(), System.out, "UTF-8");
}
break;
}
if (args[0].endsWith(".bib") && args[1].endsWith(".pdf")) {
ParserResult result = BibtexParser
.parse(new FileReader(args[0]));
Collection<BibtexEntry> entries = result.getDatabase()
.getEntries();
if (entries.size() == 0) {
System.err.println("Could not find BibtexEntry in "
+ args[0]);
} else {
XMPUtil.writeXMP(new File(args[1]), entries, result
.getDatabase(), false);
System.out.println("XMP written.");
}
break;
}
usage();
break;
}
case 3: {
if (!args[1].endsWith(".bib") && !args[2].endsWith(".pdf")) {
usage();
break;
}
ParserResult result = BibtexParser.parse(new FileReader(args[1]));
BibtexEntry e = result.getDatabase().getEntryByKey(args[0]);
if (e == null) {
System.err.println("Could not find BibtexEntry " + args[0]
+ " in " + args[0]);
} else {
XMPUtil.writeXMP(new File(args[2]), e, result.getDatabase());
System.out.println("XMP written.");
}
break;
}