This is an automated email from the ASF dual-hosted git repository.
danwatford pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new edd7960 Fixed: Use data url scheme for logo in CompanyHeader edd7960 is described below commit edd7960e4b5252f9cc7fe501e07b8197719437fb Author: Daniel Watford <[hidden email]> AuthorDate: Sun Jan 24 16:26:34 2021 +0000 Fixed: Use data url scheme for logo in CompanyHeader (OFBIZ-7327) Use a data URL rather than a regular URL for company logos when a logo has been specified as a Party Content item. This works around the problem of Apache FOP failing to retrieve content from HTTPS URLs. Thanks: Deepak Dixit for the review and suggestions --- .../order/groovyScripts/order/CompanyHeader.groovy | 35 +++++++++++++++------- .../ofbiz/webapp/ftl/OfbizContentTransform.java | 4 +-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/applications/order/groovyScripts/order/CompanyHeader.groovy b/applications/order/groovyScripts/order/CompanyHeader.groovy index 74002b2..c617a9a 100644 --- a/applications/order/groovyScripts/order/CompanyHeader.groovy +++ b/applications/order/groovyScripts/order/CompanyHeader.groovy @@ -22,10 +22,11 @@ // if none of these parameters are available then fromPartyId is used or "ORGANIZATION_PARTY" from general.properties as fallback import org.apache.ofbiz.base.util.UtilHttp +import org.apache.ofbiz.content.data.DataResourceWorker +import org.apache.ofbiz.entity.GenericValue import org.apache.ofbiz.entity.util.EntityUtil import org.apache.ofbiz.order.order.OrderReadHelper import org.apache.ofbiz.party.content.PartyContentWrapper -import org.apache.ofbiz.entity.util.EntityUtilProperties import java.sql.Timestamp @@ -75,7 +76,7 @@ if (quoteId) { // defaults: def logoImageUrl = null // the default value, "/images/ofbiz_powered.gif", is set in the screen decorators -def partyId = null +String partyId = null // reference date for filtering Timestamp referenceDate = null // get the logo partyId from order or invoice - note that it is better to do comparisons this way in case the there are null values @@ -135,15 +136,29 @@ if (!partyId) { } // the logo -partyGroup = from("PartyGroup").where("partyId", partyId).queryOne() +GenericValue partyGroup = from("PartyGroup").where("partyId", partyId).queryOne() if (partyGroup) { - partyContentWrapper = new PartyContentWrapper(dispatcher, partyGroup, locale, EntityUtilProperties.getPropertyValue("content", "defaultMimeType", "text/html; charset=utf-8", delegator)) - partyContent = partyContentWrapper.getFirstPartyContentByType(partyGroup.partyId , partyGroup, "LGOIMGURL", delegator) - if (partyContent) { - logoImageUrl = "/content/control/stream?contentId=" + partyContent.contentId - } else { - if (partyGroup?.logoImageUrl) { - logoImageUrl = partyGroup.logoImageUrl + GenericValue partyContent = PartyContentWrapper.getFirstPartyContentByType(partyId, partyGroup, "LGOIMGURL", delegator) + GenericValue dataResource = partyContent?.getRelatedOne("Content", true) + ?.getRelatedOne("DataResource", true) + + if (dataResource) { + String dataResourceTypeId = dataResource.getString("dataResourceTypeId") + if (dataResourceTypeId.contains("_FILE")) { + File logoFile = DataResourceWorker.getContentFile(dataResource.getString("dataResourceTypeId"), + dataResource.getString("objectInfo"), "") + if (logoFile.exists()) { + def logoFileBase64 = logoFile.bytes.encodeBase64() + logoImageUrl = "data:" + dataResource.mimeTypeId + ";base64," + logoFileBase64 + } + } + } + + if (!logoImageUrl) { + if (partyContent) { + logoImageUrl = "/content/control/stream?contentId=" + partyContent.contentId + } else { + logoImageUrl = partyGroup?.logoImageUrl } } } diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizContentTransform.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizContentTransform.java index 86da27a..08f4bdc 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizContentTransform.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizContentTransform.java @@ -88,8 +88,8 @@ public class OfbizContentTransform implements TemplateTransformModel { String requestUrl = buf.toString(); - // If the URL starts with http(s) then there is nothing for us to do here - if (requestUrl.startsWith("http")) { + // If the URL starts with http(s) or data then there is nothing for us to do here + if (requestUrl.startsWith("http") || requestUrl.startsWith("data")) { out.write(requestUrl); return; } |
Free forum by Nabble | Edit this page |