Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
53 changes: 53 additions & 0 deletions mycore-csl/src/main/java/org/mycore/csl/MCRCSLXMLOutputFormat.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<div class=\"csl-bib-body\">\n",
"</div>",
null, null, null, null, null, null, sfa);
}

@Override
protected String escape(String str) {
return str
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("\"", "&quot;")
.replaceAll("'", "&apos;");
}

@Override
public String getName() {
return "xml";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down