davsclaus opened a new pull request, #30693:
URL: https://github.com/apache/camel/pull/30693

   _Claude Code on behalf of davsclaus_
   
   [CAMEL-27486](https://issues.apache.org/jira/browse/CAMEL-27486)
   
   **Includes #30691 (CAMEL-27485), the commit `Namespaces(String)` that this 
builds on. Merge #30691 first, then main gets merged in here, and this PR 
becomes the one commit for CAMEL-27486.**
   
   ### Problem
   
   To give an xpath, xquery or xtokenize expression several namespaces from one 
value, such as a Kamelet option, a route had to declare a `Namespaces` bean 
(#30691) and refer to it with `namespacesRef`. That is cumbersome for a 
namespace set used once.
   
   ### Change
   
   - New `namespaceMappings` option on `NamespaceAwareExpression`, so xpath, 
xquery and xtokenize all get it, in every DSL:
     ```yaml
     - filter:
         xpath:
           expression: "/c:order/w:wine = 'Rioja'"
           namespaceMappings: "{{namespaces}}"
     ```
     ```xml
     <xpath 
namespaceMappings="c=http://acme.com/cheese,w=http://acme.com/wine";>/c:order/w:wine
 = 'Rioja'</xpath>
     ```
   - The XPath, XQuery and XML Tokenize reifiers resolve the property 
placeholders, then parse the string with `Namespaces(String)`: mappings 
separated by commas or new lines, prefix and URI split at the first `=`. This 
happens when the route is created, which is why it works with a Kamelet's 
`{{namespaces}}`. A YAML-only string form, split while loading, would only see 
the literal `{{namespaces}}`.
   - A `namespace` entry wins over a mapping for the same prefix. 
`namespacesRef` is only used when neither is given, and an empty string falls 
back to it. An invalid mapping fails the route.
   - It isn't named `namespaces`, because that is the `Map` setter of the 
`NamespaceAware` SPI.
   - Builder method `namespaceMappings(String)` on the namespace-aware 
expression builders.
   - Docs: the xpath "Several namespaces in one string" section now leads with 
`namespaceMappings`, and the bean form stays for sharing. xquery and xtokenize 
point to it.
   - Regenerated: the model and language JSON (xpath, xquery, xtokenize), the 
XML and Spring XSDs, the YAML DSL schemas and deserializers, the XML 
parser/writer, the YAML and Java DSL writers, and the catalog copies.
   
   ### Tests
   
   - `XPathNamespaceMappingsTest` (camel-core): two prefixes from the string, a 
property placeholder, a `namespace` entry winning for a prefix, winning over 
`namespacesRef`, an empty string falling back to `namespacesRef`, and an 
invalid mapping failing.
   - `XPathNamespacesRefYamlDslTest#loadsXPathWithNamespaceMappingsInline`: a 
YAML filter with `namespaceMappings: "{{namespaces}}"`.
   - Full test suites pass: camel-xml-io (438), camel-yaml-io (193), 
camel-java-io (196, including `LwJavaParserSecurityTest`), camel-yaml-dsl (530).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to