Search in sources :

Example 1 with TokenizeLanguage

use of org.apache.camel.language.tokenizer.TokenizeLanguage in project camel by apache.

the class TokenizerExpression method createExpression.

@Override
public Expression createExpression(CamelContext camelContext) {
    // special for new line tokens, if defined from XML then its 2 characters, so we replace that back to a single char
    if (token.startsWith("\\n")) {
        token = '\n' + token.substring(2);
    }
    TokenizeLanguage language = new TokenizeLanguage();
    language.setToken(token);
    language.setEndToken(endToken);
    language.setInheritNamespaceTagName(inheritNamespaceTagName);
    language.setHeaderName(headerName);
    if (regex != null) {
        language.setRegex(regex);
    }
    if (xml != null) {
        language.setXml(xml);
    }
    if (includeTokens != null) {
        language.setIncludeTokens(includeTokens);
    }
    if (group != null) {
        if (group <= 0) {
            throw new IllegalArgumentException("Group must be a positive number, was: " + group);
        }
        language.setGroup(group);
    }
    if (skipFirst != null) {
        language.setSkipFirst(skipFirst);
    }
    return language.createExpression();
}
Also used : TokenizeLanguage(org.apache.camel.language.tokenizer.TokenizeLanguage)

Example 2 with TokenizeLanguage

use of org.apache.camel.language.tokenizer.TokenizeLanguage in project camel by apache.

the class TokenizerTest method testTokenizeManualConfiguration.

public void testTokenizeManualConfiguration() throws Exception {
    TokenizeLanguage lan = new TokenizeLanguage();
    lan.setHeaderName("names");
    lan.setRegex(false);
    lan.setToken(",");
    Expression exp = lan.createExpression();
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(3, names.size());
    assertEquals("Claus", names.get(0));
    assertEquals("James", names.get(1));
    assertEquals("Willem", names.get(2));
    assertEquals("names", lan.getHeaderName());
    assertEquals(",", lan.getToken());
    assertEquals(false, lan.isRegex());
    assertEquals(false, lan.isSingleton());
}
Also used : TokenizeLanguage(org.apache.camel.language.tokenizer.TokenizeLanguage) Expression(org.apache.camel.Expression)

Example 3 with TokenizeLanguage

use of org.apache.camel.language.tokenizer.TokenizeLanguage in project camel by apache.

the class TokenizeLanguageAutoConfiguration method configureTokenizeLanguage.

@Bean(name = "tokenize-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(TokenizeLanguage.class)
public TokenizeLanguage configureTokenizeLanguage(CamelContext camelContext, TokenizeLanguageConfiguration configuration) throws Exception {
    TokenizeLanguage language = new TokenizeLanguage();
    if (CamelContextAware.class.isAssignableFrom(TokenizeLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class.cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
    return language;
}
Also used : TokenizeLanguage(org.apache.camel.language.tokenizer.TokenizeLanguage) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) Scope(org.springframework.context.annotation.Scope) 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)

Aggregations

TokenizeLanguage (org.apache.camel.language.tokenizer.TokenizeLanguage)3 HashMap (java.util.HashMap)1 CamelContextAware (org.apache.camel.CamelContextAware)1 Expression (org.apache.camel.Expression)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 Scope (org.springframework.context.annotation.Scope)1