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 * 025 * @see StringLookupFactory 026 * @see StringLookup 027 * @since 1.7 028 */ 029public enum DefaultStringLookup { 030 031 /** 032 * The lookup for Base64 decoding using the key {@value StringLookupFactory#KEY_BASE64_DECODER}. 033 */ 034 BASE64_DECODER(StringLookupFactory.KEY_BASE64_DECODER, StringLookupFactory.INSTANCE.base64DecoderStringLookup()), 035 036 /** 037 * The lookup for Base64 decoding using the key {@value StringLookupFactory#KEY_BASE64_ENCODER}. 038 */ 039 BASE64_ENCODER(StringLookupFactory.KEY_BASE64_ENCODER, StringLookupFactory.INSTANCE.base64EncoderStringLookup()), 040 041 /** 042 * The lookup for constants using the key {@value StringLookupFactory#KEY_CONST}. 043 */ 044 CONST(StringLookupFactory.KEY_CONST, StringLookupFactory.INSTANCE.constantStringLookup()), 045 046 /** 047 * The lookup for dates using the key {@value StringLookupFactory#KEY_DATE}. 048 */ 049 DATE(StringLookupFactory.KEY_DATE, StringLookupFactory.INSTANCE.dateStringLookup()), 050 051 /** 052 * The lookup for DNS using the key {@value StringLookupFactory#KEY_DNS}. 053 * 054 * @since 1.8 055 */ 056 DNS(StringLookupFactory.KEY_DNS, StringLookupFactory.INSTANCE.dnsStringLookup()), 057 058 /** 059 * The lookup for environment properties using the key {@value StringLookupFactory#KEY_ENV}. 060 */ 061 ENVIRONMENT(StringLookupFactory.KEY_ENV, StringLookupFactory.INSTANCE.environmentVariableStringLookup()), 062 063 /** 064 * The lookup for files using the key {@value StringLookupFactory#KEY_FILE}. 065 */ 066 FILE(StringLookupFactory.KEY_FILE, StringLookupFactory.INSTANCE.fileStringLookup()), 067 068 /** 069 * The lookup for Java platform information using the key {@value StringLookupFactory#KEY_JAVA}. 070 */ 071 JAVA(StringLookupFactory.KEY_JAVA, StringLookupFactory.INSTANCE.javaPlatformStringLookup()), 072 073 /** 074 * The lookup for localhost information using the key {@value StringLookupFactory#KEY_LOCALHOST}. 075 */ 076 LOCAL_HOST(StringLookupFactory.KEY_LOCALHOST, StringLookupFactory.INSTANCE.localHostStringLookup()), 077 078 /** 079 * The lookup for properties using the key {@value StringLookupFactory#KEY_PROPERTIES}. 080 */ 081 PROPERTIES(StringLookupFactory.KEY_PROPERTIES, StringLookupFactory.INSTANCE.propertiesStringLookup()), 082 083 /** 084 * The lookup for resource bundles using the key {@value StringLookupFactory#KEY_RESOURCE_BUNDLE}. 085 */ 086 RESOURCE_BUNDLE(StringLookupFactory.KEY_RESOURCE_BUNDLE, StringLookupFactory.INSTANCE.resourceBundleStringLookup()), 087 088 /** 089 * The lookup for scripts using the key {@value StringLookupFactory#KEY_SCRIPT}. 090 */ 091 SCRIPT(StringLookupFactory.KEY_SCRIPT, StringLookupFactory.INSTANCE.scriptStringLookup()), 092 093 /** 094 * The lookup for system properties using the key {@value StringLookupFactory#KEY_SYS}. 095 */ 096 SYSTEM_PROPERTIES(StringLookupFactory.KEY_SYS, StringLookupFactory.INSTANCE.systemPropertyStringLookup()), 097 098 /** 099 * The lookup for URLs using the key {@value StringLookupFactory#KEY_URL}. 100 */ 101 URL(StringLookupFactory.KEY_URL, StringLookupFactory.INSTANCE.urlStringLookup()), 102 103 /** 104 * The lookup for URL decoding using the key {@value StringLookupFactory#KEY_URL_DECODER}. 105 */ 106 URL_DECODER(StringLookupFactory.KEY_URL_DECODER, StringLookupFactory.INSTANCE.urlDecoderStringLookup()), 107 108 /** 109 * The lookup for URL decoding using the key {@value StringLookupFactory#KEY_URL_ENCODER}. 110 */ 111 URL_ENCODER(StringLookupFactory.KEY_URL_ENCODER, StringLookupFactory.INSTANCE.urlEncoderStringLookup()), 112 113 /** 114 * The lookup for URL decoding using the key {@value StringLookupFactory#KEY_XML}. 115 */ 116 XML(StringLookupFactory.KEY_XML, StringLookupFactory.INSTANCE.xmlStringLookup()); 117 118 /** The prefix under which the associated lookup object is registered. */ 119 private final String key; 120 121 /** The associated lookup instance. */ 122 private final StringLookup lookup; 123 124 /** 125 * Creates a new instance of {@link DefaultStringLookup} and sets the key and the associated lookup instance. 126 * 127 * @param prefix the prefix 128 * @param lookup the {@link StringLookup} instance 129 */ 130 DefaultStringLookup(final String prefix, final StringLookup lookup) { 131 this.key = prefix; 132 this.lookup = lookup; 133 } 134 135 /** 136 * Returns the standard prefix for the lookup object of this kind. 137 * 138 * @return the prefix 139 */ 140 public String getKey() { 141 return key; 142 } 143 144 /** 145 * Returns the standard {@link StringLookup} instance of this kind. 146 * 147 * @return the associated {@link StringLookup} object 148 */ 149 public StringLookup getStringLookup() { 150 return lookup; 151 } 152}