From 978aee6088f9408d4211b541dfb7276403d34754 Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 26 Jan 2018 14:01:24 +0000 Subject: [PATCH] CCM NG: Load files from a theme from the master theme if the child theme does not have the file git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5222 8810af33-2d31-482b-a856-94f89814c4df --- .../java/org/libreccm/theming/Themes.java | 24 ++++++++++++++++--- .../theming/xslt/XsltThemeProcessor.java | 22 ++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ccm-core/src/main/java/org/libreccm/theming/Themes.java b/ccm-core/src/main/java/org/libreccm/theming/Themes.java index e4cf7c0f8..5c92be058 100644 --- a/ccm-core/src/main/java/org/libreccm/theming/Themes.java +++ b/ccm-core/src/main/java/org/libreccm/theming/Themes.java @@ -172,9 +172,27 @@ public class Themes implements Serializable { } final ThemeProvider provider = forTheme.get(); - return provider.getThemeFileAsStream(theme.getName(), - theme.getVersion(), - path); + final Optional result = provider + .getThemeFileAsStream(theme.getName(), theme.getVersion(), path); + + if (result.isPresent()) { + return result; + } else if (theme.getManifest().getMasterTheme() == null + || theme.getManifest().getMasterTheme().isEmpty() + || theme.getManifest().getMasterTheme().matches("\\s*")) { + + return Optional.empty(); + } else { + final Optional masterTheme = getTheme( + theme.getManifest().getMasterTheme(), + theme.getVersion()); + + if (masterTheme.isPresent()) { + return getFileFromTheme(masterTheme.get(), path); + } else { + return Optional.empty(); + } + } } } diff --git a/ccm-core/src/main/java/org/libreccm/theming/xslt/XsltThemeProcessor.java b/ccm-core/src/main/java/org/libreccm/theming/xslt/XsltThemeProcessor.java index 585f25cb6..0746a55f7 100644 --- a/ccm-core/src/main/java/org/libreccm/theming/xslt/XsltThemeProcessor.java +++ b/ccm-core/src/main/java/org/libreccm/theming/xslt/XsltThemeProcessor.java @@ -49,13 +49,12 @@ import net.sf.saxon.om.Item; import net.sf.saxon.om.Sequence; import net.sf.saxon.om.StructuredQName; import net.sf.saxon.trans.XPathException; -import net.sf.saxon.value.Int64Value; -import net.sf.saxon.value.IntegerValue; import net.sf.saxon.value.SequenceType; import net.sf.saxon.value.StringValue; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.libreccm.theming.ProcessesThemes; +import org.libreccm.theming.Themes; import org.libreccm.theming.manifest.ThemeTemplate; import org.libreccm.theming.utils.SettingsUtils; import org.libreccm.theming.utils.SystemInfoUtils; @@ -107,6 +106,9 @@ public class XsltThemeProcessor implements ThemeProcessor { @Inject private TextUtils textUtils; + @Inject + private Themes themes; + @Override public String process(final Map page, final ThemeInfo theme, @@ -170,10 +172,18 @@ public class XsltThemeProcessor implements ThemeProcessor { pathToTemplate = theme.getManifest().getDefaultTemplate(); } - final InputStream xslFileInputStream = themeProvider - .getThemeFileAsStream(theme.getName(), - theme.getVersion(), - pathToTemplate) +// final InputStream xslFileInputStream = themeProvider +// .getThemeFileAsStream(theme.getName(), +// theme.getVersion(), +// pathToTemplate) +// .orElseThrow(() -> new UnexpectedErrorException(String +// .format("Failed to open XSL file \"%s\" from theme \"%s\" for " +// + "reading.", +// pathToTemplate, +// theme.getName()))); + final InputStream xslFileInputStream = themes + .getFileFromTheme(theme, + pathToTemplate) .orElseThrow(() -> new UnexpectedErrorException(String .format("Failed to open XSL file \"%s\" from theme \"%s\" for " + "reading.",