Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Bibtexml exporter #2017

Merged
merged 5 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.xml.bind.JAXBContext;
Expand Down Expand Up @@ -43,6 +42,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Export format for the BibTeXML format.
*/
public class BibTeXMLExportFormat extends ExportFormat {
Copy link
Contributor

@boceckts boceckts Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a javadoc comment.


private static final String BIBTEXML_NAMESPACE_URI = "http://bibtexml.sf.net/";
Expand All @@ -68,10 +70,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String
for (BibEntry bibEntry : entries) {
Entry entry = new Entry();

Optional<String> citeKey = bibEntry.getCiteKeyOptional();
if (citeKey.isPresent()) {
entry.setId(citeKey.get());
}
bibEntry.getCiteKeyOptional().ifPresent(citeKey -> entry.setId(citeKey));

String type = bibEntry.getType().toLowerCase(ENGLISH);
switch (type) {
Expand Down Expand Up @@ -141,7 +140,7 @@ private void createMarshallerAndWriteToFile(File file, String resultFile) throws
}

/**
* Contains same logic as the parse method, but inbook needs a special treatment, because
* Contains same logic as the {@link parse()} method, but inbook needs a special treatment, because
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To link to a method you need to use the following annotation {@link #parse()}, But the rest is good to me.

* the contents of inbook are stored in a List of JAXBElements. So we first need to create
* a JAXBElement for every field and then add it to the content list.
*/
Expand Down Expand Up @@ -223,11 +222,11 @@ private <T> void parse(T entryType, BibEntry bibEntry, Entry entry) {
}

//set the entryType to the entry
List<Method> entryMethods = getListOfSetMethods(entryType);
List<Method> entryMethods = getListOfSetMethods(entry);
for (Method method : entryMethods) {
String methodWithoutSet = method.getName().replace("set", "");
String simpleClassName = entryType.getClass().getSimpleName().replaceAll("\\[", "").replaceAll("\\]",
"");
String simpleClassName = entryType.getClass().getSimpleName();

if (methodWithoutSet.equals(simpleClassName)) {
try {
method.invoke(entry, entryType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public static void initAllExports(Map<String, ExportFormat> customFormats,
savePreferences));
ExportFormats.putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", ".rtf",
layoutPreferences, savePreferences));
ExportFormats.putFormat(
new BibTeXMLExportFormat());
ExportFormats.putFormat(
new ExportFormat("BibO RDF", "bibordf", "bibordf", null, ".rdf", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs",
Expand All @@ -56,6 +54,7 @@ public static void initAllExports(Map<String, ExportFormat> customFormats,
ExportFormats.putFormat(
new ExportFormat("MIS Quarterly", "misq", "misq", "misq", ".rtf", layoutPreferences, savePreferences));

ExportFormats.putFormat(new BibTeXMLExportFormat());
ExportFormats.putFormat(new OpenOfficeDocumentCreator());
ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator());
ExportFormats.putFormat(new MSBibExportFormat());
Expand Down