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