1 16 package org.apache.axis.tools.ant.foreach; 17 18 import org.apache.tools.ant.DirectoryScanner; 19 import org.apache.tools.ant.Project; 20 import org.apache.tools.ant.types.EnumeratedAttribute; 21 import org.apache.tools.ant.types.FileSet; 22 23 import java.io.File; 24 import java.util.Enumeration; 25 import java.util.Vector; 26 27 35 public class ParamSet { 36 public static final String TYPE_FILE = "file".intern(); 37 public static final String TYPE_DIR = "dir".intern(); 38 public static final String TYPE_BOTH = "both".intern(); 39 40 44 public static class FileDirBoth extends EnumeratedAttribute { 45 public String[] getValues() { 46 return new String[]{ 47 TYPE_FILE, TYPE_DIR, TYPE_BOTH 48 }; 49 } 50 } 51 52 53 protected String type = TYPE_FILE; 54 private Vector filesets; 55 private Vector items; 56 private String name; 57 58 public ParamSet() { 59 filesets = new Vector(); 60 items = new Vector(); 61 } 62 63 public void addFileset(FileSet fileset) { 64 filesets.addElement(fileset); 65 } 66 67 public ParamItem createItem() { 68 ParamItem item = new ParamItem(); 69 items.addElement(item); 70 return item; 71 } 72 73 public void setName(String name) { 74 this.name = name; 75 } 76 77 public String getName() { 78 return name; 79 } 80 81 public Enumeration getValues(Project project) { 82 85 Vector values = new Vector(); 86 Enumeration enum = filesets.elements(); 87 while (enum.hasMoreElements()) { 88 FileSet fileSet = (FileSet) enum.nextElement(); 89 File base = fileSet.getDir(project); 90 DirectoryScanner scanner = fileSet.getDirectoryScanner(project); 91 if (TYPE_DIR != type) { 92 String[] files = getFiles(base, scanner); 93 for (int j = 0; j < files.length; j++) { 94 File f = new File(base, files[j]); 95 values.addElement(f.getAbsolutePath()); 96 } 97 } 98 if (TYPE_FILE != type) { 99 String[] dirs = getDirs(base, scanner); 100 for (int j = 0; j < dirs.length; j++) { 101 File f = new File(base, dirs[j]); 102 values.addElement(f.getAbsolutePath()); 103 } 104 } 105 } 106 enum = items.elements(); 107 while (enum.hasMoreElements()) { 108 ParamItem item = (ParamItem) enum.nextElement(); 109 values.addElement(item.getValue()); 110 } 111 return values.elements(); 112 } 113 114 117 public void setType(FileDirBoth type) { 118 this.type = type.getValue().intern(); 119 } 120 121 125 protected String[] getFiles(File basedir, DirectoryScanner ds) { 126 return ds.getIncludedFiles(); 127 } 128 129 133 protected String[] getDirs(File basedir, DirectoryScanner ds) { 134 return ds.getIncludedDirectories(); 135 } 136 } 137 | Popular Tags |