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