Author: mbrohl
Date: Wed Jul 5 09:42:23 2017 New Revision: 1800853 URL: http://svn.apache.org/viewvc?rev=1800853&view=rev Log: Fixed: ContentWorker#findAlternateLocaleContent(Delegator, GenericValue, Locale) does not use fallback locale. (OFBIZ-9445) 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. Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java?rev=1800853&r1=1800852&r2=1800853&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentWorker.java Wed Jul 5 09:42:23 2017 @@ -39,6 +39,7 @@ import org.apache.ofbiz.base.util.UtilCo 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 or } 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,10 +413,13 @@ public class ContentWorker implements or 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; } alternateViews = EntityUtil.filterByDate(alternateViews, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true); + // also check the given view for a matching locale + alternateViews.add(0, view); + for (GenericValue thisView : alternateViews) { String currentLocaleString = thisView.getString("localeString"); if (UtilValidate.isEmpty(currentLocaleString)) { @@ -454,6 +458,14 @@ public class ContentWorker implements or } } + 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; } |
Free forum by Nabble | Edit this page |