This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch 3.15.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 40a489829ec2557d9e94c206b38738aa281fe802
Author: James Netherton <[email protected]>
AuthorDate: Thu Oct 17 11:11:36 2024 +0100

    Add header details and examples to Qute documentation
---
 .../ROOT/pages/reference/extensions/qute.adoc      | 105 +++++++++++++++++++++
 .../org/apache/camel/component/qute/qute.json      |   6 ++
 .../apache/camel/component/qute/QuteConstants.java |   6 ++
 .../apache/camel/component/qute/QuteEndpoint.java  |   2 +-
 extensions/qute/runtime/src/main/doc/usage.adoc    | 101 ++++++++++++++++++++
 5 files changed, 219 insertions(+), 1 deletion(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/qute.adoc 
b/docs/modules/ROOT/pages/reference/extensions/qute.adoc
index 7be8da74f8..abdc38cb62 100644
--- a/docs/modules/ROOT/pages/reference/extensions/qute.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/qute.adoc
@@ -42,6 +42,111 @@ endif::[]
 == Usage
 include::partial$component-configure-options.adoc[]
 include::partial$component-endpoint-options.adoc[]
+include::partial$component-endpoint-headers.adoc[]
+
+[id="extensions-qute-usage-qute-template-data"]
+=== Qute template data
+
+Camel will populate the Qute `TemplateInstance` data model with exchange 
information. The following options are available within Qute templates as 
variables:
+
+[width="100%",cols="50%,50%",options="header",]
+|=======================================================================
+|key |value
+
+|`exchange` |The `Exchange` itself.
+
+|`exchange.properties` |The `Exchange` properties.
+
+|`variables` |The exchange variables
+
+|`headers` |The headers of the In message.
+
+|`camelContext` |The Camel Context.
+
+|`request` |The In message.
+
+|`body` |The In message body.
+
+|`response` |The Out message (only for InOut message exchange pattern).
+|=======================================================================
+
+You can configure your own template data with the message header 
`CamelQuteTemplateData` like this.
+
+[source,java]
+--------------------------------------------------------------------
+Map<String, Object> variableMap = new HashMap<String, Object>();
+variableMap.put("headers", headersMap);
+variableMap.put("body", "Monday");
+variableMap.put("exchange", exchange);
+exchange.getMessage().setHeader("CamelQuteTemplateData", variableMap);
+--------------------------------------------------------------------
+
+[id="extensions-qute-usage-dynamic-templates"]
+=== Dynamic templates
+
+Camel provides headers `CamelQuteResourceUri`, `CamelQuteTemplate` and 
`CamelQuteTemplateInstance` which can be used to define a different resource
+location for a template, or provide the template instance itself. If any of 
these headers is set, then Camel uses this over
+the endpoint configured resource. This allows you to provide a dynamic 
template at runtime.
+
+[id="extensions-qute-usage-examples"]
+=== Examples
+
+Processing an exchange with a Qute template read from the classpath.
+
+[source,java]
+-------------------------------------------
+from("direct:start")
+    .to("qute:org/acme/myTemplate.txt");
+-------------------------------------------
+
+Processing an exchange with a Qute template read from a file-based resource.
+
+[source,java]
+-------------------------------------------
+from("direct:start")
+    .to("qute:file://path/to/myTemplate.txt");
+-------------------------------------------
+
+Dynamic template path URI.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_RESOURCE_URI).constant("org/acme/template.txt")
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Dynamic template content.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_TEMPLATE).constant("<hello>{headers.greeting}</hello>")
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Dynamic template instance.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE).constant(myTemplateInstance)
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Qute template example.
+
+----------------------------------------------
+Dear {headers.lastName}, {headers.firstName}
+
+Thanks for the order of {headers.item}.
+
+Regards Camel Riders Bookstore
+{body}
+----------------------------------------------
+
+[id="extensions-qute-usage-quarkus-qute-documentation"]
+=== Quarkus Qute documentation
 
 For more information about Qute, please refer to the 
https://quarkus.io/guides/qute[Quarkus Qute] documentation.
 
