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