Claus Ibsen created CAMEL-27751:
-----------------------------------

             Summary: camel-fop - apply CamelFop.Render and CamelFop.Encrypt 
header values as given
                 Key: CAMEL-27751
                 URL: https://issues.apache.org/jira/browse/CAMEL-27751
             Project: Camel
          Issue Type: Bug
          Components: camel-fop
            Reporter: Claus Ibsen
             Fix For: 4.24.0, 4.18.7, 4.22.4


The fop producer reads the {{CamelFop.Render.*}} and {{CamelFop.Encrypt.*}} 
message headers (for example {{CamelFop.Render.title}} or 
{{CamelFop.Encrypt.userPassword}}) to set per-document PDF metadata and 
encryption settings.

*Today*
{{FopProducer.setRenderParameters}} and {{FopProducer.setEncryptionParameters}} 
pass all such headers to {{PropertyBindingSupport.bindProperties}}, the same 
general purpose binder that is used for endpoint and component configuration. 
As a result:
* a header value is not always applied as given: text with double curly braces 
or a value that starts with {{#}} is interpreted by the binder (property 
placeholder or reference syntax) instead of being written into the PDF as is;
* any property of {{FOUserAgent}} / {{PDFEncryptionParams}} can be set from a 
header, including object-typed ones (renderer and event handler overrides, 
output file, event broadcaster) that are not meant to be configured per message;
* unknown names are silently ignored.

*After the change*
Only the documented options are applied, and each value is taken as given, 
converted to the setter type with the Camel type converter:
* {{CamelFop.Render.*}} -> {{FOUserAgent}}: {{producer}}, {{creator}}, 
{{author}}, {{title}}, {{subject}}, {{keywords}} (String), {{creationDate}} 
(Date), plus the plain-typed {{targetResolution}}, {{accessibility}}, 
{{pdfUAEnabled}}, {{keepEmptyTags}}, {{locatorEnabled}}, 
{{conserveMemoryPolicy}};
* {{CamelFop.Encrypt.*}} -> {{PDFEncryptionParams}}: {{userPassword}}, 
{{ownerPassword}} (String), {{allowPrint}}, {{allowCopyContent}}, 
{{allowEditContent}}, {{allowEditAnnotations}}, {{allowFillInForms}}, 
{{allowAccessContent}}, {{allowAssembleDocument}}, {{allowPrintHq}}, 
{{encryptMetadata}} (boolean), {{encryptionLengthInBits}} (int).
Option names are matched case-insensitively (as today, e.g. 
{{CamelFop.Render.Creator}}). Other names are ignored and logged. Routes that 
need a property placeholder or a bean value in these headers resolve it in the 
route (for example with the simple language) before the fop endpoint. Other FOP 
user agent settings are configured through the FOP configuration file 
({{userConfigURL}}) or a custom {{FopFactory}}.

*Code changes*
* 
{{components/camel-fop/src/main/java/org/apache/camel/component/fop/FopProducer.java}}:
 replace the two {{PropertyBindingSupport.bindProperties}} calls with an 
explicit mapping of the option names above to the {{FOUserAgent}} and 
{{PDFEncryptionParams}} setters, using {{TypeConverter.mandatoryConvertTo}} for 
the values.
* {{FopConstants}}: optionally add header constants with {{@Metadata}} for the 
supported names so they show in the generated header table (regenerate 
{{src/generated}} and the catalog JSON).
* {{fop-component.adoc}}: list the supported names and state that values are 
used as given; regenerate the catalog doc copy.
* Upgrade guide (4.24, and the 4.22.4 / 4.18.7 entries on main): only the 
listed names are applied and their values are taken as given.

*Tests* (camel-fop, offline, reading the generated PDF with PDFBox)
* {{FopMetadataHeadersTest}}: metadata headers are written to the PDF; a value 
with double curly braces or a leading {{#}} (e.g. author {{#1 Team}}) is 
written exactly as given; header names are case-insensitive; an unsupported 
render header is ignored.
* {{FopEncryptionHeadersTest}}: the password header opens the PDF exactly as 
given; permission headers (e.g. {{allowPrint=false}}) are reflected in the 
access permissions.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to