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 properties using the key {@code "properties"}.
111     *
112     * @see StringLookupFactory#KEY_PROPERTIES
113     * @see StringLookupFactory#propertiesStringLookup()
114     */
115    PROPERTIES(StringLookupFactory.KEY_PROPERTIES, StringLookupFactory.INSTANCE.propertiesStringLookup()),
116
117    /**
118     * The lookup for resource bundles using the key {@code "resourceBundle"}.
119     *
120     * @see StringLookupFactory#KEY_RESOURCE_BUNDLE
121     * @see StringLookupFactory#resourceBundleStringLookup()
122     */
123    RESOURCE_BUNDLE(StringLookupFactory.KEY_RESOURCE_BUNDLE, StringLookupFactory.INSTANCE.resourceBundleStringLookup()),
124
125    /**
126     * The lookup for scripts using the key {@code "script"}.
127     *
128     * @see StringLookupFactory#KEY_SCRIPT
129     * @see StringLookupFactory#scriptStringLookup()
130     */
131    SCRIPT(StringLookupFactory.KEY_SCRIPT, StringLookupFactory.INSTANCE.scriptStringLookup()),
132
133    /**
134     * The lookup for system properties using the key {@code "sys"}.
135     *
136     * @see StringLookupFactory#KEY_SYS
137     * @see StringLookupFactory#systemPropertyStringLookup()
138     */
139    SYSTEM_PROPERTIES(StringLookupFactory.KEY_SYS, StringLookupFactory.INSTANCE.systemPropertyStringLookup()),
140
141    /**
142     * The lookup for URLs using the key {@code "url"}.
143     *
144     * @see StringLookupFactory#KEY_URL
145     * @see StringLookupFactory#urlStringLookup()
146     */
147    URL(StringLookupFactory.KEY_URL, StringLookupFactory.INSTANCE.urlStringLookup()),
148
149    /**
150     * The lookup for URL decoding using the key {@code "urlDecoder"}.
151     *
152     * @see StringLookupFactory#KEY_URL_DECODER
153     * @see StringLookupFactory#urlDecoderStringLookup()
154     */
155    URL_DECODER(StringLookupFactory.KEY_URL_DECODER, StringLookupFactory.INSTANCE.urlDecoderStringLookup()),
156
157    /**
158     * The lookup for URL encoding using the key {@code "urlEncoder"}.
159     *
160     * @see StringLookupFactory#KEY_URL_ENCODER
161     * @see StringLookupFactory#urlEncoderStringLookup()
162     */
163    URL_ENCODER(StringLookupFactory.KEY_URL_ENCODER, StringLookupFactory.INSTANCE.urlEncoderStringLookup()),
164
165    /**
166     * The lookup for XML decoding using the key {@code "xml"}.
167     *
168     * @see StringLookupFactory#KEY_XML
169     * @see StringLookupFactory#xmlStringLookup()
170     */
171    XML(StringLookupFactory.KEY_XML, StringLookupFactory.INSTANCE.xmlStringLookup()),
172
173    /**
174     * The lookup for XML decoding using the key {@code "xmlDecoder"}.
175     *
176     * @see StringLookupFactory#KEY_XML_DECODER
177     * @see StringLookupFactory#xmlDecoderStringLookup()
178     * @since 1.11.0
179     */
180    XML_DECODER(StringLookupFactory.KEY_XML_DECODER, StringLookupFactory.INSTANCE.xmlDecoderStringLookup()),
181
182    /**
183     * The lookup for XML encoding using the key {@code "xmlEncoder"}.
184     *
185     * @see StringLookupFactory#KEY_XML_ENCODER
186     * @see StringLookupFactory#xmlEncoderStringLookup()
187     * @since 1.11.0
188     */
189    XML_ENCODER(StringLookupFactory.KEY_XML_ENCODER, StringLookupFactory.INSTANCE.xmlEncoderStringLookup());
190
191    /** The prefix under which the associated lookup object is registered. */
192    private final String key;
193
194    /** The associated lookup instance. */
195    private final StringLookup lookup;
196
197    /**
198     * Constructs a new instance of {@link DefaultStringLookup} and sets the key and the associated lookup instance.
199     *
200     * @param prefix the prefix
201     * @param lookup the {@link StringLookup} instance
202     */
203    DefaultStringLookup(final String prefix, final StringLookup lookup) {
204        this.key = prefix;
205        this.lookup = lookup;
206    }
207
208    /**
209     * Gets the standard prefix for the lookup object of this kind.
210     *
211     * @return the prefix
212     */
213    public String getKey() {
214        return key;
215    }
216
217    /**
218     * Gets the standard {@link StringLookup} instance of this kind.
219     *
220     * @return the associated {@link StringLookup} object
221     */
222    public StringLookup getStringLookup() {
223        return lookup;
224    }
225}