1 package org.apache.velocity.tools.generic; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 /** 23 * Implements common logic and constants for tools which allow their 24 * default format to be configured. 25 * 26 * @author Nathan Bubna 27 * @since VelocityTools 2.0 28 */ 29 public class FormatConfig extends LocaleConfig 30 { 31 /** 32 * The default format to be used when none is specified. 33 */ 34 public static final String DEFAULT_FORMAT = "default"; 35 36 /** 37 * The key used for specifying a default format via tool configuration. 38 */ 39 public static final String FORMAT_KEY = "format"; 40 41 private String format = DEFAULT_FORMAT; 42 43 /** 44 * Does the actual configuration. This is protected, so 45 * subclasses may share the same ValueParser and call configure 46 * at any time, while preventing templates from doing so when 47 * configure(Map) is locked. 48 */ 49 protected void configure(ValueParser values) 50 { 51 super.configure(values); 52 53 String format = values.getString(FORMAT_KEY); 54 if (format != null) 55 { 56 setFormat(format); 57 } 58 } 59 60 /** 61 * This returns the configured default format for this tool. 62 * 63 * @return the default {@link String} 64 */ 65 public String getFormat() 66 { 67 return this.format; 68 } 69 70 /** 71 * Sets the default format for this instance. 72 */ 73 protected void setFormat(String format) 74 { 75 this.format = format; 76 } 77 78 }