View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.vafer.jdeb.mapping;
17  
18  import org.apache.tools.tar.TarEntry;
19  import org.vafer.jdeb.utils.Utils;
20  
21  /**
22   * Just adds a prefix to the entry coming in
23   *  
24   * @author Torsten Curdt <tcurdt@vafer.org>
25   */
26  public final class PrefixMapper implements Mapper {
27  
28  	private final int strip;
29  	private final String prefix;
30  	
31  	public PrefixMapper( final int pStrip, final String pPrefix ) {
32  		strip = pStrip;
33  		prefix = pPrefix;
34  	}
35  		
36  	public TarEntry map( final TarEntry pEntry ) {
37  		
38  		final String name = pEntry.getName();
39  
40  		final TarEntry newEntry = new TarEntry(prefix + '/' + Utils.stripPath(strip, name));		
41  		
42  		newEntry.setUserId(pEntry.getUserId());
43  		newEntry.setGroupId(pEntry.getGroupId());
44  		newEntry.setUserName(pEntry.getUserName());
45  		newEntry.setGroupName(pEntry.getGroupName());
46  		newEntry.setMode(pEntry.getMode());
47  		newEntry.setSize(pEntry.getSize());
48  
49  		return newEntry;
50  	}
51  
52  }