diff --git a/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformer.java b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformer.java index 6c8fc6979b..2dfe619636 100644 --- a/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformer.java +++ b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformer.java @@ -127,8 +127,11 @@ private void returnTransformerInstance(MCRCSLTransformerInstance instance, Strin try { instance.getCitationProcessor().reset(); instance.getDataProvider().reset(); - instance.getCitationProcessor().setOutputFormat(format); - instance.getCitationProcessor().setOutputFormat(format); + if ("xml".equals(format)) { + instance.getCitationProcessor().setOutputFormat(new MCRCSLXMLOutputFormat()); + } else { + instance.getCitationProcessor().setOutputFormat(format); + } } catch (RuntimeException e) { // if an error happens the instances may be not reset, so we throw away the instance LogManager.getLogger().error("Error while resetting transformer instance", e); diff --git a/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformerInstance.java b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformerInstance.java index e24bee4de3..7be094730d 100644 --- a/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformerInstance.java +++ b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLTransformerInstance.java @@ -50,7 +50,12 @@ public MCRCSLTransformerInstance(String style, String format, AutoCloseable clos } catch (IOException e) { throw new MCRConfigurationException("Error while creating CSL with Style " + style, e); } - this.citationProcessor.setOutputFormat(format); + + if ("xml".equalsIgnoreCase(format)) { + this.citationProcessor.setOutputFormat(new MCRCSLXMLOutputFormat()); + } else { + this.citationProcessor.setOutputFormat(format); + } } public CSL getCitationProcessor() { diff --git a/mycore-csl/src/main/java/org/mycore/csl/MCRCSLXMLOutputFormat.java b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLXMLOutputFormat.java new file mode 100644 index 0000000000..3f295f56f3 --- /dev/null +++ b/mycore-csl/src/main/java/org/mycore/csl/MCRCSLXMLOutputFormat.java @@ -0,0 +1,53 @@ +/* + * This file is part of *** M y C o R e *** + * See https://www.mycore.de/ for details. + * + * MyCoRe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MyCoRe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MyCoRe. If not, see . + */ + +package org.mycore.csl; + +import de.undercouch.citeproc.csl.internal.SBibliography; +import de.undercouch.citeproc.csl.internal.format.HtmlFormat; +import de.undercouch.citeproc.output.Bibliography; +import de.undercouch.citeproc.output.SecondFieldAlign; + +/** + * Class to enable XML output in the {@link de.undercouch.citeproc.CSL} processor. + * */ +public class MCRCSLXMLOutputFormat extends HtmlFormat { + + @Override + public Bibliography makeBibliography(String[] entries, SBibliography bibliographyElement) { + SecondFieldAlign sfa = bibliographyElement.getSecondFieldAlign(); + return new Bibliography(entries, "\n
\n", + "
", + null, null, null, null, null, null, sfa); + } + + @Override + protected String escape(String str) { + return str + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll("\"", """) + .replaceAll("'", "'"); + } + + @Override + public String getName() { + return "xml"; + } +} diff --git a/mycore-csl/src/main/resources/components/csl/config/mycore.properties b/mycore-csl/src/main/resources/components/csl/config/mycore.properties index 1bacf5ef65..9dc32363b6 100644 --- a/mycore-csl/src/main/resources/components/csl/config/mycore.properties +++ b/mycore-csl/src/main/resources/components/csl/config/mycore.properties @@ -4,7 +4,7 @@ MCR.CSL.DefaultLocale = en # via MCRModsItemDataProvider # MCR.ContentTransformer.mods2csl.Class=org.mycore.csl.MCRCSLTransformer -# MCR.ContentTransformer.mods2csl.format=html +# MCR.ContentTransformer.mods2csl.format=html | xml # MCR.ContentTransformer.mods2csl.style=elsevier-harvard # MCR.ContentTransformer.mods2csl.ItemProviderClass=org.mycore.mods.csl.MCRModsItemDataProvider # MCR.ContentTransformer.mods2csl.MIMEType=text/html; charset\="UTF-8"