Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EnvironmentLookup |
|
| 1.0;1 |
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.configuration.interpol; | |
18 | ||
19 | import org.apache.commons.configuration.EnvironmentConfiguration; | |
20 | import org.apache.commons.lang.text.StrLookup; | |
21 | ||
22 | /** | |
23 | * <p> | |
24 | * A specialized lookup implementation that allows access to environment | |
25 | * variables. | |
26 | * </p> | |
27 | * <p> | |
28 | * This implementation relies on {@link EnvironmentConfiguration} to resolve | |
29 | * environment variables. It can be used for referencing environment variables | |
30 | * in configuration files in an easy way, for instance: | |
31 | * | |
32 | * <pre> | |
33 | * java.home = ${env:JAVA_HOME} | |
34 | * </pre> | |
35 | * | |
36 | * </p> | |
37 | * <p> | |
38 | * {@code EnvironmentLookup} is one of the standard lookups that is | |
39 | * registered per default for each configuration. | |
40 | * </p> | |
41 | * | |
42 | * @author <a | |
43 | * href="http://commons.apache.org/configuration/team-list.html">Commons | |
44 | * Configuration team</a> | |
45 | * @since 1.7 | |
46 | * @version $Id: EnvironmentLookup.java 1210620 2011-12-05 20:57:31Z oheger $ | |
47 | */ | |
48 | 3 | public class EnvironmentLookup extends StrLookup |
49 | { | |
50 | /** Stores the underlying {@code EnvironmentConfiguration}. */ | |
51 | 3 | private final EnvironmentConfiguration environmentConfig = new EnvironmentConfiguration(); |
52 | ||
53 | /** | |
54 | * Performs a lookup for the specified variable. This implementation | |
55 | * directly delegates to a {@code EnvironmentConfiguration}. | |
56 | * | |
57 | * @param key the key to lookup | |
58 | * @return the value of this key or <b>null</b> if it cannot be resolved | |
59 | */ | |
60 | @Override | |
61 | public String lookup(String key) | |
62 | { | |
63 | 95 | return environmentConfig.getString(key); |
64 | } | |
65 | } |