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.dataformat; 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.model.DataFormatDefinition; 025import org.apache.camel.spi.Metadata; 026 027/** 028 * The Grok data format is used for unmarshalling unstructured data to objects 029 * using Logstash based Grok patterns. 030 */ 031@Metadata(label = "dataformat,transformation", title = "Grok", firstVersion = "3.0.0") 032@XmlRootElement(name = "grok") 033@XmlAccessorType(XmlAccessType.FIELD) 034public class GrokDataFormat extends DataFormatDefinition { 035 @XmlAttribute(required = true) 036 @Metadata 037 private String pattern; 038 039 @XmlAttribute 040 @Metadata(defaultValue = "false") 041 private Boolean flattened = false; 042 043 @XmlAttribute 044 @Metadata(defaultValue = "true") 045 private Boolean allowMultipleMatchesPerLine = true; 046 047 @XmlAttribute 048 @Metadata(defaultValue = "false") 049 private Boolean namedOnly = false; 050 051 public GrokDataFormat() { 052 super("grok"); 053 } 054 055 public String getPattern() { 056 return pattern; 057 } 058 059 /** 060 * The grok pattern to match lines of input 061 */ 062 public void setPattern(String pattern) { 063 this.pattern = pattern; 064 } 065 066 public boolean isFlattened() { 067 return flattened; 068 } 069 070 /** 071 * Turns on flattened mode. In flattened mode the exception is thrown when 072 * there are multiple pattern matches with same key. 073 */ 074 public void setFlattened(boolean flattened) { 075 this.flattened = flattened; 076 } 077 078 public boolean isAllowMultipleMatchesPerLine() { 079 return allowMultipleMatchesPerLine; 080 } 081 082 /** 083 * If false, every line of input is matched for pattern only once. Otherwise 084 * the line can be scanned multiple times when non-terminal pattern is used. 085 */ 086 public void setAllowMultipleMatchesPerLine(boolean allowMultipleMatchesPerLine) { 087 this.allowMultipleMatchesPerLine = allowMultipleMatchesPerLine; 088 } 089 090 public boolean isNamedOnly() { 091 return namedOnly; 092 } 093 094 /** 095 * Whether to capture named expressions only or not (i.e. %{IP:ip} but not 096 * ${IP}) 097 */ 098 public void setNamedOnly(boolean namedOnly) { 099 this.namedOnly = namedOnly; 100 } 101 102 @Override 103 public String toString() { 104 return "GrokDataFormat[" + pattern + ']'; 105 } 106}