Korrekturen am BibTeX Importer

git-svn-id: https://svn.libreccm.org/ccm/trunk@2043 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-01-17 10:07:51 +00:00
parent 2082346610
commit e255dc6198
18 changed files with 105 additions and 47 deletions

View File

@ -1 +1,2 @@
com.arsdigita.cms.scipublications.importer.ris.RisImporter com.arsdigita.cms.scipublications.importer.ris.RisImporter
com.arsdigita.cms.scipublications.importer.bibtex.BibTeXPublicationsImporter

View File

@ -57,7 +57,7 @@ public class BibTeXConverters {
final PublicationImportReport report = new PublicationImportReport(); final PublicationImportReport report = new PublicationImportReport();
BibTeXConverter<Publication, PublicationBundle> converter = converters.get(bibTeXEntry. BibTeXConverter<Publication, PublicationBundle> converter = converters.get(bibTeXEntry.
getType().getValue()); getType().getValue().toLowerCase());
if (converter == null) { if (converter == null) {
report.addMessage(String.format("No converter for BibTeX type '%s' available. Publication '%s' has not" report.addMessage(String.format("No converter for BibTeX type '%s' available. Publication '%s' has not"
@ -98,7 +98,6 @@ public class BibTeXConverters {
publication.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); publication.setLanguage(Kernel.getConfig().getLanguagesIndependentCode());
} }
final PublicationBundle bundle = converter.createBundle(publication, pretend); final PublicationBundle bundle = converter.createBundle(publication, pretend);
report.setType(publication.BASE_DATA_OBJECT_TYPE);
converter.processFields(bibTeXEntry, publication, importerUtil, report, pretend); converter.processFields(bibTeXEntry, publication, importerUtil, report, pretend);

View File

@ -5,8 +5,11 @@ import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException
import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter; import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter;
import com.arsdigita.cms.scipublications.importer.report.ImportReport; import com.arsdigita.cms.scipublications.importer.report.ImportReport;
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader; import java.io.StringReader;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import javax.activation.MimeType; import javax.activation.MimeType;
import javax.activation.MimeTypeParseException; import javax.activation.MimeTypeParseException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -14,6 +17,7 @@ import org.jbibtex.BibTeXDatabase;
import org.jbibtex.BibTeXEntry; import org.jbibtex.BibTeXEntry;
import org.jbibtex.BibTeXParser; import org.jbibtex.BibTeXParser;
import org.jbibtex.Key; import org.jbibtex.Key;
import org.jbibtex.ParseException;
/** /**
* *
@ -44,9 +48,27 @@ public class BibTeXPublicationsImporter implements SciPublicationsImporter {
final ImporterUtil importerUtil = new ImporterUtil(publishNewItems); final ImporterUtil importerUtil = new ImporterUtil(publishNewItems);
final BibTeXConverters converters = BibTeXConverters.getInstance(); final BibTeXConverters converters = BibTeXConverters.getInstance();
report.setImporter(BibTeXPublicationsImporter.class.getName());
report.setPretend(pretend);
final StringReader reader = new StringReader(publications); final StringReader reader = new StringReader(publications);
final BibTeXParser parser = new BibTeXParser(reader); final BibTeXParser parser = new BibTeXParser();
final BibTeXDatabase database = parser.getDatabase(); final BibTeXDatabase database;
try {
database = parser.parse(reader);
} catch (IOException ex) {
final PrintWriter writer = new PrintWriter(System.err);
writer.print("Failed to parse BibTeX file.");
ex.printStackTrace(writer);
return report;
} catch (ParseException ex) {
final PrintWriter writer = new PrintWriter(System.err);
writer.print("Failed to parse BibTeX file.");
ex.printStackTrace(writer);
return report;
}
final Map<Key, BibTeXEntry> entries = database.getEntries(); final Map<Key, BibTeXEntry> entries = database.getEntries();
for (BibTeXEntry entry : entries.values()) { for (BibTeXEntry entry : entries.values()) {

View File

@ -49,6 +49,8 @@ public class ArticleConverter implements BibTeXConverter<ArticleInJournal, Artic
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(ArticleInJournal.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -52,6 +52,8 @@ public class BookConverter implements BibTeXConverter<Monograph, PublicationWith
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(Monograph.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -49,6 +49,8 @@ public class BookletConverter implements BibTeXConverter<Monograph, PublicationW
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(Monograph.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -50,6 +50,8 @@ public class InBookConverter implements BibTeXConverter<ArticleInCollectedVolume
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(ArticleInCollectedVolume.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -50,6 +50,8 @@ public class InCollectionConverter implements BibTeXConverter<ArticleInCollected
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(ArticleInCollectedVolume.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -49,6 +49,8 @@ public class InProceedingsConverter implements BibTeXConverter<InProceedings, In
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(InProceedings.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -50,6 +50,8 @@ public class ManualConverter implements BibTeXConverter<Monograph, PublicationWi
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(Monograph.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -50,6 +50,8 @@ public class MasterThesisConverter implements BibTeXConverter<GreyLiterature, Un
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(GreyLiterature.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -49,6 +49,8 @@ public class MiscConverter implements BibTeXConverter<GreyLiterature, UnPublishe
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(GreyLiterature.class.getName());
bibTeXUtil.processIntField(pubKey, bibTeXUtil.processIntField(pubKey,
BibTeXEntry.KEY_YEAR, BibTeXEntry.KEY_YEAR,
bibTeXEntry.getField(BibTeXEntry.KEY_YEAR), bibTeXEntry.getField(BibTeXEntry.KEY_YEAR),

View File

@ -49,6 +49,8 @@ public class PhdThesisConverter implements BibTeXConverter<Monograph, Publicatio
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(Monograph.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -49,6 +49,8 @@ public class ProceedingsConverter implements BibTeXConverter<Proceedings, Procee
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(Proceedings.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_EDITOR), bibTeXEntry.getField(BibTeXEntry.KEY_EDITOR),
publication, publication,

View File

@ -50,6 +50,8 @@ public class TechReportConverter implements BibTeXConverter<GreyLiterature, UnPu
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(GreyLiterature.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -49,6 +49,8 @@ public class UnPublishedConverter implements BibTeXConverter<GreyLiterature, UnP
final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil); final BibTeXUtil bibTeXUtil = new BibTeXUtil(importerUtil);
final Key pubKey = bibTeXEntry.getKey(); final Key pubKey = bibTeXEntry.getKey();
importReport.setType(GreyLiterature.class.getName());
bibTeXUtil.processAuthors(pubKey, bibTeXUtil.processAuthors(pubKey,
bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR), bibTeXEntry.getField(BibTeXEntry.KEY_AUTHOR),
publication, publication,

View File

@ -41,24 +41,16 @@ public class AuthorListParser {
parseLastName(nameTokens[0], author); parseLastName(nameTokens[0], author);
} else if (nameTokens.length == 1) { } else if (nameTokens.length == 1) {
final String[] nameParts = nameTokens[0].split(" "); final String[] nameParts = nameTokens[0].split(" ");
if (nameParts.length == 1) { if (nameParts.length == 1) {
author.setLast(nameParts[0]); author.setLast(nameParts[0]);
return;
} else if (nameParts.length == 2) { } else if (nameParts.length == 2) {
author.setFirst(nameParts[0]); author.setFirst(nameParts[0]);
author.setLast(nameParts[1]); author.setLast(nameParts[1]);
return;
} else if (nameParts.length >= 3) { } else if (nameParts.length >= 3) {
author.setFirst(nameParts[0]); author.setFirst(nameParts[0]);
author.setPreLast(nameParts[1]); author.setPreLast(nameParts[1]);
author.setLast(nameParts[2]); author.setLast(nameParts[2]);
return;
} }
} }
authorList.add(author); authorList.add(author);

View File

@ -7,6 +7,7 @@ import com.arsdigita.cms.contenttypes.InternetArticle;
import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationWithPublisher; import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
import com.arsdigita.cms.contenttypes.UnPublished; import com.arsdigita.cms.contenttypes.UnPublished;
import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport;
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.cms.scipublications.importer.util.AuthorData; import com.arsdigita.cms.scipublications.importer.util.AuthorData;
@ -108,7 +109,10 @@ public class BibTeXUtil {
final List<Author> authorList = authorListParser.parse(toPlainString(authors)); final List<Author> authorList = authorListParser.parse(toPlainString(authors));
for (Author author : authorList) { for (Author author : authorList) {
importerUtil.processAuthor(publication, createAuthorData(author, editors), pretend); final AuthorImportReport authorReport = importerUtil.processAuthor(publication,
createAuthorData(author, editors),
pretend);
importReport.addAuthor(authorReport);
} }
} catch (IOException ex) { } catch (IOException ex) {
@ -144,9 +148,15 @@ public class BibTeXUtil {
try { try {
if (address == null) { if (address == null) {
importerUtil.processPublisher(publication, "", toPlainString(publisher), pretend); importReport.setPublisher(importerUtil.processPublisher(publication,
"",
toPlainString(publisher),
pretend));
} else { } else {
importerUtil.processPublisher(publication, toPlainString(address), toPlainString(publisher), pretend); importReport.setPublisher(importerUtil.processPublisher(publication,
toPlainString(address),
toPlainString(publisher),
pretend));
} }
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse publisher for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse publisher for publication '%s'.", pubKey.getValue()),
@ -169,7 +179,7 @@ public class BibTeXUtil {
} }
try { try {
importerUtil.processSeries(publication, toPlainString(series), pretend); importReport.setSeries(importerUtil.processSeries(publication, toPlainString(series), pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse series for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse series for publication '%s'.", pubKey.getValue()),
ex, ex,
@ -190,7 +200,7 @@ public class BibTeXUtil {
return; return;
} }
try { try {
importerUtil.processJournal(article, toPlainString(journal), pretend); importReport.setJournal(importerUtil.processJournal(article, toPlainString(journal), pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse journal for article '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse journal for article '%s'.", pubKey.getValue()),
ex, ex,
@ -226,14 +236,14 @@ public class BibTeXUtil {
authorData.add(createAuthorData(author, false)); authorData.add(createAuthorData(author, false));
} }
importerUtil.processCollectedVolume(article, importReport.setCollectedVolume(importerUtil.processCollectedVolume(article,
toPlainString(collectedVolume), toPlainString(collectedVolume),
toPlainString(yearValue), toPlainString(yearValue),
authorData, authorData,
toPlainString(publisherValue), toPlainString(publisherValue),
toPlainString(addressValue), toPlainString(addressValue),
toPlainString(editonValue), toPlainString(editonValue),
pretend); pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse collected volume for article '%s'.", addExceptionMsg(String.format("Failed to parse collected volume for article '%s'.",
bibTeXEntry.getKey().getValue()), bibTeXEntry.getKey().getValue()),
@ -270,14 +280,14 @@ public class BibTeXUtil {
authorData.add(createAuthorData(author, false)); authorData.add(createAuthorData(author, false));
} }
importerUtil.processProceedings(inProceedings, importReport.setProceedings(importerUtil.processProceedings(inProceedings,
toPlainString(proceedings), toPlainString(proceedings),
toPlainString(yearValue), toPlainString(yearValue),
"", "",
authorData, authorData,
toPlainString(publisherValue), toPlainString(publisherValue),
toPlainString(addressValue), toPlainString(addressValue),
pretend); pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse proceedings for in proceedings '%s'.", addExceptionMsg(String.format("Failed to parse proceedings for in proceedings '%s'.",
bibTeXEntry.getKey().getValue()), bibTeXEntry.getKey().getValue()),
@ -301,7 +311,9 @@ public class BibTeXUtil {
return; return;
} }
try { try {
importerUtil.processOrganization(publication, toPlainString(organization), pretend); importReport.addOrgaUnit(importerUtil.processOrganization(publication,
toPlainString(organization),
pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse organization for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse organization for publication '%s'.", pubKey.getValue()),
ex, ex,
@ -323,7 +335,7 @@ public class BibTeXUtil {
return; return;
} }
try { try {
importerUtil.processOrganization(article, toPlainString(organization), pretend); importReport.addOrgaUnit(importerUtil.processOrganization(article, toPlainString(organization), pretend));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse organization for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse organization for publication '%s'.", pubKey.getValue()),
ex, ex,
@ -401,8 +413,11 @@ public class BibTeXUtil {
try { try {
final String str = toPlainString(value); final String str = toPlainString(value);
final int intValue = Integer.parseInt(str); final int intValue = Integer.parseInt(str);
publication.set(target, intValue);
if (!pretend) {
publication.set(target, intValue);
}
importReport.addField(new FieldImportReport(target, str));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse field '%s' for publication '%s'.", addExceptionMsg(String.format("Failed to parse field '%s' for publication '%s'.",
pubKey.getValue(), pubKey.getValue(),
@ -437,7 +452,10 @@ public class BibTeXUtil {
} }
try { try {
if (!pretend) {
publication.set(target, toPlainString(value)); publication.set(target, toPlainString(value));
}
importReport.addField(new FieldImportReport(target, toPlainString(value)));
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse value of field '%s' for publication '%s'.", addExceptionMsg(String.format("Failed to parse value of field '%s' for publication '%s'.",
pubKey.getValue(), pubKey.getValue(),