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();
}
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());
}
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;
}
Aggregations