Author: nmalin
Date: Fri Aug 25 21:25:26 2017 New Revision: 1806237 URL: http://svn.apache.org/viewvc?rev=1806237&view=rev Log: Fixed: Correct library ftl call to render the email body (OFBIZ-9138 Create a common theme) add possibility to call the ThemeFactory.resolveTheme() with empty request if the visualTheme normaly present on the service context isn't found, so we return the default theme define in general.properties Thanks to Jacques for raise this problem Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java Modified: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java?rev=1806237&r1=1806236&r2=1806237&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/email/EmailServices.java Fri Aug 25 21:25:26 2017 @@ -73,8 +73,10 @@ import org.apache.ofbiz.service.LocalDis import org.apache.ofbiz.service.ServiceUtil; import org.apache.ofbiz.service.mail.MimeMessageWrapper; import org.apache.ofbiz.webapp.view.ApacheFopWorker; +import org.apache.ofbiz.widget.model.ThemeFactory; import org.apache.ofbiz.widget.renderer.ScreenRenderer; import org.apache.ofbiz.widget.renderer.ScreenStringRenderer; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.apache.ofbiz.widget.renderer.macro.MacroScreenRenderer; import org.xml.sax.SAXException; @@ -431,6 +433,8 @@ public class EmailServices { String attachmentNameParam = (String) serviceContext.remove("attachmentName"); List<String> xslfoAttachScreenLocationListParam = UtilGenerics.checkList(serviceContext.remove("xslfoAttachScreenLocationList")); List<String> attachmentNameListParam = UtilGenerics.checkList(serviceContext.remove("attachmentNameList")); + VisualTheme visualTheme = (VisualTheme) rServiceContext.get("visualTheme"); + if (visualTheme == null) visualTheme = ThemeFactory.resolveVisualTheme(null); List<String> xslfoAttachScreenLocationList = new LinkedList<String>(); List<String> attachmentNameList = new LinkedList<String>(); @@ -473,8 +477,7 @@ public class EmailServices { ScreenStringRenderer screenStringRenderer = null; try { - screenStringRenderer = new MacroScreenRenderer(EntityUtilProperties.getPropertyValue("widget", "screen.name", dctx.getDelegator()), - EntityUtilProperties.getPropertyValue("widget", "screen.screenrenderer", dctx.getDelegator())); + screenStringRenderer = new MacroScreenRenderer("screen", visualTheme.getModelTheme().getScreenRendererLocation("screen")); } catch (TemplateException e) { Debug.logError(e, "Error rendering screen for email: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonEmailSendRenderingScreenEmailError", UtilMisc.toMap("errorString", e.toString()), locale)); Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java?rev=1806237&r1=1806236&r2=1806237&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java Fri Aug 25 21:25:26 2017 @@ -191,30 +191,32 @@ public class ThemeFactory { */ public static VisualTheme resolveVisualTheme(HttpServletRequest request) { String visualThemeId = null; - HttpSession session = request.getSession(); - GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); - //search on request only if a userLogin is present on session (otherwise this implied that the user isn't identify so wait - if (userLogin != null) { - VisualTheme visualTheme = (VisualTheme) session.getAttribute("visualTheme"); - if (visualTheme != null) return visualTheme; + if (request != null) { + HttpSession session = request.getSession(); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + //search on request only if a userLogin is present on session (otherwise this implied that the user isn't identify so wait + if (userLogin != null) { + VisualTheme visualTheme = (VisualTheme) session.getAttribute("visualTheme"); + if (visualTheme != null) return visualTheme; - //resolve on user pref - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - if (dispatcher != null) { - try { - Map<String, Object> userPreferencesResult = dispatcher.runSync("getUserPreference", - UtilMisc.toMap("userLogin", userLogin, "userPrefTypeId", "VISUAL_THEME")); - visualThemeId = (String) userPreferencesResult.get("userPrefValue"); - } catch (GenericServiceException e) { - Debug.logError("Impossible to resolve the theme from user prefrence for " + userLogin.get("userLoginId"), module); + //resolve on user pref + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + if (dispatcher != null) { + try { + Map<String, Object> userPreferencesResult = dispatcher.runSync("getUserPreference", + UtilMisc.toMap("userLogin", userLogin, "userPrefTypeId", "VISUAL_THEME")); + visualThemeId = (String) userPreferencesResult.get("userPrefValue"); + } catch (GenericServiceException e) { + Debug.logError("Impossible to resolve the theme from user prefrence for " + userLogin.get("userLoginId"), module); + } } } - } - //resolve from webapp - if (visualThemeId == null) { - ServletContext servletContext = request.getServletContext(); - visualThemeId = servletContext.getInitParameter("visualThemeId"); + //resolve from webapp + if (visualThemeId == null) { + ServletContext servletContext = request.getServletContext(); + visualThemeId = servletContext.getInitParameter("visualThemeId"); + } } //resolve from general properties |
Free forum by Nabble | Edit this page |