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