View Javadoc
1   package org.codehaus.plexus.components.io.filemappers;
2   
3   /*
4    * Copyright 2007 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import javax.annotation.Nonnull;
20  
21  /**
22   * A file mapper, which maps by adding a prefix.
23   */
24  public class PrefixFileMapper extends AbstractFileMapper
25  {
26      /**
27       * The merge mappers role-hint: "prefix".
28       */
29      public static final String ROLE_HINT = "prefix";
30  
31      private String prefix;
32  
33      @Nonnull public String getMappedFileName( @Nonnull String name )
34      {
35          final String s = super.getMappedFileName( name ); // Check for null, etc.
36          return getMappedFileName( prefix, s );
37      }
38  
39      /**
40       * Returns the prefix to add.
41       */
42      public String getPrefix()
43      {
44          return prefix;
45      }
46  
47      /**
48       * Sets the prefix to add.
49       */
50      public void setPrefix( String prefix )
51      {
52          this.prefix = prefix;
53      }
54  
55      /**
56       * Performs the mapping of a file name by adding a prefix.
57       */
58      public static String getMappedFileName( String prefix, String name )
59      {
60          if ( prefix == null || prefix.length() == 0 )
61          {
62              return name;
63          }
64          return prefix + name;
65      }
66  }