-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Refactor ModsExporter to use StaX from JAXB #9740
Conversation
Alternatively, I could get rid of modsCollection altogether and write directly to the export file in each respective 'add' method. I would call createStaxWriter first, before the loop. |
Some solid progress for refactoring, but need to figure out a different way to handle OriginInformation and RelatedInformation |
Working on fixing checkstyle and cleaning up the code |
addIdentifier(writer, new UnknownField("citekey"), citeKey); | ||
} catch ( | ||
XMLStreamException e) { | ||
throw new RuntimeException(e); // cant throw SaveException? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit odd to me. What is the purpose?
Why not use the isPresent? Or set it to an empty string? e.g. ifPresent.OrElse(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you asking about the purpose of using try-catch here? Or the use of ifPresent(citekey ...
?
I used ifPresent because that is what the code had originally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both. First question: Why do you need the cry catch? I would assume if there is no citeKey we set it to empty string or something like this and the other line does a similar check down below. So it's kind of duplicated code
Changelog entries should be understandable for the normal average user, they can't do anything with the technical detils |
We don't need a changelog entry here as there is no functionality changed, is it? |
Regarding checkstyle: You can click on https://github.com/JabRef/jabref/pull/9740/files to directly see the checkstyle comments. Moreover, IntelliJ has a build-in checkstyle plugin. The setup is explained at https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace. Search for "checkstyle". If everything works, checkstyle checking can be started with one click: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments.
Are there tests for the modsexporter? I saw some TODOs in the code - is the expected output covered by test cases?
import org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition; | ||
import org.jabref.logic.importer.fileformat.mods.TypeOfResourceDefinition; | ||
import org.jabref.logic.importer.fileformat.mods.UrlDefinition; | ||
// relevant StAX imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to comment on this, just remove that.
@@ -76,267 +49,343 @@ public void export(final BibDatabaseContext databaseContext, final Path file, Li | |||
} | |||
|
|||
try { | |||
ModsCollectionDefinition modsCollection = new ModsCollectionDefinition(); | |||
// create writer | |||
IndentingXMLStreamWriter writer = createWriter(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, the writer should be in the "try" statement - to have it auto closable:
try (IndentingXMLStreamWriter writer = createWriter(file))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work! StreamWriter does not support auto closable.
writer.flush(); | ||
writer.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obsolete at try-with-resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentionend earlier, java's XMLWriter do not implement auto closable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there is a JavaComment on that. Thank you!
What is the status here? It would be great if you continue working on this. |
* upstream/main: (110 commits) remove extra hack rather add a todo Enable CompareEnumsWithEqualityOperator cleanup checkstyle checkstyle Prefer u over y, remove some patterns that have not a test yet make parameterized test Enable ChainStringBuilderAppendCalls Add four rules not having any effect Apply BooleanChecksNotInverted Remove unused RadioButtonCell move exception handling upwards Minimal config for openRewrite Fix missing # Update CHANGELOG.md exchange locations between library mode and library encoding added to Changelog exchange locations between library mode and library encoding in general tab Fix modernizer (JabRef#9824) CHANGELOG.md Removed unused code Refined ui ... # Conflicts: # src/main/java/org/jabref/logic/exporter/ModsExporter.java
…m.sun.xml set indendation and standalone
Some starting changes to ModsExporter, refactoring from using JAXB to StAX. Not done yet, just wanted to commit some initial changes.
Fix for #9682
Compulsory checks