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.CamelContext; 025import org.apache.camel.Expression; 026import org.apache.camel.Predicate; 027import org.apache.camel.language.tokenizer.XMLTokenizeLanguage; 028import org.apache.camel.spi.Metadata; 029 030/** 031 * For expressions and predicates using a body or header tokenizer 032 * 033 * @see XMLTokenizeLanguage 034 */ 035@Metadata(label = "language,core,xml", title = "XML Tokenize") 036@XmlRootElement(name = "xtokenize") 037@XmlAccessorType(XmlAccessType.FIELD) 038public class XMLTokenizerExpression extends NamespaceAwareExpression { 039 @XmlAttribute 040 private String headerName; 041 @XmlAttribute 042 private String mode; 043 @XmlAttribute 044 private Integer group; 045 046 public XMLTokenizerExpression() { 047 } 048 049 public XMLTokenizerExpression(String expression) { 050 super(expression); 051 } 052 053 @Override 054 public String getLanguage() { 055 return "xtokenize"; 056 } 057 058 public String getHeaderName() { 059 return headerName; 060 } 061 062 /** 063 * Name of header to tokenize instead of using the message body. 064 */ 065 public void setHeaderName(String headerName) { 066 this.headerName = headerName; 067 } 068 069 public String getMode() { 070 return mode; 071 } 072 073 /** 074 * The extraction mode. The available extraction modes are: 075 * <ul> 076 * <li>i - injecting the contextual namespace bindings into the extracted token (default)</li> 077 * <li>w - wrapping the extracted token in its ancestor context</li> 078 * <li>u - unwrapping the extracted token to its child content</li> 079 * <li>t - extracting the text content of the specified element</li> 080 * </ul> 081 */ 082 public void setMode(String mode) { 083 this.mode = mode; 084 } 085 086 public Integer getGroup() { 087 return group; 088 } 089 090 /** 091 * To group N parts together 092 */ 093 public void setGroup(Integer group) { 094 this.group = group; 095 } 096 097 @Override 098 protected void configureExpression(CamelContext camelContext, Expression expression) { 099 if (headerName != null) { 100 setProperty(expression, "headerName", headerName); 101 } 102 if (mode != null) { 103 setProperty(expression, "mode", mode); 104 } 105 if (group != null) { 106 setProperty(expression, "group", group); 107 } 108 super.configureExpression(camelContext, expression); 109 } 110 111 @Override 112 protected void configurePredicate(CamelContext camelContext, Predicate predicate) { 113 if (headerName != null) { 114 setProperty(predicate, "headerName", headerName); 115 } 116 if (mode != null) { 117 setProperty(predicate, "mode", mode); 118 } 119 if (group != null) { 120 setProperty(predicate, "group", group); 121 } 122 super.configurePredicate(camelContext, predicate); 123 } 124 125}