001/* 002 * Copyright 2011 Atteo. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014package org.atteo.evo.filtering; 015 016/** 017 * Resolves any properties prefixed with 'env.' as {@link System#getenv(String) environment 018 * variables}. 019 * <p> 020 * For instance {@code ${env.PATH}} will be resolved into the value of the '{@code PATH}' environment variable. 021 * </p> 022 * <p> 023 * Due to security concerns it does not recursively resolve properties by default. 024 * </p> 025 */ 026public class EnvironmentPropertyResolver extends SimplePropertyResolver { 027 private final static String prefix = "env."; 028 029 public EnvironmentPropertyResolver() { 030 filterResult = false; 031 } 032 033 @Override 034 public String getProperty(String name) throws PropertyNotFoundException { 035 if (!name.startsWith(prefix)) { 036 return null; 037 } 038 name = name.substring(prefix.length()); 039 return System.getenv(name); 040 } 041}