From e13c0a76f9a7405295743024888992fef08cf59b Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 15 Mar 2017 09:50:18 +0100 Subject: [PATCH] OO-2593: get every time the current custom CSS from the window object itself --- .../org/olat/core/gui/components/Window.java | 4 ++- .../htmlheader/jscss/CustomCSS.java | 4 +-- .../htmlheader/jscss/CustomCSSDelegate.java | 32 +++++++++++++++++++ .../generic/iframe/IFrameDeliveryMapper.java | 10 ++++++ .../iframe/IFrameDisplayController.java | 6 ++-- 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSSDelegate.java diff --git a/src/main/java/org/olat/core/gui/components/Window.java b/src/main/java/org/olat/core/gui/components/Window.java index 26ffcbb1d88..ada59dae81e 100644 --- a/src/main/java/org/olat/core/gui/components/Window.java +++ b/src/main/java/org/olat/core/gui/components/Window.java @@ -47,6 +47,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.Windows; import org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException; import org.olat.core.gui.components.htmlheader.jscss.CustomCSS; +import org.olat.core.gui.components.htmlheader.jscss.CustomCSSDelegate; import org.olat.core.gui.components.panel.Panel; import org.olat.core.gui.control.ChiefController; import org.olat.core.gui.control.Controller; @@ -95,7 +96,7 @@ import org.olat.core.util.component.ComponentVisitor; * * @author Felix Jost */ -public class Window extends AbstractComponent { +public class Window extends AbstractComponent implements CustomCSSDelegate { private static final OLog log = Tracing.createLoggerFor(Window.class); private static final DispatchResult NO_DISPATCHRESULT = new DispatchResult(false, false, false); @@ -843,6 +844,7 @@ public class Window extends AbstractComponent { this.dTabs = dTabs; } + @Override public CustomCSS getCustomCSS() { return customCSS; } diff --git a/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSS.java b/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSS.java index 418d18f629f..119508d3601 100644 --- a/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSS.java +++ b/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSS.java @@ -27,7 +27,6 @@ import org.olat.core.dispatcher.mapper.MapperService; import org.olat.core.dispatcher.mapper.manager.MapperKey; import org.olat.core.gui.control.Disposable; import org.olat.core.gui.control.JSAndCSSAdder; -import org.olat.core.logging.LogDelegator; import org.olat.core.util.CodeHelper; import org.olat.core.util.UserSession; import org.olat.core.util.vfs.VFSContainer; @@ -46,7 +45,7 @@ import org.olat.core.util.vfs.VFSManager; * * @author gnaegi */ -public class CustomCSS extends LogDelegator implements Disposable { +public class CustomCSS implements Disposable { private final String relCssFilename; private final String relCssFileIframe; @@ -91,7 +90,6 @@ public class CustomCSS extends LogDelegator implements Disposable { String fulluri = cssUriMapperKey.getUrl() + relCssFilename; // load CSS after the theme jsAndCssComp.addAutoRemovedCssPathName(fulluri, JSAndCSSAdder.CSS_INDEX_AFTER_THEME); - } /** diff --git a/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSSDelegate.java b/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSSDelegate.java new file mode 100644 index 00000000000..cb970d2bc89 --- /dev/null +++ b/src/main/java/org/olat/core/gui/components/htmlheader/jscss/CustomCSSDelegate.java @@ -0,0 +1,32 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.gui.components.htmlheader.jscss; + +/** + * + * Initial date: 15 mars 2017<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public interface CustomCSSDelegate { + + public CustomCSS getCustomCSS(); + +} diff --git a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java index 9a4ffa0e4af..43ac1cca8d5 100644 --- a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java +++ b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDeliveryMapper.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import org.olat.core.dispatcher.impl.StaticMediaDispatcher; import org.olat.core.dispatcher.mapper.Mapper; +import org.olat.core.gui.components.htmlheader.jscss.CustomCSSDelegate; import org.olat.core.gui.media.MediaResource; import org.olat.core.gui.media.NotFoundMediaResource; import org.olat.core.gui.media.StringMediaResource; @@ -75,6 +76,7 @@ public class IFrameDeliveryMapper implements Mapper { private String frameId; private String customCssURL; + private CustomCSSDelegate customCssDelegate; private String themeBaseUri; private String customHeaderContent; @@ -169,6 +171,10 @@ public class IFrameDeliveryMapper implements Mapper { public void setCustomCssURL(String customCssURL) { this.customCssURL = customCssURL; } + + public void setCustomCssDelegate(CustomCSSDelegate customCssDelegate) { + this.customCssDelegate = customCssDelegate; + } @Override public MediaResource handle(String relPath, HttpServletRequest request) { @@ -325,6 +331,10 @@ public class IFrameDeliveryMapper implements Mapper { if (customCssURL != null) { // add the custom CSS, e.g. the course css that overrides the standard content css sb.appendCss(customCssURL, "customcss"); + } else if(customCssDelegate != null && customCssDelegate.getCustomCSS() != null + && customCssDelegate.getCustomCSS().getCSSURLIFrame() != null) { + String customCssURL = customCssDelegate.getCustomCSS().getCSSURLIFrame(); + sb.appendCss(customCssURL, "customcss"); } } diff --git a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java index a4447acec8e..dcbc6111adb 100644 --- a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java +++ b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java @@ -433,6 +433,7 @@ public class IFrameDisplayController extends BasicController implements GenericE * this event gets fired from the TextMarkerController when the user swiches on/off textmarking * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event) */ + @Override public void event(Event event) { if (event instanceof MultiUserEvent) { if (event.getCommand().equals("glossaryOn")) { @@ -440,8 +441,7 @@ public class IFrameDisplayController extends BasicController implements GenericE } else if (event.getCommand().equals("glossaryOff")) { contentMapper.setEnableTextmarking(false); } - } - else if (event.equals(Window.BEFORE_INLINE_RENDERING)){ + } else if (event.equals(Window.BEFORE_INLINE_RENDERING)){ // Set the custom CSS URL that is used by the current tab or site if // available. The reason why we do this here and not in the constructor is // that during the constructing phase this property is not yet set on the @@ -449,7 +449,7 @@ public class IFrameDisplayController extends BasicController implements GenericE Window myWindow = getWindowControl().getWindowBackOffice().getWindow(); CustomCSS currentCustomCSS = myWindow.getCustomCSS(); if (currentCustomCSS != null) { - contentMapper.setCustomCssURL(currentCustomCSS.getCSSURLIFrame()); + contentMapper.setCustomCssDelegate(myWindow); } // done, remove us as listener getWindowControl().getWindowBackOffice().removeCycleListener(this); -- GitLab