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 * @see StringLookupFactory#KEY_BASE64_DECODER 039 * @see StringLookupFactory#base64DecoderStringLookup() 040 */ 041 BASE64_DECODER(StringLookupFactory.KEY_BASE64_DECODER, StringLookupFactory.INSTANCE.base64DecoderStringLookup()), 042 043 /** 044 * The lookup for Base64 encoding using the key {@code "base64Encoder"}. 045 * @see StringLookupFactory#KEY_BASE64_ENCODER 046 * @see StringLookupFactory#base64EncoderStringLookup() 047 */ 048 BASE64_ENCODER(StringLookupFactory.KEY_BASE64_ENCODER, StringLookupFactory.INSTANCE.base64EncoderStringLookup()), 049 050 /** 051 * The lookup for Java static class member constants using the key {@code "const"}. 052 * @see StringLookupFactory#KEY_CONST 053 * @see StringLookupFactory#constantStringLookup() 054 */ 055 CONST(StringLookupFactory.KEY_CONST, StringLookupFactory.INSTANCE.constantStringLookup()), 056 057 /** 058 * The lookup for formatting the current date using the key {@code "date"}. 059 * @see StringLookupFactory#KEY_DATE 060 * @see StringLookupFactory#dateStringLookup() 061 */ 062 DATE(StringLookupFactory.KEY_DATE, StringLookupFactory.INSTANCE.dateStringLookup()), 063 064 /** 065 * The lookup for DNS using the key {@code "dns"}. 066 * @see StringLookupFactory#KEY_DNS 067 * @see StringLookupFactory#dnsStringLookup() 068 * @since 1.8 069 */ 070 DNS(StringLookupFactory.KEY_DNS, StringLookupFactory.INSTANCE.dnsStringLookup()), 071 072 /** 073 * The lookup for environment properties using the key {@code "env"}. 074 * @see StringLookupFactory#KEY_ENV 075 * @see StringLookupFactory#environmentVariableStringLookup() 076 */ 077 ENVIRONMENT(StringLookupFactory.KEY_ENV, StringLookupFactory.INSTANCE.environmentVariableStringLookup()), 078 079 /** 080 * The lookup for files using the key {@code "file"}. 081 * @see StringLookupFactory#KEY_FILE 082 * @see StringLookupFactory#fileStringLookup() 083 */ 084 FILE(StringLookupFactory.KEY_FILE, StringLookupFactory.INSTANCE.fileStringLookup()), 085 086 /** 087 * The lookup for Java platform information using the key {@code "java"}. 088 * @see StringLookupFactory#KEY_JAVA 089 * @see StringLookupFactory#javaPlatformStringLookup() 090 */ 091 JAVA(StringLookupFactory.KEY_JAVA, StringLookupFactory.INSTANCE.javaPlatformStringLookup()), 092 093 /** 094 * The lookup for local host information using the key {@code "localhost"}. 095 * @see StringLookupFactory#KEY_LOCALHOST 096 * @see StringLookupFactory#localHostStringLookup() 097 */ 098 LOCAL_HOST(StringLookupFactory.KEY_LOCALHOST, StringLookupFactory.INSTANCE.localHostStringLookup()), 099 100 /** 101 * The lookup for properties using the key {@code "properties"}. 102 * @see StringLookupFactory#KEY_PROPERTIES 103 * @see StringLookupFactory#propertiesStringLookup() 104 */ 105 PROPERTIES(StringLookupFactory.KEY_PROPERTIES, StringLookupFactory.INSTANCE.propertiesStringLookup()), 106 107 /** 108 * The lookup for resource bundles using the key {@code "resourceBundle"}. 109 * @see StringLookupFactory#KEY_RESOURCE_BUNDLE 110 * @see StringLookupFactory#resourceBundleStringLookup() 111 */ 112 RESOURCE_BUNDLE(StringLookupFactory.KEY_RESOURCE_BUNDLE, StringLookupFactory.INSTANCE.resourceBundleStringLookup()), 113 114 /** 115 * The lookup for scripts using the key {@code "script"}. 116 * @see StringLookupFactory#KEY_SCRIPT 117 * @see StringLookupFactory#scriptStringLookup() 118 */ 119 SCRIPT(StringLookupFactory.KEY_SCRIPT, StringLookupFactory.INSTANCE.scriptStringLookup()), 120 121 /** 122 * The lookup for system properties using the key {@code "sys"}. 123 * @see StringLookupFactory#KEY_SYS 124 * @see StringLookupFactory#systemPropertyStringLookup() 125 */ 126 SYSTEM_PROPERTIES(StringLookupFactory.KEY_SYS, StringLookupFactory.INSTANCE.systemPropertyStringLookup()), 127 128 /** 129 * The lookup for URLs using the key {@code "url"}. 130 * @see StringLookupFactory#KEY_URL 131 * @see StringLookupFactory#urlStringLookup() 132 */ 133 URL(StringLookupFactory.KEY_URL, StringLookupFactory.INSTANCE.urlStringLookup()), 134 135 /** 136 * The lookup for URL decoding using the key {@code "urlDecoder"}. 137 * @see StringLookupFactory#KEY_URL_DECODER 138 * @see StringLookupFactory#urlDecoderStringLookup() 139 */ 140 URL_DECODER(StringLookupFactory.KEY_URL_DECODER, StringLookupFactory.INSTANCE.urlDecoderStringLookup()), 141 142 /** 143 * The lookup for URL encoding using the key {@code "urlEncoder"}. 144 * @see StringLookupFactory#KEY_URL_ENCODER 145 * @see StringLookupFactory#urlEncoderStringLookup() 146 */ 147 URL_ENCODER(StringLookupFactory.KEY_URL_ENCODER, StringLookupFactory.INSTANCE.urlEncoderStringLookup()), 148 149 /** 150 * The lookup for XML decoding using the key {@code "xml"}. 151 * @see StringLookupFactory#KEY_XML 152 * @see StringLookupFactory#xmlStringLookup() 153 */ 154 XML(StringLookupFactory.KEY_XML, StringLookupFactory.INSTANCE.xmlStringLookup()), 155 156 /** 157 * The lookup for XML decoding using the key {@code "xmlDecoder"}. 158 * @see StringLookupFactory#KEY_XML_DECODER 159 * @see StringLookupFactory#xmlDecoderStringLookup() 160 * @since 1.11.0 161 */ 162 XML_DECODER(StringLookupFactory.KEY_XML_DECODER, StringLookupFactory.INSTANCE.xmlDecoderStringLookup()), 163 164 /** 165 * The lookup for XML encoding using the key {@code "xmlEncoder"}. 166 * @see StringLookupFactory#KEY_XML_ENCODER 167 * @see StringLookupFactory#xmlEncoderStringLookup() 168 * @since 1.11.0 169 */ 170 XML_ENCODER(StringLookupFactory.KEY_XML_ENCODER, StringLookupFactory.INSTANCE.xmlEncoderStringLookup()); 171 172 /** The prefix under which the associated lookup object is registered. */ 173 private final String key; 174 175 /** The associated lookup instance. */ 176 private final StringLookup lookup; 177 178 /** 179 * Creates a new instance of {@link DefaultStringLookup} and sets the key and the associated lookup instance. 180 * 181 * @param prefix the prefix 182 * @param lookup the {@link StringLookup} instance 183 */ 184 DefaultStringLookup(final String prefix, final StringLookup lookup) { 185 this.key = prefix; 186 this.lookup = lookup; 187 } 188 189 /** 190 * Returns the standard prefix for the lookup object of this kind. 191 * 192 * @return the prefix 193 */ 194 public String getKey() { 195 return key; 196 } 197 198 /** 199 * Returns the standard {@link StringLookup} instance of this kind. 200 * 201 * @return the associated {@link StringLookup} object 202 */ 203 public StringLookup getStringLookup() { 204 return lookup; 205 } 206}