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 */ 017package org.apache.camel.model.language; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.language.tokenizer.TokenizeLanguage; 025import org.apache.camel.spi.Metadata; 026 027/** 028 * To use Camel message body or header with a tokenizer in Camel expressions or 029 * predicates. 030 * 031 * @see TokenizeLanguage 032 */ 033@Metadata(firstVersion = "2.0.0", label = "language,core", title = "Tokenize") 034@XmlRootElement(name = "tokenize") 035@XmlAccessorType(XmlAccessType.FIELD) 036public class TokenizerExpression extends ExpressionDefinition { 037 @XmlAttribute(required = true) 038 private String token; 039 @XmlAttribute 040 private String endToken; 041 @XmlAttribute 042 private String inheritNamespaceTagName; 043 @XmlAttribute 044 private String headerName; 045 @XmlAttribute 046 @Metadata(javaType = "java.lang.Boolean") 047 private String regex; 048 @XmlAttribute 049 @Metadata(javaType = "java.lang.Boolean") 050 private String xml; 051 @XmlAttribute 052 @Metadata(javaType = "java.lang.Boolean") 053 private String includeTokens; 054 @XmlAttribute 055 private String group; 056 @XmlAttribute 057 private String groupDelimiter; 058 @XmlAttribute 059 @Metadata(javaType = "java.lang.Boolean") 060 private String skipFirst; 061 062 public TokenizerExpression() { 063 } 064 065 public TokenizerExpression(String token) { 066 this.token = token; 067 } 068 069 @Override 070 public String getLanguage() { 071 return "tokenize"; 072 } 073 074 public String getToken() { 075 return token; 076 } 077 078 /** 079 * The (start) token to use as tokenizer, for example you can use the new 080 * line token. You can use simple language as the token to support dynamic 081 * tokens. 082 */ 083 public void setToken(String token) { 084 this.token = token; 085 } 086 087 public String getEndToken() { 088 return endToken; 089 } 090 091 /** 092 * The end token to use as tokenizer if using start/end token pairs. You can 093 * use simple language as the token to support dynamic tokens. 094 */ 095 public void setEndToken(String endToken) { 096 this.endToken = endToken; 097 } 098 099 public String getHeaderName() { 100 return headerName; 101 } 102 103 /** 104 * Name of header to tokenize instead of using the message body. 105 */ 106 public void setHeaderName(String headerName) { 107 this.headerName = headerName; 108 } 109 110 /** 111 * If the token is a regular expression pattern. 112 * <p/> 113 * The default value is false 114 */ 115 public void setRegex(String regex) { 116 this.regex = regex; 117 } 118 119 public String getRegex() { 120 return regex; 121 } 122 123 public String getInheritNamespaceTagName() { 124 return inheritNamespaceTagName; 125 } 126 127 /** 128 * To inherit namespaces from a root/parent tag name when using XML You can 129 * use simple language as the tag name to support dynamic names. 130 */ 131 public void setInheritNamespaceTagName(String inheritNamespaceTagName) { 132 this.inheritNamespaceTagName = inheritNamespaceTagName; 133 } 134 135 public String getXml() { 136 return xml; 137 } 138 139 /** 140 * Whether the input is XML messages. This option must be set to true if 141 * working with XML payloads. 142 */ 143 public void setXml(String xml) { 144 this.xml = xml; 145 } 146 147 public String getIncludeTokens() { 148 return includeTokens; 149 } 150 151 /** 152 * Whether to include the tokens in the parts when using pairs 153 * <p/> 154 * The default value is false 155 */ 156 public void setIncludeTokens(String includeTokens) { 157 this.includeTokens = includeTokens; 158 } 159 160 public String getGroup() { 161 return group; 162 } 163 164 /** 165 * To group N parts together, for example to split big files into chunks of 166 * 1000 lines. You can use simple language as the group to support dynamic 167 * group sizes. 168 */ 169 public void setGroup(String group) { 170 this.group = group; 171 } 172 173 public String getGroupDelimiter() { 174 return groupDelimiter; 175 } 176 177 /** 178 * Sets the delimiter to use when grouping. If this has not been set then 179 * token will be used as the delimiter. 180 */ 181 public void setGroupDelimiter(String groupDelimiter) { 182 this.groupDelimiter = groupDelimiter; 183 } 184 185 public String getSkipFirst() { 186 return skipFirst; 187 } 188 189 /** 190 * To skip the very first element 191 */ 192 public void setSkipFirst(String skipFirst) { 193 this.skipFirst = skipFirst; 194 } 195 196 @Override 197 public String toString() { 198 if (endToken != null) { 199 return "tokenize{body() using tokens: " + token + "..." + endToken + "}"; 200 } else { 201 return "tokenize{" + (headerName != null ? "header: " + headerName : "body()") + " using token: " + token + "}"; 202 } 203 } 204}