From 6639ffa89d3b716fa643aea14cd2ec7664e2f03f Mon Sep 17 00:00:00 2001 From: Michael Brohl Date: Tue, 4 Jul 2017 12:56:38 +0000 Subject: [PATCH] Fixed: ContentWorker#findAlternateLocaleContent(Delegator, GenericValue, Locale) does not use fallback locale. (OFBIZ-9445) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If no alternate locale content for the requested locale is found, search for an alternate locale content with the locale configured in general.properties at locale.properties.fallback. If this one isn't found either we can still return the original content. Thanks Tobias Laufkötter for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1800780 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/content/content/ContentWorker.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java index 7a24575aec..3119ad857f 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java @@ -39,6 +39,7 @@ import org.apache.ofbiz.base.util.UtilCodec; import org.apache.ofbiz.base.util.UtilDateTime; import org.apache.ofbiz.base.util.UtilGenerics; import org.apache.ofbiz.base.util.UtilMisc; +import org.apache.ofbiz.base.util.UtilProperties; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.base.util.string.FlexibleStringExpander; import org.apache.ofbiz.content.ContentManagementWorker; @@ -399,9 +400,9 @@ public class ContentWorker implements org.apache.ofbiz.widget.content.ContentWor } public static GenericValue findAlternateLocaleContent(Delegator delegator, GenericValue view, Locale locale) { - GenericValue contentAssocDataResourceViewFrom = view; + GenericValue contentAssocDataResourceViewFrom = null; if (locale == null) { - return contentAssocDataResourceViewFrom; + return view; } String localeStr = locale.toString(); @@ -412,9 +413,12 @@ public class ContentWorker implements org.apache.ofbiz.widget.content.ContentWor alternateViews = view.getRelated("ContentAssocDataResourceViewTo", UtilMisc.toMap("caContentAssocTypeId", "ALTERNATE_LOCALE"), UtilMisc.toList("-caFromDate"), true); } catch (GenericEntityException e) { Debug.logError(e, "Error finding alternate locale content: " + e.toString(), module); - return contentAssocDataResourceViewFrom; + return view; } + // also check the given view for a matching locale + alternateViews.add(0, view); + alternateViews = EntityUtil.filterByDate(alternateViews, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true); for (GenericValue thisView : alternateViews) { String currentLocaleString = thisView.getString("localeString"); @@ -454,6 +458,14 @@ public class ContentWorker implements org.apache.ofbiz.widget.content.ContentWor } } + if (contentAssocDataResourceViewFrom == null) { + // no content matching the given locale found. + Locale fallbackLocale = UtilProperties.getFallbackLocale(); + contentAssocDataResourceViewFrom = locale.equals(fallbackLocale) ? view + // only search for a content with the fallbackLocale if it is different to the given locale + : findAlternateLocaleContent(delegator, view, fallbackLocale); + } + return contentAssocDataResourceViewFrom; }