Skip to content

Commit

Permalink
MCR-2999 remove default stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteph-de committed Nov 14, 2023
1 parent 9404f27 commit 1178aa4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.mycore.backend.jpa.MCREntityManagerProvider;
import org.mycore.common.MCRConstants;
import org.mycore.common.MCRException;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.content.MCRSourceContent;
import org.mycore.common.content.MCRURLContent;
import org.mycore.common.xml.MCRXMLParserFactory;
Expand Down Expand Up @@ -78,11 +77,6 @@ public class MCRClassification2Commands extends MCRAbstractCommands {

private static final MCRCategoryDAO DAO = MCRCategoryDAOFactory.getInstance();

/** Default transformer script */
public static final String DEFAULT_STYLE
= MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder")
+ "/save-classification.xsl";

/** Static compiled transformer stylesheets */
private static final Map<String, Transformer> TRANSFORMER_CACHE = new HashMap<>();

Expand Down Expand Up @@ -279,7 +273,7 @@ public static void export(String id, String dirname, String style) throws Except
Document classDoc = MCRCategoryTransformer.getMetaDataDocument(cl, false);

Transformer trans
= MCRCommandUtils.getTransformer(style, DEFAULT_STYLE, TRANSFORMER_CACHE);
= MCRCommandUtils.getTransformer(style, TRANSFORMER_CACHE);
String extension = MCRXSLTransformerUtils.getFileExtension(trans, "xml");

File xmlOutput = new File(dir, id + "." + extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,12 @@ public static Stream<String> getIdsFromIdToId(final String startId, final String
* The transformer cache to be used.
* @return the transformer
*/
public static Transformer getTransformer(String style, String defaultStyle, Map<String, Transformer> cache) {
public static Transformer getTransformer(String style, Map<String, Transformer> cache) {
if (cache.containsKey(style)) {
return cache.get(style);
}

Element element = MCRURIResolver.instance().resolve("resource:" + style);
if(element == null) {
LOGGER.warn("Could not load transformer from resource {}, trying default {}.", style, defaultStyle);
element = MCRURIResolver.instance().resolve("resource:" + defaultStyle);
}
try {
if (element != null) {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.mycore.access.MCRRuleAccessInterface;
import org.mycore.common.MCRException;
import org.mycore.common.MCRPersistenceException;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.MCRPathContent;
import org.mycore.common.content.transformer.MCRXSLTransformer;
Expand Down Expand Up @@ -97,11 +96,6 @@ public class MCRDerivateCommands extends MCRAbstractCommands {
/** The ACL interface */
private static final MCRAccessInterface ACCESS_IMPL = MCRAccessManager.getAccessImpl();

/** Default transformer script */
public static final String DEFAULT_STYLE
= MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder")
+ "/save-derivate.xsl";

/** Static compiled transformer stylesheets */
private static final Map<String, Transformer> TRANSFORMER_CACHE = new HashMap<>();

Expand Down Expand Up @@ -377,7 +371,7 @@ public static void show(String id, String dirname) {
@MCRCommand(
syntax = "export derivate {0} to directory {1} with stylesheet {2}",
help = "Stores the derivate with the MCRObjectID {0} to the directory {1} with the stylesheet {2}. "
+ "The default for {2} is '{MCR.Layout.Transformer.Factory.XSLFolder}/save-derivate.xsl'.",
+ "The recommendation for {2} is '{MCR.Layout.Transformer.Factory.XSLFolder}/save-derivate.xsl'.",
order = 90)
public static void exportWithStylesheet(String id, String dirname, String style) {
exportWithStylesheet(id, id, dirname, style);
Expand Down Expand Up @@ -431,7 +425,7 @@ public static void exportWithStylesheet(String fromID, String toID, String dirna
}

Transformer trans
= MCRCommandUtils.getTransformer(style, DEFAULT_STYLE, TRANSFORMER_CACHE);
= MCRCommandUtils.getTransformer(style, TRANSFORMER_CACHE);
String extension = MCRXSLTransformerUtils.getFileExtension(trans, "xml");

int k = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ public class MCRObjectCommands extends MCRAbstractCommands {
/** The logger */
private static final Logger LOGGER = LogManager.getLogger(MCRObjectCommands.class);

/** Default transformer script */
public static final String DEFAULT_STYLE
= MCRConfiguration2.getStringOrThrow("MCR.Layout.Transformer.Factory.XSLFolder")
+ "/save-object.xsl";

/** Static compiled transformer stylesheets */
private static final Map<String, Transformer> TRANSFORMER_CACHE = new HashMap<>();

Expand Down Expand Up @@ -630,7 +625,7 @@ public static void exportWithTransformer(String id, String dirname, String trans
order = 100)
public static void exportWithStylesheet(String fromID, String toID, String dirname, String style) {
Transformer transformer
= MCRCommandUtils.getTransformer(style, DEFAULT_STYLE, TRANSFORMER_CACHE);
= MCRCommandUtils.getTransformer(style, TRANSFORMER_CACHE);
String extension = MCRXSLTransformerUtils.getFileExtension(transformer, "xml");
exportWith(fromID, toID, dirname, extension, (content, out) -> {
StreamResult sr = new StreamResult(out);
Expand Down Expand Up @@ -1253,7 +1248,7 @@ public static void validateObjectWithTransformer(String objectID, String style)
if (style != null) {
// getTransformer with non-existent input successfully returns a working transformer
// that "successfully transforms", an error would be preferable
trafo = MCRCommandUtils.getTransformer(style, DEFAULT_STYLE, TRANSFORMER_CACHE);
trafo = MCRCommandUtils.getTransformer(style, TRANSFORMER_CACHE);
LOGGER.debug("Transformer for stylesheet {} has been loaded.", style);
}
MCRObjectID objID = MCRObjectID.getInstance(objectID);
Expand Down

0 comments on commit 1178aa4

Please sign in to comment.