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.text.lookup; 018 019/** 020 * An enumeration defining {@link StringLookup} objects available through {@link StringLookupFactory}. 021 * <p> 022 * This enum was adapted and expanded from Apache Commons Configuration 2.4. 023 * </p> 024 * <p><strong>NOTE:</strong> Starting in version 1.10.0, not all lookups defined in this class are 025 * included by default in the 026 * {@link StringLookupFactory#addDefaultStringLookups(java.util.Map) StringLookupFactory.addDefaultStringLookups} 027 * method. See the {@link StringLookupFactory} class documentation for details. 028 * </p> 029 * 030 * @see StringLookupFactory 031 * @see StringLookup 032 * @since 1.7 033 */ 034public enum DefaultStringLookup { 035 036 /** 037 * The lookup for Base64 decoding using the key {@code "base64Decoder"}. 038 * 039 * @see StringLookupFactory#KEY_BASE64_DECODER 040 * @see StringLookupFactory#base64DecoderStringLookup() 041 */ 042 BASE64_DECODER(StringLookupFactory.KEY_BASE64_DECODER, StringLookupFactory.INSTANCE.base64DecoderStringLookup()), 043 044 /** 045 * The lookup for Base64 encoding using the key {@code "base64Encoder"}. 046 * 047 * @see StringLookupFactory#KEY_BASE64_ENCODER 048 * @see StringLookupFactory#base64EncoderStringLookup() 049 */ 050 BASE64_ENCODER(StringLookupFactory.KEY_BASE64_ENCODER, StringLookupFactory.INSTANCE.base64EncoderStringLookup()), 051 052 /** 053 * The lookup for Java static class member constants using the key {@code "const"}. 054 * 055 * @see StringLookupFactory#KEY_CONST 056 * @see StringLookupFactory#constantStringLookup() 057 */ 058 CONST(StringLookupFactory.KEY_CONST, StringLookupFactory.INSTANCE.constantStringLookup()), 059 060 /** 061 * The lookup for formatting the current date using the key {@code "date"}. 062 * 063 * @see StringLookupFactory#KEY_DATE 064 * @see StringLookupFactory#dateStringLookup() 065 */ 066 DATE(StringLookupFactory.KEY_DATE, StringLookupFactory.INSTANCE.dateStringLookup()), 067 068 /** 069 * The lookup for DNS using the key {@code "dns"}. 070 * 071 * @see StringLookupFactory#KEY_DNS 072 * @see StringLookupFactory#dnsStringLookup() 073 * @since 1.8 074 */ 075 DNS(StringLookupFactory.KEY_DNS, StringLookupFactory.INSTANCE.dnsStringLookup()), 076 077 /** 078 * The lookup for environment properties using the key {@code "env"}. 079 * 080 * @see StringLookupFactory#KEY_ENV 081 * @see StringLookupFactory#environmentVariableStringLookup() 082 */ 083 ENVIRONMENT(StringLookupFactory.KEY_ENV, StringLookupFactory.INSTANCE.environmentVariableStringLookup()), 084 085 /** 086 * The lookup for files using the key {@code "file"}. 087 * 088 * @see StringLookupFactory#KEY_FILE 089 * @see StringLookupFactory#fileStringLookup() 090 */ 091 FILE(StringLookupFactory.KEY_FILE, StringLookupFactory.INSTANCE.fileStringLookup()), 092 093 /** 094 * The lookup for Java platform information using the key {@code "java"}. 095 * 096 * @see StringLookupFactory#KEY_JAVA 097 * @see StringLookupFactory#javaPlatformStringLookup() 098 */ 099 JAVA(StringLookupFactory.KEY_JAVA, StringLookupFactory.INSTANCE.javaPlatformStringLookup()), 100 101 /** 102 * The lookup for local host information using the key {@code "localhost"}. 103 * 104 * @see StringLookupFactory#KEY_LOCALHOST 105 * @see StringLookupFactory#localHostStringLookup() 106 */ 107 LOCAL_HOST(StringLookupFactory.KEY_LOCALHOST, StringLookupFactory.INSTANCE.localHostStringLookup()), 108 109 /** 110 * The lookup for local host information using the key {@code "loopbackAddress"}. 111 * 112 * @see StringLookupFactory#KEY_LOOPBACK_ADDRESS 113 * @see StringLookupFactory#loopbackAddressStringLookup() 114 */ 115 LOOPBACK_ADDRESS(StringLookupFactory.KEY_LOOPBACK_ADDRESS, StringLookupFactory.INSTANCE.loopbackAddressStringLookup()), 116 117 /** 118 * The lookup for properties using the key {@code "properties"}. 119 * 120 * @see StringLookupFactory#KEY_PROPERTIES 121 * @see StringLookupFactory#propertiesStringLookup() 122 */ 123 PROPERTIES(StringLookupFactory.KEY_PROPERTIES, StringLookupFactory.INSTANCE.propertiesStringLookup()), 124 125 /** 126 * The lookup for resource bundles using the key {@code "resourceBundle"}. 127 * 128 * @see StringLookupFactory#KEY_RESOURCE_BUNDLE 129 * @see StringLookupFactory#resourceBundleStringLookup() 130 */ 131 RESOURCE_BUNDLE(StringLookupFactory.KEY_RESOURCE_BUNDLE, StringLookupFactory.INSTANCE.resourceBundleStringLookup()), 132 133 /** 134 * The lookup for scripts using the key {@code "script"}. 135 * 136 * @see StringLookupFactory#KEY_SCRIPT 137 * @see StringLookupFactory#scriptStringLookup() 138 */ 139 SCRIPT(StringLookupFactory.KEY_SCRIPT, StringLookupFactory.INSTANCE.scriptStringLookup()), 140 141 /** 142 * The lookup for system properties using the key {@code "sys"}. 143 * 144 * @see StringLookupFactory#KEY_SYS 145 * @see StringLookupFactory#systemPropertyStringLookup() 146 */ 147 SYSTEM_PROPERTIES(StringLookupFactory.KEY_SYS, StringLookupFactory.INSTANCE.systemPropertyStringLookup()), 148 149 /** 150 * The lookup for URLs using the key {@code "url"}. 151 * 152 * @see StringLookupFactory#KEY_URL 153 * @see StringLookupFactory#urlStringLookup() 154 */ 155 URL(StringLookupFactory.KEY_URL, StringLookupFactory.INSTANCE.urlStringLookup()), 156 157 /** 158 * The lookup for URL decoding using the key {@code "urlDecoder"}. 159 * 160 * @see StringLookupFactory#KEY_URL_DECODER 161 * @see StringLookupFactory#urlDecoderStringLookup() 162 */ 163 URL_DECODER(StringLookupFactory.KEY_URL_DECODER, StringLookupFactory.INSTANCE.urlDecoderStringLookup()), 164 165 /** 166 * The lookup for URL encoding using the key {@code "urlEncoder"}. 167 * 168 * @see StringLookupFactory#KEY_URL_ENCODER 169 * @see StringLookupFactory#urlEncoderStringLookup() 170 */ 171 URL_ENCODER(StringLookupFactory.KEY_URL_ENCODER, StringLookupFactory.INSTANCE.urlEncoderStringLookup()), 172 173 /** 174 * The lookup for XML decoding using the key {@code "xml"}. 175 * 176 * @see StringLookupFactory#KEY_XML 177 * @see StringLookupFactory#xmlStringLookup() 178 */ 179 XML(StringLookupFactory.KEY_XML, StringLookupFactory.INSTANCE.xmlStringLookup()), 180 181 /** 182 * The lookup for XML decoding using the key {@code "xmlDecoder"}. 183 * 184 * @see StringLookupFactory#KEY_XML_DECODER 185 * @see StringLookupFactory#xmlDecoderStringLookup() 186 * @since 1.11.0 187 */ 188 XML_DECODER(StringLookupFactory.KEY_XML_DECODER, StringLookupFactory.INSTANCE.xmlDecoderStringLookup()), 189 190 /** 191 * The lookup for XML encoding using the key {@code "xmlEncoder"}. 192 * 193 * @see StringLookupFactory#KEY_XML_ENCODER 194 * @see StringLookupFactory#xmlEncoderStringLookup() 195 * @since 1.11.0 196 */ 197 XML_ENCODER(StringLookupFactory.KEY_XML_ENCODER, StringLookupFactory.INSTANCE.xmlEncoderStringLookup()); 198 199 /** The prefix under which the associated lookup object is registered. */ 200 private final String key; 201 202 /** The associated lookup instance. */ 203 private final StringLookup lookup; 204 205 /** 206 * Constructs a new instance of {@link DefaultStringLookup} and sets the key and the associated lookup instance. 207 * 208 * @param prefix the prefix 209 * @param lookup the {@link StringLookup} instance 210 */ 211 DefaultStringLookup(final String prefix, final StringLookup lookup) { 212 this.key = prefix; 213 this.lookup = lookup; 214 } 215 216 /** 217 * Gets the standard prefix for the lookup object of this kind. 218 * 219 * @return the prefix 220 */ 221 public String getKey() { 222 return key; 223 } 224 225 /** 226 * Gets the standard {@link StringLookup} instance of this kind. 227 * 228 * @return the associated {@link StringLookup} object 229 */ 230 public StringLookup getStringLookup() { 231 return lookup; 232 } 233}