Search in sources :

Example 1 with XsltComponent

use of org.apache.camel.component.xslt.XsltComponent in project camel by apache.

the class XsltComponentAutoConfiguration method configureXsltComponent.

@Lazy
@Bean(name = "xslt-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(XsltComponent.class)
public XsltComponent configureXsltComponent(CamelContext camelContext, XsltComponentConfiguration configuration) throws Exception {
    XsltComponent component = new XsltComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : XsltComponent(org.apache.camel.component.xslt.XsltComponent) HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with XsltComponent

use of org.apache.camel.component.xslt.XsltComponent in project camel by apache.

the class XsltComponentConfigurationAndDocumentationTest method testComponentConfiguration.

@Test
public void testComponentConfiguration() throws Exception {
    XsltComponent comp = context.getComponent("xslt", XsltComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("xslt:foo?deleteOutputFile=true");
    assertEquals("true", conf.getParameter("deleteOutputFile"));
    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);
    assertTrue(json.contains("\"resourceUri\": { \"kind\": \"path\", \"displayName\": \"Resource Uri\", \"group\": \"producer\", \"required\": true"));
    assertTrue(json.contains("\"allowStAX\": { \"kind\": \"parameter\", \"displayName\": \"Allow StAX\", \"group\": \"producer\", \"type\": \"boolean\""));
    assertTrue(json.contains("\"transformerFactoryClass\": { \"kind\": \"parameter\", \"displayName\": \"Transformer Factory Class\", \"group\": \"advanced\", \"label\": \"advanced\""));
}
Also used : ComponentConfiguration(org.apache.camel.ComponentConfiguration) XsltComponent(org.apache.camel.component.xslt.XsltComponent) EndpointConfiguration(org.apache.camel.EndpointConfiguration) Test(org.junit.Test)

Aggregations

XsltComponent (org.apache.camel.component.xslt.XsltComponent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ComponentConfiguration (org.apache.camel.ComponentConfiguration)1 EndpointConfiguration (org.apache.camel.EndpointConfiguration)1 Test (org.junit.Test)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1