001    /*
002     * Copyright 2010 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.vafer.jdeb.mapping;
017    
018    import org.apache.tools.tar.TarEntry;
019    import org.vafer.jdeb.utils.Utils;
020    
021    /**
022     * Just adds a prefix to the entry coming in
023     *  
024     * @author Torsten Curdt <tcurdt@vafer.org>
025     */
026    public class PrefixMapper implements Mapper {
027    
028        protected final int strip;
029        protected final String prefix;
030        
031        public PrefixMapper( final int pStrip, final String pPrefix ) {
032            strip = pStrip;
033            prefix = (pPrefix == null) ? "" : pPrefix;
034        }
035            
036        public TarEntry map( final TarEntry pEntry ) {
037            
038            final String name = pEntry.getName();
039    
040            final TarEntry newEntry = new TarEntry(prefix + '/' + Utils.stripPath(strip, name));        
041            
042            newEntry.setUserId(pEntry.getUserId());
043            newEntry.setGroupId(pEntry.getGroupId());
044            newEntry.setUserName(pEntry.getUserName());
045            newEntry.setGroupName(pEntry.getGroupName());
046            newEntry.setMode(pEntry.getMode());
047            newEntry.setSize(pEntry.getSize());
048    
049            return newEntry;
050        }
051    
052    }