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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 8245282  Introduce TransformerFactoryConfigurationStrategy to be able 
to configure a TransformerFactory per XsltEndpoint (#3353)
8245282 is described below

commit 824528288c42ffae7c3dc7588f67e3dac77d846c
Author: Peter Palaga <[email protected]>
AuthorDate: Thu Nov 21 10:04:20 2019 +0100

    Introduce TransformerFactoryConfigurationStrategy to be able to configure a 
TransformerFactory per XsltEndpoint (#3353)
---
 .../camel-xslt/src/main/docs/xslt-component.adoc   |  7 +++--
 .../TransformerFactoryConfigurationStrategy.java   | 33 ++++++++++++++++++++
 .../apache/camel/component/xslt/XsltComponent.java | 27 ++++++++++++++++
 .../apache/camel/component/xslt/XsltEndpoint.java  | 36 +++++++++++++++++++---
 .../endpoint/dsl/XsltEndpointBuilderFactory.java   | 28 +++++++++++++++++
 .../springboot/XsltComponentConfiguration.java     | 28 +++++++++++++++++
 6 files changed, 152 insertions(+), 7 deletions(-)

diff --git a/components/camel-xslt/src/main/docs/xslt-component.adoc 
b/components/camel-xslt/src/main/docs/xslt-component.adoc
index efe6f7b..a9caa42 100644
--- a/components/camel-xslt/src/main/docs/xslt-component.adoc
+++ b/components/camel-xslt/src/main/docs/xslt-component.adoc
@@ -39,7 +39,7 @@ You can append query options to the URI in the following 
format:
 == Options
 
 // component options: START
-The XSLT component supports 6 options, which are listed below.
+The XSLT component supports 8 options, which are listed below.
 
 
 
@@ -49,6 +49,8 @@ The XSLT component supports 6 options, which are listed below.
 | *uriResolverFactory* (advanced) | To use a custom UriResolver which depends 
on a dynamic endpoint resource URI. Should not be used together with the option 
'uriResolver'. |  | XsltUriResolverFactory
 | *uriResolver* (advanced) | To use a custom UriResolver. Should not be used 
together with the option 'uriResolverFactory'. |  | URIResolver
 | *contentCache* (producer) | Cache for the resource content (the stylesheet 
file) when it is loaded. If set to false Camel will reload the stylesheet file 
on each message processing. This is good for development. A cached stylesheet 
can be forced to reload at runtime via JMX using the clearCachedStylesheet 
operation. | true | boolean
+| *transformerFactory ConfigurationStrategy* (advanced) | A configuration 
strategy to apply on freshly created instances of TransformerFactory. |  | 
TransformerFactoryConfigurationStrategy
+| *transformerFactoryClass* (advanced) | To use a custom XSLT transformer 
factory, specified as a FQN class name |  | String
 | *basicPropertyBinding* (advanced) | Whether the component should use basic 
property binding (Camel 2.x) or the newer property binding with additional 
capabilities | false | boolean
 | *lazyStartProducer* (producer) | Whether the producer should be started lazy 
(on the first message). By starting lazy you can use this to allow CamelContext 
and routes to startup in situations where a producer may otherwise fail during 
starting and cause the route to fail being started. By deferring this startup 
to be lazy then the startup failure can be handled during routing messages via 
Camel's routing error handlers. Beware that when the first message is processed 
then creating and [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the 
Camel routing Error Handler, which mean any exceptions occurred while the 
consumer is trying to pickup incoming messages, or the likes, will now be 
processed as a message and handled by the routing Error Handler. By default the 
consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions, that will be logged at WARN or ERROR level and ignored. | false | 
boolean
@@ -75,7 +77,7 @@ with the following path and query parameters:
 |===
 
 
-=== Query Parameters (14 parameters):
+=== Query Parameters (15 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -94,6 +96,7 @@ with the following path and query parameters:
 | *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used, or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
 | *transformerFactory* (advanced) | To use a custom XSLT transformer factory | 
 | TransformerFactory
 | *transformerFactoryClass* (advanced) | To use a custom XSLT transformer 
factory, specified as a FQN class name |  | String
+| *transformerFactory ConfigurationStrategy* (advanced) | A configuration 
strategy to apply on freshly created instances of TransformerFactory. |  | 
TransformerFactoryConfigurationStrategy
 | *uriResolver* (advanced) | To use a custom javax.xml.transform.URIResolver | 
 | URIResolver
 |===
 // endpoint options: END
diff --git 
a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/TransformerFactoryConfigurationStrategy.java
 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/TransformerFactoryConfigurationStrategy.java
new file mode 100644
index 0000000..6c31086
--- /dev/null
+++ 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/TransformerFactoryConfigurationStrategy.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xslt;
+
+import javax.xml.transform.TransformerFactory;
+
+/**
+ * A configuration strategy applied to freshly created instances of {@link 
TransformerFactory}.
+ */
+public interface TransformerFactoryConfigurationStrategy {
+
+    /**
+     * Configure the given {@code factory} associated with the given {@code 
endpoint}.
+     *
+     * @param factory the {@link TransformerFactory} to configure
+     * @param endpoint the {@link XsltEndpoint} owning the given {@code 
factory}
+     */
+    public void configure(TransformerFactory factory, XsltEndpoint endpoint);
+}
diff --git 
a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
index cc6886a..573163d 100644
--- 
a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
+++ 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
@@ -38,6 +38,10 @@ public class XsltComponent extends DefaultComponent {
     private XsltUriResolverFactory uriResolverFactory;
     @Metadata(defaultValue = "true")
     private boolean contentCache = true;
+    @Metadata(label = "advanced")
+    private TransformerFactoryConfigurationStrategy 
transformerFactoryConfigurationStrategy;
+    @Metadata(label = "advanced")
+    private String transformerFactoryClass;
 
     public XsltComponent() {
     }
@@ -77,6 +81,29 @@ public class XsltComponent extends DefaultComponent {
         this.contentCache = contentCache;
     }
 
+    public TransformerFactoryConfigurationStrategy 
getTransformerFactoryConfigurationStrategy() {
+        return transformerFactoryConfigurationStrategy;
+    }
+
+    /**
+     * A configuration strategy to apply on freshly created instances of 
TransformerFactory.
+     */
+    public void setTransformerFactoryConfigurationStrategy(
+            TransformerFactoryConfigurationStrategy 
transformerFactoryConfigurationStrategy) {
+        this.transformerFactoryConfigurationStrategy = 
transformerFactoryConfigurationStrategy;
+    }
+
+    public String getTransformerFactoryClass() {
+        return transformerFactoryClass;
+    }
+
+    /**
+     * To use a custom XSLT transformer factory, specified as a FQN class name
+     */
+    public void setTransformerFactoryClass(String transformerFactoryClass) {
+        this.transformerFactoryClass = transformerFactoryClass;
+    }
+
     @Override
     protected Endpoint createEndpoint(String uri, final String remaining, 
Map<String, Object> parameters) throws Exception {
         XsltEndpoint endpoint = createXsltEndpoint(uri);
diff --git 
a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
index 644ea06..b73f8e8 100644
--- 
a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
+++ 
b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
@@ -78,6 +78,8 @@ public class XsltEndpoint extends ProcessorEndpoint {
     private boolean deleteOutputFile;
     @UriParam(label = "advanced")
     private EntityResolver entityResolver;
+    @UriParam(label = "advanced")
+    private TransformerFactoryConfigurationStrategy 
transformerFactoryConfigurationStrategy;
 
     public XsltEndpoint(String endpointUri, Component component) {
         super(endpointUri, component);
@@ -288,6 +290,18 @@ public class XsltEndpoint extends ProcessorEndpoint {
         this.parameters = parameters;
     }
 
+    public TransformerFactoryConfigurationStrategy 
getTransformerFactoryConfigurationStrategy() {
+        return transformerFactoryConfigurationStrategy;
+    }
+
+    /**
+     * A configuration strategy to apply on freshly created instances of 
TransformerFactory.
+     */
+    public void setTransformerFactoryConfigurationStrategy(
+            TransformerFactoryConfigurationStrategy 
transformerFactoryConfigurationStrategy) {
+        this.transformerFactoryConfigurationStrategy = 
transformerFactoryConfigurationStrategy;
+    }
+
     /**
      * Loads the resource.
      *
@@ -326,11 +340,23 @@ public class XsltEndpoint extends ProcessorEndpoint {
         final XsltBuilder xslt = injector.newInstance(XsltBuilder.class);
 
         TransformerFactory factory = transformerFactory;
-        if (factory == null && transformerFactoryClass != null) {
-            // provide the class loader of this component to work in OSGi 
environments
-            Class<TransformerFactory> factoryClass = 
resolver.resolveMandatoryClass(transformerFactoryClass, 
TransformerFactory.class, XsltComponent.class.getClassLoader());
-            log.debug("Using TransformerFactoryClass {}", factoryClass);
-            factory = injector.newInstance(factoryClass);
+        if (factory == null) {
+            final String trFactoryClass = transformerFactoryClass != null
+                    ? transformerFactoryClass
+                    : ((XsltComponent) 
getComponent()).getTransformerFactoryClass();
+            if (trFactoryClass != null) {
+                // provide the class loader of this component to work in OSGi 
environments
+                Class<TransformerFactory> factoryClass = 
resolver.resolveMandatoryClass(trFactoryClass, TransformerFactory.class, 
XsltComponent.class.getClassLoader());
+                log.debug("Using TransformerFactoryClass {}", factoryClass);
+                factory = injector.newInstance(factoryClass);
+
+                final TransformerFactoryConfigurationStrategy tfConfigStrategy 
= transformerFactoryConfigurationStrategy != null
+                        ? transformerFactoryConfigurationStrategy
+                        : ((XsltComponent) 
getComponent()).getTransformerFactoryConfigurationStrategy();
+                if (tfConfigStrategy != null) {
+                    tfConfigStrategy.configure(factory, this);
+                }
+            }
         }
 
         if (factory != null) {
diff --git 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/XsltEndpointBuilderFactory.java
 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/XsltEndpointBuilderFactory.java
index 4465e6c..82bd400 100644
--- 
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/XsltEndpointBuilderFactory.java
+++ 
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/XsltEndpointBuilderFactory.java
@@ -406,6 +406,34 @@ public interface XsltEndpointBuilderFactory {
             return this;
         }
         /**
+         * A configuration strategy to apply on freshly created instances of
+         * TransformerFactory.
+         * 
+         * The option is a:
+         * 
<code>org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy</code>
 type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedXsltEndpointBuilder 
transformerFactoryConfigurationStrategy(
+                Object transformerFactoryConfigurationStrategy) {
+            doSetProperty("transformerFactoryConfigurationStrategy", 
transformerFactoryConfigurationStrategy);
+            return this;
+        }
+        /**
+         * A configuration strategy to apply on freshly created instances of
+         * TransformerFactory.
+         * 
+         * The option will be converted to a
+         * 
<code>org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy</code>
 type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedXsltEndpointBuilder 
transformerFactoryConfigurationStrategy(
+                String transformerFactoryConfigurationStrategy) {
+            doSetProperty("transformerFactoryConfigurationStrategy", 
transformerFactoryConfigurationStrategy);
+            return this;
+        }
+        /**
          * To use a custom javax.xml.transform.URIResolver.
          * 
          * The option is a: <code>javax.xml.transform.URIResolver</code> type.
diff --git 
a/platforms/spring-boot/components-starter/camel-xslt-starter/src/main/java/org/apache/camel/component/xslt/springboot/XsltComponentConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-xslt-starter/src/main/java/org/apache/camel/component/xslt/springboot/XsltComponentConfiguration.java
index caaf49e..4aa76ee 100644
--- 
a/platforms/spring-boot/components-starter/camel-xslt-starter/src/main/java/org/apache/camel/component/xslt/springboot/XsltComponentConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-xslt-starter/src/main/java/org/apache/camel/component/xslt/springboot/XsltComponentConfiguration.java
@@ -57,6 +57,17 @@ public class XsltComponentConfiguration
      */
     private Boolean contentCache = true;
     /**
+     * A configuration strategy to apply on freshly created instances of
+     * TransformerFactory. The option is a
+     * org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy
+     * type.
+     */
+    private String transformerFactoryConfigurationStrategy;
+    /**
+     * To use a custom XSLT transformer factory, specified as a FQN class name
+     */
+    private String transformerFactoryClass;
+    /**
      * Whether the component should use basic property binding (Camel 2.x) or
      * the newer property binding with additional capabilities
      */
@@ -106,6 +117,23 @@ public class XsltComponentConfiguration
         this.contentCache = contentCache;
     }
 
+    public String getTransformerFactoryConfigurationStrategy() {
+        return transformerFactoryConfigurationStrategy;
+    }
+
+    public void setTransformerFactoryConfigurationStrategy(
+            String transformerFactoryConfigurationStrategy) {
+        this.transformerFactoryConfigurationStrategy = 
transformerFactoryConfigurationStrategy;
+    }
+
+    public String getTransformerFactoryClass() {
+        return transformerFactoryClass;
+    }
+
+    public void setTransformerFactoryClass(String transformerFactoryClass) {
+        this.transformerFactoryClass = transformerFactoryClass;
+    }
+
     public Boolean getBasicPropertyBinding() {
         return basicPropertyBinding;
     }

Reply via email to