View Javadoc
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    *     http://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 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 }