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 * https://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.commons.text.lookup;
18
19 /**
20 * An enumeration defining {@link StringLookup} objects available through {@link StringLookupFactory}.
21 * <p>
22 * This enum was adapted and expanded from Apache Commons Configuration 2.4.
23 * </p>
24 * <p><strong>NOTE:</strong> Starting in version 1.10.0, not all lookups defined in this class are
25 * included by default in the
26 * {@link StringLookupFactory#addDefaultStringLookups(java.util.Map) StringLookupFactory.addDefaultStringLookups}
27 * method. See the {@link StringLookupFactory} class documentation for details.
28 * </p>
29 *
30 * @see StringLookupFactory
31 * @see StringLookup
32 * @since 1.7
33 */
34 public enum DefaultStringLookup {
35
36 /**
37 * The lookup for Base64 decoding using the key {@code "base64Decoder"}.
38 *
39 * @see StringLookupFactory#KEY_BASE64_DECODER
40 * @see StringLookupFactory#base64DecoderStringLookup()
41 */
42 BASE64_DECODER(StringLookupFactory.KEY_BASE64_DECODER, StringLookupFactory.INSTANCE.base64DecoderStringLookup()),
43
44 /**
45 * The lookup for Base64 encoding using the key {@code "base64Encoder"}.
46 *
47 * @see StringLookupFactory#KEY_BASE64_ENCODER
48 * @see StringLookupFactory#base64EncoderStringLookup()
49 */
50 BASE64_ENCODER(StringLookupFactory.KEY_BASE64_ENCODER, StringLookupFactory.INSTANCE.base64EncoderStringLookup()),
51
52 /**
53 * The lookup for Java static class member constants using the key {@code "const"}.
54 *
55 * @see StringLookupFactory#KEY_CONST
56 * @see StringLookupFactory#constantStringLookup()
57 */
58 CONST(StringLookupFactory.KEY_CONST, StringLookupFactory.INSTANCE.constantStringLookup()),
59
60 /**
61 * The lookup for formatting the current date using the key {@code "date"}.
62 *
63 * @see StringLookupFactory#KEY_DATE
64 * @see StringLookupFactory#dateStringLookup()
65 */
66 DATE(StringLookupFactory.KEY_DATE, StringLookupFactory.INSTANCE.dateStringLookup()),
67
68 /**
69 * The lookup for DNS using the key {@code "dns"}.
70 *
71 * @see StringLookupFactory#KEY_DNS
72 * @see StringLookupFactory#dnsStringLookup()
73 * @since 1.8
74 */
75 DNS(StringLookupFactory.KEY_DNS, StringLookupFactory.INSTANCE.dnsStringLookup()),
76
77 /**
78 * The lookup for environment properties using the key {@code "env"}.
79 *
80 * @see StringLookupFactory#KEY_ENV
81 * @see StringLookupFactory#environmentVariableStringLookup()
82 */
83 ENVIRONMENT(StringLookupFactory.KEY_ENV, StringLookupFactory.INSTANCE.environmentVariableStringLookup()),
84
85 /**
86 * The lookup for files using the key {@code "file"}.
87 *
88 * @see StringLookupFactory#KEY_FILE
89 * @see StringLookupFactory#fileStringLookup()
90 */
91 FILE(StringLookupFactory.KEY_FILE, StringLookupFactory.INSTANCE.fileStringLookup()),
92
93 /**
94 * The lookup for Java platform information using the key {@code "java"}.
95 *
96 * @see StringLookupFactory#KEY_JAVA
97 * @see StringLookupFactory#javaPlatformStringLookup()
98 */
99 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 }