You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by da...@apache.org on 2021/01/24 17:06:36 UTC
[ofbiz-framework] branch release18.12 updated: Fixed: Use data url
scheme for logo in CompanyHeader
This is an automated email from the ASF dual-hosted git repository.
danwatford pushed a commit to branch release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release18.12 by this push:
new a6ffc00 Fixed: Use data url scheme for logo in CompanyHeader
a6ffc00 is described below
commit a6ffc0087c0d5b9a57b9b04f8a26e7998ec866d7
Author: Daniel Watford <da...@watfordconsulting.com>
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 f92ff77..571cd76 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
orderHeader = parameters.orderHeader
orderId = parameters.orderId
@@ -73,7 +74,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
// 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
if (orderHeader) {
@@ -130,15 +131,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 2fdf4e2..179c06a 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
@@ -86,8 +86,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;
}