001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.model.language; 018 019 import javax.xml.bind.annotation.XmlAccessType; 020 import javax.xml.bind.annotation.XmlAccessorType; 021 import javax.xml.bind.annotation.XmlAttribute; 022 import javax.xml.bind.annotation.XmlRootElement; 023 024 import org.apache.camel.Expression; 025 import org.apache.camel.language.tokenizer.TokenizeLanguage; 026 import org.apache.camel.spi.RouteContext; 027 028 /** 029 * For expressions and predicates using a body or header tokenzier 030 * 031 * @version $Revision: 750806 $ 032 */ 033 @XmlRootElement(name = "tokenize") 034 @XmlAccessorType(XmlAccessType.FIELD) 035 public class TokenizerExpression extends ExpressionDefinition { 036 @XmlAttribute(required = true) 037 private String token; 038 @XmlAttribute(required = false) 039 private String headerName; 040 @XmlAttribute(required = false) 041 private Boolean regex; 042 043 public TokenizerExpression() { 044 } 045 046 @Override 047 public String getLanguage() { 048 return "tokenize"; 049 } 050 051 public String getToken() { 052 return token; 053 } 054 055 public void setToken(String token) { 056 this.token = token; 057 } 058 059 public String getHeaderName() { 060 return headerName; 061 } 062 063 public void setHeaderName(String headerName) { 064 this.headerName = headerName; 065 } 066 067 public void setRegex(boolean regex) { 068 this.regex = regex; 069 } 070 071 public Boolean getRegex() { 072 return regex; 073 } 074 075 @Override 076 public Expression createExpression(RouteContext routeContext) { 077 TokenizeLanguage language = new TokenizeLanguage(); 078 language.setToken(token); 079 language.setHeaderName(headerName); 080 if (regex != null) { 081 language.setRegex(regex); 082 } 083 return language.createExpression(); 084 } 085 086 @Override 087 public String toString() { 088 return "tokenize{" + (headerName != null ? "header: " + headerName : "body()") + " using token: " + token + "}"; 089 } 090 }