Author: jleroux
Date: Thu Jun 3 04:11:32 2010 New Revision: 950866 URL: http://svn.apache.org/viewvc?rev=950866&view=rev Log: A patch from Sumit Pandit "Issue in rendering Freemarker Template from String." (https://issues.apache.org/jira/browse/OFBIZ-3782) - OFBIZ-3782 With the help of Bob Morley (it was more a cache issue than what Sumit thought) Modified: ofbiz/trunk/applications/content/ofbiz-component.xml ofbiz/trunk/applications/content/servicedef/services_data.xml ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Modified: ofbiz/trunk/applications/content/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/ofbiz-component.xml?rev=950866&r1=950865&r2=950866&view=diff ============================================================================== --- ofbiz/trunk/applications/content/ofbiz-component.xml (original) +++ ofbiz/trunk/applications/content/ofbiz-component.xml Thu Jun 3 04:11:32 2010 @@ -28,6 +28,7 @@ under the License. <classpath type="jar" location="lib/uno/*"/> <classpath type="jar" location="build/lib/*"/> <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/> + <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/ContentTypeData.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/ContentOperationData.xml"/> <entity-resource type="data" reader-name="seed" loader="main" location="data/MimeTypeData.xml"/> Modified: ofbiz/trunk/applications/content/servicedef/services_data.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/servicedef/services_data.xml?rev=950866&r1=950865&r2=950866&view=diff ============================================================================== --- ofbiz/trunk/applications/content/servicedef/services_data.xml (original) +++ ofbiz/trunk/applications/content/servicedef/services_data.xml Thu Jun 3 04:11:32 2010 @@ -252,4 +252,11 @@ <attribute mode="IN" name="rootDir" optional="true" type="String"/> </service> --> + + <!-- Cleared associated DataResource rendered cache from UtilCache. --> + <service name="clearAssociatedRenderCache" engine="java" auth="true" default-entity-name="DataResource" + location="org.ofbiz.content.data.DataServices" invoke="clearAssociatedRenderCache"> + <auto-attributes include="pk" mode="IN" /> + </service> + </services> \ No newline at end of file Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=950866&r1=950865&r2=950866&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Thu Jun 3 04:11:32 2010 @@ -546,6 +546,20 @@ public class DataResourceWorker impleme // DataResource rendering methods // ------------------------------------- + public static void clearAssociatedRenderCache(Delegator delegator, String dataResourceId) throws GeneralException { + if (dataResourceId == null) { + throw new GeneralException("Cannot clear dataResource related cache for a null dataResourceId"); + } + + GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId)); + if (dataResource != null) { + String dataTemplateTypeId = dataResource.getString("dataTemplateTypeId"); + if ("FTL".equals(dataTemplateTypeId)) { + FreeMarkerWorker.clearTemplateFromCache("DataResource:" + dataResourceId); + } + } + } + public static String renderDataResourceAsText(Delegator delegator, String dataResourceId, Map<String, Object> templateContext, Locale locale, String targetMimeTypeId, boolean cache) throws GeneralException, IOException { Writer writer = new StringWriter(); Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java?rev=950866&r1=950865&r2=950866&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java (original) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataServices.java Thu Jun 3 04:11:32 2010 @@ -54,6 +54,19 @@ public class DataServices { public static final String module = DataServices.class.getName(); + public static Map<String, Object> clearAssociatedRenderCache(DispatchContext dctx, Map<String, Object> context) { + Delegator delegator = dctx.getDelegator(); + String dataResourceId = (String) context.get("dataResourceId"); + try { + DataResourceWorker.clearAssociatedRenderCache(delegator, dataResourceId); + } catch (GeneralException e) { + String errMsg = "Unable to clear associated render cache with dataResourceId=" + dataResourceId; + Debug.logError(e, errMsg, module); + return ServiceUtil.returnError(errMsg); + } + return ServiceUtil.returnSuccess(); + } + /** * A top-level service for creating a DataResource and ElectronicText together. */ Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java?rev=950866&r1=950865&r2=950866&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Thu Jun 3 04:11:32 2010 @@ -173,6 +173,12 @@ public class FreeMarkerWorker { renderTemplate(template, context, outWriter); } + public static void clearTemplateFromCache(String templateLocation) { + synchronized (cachedTemplates) { + cachedTemplates.remove(templateLocation); + } + } + public static Environment renderTemplateFromString(String templateString, String templateLocation, Map<String, Object> context, Appendable outWriter) throws TemplateException, IOException { Template template = cachedTemplates.get(templateLocation); if (template == null) { @@ -186,7 +192,6 @@ public class FreeMarkerWorker { } } } - return renderTemplate(template, context, outWriter); } |
Free forum by Nabble | Edit this page |