diff --git 
a/extensions/qute/component/src/generated/resources/META-INF/org/apache/camel/component/qute/qute.json
 
b/extensions/qute/component/src/generated/resources/META-INF/org/apache/camel/component/qute/qute.json
index 048b791d76..32d6ff453c 100644
--- 
a/extensions/qute/component/src/generated/resources/META-INF/org/apache/camel/component/qute/qute.json
+++ 
b/extensions/qute/component/src/generated/resources/META-INF/org/apache/camel/component/qute/qute.json
@@ -28,6 +28,12 @@
     "autowiredEnabled": { "index": 2, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"Whether autowiring is enabled. This is used for automatic autowiring options 
(the option must be marked as autowired) by looking up in the registry to find 
if there is a single instance of matching t [...]
     "quteEngine": { "index": 3, "kind": "property", "displayName": "Qute 
Engine", "group": "advanced", "label": "advanced", "required": false, "type": 
"object", "javaType": "io.quarkus.qute.Engine", "deprecated": false, 
"autowired": false, "secret": false, "description": "To use the Engine 
otherwise a new engine is created" }
   },
+  "headers": {
+    "CamelQuteResourceUri": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "A URI for the template resource to use instead of the 
endpoint configured one.", "constantName": 
"org.apache.camel.component.qute.QuteConstants#QUTE_RESOURCE_URI" },
+    "CamelQuteTemplate": { "index": 1, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The template to use instead of the endpoint configured 
one.", "constantName": 
"org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE" },
+    "CamelQuteTemplateInstance": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "TemplateInstance", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "The template instance to 
use instead of the endpoint configured one.", "constantName": 
"org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE_INSTANCE" },
+    "CamelQuteTemplateData": { "index": 3, "kind": "header", "displayName": 
"", "group": "producer", "label": "", "required": false, "javaType": "Map", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The template model data.", "constantName": 
"org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE_DATA" }
+  },
   "properties": {
     "resourceUri": { "index": 0, "kind": "path", "displayName": "Resource 
Uri", "group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "supportFileReference": true, 
"description": "Path to the resource. You can prefix with: classpath, file, 
http, ref, or bean. classpath, file and http loads the resource using these 
protocols (classpath is default). ref will look [...]
     "allowContextMapAll": { "index": 1, "kind": "parameter", "displayName": 
"Allow Context Map All", "group": "producer", "label": "", "required": false, 
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": 
false, "secret": false, "defaultValue": false, "description": "Sets whether the 
context map should allow access to all details. By default only the message 
body and headers can be accessed. This option can be enabled for full access to 
the current Exchange and C [...]
diff --git 
a/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteConstants.java
 
b/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteConstants.java
index 70d8d44100..386f13c6d7 100644
--- 
a/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteConstants.java
+++ 
b/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteConstants.java
@@ -16,10 +16,16 @@
  */
 package org.apache.camel.component.qute;
 
+import org.apache.camel.spi.Metadata;
+
 public final class QuteConstants {
+    @Metadata(description = "A URI for the template resource to use instead of 
the endpoint configured one.", javaType = "String")
     public static final String QUTE_RESOURCE_URI = "CamelQuteResourceUri";
+    @Metadata(description = "The template to use instead of the endpoint 
configured one.", javaType = "String")
     public static final String QUTE_TEMPLATE = "CamelQuteTemplate";
+    @Metadata(description = "The template instance to use instead of the 
endpoint configured one.", javaType = "TemplateInstance")
     public static final String QUTE_TEMPLATE_INSTANCE = 
"CamelQuteTemplateInstance";
+    @Metadata(description = "The template model data.", javaType = "Map")
     public static final String QUTE_TEMPLATE_DATA = "CamelQuteTemplateData";
 
     private QuteConstants() {
diff --git 
a/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteEndpoint.java
 
b/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteEndpoint.java
index dd736d4f08..a166cc05dc 100644
--- 
a/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteEndpoint.java
+++ 
b/extensions/qute/component/src/main/java/org/apache/camel/component/qute/QuteEndpoint.java
@@ -42,7 +42,7 @@ import org.apache.camel.util.ObjectHelper;
 /**
  * Transforms the message using a Quarkus Qute template.
  */
-@UriEndpoint(firstVersion = "3.2.0", scheme = "qute", title = "Qute", syntax = 
"qute:resourceUri", producerOnly = true, category = Category.TRANSFORMATION)
+@UriEndpoint(firstVersion = "3.2.0", scheme = "qute", title = "Qute", syntax = 
"qute:resourceUri", producerOnly = true, category = Category.TRANSFORMATION, 
headersClass = QuteConstants.class)
 public class QuteEndpoint extends ResourceEndpoint {
     private Engine quteEngine;
 
diff --git a/extensions/qute/runtime/src/main/doc/usage.adoc 
b/extensions/qute/runtime/src/main/doc/usage.adoc
index a67aa367e1..728c03ff46 100644
--- a/extensions/qute/runtime/src/main/doc/usage.adoc
+++ b/extensions/qute/runtime/src/main/doc/usage.adoc
@@ -1,4 +1,105 @@
 include::partial$component-configure-options.adoc[]
 include::partial$component-endpoint-options.adoc[]
+include::partial$component-endpoint-headers.adoc[]
+
+=== Qute template data
+
+Camel will populate the Qute `TemplateInstance` data model with exchange 
information. The following options are available within Qute templates as 
variables:
+
+[width="100%",cols="50%,50%",options="header",]
+|=======================================================================
+|key |value
+
+|`exchange` |The `Exchange` itself.
+
+|`exchange.properties` |The `Exchange` properties.
+
+|`variables` |The exchange variables
+
+|`headers` |The headers of the In message.
+
+|`camelContext` |The Camel Context.
+
+|`request` |The In message.
+
+|`body` |The In message body.
+
+|`response` |The Out message (only for InOut message exchange pattern).
+|=======================================================================
+
+You can configure your own template data with the message header 
`CamelQuteTemplateData` like this.
+
+[source,java]
+--------------------------------------------------------------------
+Map<String, Object> variableMap = new HashMap<String, Object>();
+variableMap.put("headers", headersMap);
+variableMap.put("body", "Monday");
+variableMap.put("exchange", exchange);
+exchange.getMessage().setHeader("CamelQuteTemplateData", variableMap);
+--------------------------------------------------------------------
+
+=== Dynamic templates
+
+Camel provides headers `CamelQuteResourceUri`, `CamelQuteTemplate` and 
`CamelQuteTemplateInstance` which can be used to define a different resource
+location for a template, or provide the template instance itself. If any of 
these headers is set, then Camel uses this over
+the endpoint configured resource. This allows you to provide a dynamic 
template at runtime.
+
+=== Examples
+
+Processing an exchange with a Qute template read from the classpath.
+
+[source,java]
+-------------------------------------------
+from("direct:start")
+    .to("qute:org/acme/myTemplate.txt");
+-------------------------------------------
+
+Processing an exchange with a Qute template read from a file-based resource.
+
+[source,java]
+-------------------------------------------
+from("direct:start")
+    .to("qute:file://path/to/myTemplate.txt");
+-------------------------------------------
+
+Dynamic template path URI.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_RESOURCE_URI).constant("org/acme/template.txt")
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Dynamic template content.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_TEMPLATE).constant("<hello>{headers.greeting}</hello>")
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Dynamic template instance.
+
+[source,java]
+---------------------------------------------------------------------------------------------
+from("direct:start")
+    
.setHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE).constant(myTemplateInstance)
+    .to("qute:dynamic?allowTemplateFromHeader=true");
+---------------------------------------------------------------------------------------------
+
+Qute template example.
+
+----------------------------------------------
+Dear {headers.lastName}, {headers.firstName}
+
+Thanks for the order of {headers.item}.
+
+Regards Camel Riders Bookstore
+{body}
+----------------------------------------------
+
+=== Quarkus Qute documentation
 
 For more information about Qute, please refer to the 
https://quarkus.io/guides/qute[Quarkus Qute] documentation.

Reply via email to