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.commons.configuration2.interpol; 018 019import org.apache.commons.text.lookup.StringLookupFactory; 020 021/** 022 * <p> 023 * An enumeration class defining constants for the {@code Lookup} objects available for each {@code Configuration} 024 * object per default. 025 * </p> 026 * <p> 027 * When a new configuration object derived from {@code AbstractConfiguration} is created it installs a 028 * {@link ConfigurationInterpolator} with a default set of {@link Lookup} objects. These lookups are defined by this 029 * enumeration class. 030 * </p> 031 * <p> 032 * All the default {@code Lookup} classes are state-less, thus their instances can be shared between multiple 033 * configuration objects. Therefore, it makes sense to keep shared instances in this enumeration class. 034 * </p> 035 * 036 * Provides access to lookups defined in Apache Commons Text: 037 * <ul> 038 * <li>"base64Decoder" for the {@code Base64DecoderStringLookup} since Apache Commons Text 1.6.</li> 039 * <li>"base64Encoder" for the {@code Base64EncoderStringLookup} since Apache Commons Text 1.6.</li> 040 * <li>"const" for the {@code ConstantStringLookup} since Apache Commons Text 1.5.</li> 041 * <li>"date" for the {@code DateStringLookup}.</li> 042 * <li>"env" for the {@code EnvironmentVariableStringLookup}.</li> 043 * <li>"file" for the {@code FileStringLookup} since Apache Commons Text 1.5.</li> 044 * <li>"java" for the {@code JavaPlatformStringLookup}.</li> 045 * <li>"localhost" for the {@code LocalHostStringLookup}, see {@code #localHostStringLookup()} for key names; since 046 * Apache Commons Text 1.3.</li> 047 * <li>"properties" for the {@code PropertiesStringLookup} since Apache Commons Text 1.5.</li> 048 * <li>"resourceBundle" for the {@code ResourceBundleStringLookup} since Apache Commons Text 1.5.</li> 049 * <li>"script" for the {@code ScriptStringLookup} since Apache Commons Text 1.5.</li> 050 * <li>"sys" for the {@code SystemPropertyStringLookup}.</li> 051 * <li>"url" for the {@code UrlStringLookup} since Apache Commons Text 1.5.</li> 052 * <li>"urlDecoder" for the {@code UrlDecoderStringLookup} since Apache Commons Text 1.6.</li> 053 * <li>"urlEncoder" for the {@code UrlEncoderStringLookup} since Apache Commons Text 1.6.</li> 054 * <li>"xml" for the {@code XmlStringLookup} since Apache Commons Text 1.5.</li> 055 * </ul> 056 * 057 * @since 2.0 058 */ 059public enum DefaultLookups 060{ 061 062 /** 063 * The lookup for Base64 decoding. 064 * 065 * @since 2.4 066 */ 067 BASE64_DECODER(StringLookupFactory.KEY_BASE64_DECODER, 068 new StringLookupAdapter(StringLookupFactory.INSTANCE.base64DecoderStringLookup())), 069 070 /** 071 * The lookup for Base64 decoding. 072 * 073 * @since 2.4 074 */ 075 BASE64_ENCODER(StringLookupFactory.KEY_BASE64_ENCODER, 076 new StringLookupAdapter(StringLookupFactory.INSTANCE.base64EncoderStringLookup())), 077 078 /** 079 * The lookup for constants. 080 * 081 * @since 2.4 082 */ 083 CONST(StringLookupFactory.KEY_CONST, new StringLookupAdapter(StringLookupFactory.INSTANCE.constantStringLookup())), 084 085 /** 086 * The lookup for dates. 087 * 088 * @since 2.4 089 */ 090 DATE(StringLookupFactory.KEY_DATE, new StringLookupAdapter(StringLookupFactory.INSTANCE.dateStringLookup())), 091 092 /** 093 * The lookup for environment properties. 094 */ 095 ENVIRONMENT(StringLookupFactory.KEY_ENV, 096 new StringLookupAdapter(StringLookupFactory.INSTANCE.environmentVariableStringLookup())), 097 098 /** 099 * The lookup for files. 100 * 101 * @since 2.4 102 */ 103 FILE(StringLookupFactory.KEY_FILE, new StringLookupAdapter(StringLookupFactory.INSTANCE.fileStringLookup())), 104 105 /** 106 * The lookup for Java platform information. 107 * 108 * @since 2.4 109 */ 110 JAVA(StringLookupFactory.KEY_JAVA, 111 new StringLookupAdapter(StringLookupFactory.INSTANCE.javaPlatformStringLookup())), 112 113 /** 114 * The lookup for localhost information. 115 * 116 * @since 2.4 117 */ 118 LOCAL_HOST(StringLookupFactory.KEY_LOCALHOST, 119 new StringLookupAdapter(StringLookupFactory.INSTANCE.localHostStringLookup())), 120 121 /** 122 * The lookup for properties. 123 * 124 * @since 2.4 125 */ 126 PROPERTIES(StringLookupFactory.KEY_PROPERTIES, 127 new StringLookupAdapter(StringLookupFactory.INSTANCE.propertiesStringLookup())), 128 129 /** 130 * The lookup for resource bundles. 131 * 132 * @since 2.4 133 */ 134 RESOURCE_BUNDLE(StringLookupFactory.KEY_RESOURCE_BUNDLE, 135 new StringLookupAdapter(StringLookupFactory.INSTANCE.resourceBundleStringLookup())), 136 137 /** 138 * The lookup for scripts. 139 * 140 * @since 2.4 141 */ 142 SCRIPT(StringLookupFactory.KEY_SCRIPT, new StringLookupAdapter(StringLookupFactory.INSTANCE.scriptStringLookup())), 143 144 /** 145 * The lookup for system properties. 146 */ 147 SYSTEM_PROPERTIES(StringLookupFactory.KEY_SYS, 148 new StringLookupAdapter(StringLookupFactory.INSTANCE.systemPropertyStringLookup())), 149 150 /** 151 * The lookup for URLs. 152 * 153 * @since 2.4 154 */ 155 URL(StringLookupFactory.KEY_URL, new StringLookupAdapter(StringLookupFactory.INSTANCE.urlStringLookup())), 156 157 /** 158 * The lookup for URL decoding. 159 * 160 * @since 2.4 161 */ 162 URL_DECODER(StringLookupFactory.KEY_URL_DECODER, 163 new StringLookupAdapter(StringLookupFactory.INSTANCE.urlDecoderStringLookup())), 164 165 /** 166 * The lookup for URL decoding. 167 * 168 * @since 2.4 169 */ 170 URL_ENCODER(StringLookupFactory.KEY_URL_ENCODER, 171 new StringLookupAdapter(StringLookupFactory.INSTANCE.urlEncoderStringLookup())), 172 173 /** 174 * The lookup for URL decoding. 175 * 176 * @since 2.4 177 */ 178 XML(StringLookupFactory.KEY_XML, new StringLookupAdapter(StringLookupFactory.INSTANCE.xmlStringLookup())); 179 180 /** The associated lookup instance. */ 181 private final Lookup lookup; 182 183 /** The prefix under which the associated lookup object is registered. */ 184 private final String prefix; 185 186 /** 187 * Creates a new instance of {@code DefaultLookups} and sets the prefix and the associated lookup instance. 188 * 189 * @param prefix 190 * the prefix 191 * @param lookup 192 * the {@code Lookup} instance 193 */ 194 private DefaultLookups(final String prefix, final Lookup lookup) 195 { 196 this.prefix = prefix; 197 this.lookup = lookup; 198 } 199 200 /** 201 * Returns the standard {@code Lookup} instance of this kind. 202 * 203 * @return the associated {@code Lookup} object 204 */ 205 public Lookup getLookup() 206 { 207 return lookup; 208 } 209 210 /** 211 * Returns the standard prefix for the lookup object of this kind. 212 * 213 * @return the prefix 214 */ 215 public String getPrefix() 216 { 217 return prefix; 218 } 219}