View Javadoc
1   package org.codehaus.plexus.interpolation.fixed;
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
33      extends AbstractDelegatingValueSource
34  {
35  
36      /**
37       * Wrap the specified properties file with a new {@link org.codehaus.plexus.interpolation.PropertiesBasedValueSource}, then
38       * wrap that source with a new {@link org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper} that uses the specified
39       * expression prefix. Finally, set this wrapper source as a delegate for this
40       * instance to use.
41       *
42       * @param prefix     The expression prefix to trim
43       * @param properties The properties instance to wrap
44       */
45      public PrefixedPropertiesValueSource( String prefix, Properties properties )
46      {
47          super( new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( properties ), prefix ) );
48      }
49  
50      /**
51       * Wrap the specified properties file with a new {@link org.codehaus.plexus.interpolation.PropertiesBasedValueSource}, then
52       * wrap that source with a new {@link org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper} that uses the specified
53       * expression-prefix list. Finally, set this wrapper source as a delegate for this
54       * instance to use.
55       *
56       * @param possiblePrefixes The expression-prefix list to trim
57       * @param properties       The properties instance to wrap
58       * @param allowUnprefixedExpressions allow unprefixed expressions or not.
59       */
60      public PrefixedPropertiesValueSource( List<String> possiblePrefixes, Properties properties,
61                                            boolean allowUnprefixedExpressions )
62      {
63          super( new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( properties ), possiblePrefixes,
64                                                 allowUnprefixedExpressions ) );
65      }
66  }