1 package org.codehaus.plexus.interpolation; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.List; 23 import java.util.Properties; 24 25 /** 26 * Legacy support. Allow trimming one of a set of expression prefixes, the lookup 27 * the remaining expression as a literal key from the wrapped properties instance. 28 * <p>This is just a convenience implementation to provide a shorthand for constructing 29 * the properties value source and then wrapping it with a prefixed value-source wrapper.</p> 30 * 31 */ 32 public class PrefixedPropertiesValueSource extends AbstractDelegatingValueSource implements QueryEnabledValueSource { 33 34 /** 35 * Wrap the specified properties file with a new {@link PropertiesBasedValueSource}, then 36 * wrap that source with a new {@link PrefixedValueSourceWrapper} that uses the specified 37 * expression prefix. Finally, set this wrapper source as a delegate for this 38 * instance to use. 39 * 40 * @param prefix The expression prefix to trim 41 * @param properties The properties instance to wrap 42 */ 43 public PrefixedPropertiesValueSource(String prefix, Properties properties) { 44 super(new PrefixedValueSourceWrapper(new PropertiesBasedValueSource(properties), prefix)); 45 } 46 47 /** 48 * Wrap the specified properties file with a new {@link PropertiesBasedValueSource}, then 49 * wrap that source with a new {@link PrefixedValueSourceWrapper} that uses the specified 50 * expression-prefix list. Finally, set this wrapper source as a delegate for this 51 * instance to use. 52 * 53 * @param possiblePrefixes The expression-prefix list to trim 54 * @param properties The properties instance to wrap 55 * @param allowUnprefixedExpressions allow unprefixed expressions or not. 56 */ 57 public PrefixedPropertiesValueSource( 58 List<String> possiblePrefixes, Properties properties, boolean allowUnprefixedExpressions) { 59 super(new PrefixedValueSourceWrapper( 60 new PropertiesBasedValueSource(properties), possiblePrefixes, allowUnprefixedExpressions)); 61 } 62 63 /** 64 * {@inheritDoc} 65 */ 66 public String getLastExpression() { 67 return ((QueryEnabledValueSource) getDelegate()).getLastExpression(); 68 } 69 }