    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     */
    017    package org.apache.logging.log4j.core.pattern;
    018
    019
    020    /**
    021     * Abstract base class for other pattern converters which can return only parts of their name.
    022     */
    023    public abstract class NamePatternConverter extends LogEventPatternConverter {
    024        /**
    025         * Abbreviator.
    026         */
    027        private final NameAbbreviator abbreviator;
    028
    029        /**
    030         * Constructor.
    031         *
    032         * @param name    name of converter.
    033         * @param style   style name for associated output.
    034         * @param options options, may be null, first element will be interpreted as an abbreviation pattern.
    035         */
    036        protected NamePatternConverter(final String name, final String style, final String[] options) {
    037            super(name, style);
    038
    039            if (options != null && options.length > 0) {
    040                abbreviator = NameAbbreviator.getAbbreviator(options[0]);
    041            } else {
    042                abbreviator = NameAbbreviator.getDefaultAbbreviator();
    043            }
    044        }
    045
    046        /**
    047         * Abbreviate name in string buffer.
    048         *
    049         * @param buf       string buffer containing name.
    050         * @return The abbreviated name.
    051         */
    052        protected final String abbreviate(final String buf) {
    053            return abbreviator.abbreviate(buf);
    054        }
    055    }