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,7 +60,8 @@ 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(
"Failed to parse title for BibTeX entry '%s'. Using key as title. ",
bibTeXEntry.getKey().getValue()), bibTeXEntry.getKey().getValue()),
ex, ex,
importReport); importReport);
@ -76,7 +77,8 @@ 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(
"Failed to parse title for BibTeX entry '%s'. Using key as title. ",
bibTeXEntry.getKey().getValue()), 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,10 +389,13 @@ 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(
"Failed to parse pages for publication '%s'. "
+ "One of the values given is not an integer.", + "One of the values given is not an integer.",
pubKey.getValue())); pubKey.getValue()));
} }
@ -377,9 +405,11 @@ 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(
"Failed to parse pages for publication '%s'. "
+ "Value is not an integer.", + "Value is not an integer.",
pubKey.getValue())); pubKey.getValue()));
} }
@ -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,7 +489,8 @@ 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(
"Failed to parse value of field '%s' for publication '%s'.",
pubKey.getValue(), pubKey.getValue(),
fieldKey.getValue()), fieldKey.getValue()),
ex, ex,
@ -468,8 +501,12 @@ public class BibTeXUtil {
} }
public String toPlainString(final Value value) throws IOException, ParseException { public String toPlainString(final Value value) throws IOException, ParseException {
if (value == null) {
return null;
} else {
return toPlainString(value.toUserString()); return toPlainString(value.toUserString());
} }
}
private String toPlainString(final String str) throws IOException, ParseException { private String toPlainString(final String str) throws IOException, ParseException {
final List<LaTeXObject> objects = parseLaTeX(str); final List<LaTeXObject> objects = parseLaTeX(str);
@ -507,7 +544,8 @@ public class BibTeXUtil {
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);