BugFixes for the BibTeX Importer of the SciPublication module

git-svn-id: https://svn.libreccm.org/ccm/trunk@2520 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-02-12 10:28:52 +00:00
parent 2f3b425ddd
commit 73f29fa6b5
2 changed files with 81 additions and 43 deletions

View File

@ -354,7 +354,7 @@ public class PublicationsConfig extends AbstractConfig {
} }
} }
return null; return ContentSection.getDefaultSection().getRootFolder();
} }
public Boolean getAttachOrgaUnitsStep() { public Boolean getAttachOrgaUnitsStep() {

View File

@ -60,8 +60,9 @@ public class BibTeXUtil {
} }
importReport.setTitle(title); importReport.setTitle(title);
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse title for BibTeX entry '%s'. Using key as title. ", addExceptionMsg(String.format(
bibTeXEntry.getKey().getValue()), "Failed to parse title for BibTeX entry '%s'. Using key as title. ",
bibTeXEntry.getKey().getValue()),
ex, ex,
importReport); importReport);
@ -76,8 +77,9 @@ public class BibTeXUtil {
} }
importReport.setTitle(bibTeXEntry.getKey().getValue()); importReport.setTitle(bibTeXEntry.getKey().getValue());
} catch (ParseException ex) { } catch (ParseException ex) {
addExceptionMsg(String.format("Failed to parse title for BibTeX entry '%s'. Using key as title. ", addExceptionMsg(String.format(
bibTeXEntry.getKey().getValue()), "Failed to parse title for BibTeX entry '%s'. Using key as title. ",
bibTeXEntry.getKey().getValue()),
ex, ex,
importReport); importReport);
@ -110,7 +112,8 @@ public class BibTeXUtil {
for (Author author : authorList) { for (Author author : authorList) {
final AuthorImportReport authorReport = importerUtil.processAuthor(publication, final AuthorImportReport authorReport = importerUtil.processAuthor(publication,
createAuthorData(author, editors), createAuthorData(
author, editors),
pretend); pretend);
importReport.addAuthor(authorReport); importReport.addAuthor(authorReport);
} }
@ -159,11 +162,13 @@ public class BibTeXUtil {
pretend)); 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()),
ex, ex,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException 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()),
ex, ex,
importReport); importReport);
} }
@ -179,13 +184,16 @@ public class BibTeXUtil {
} }
try { try {
importReport.setSeries(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,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException 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,
importReport); importReport);
} }
@ -200,13 +208,16 @@ public class BibTeXUtil {
return; return;
} }
try { try {
importReport.setJournal(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,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException 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,
importReport); importReport);
} }
@ -237,12 +248,17 @@ public class BibTeXUtil {
} }
importReport.setCollectedVolume(importerUtil.processCollectedVolume(article, importReport.setCollectedVolume(importerUtil.processCollectedVolume(article,
toPlainString(collectedVolume), toPlainString(
toPlainString(yearValue), collectedVolume),
toPlainString(
yearValue),
authorData, authorData,
toPlainString(publisherValue), toPlainString(
toPlainString(addressValue), publisherValue),
toPlainString(editonValue), toPlainString(
addressValue),
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'.",
@ -315,11 +331,13 @@ public class BibTeXUtil {
toPlainString(organization), toPlainString(organization),
pretend)); 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,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException 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,
importReport); importReport);
} }
@ -335,13 +353,16 @@ public class BibTeXUtil {
return; return;
} }
try { try {
importReport.addOrgaUnit(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,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException 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,
importReport); importReport);
} }
@ -355,6 +376,10 @@ public class BibTeXUtil {
try { try {
final String pagesStr = toPlainString(pages); final String pagesStr = toPlainString(pages);
if (pagesStr == null) {
return;
}
final String[] tokens = pagesStr.split("-"); final String[] tokens = pagesStr.split("-");
if (tokens.length == 2) { if (tokens.length == 2) {
try { try {
@ -364,12 +389,15 @@ public class BibTeXUtil {
publication.set("pagesFrom", pagesFrom); publication.set("pagesFrom", pagesFrom);
publication.set("pagesTo", pagesTo); publication.set("pagesTo", pagesTo);
} }
importReport.addField(new FieldImportReport("pagesFrom", Integer.toString(pagesFrom))); importReport.addField(new FieldImportReport("pagesFrom", Integer.toString(
importReport.addField(new FieldImportReport("pagesTo", Integer.toString(pagesTo))); pagesFrom)));
importReport.addField(
new FieldImportReport("pagesTo", Integer.toString(pagesTo)));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
importReport.addMessage(String.format("Failed to parse pages for publication '%s'. " importReport.addMessage(String.format(
+ "One of the values given is not an integer.", "Failed to parse pages for publication '%s'. "
pubKey.getValue())); + "One of the values given is not an integer.",
pubKey.getValue()));
} }
} else if (tokens.length == 1) { } else if (tokens.length == 1) {
try { try {
@ -377,11 +405,13 @@ public class BibTeXUtil {
if (!pretend) { if (!pretend) {
publication.set("pagesFrom", pagesFrom); publication.set("pagesFrom", pagesFrom);
} }
importReport.addField(new FieldImportReport("pagesFrom", Integer.toString(pagesFrom))); importReport.addField(new FieldImportReport("pagesFrom", Integer.toString(
pagesFrom)));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
importReport.addMessage(String.format("Failed to parse pages for publication '%s'. " importReport.addMessage(String.format(
+ "Value is not an integer.", "Failed to parse pages for publication '%s'. "
pubKey.getValue())); + "Value is not an integer.",
pubKey.getValue()));
} }
} else { } else {
importReport.addMessage(String.format("Failed to parse pages for publication '%s'.", importReport.addMessage(String.format("Failed to parse pages for publication '%s'.",
@ -389,11 +419,13 @@ public class BibTeXUtil {
} }
} catch (IOException ex) { } catch (IOException ex) {
addExceptionMsg(String.format("Failed to parse pages for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse pages for publication '%s'.", pubKey.
getValue()),
ex, ex,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException ex) {
addExceptionMsg(String.format("Failed to parse pages for publication '%s'.", pubKey.getValue()), addExceptionMsg(String.format("Failed to parse pages for publication '%s'.", pubKey.
getValue()),
ex, ex,
importReport); importReport);
} }
@ -457,9 +489,10 @@ public class BibTeXUtil {
} }
importReport.addField(new FieldImportReport(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(
pubKey.getValue(), "Failed to parse value of field '%s' for publication '%s'.",
fieldKey.getValue()), pubKey.getValue(),
fieldKey.getValue()),
ex, ex,
importReport); importReport);
} catch (ParseException ex) { } catch (ParseException ex) {
@ -468,7 +501,11 @@ public class BibTeXUtil {
} }
public String toPlainString(final Value value) throws IOException, ParseException { public String toPlainString(final Value value) throws IOException, ParseException {
return toPlainString(value.toUserString()); if (value == null) {
return null;
} else {
return toPlainString(value.toUserString());
}
} }
private String toPlainString(final String str) throws IOException, ParseException { private String toPlainString(final String str) throws IOException, ParseException {
@ -500,14 +537,15 @@ public class BibTeXUtil {
return "null"; return "null";
} }
return str.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue"). return str.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue").
replace( replace(
"Ä", "Ae").replace("Ü", "Ue").replace("Ö", "Oe").replace("ß", "Ä", "Ae").replace("Ü", "Ue").replace("Ö", "Oe").replace("ß",
"ss"). "ss").
replace(" ", "-"). replace(" ", "-").
replaceAll("[^a-zA-Z0-9\\-]", "").toLowerCase().trim(); replaceAll("[^a-zA-Z0-9\\-]", "").toLowerCase().trim();
} }
private void addExceptionMsg(final String msg, final Exception exception, final PublicationImportReport importReport) { private void addExceptionMsg(final String msg, final Exception exception,
final PublicationImportReport importReport) {
final StringWriter strWriter = new StringWriter(); final StringWriter strWriter = new StringWriter();
final PrintWriter writer = new PrintWriter(strWriter); final PrintWriter writer = new PrintWriter(strWriter);