1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.pattern; 18 19 20 /** 21 * <p>AbstractPatternConverter is an abstract class that provides the 22 * formatting functionality that derived classes need. 23 * <p/> 24 * <p>Conversion specifiers in a conversion patterns are parsed to 25 * individual PatternConverters. Each of which is responsible for 26 * converting an object in a converter specific manner. 27 */ 28 public abstract class AbstractPatternConverter implements PatternConverter { 29 /** 30 * Converter name. 31 */ 32 private final String name; 33 34 /** 35 * Converter style name. 36 */ 37 private final String style; 38 39 /** 40 * Create a new pattern converter. 41 * 42 * @param name name for pattern converter. 43 * @param style CSS style for formatted output. 44 */ 45 protected AbstractPatternConverter(final String name, final String style) { 46 this.name = name; 47 this.style = style; 48 } 49 50 /** 51 * This method returns the name of the conversion pattern. 52 * <p/> 53 * The name can be useful to certain Layouts such as HTMLLayout. 54 * 55 * @return the name of the conversion pattern 56 */ 57 @Override 58 public final String getName() { 59 return name; 60 } 61 62 /** 63 * This method returns the CSS style class that should be applied to 64 * the LoggingEvent passed as parameter, which can be null. 65 * <p/> 66 * This information is currently used only by HTMLLayout. 67 * 68 * @param e null values are accepted 69 * @return the name of the conversion pattern 70 */ 71 @Override 72 public String getStyleClass(final Object e) { 73 return style; 74 } 75 }