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.ant;
017
018 import java.io.File;
019 import java.io.FileInputStream;
020
021 import org.vafer.jdeb.mapping.LsMapper;
022 import org.vafer.jdeb.mapping.NullMapper;
023 import org.vafer.jdeb.mapping.PermMapper;
024 import org.vafer.jdeb.mapping.PrefixMapper;
025
026 /**
027 * Ant "mapper" element acting as factory for the entry mapper.
028 * Supported types: ls, prefix, perm
029 *
030 * @author Torsten Curdt <tcurdt@vafer.org>
031 */
032 public final class Mapper {
033
034 private String mapperType;
035 private File src;
036
037 private String prefix;
038 private int strip;
039 private int uid = -1;
040 private int gid = -1;
041 private String user;
042 private String group;
043 private int fileMode = -1;
044 private int dirMode = -1;
045
046 public void setType( final String pType ) {
047 mapperType = pType;
048 }
049
050 public void setSrc( final File pSrc ) {
051 src = pSrc;
052 }
053
054
055 public void setPrefix( final String pPrefix ) {
056 prefix = pPrefix;
057 }
058
059 public void setStrip( final int pStrip ) {
060 strip = pStrip;
061 }
062
063
064 public void setUid( final int pUid ) {
065 uid = pUid;
066 }
067
068 public void setGid( final int pGid ) {
069 gid = pGid;
070 }
071
072 public void setUser( final String pUser ) {
073 user = pUser;
074 }
075
076 public void setGroup( final String pGroup ) {
077 group = pGroup;
078 }
079
080 public void setFileMode( final int pFileMode ) {
081 fileMode = pFileMode;
082 }
083
084 public void setDirMode(int pDirMode) {
085 dirMode = pDirMode;
086 }
087
088 public org.vafer.jdeb.mapping.Mapper createMapper() {
089
090 if ("perm".equalsIgnoreCase(mapperType)) {
091 return new PermMapper(uid, gid, user, group, fileMode, dirMode, strip, prefix);
092 }
093
094 if ("prefix".equalsIgnoreCase(mapperType)) {
095 return new PrefixMapper(strip, prefix);
096 }
097
098 if ("ls".equalsIgnoreCase(mapperType)) {
099 try {
100 return new LsMapper(new FileInputStream(src));
101 } catch (Exception e) {
102 e.printStackTrace();
103 }
104 }
105
106 return new NullMapper();
107 }
108
109 }