import com.sun.star.tool.starjar.FilterElement;
import com.sun.star.tool.starjar.regex.MalformedPatternException;
public class JarFilteredDirectory {
public static void main(String[] args) {
StarJar starJar = new StarJar();
Vector filter = new Vector();
Vector fileListVector = new Vector();
try {
starJar.parseDirectoryTree(fileListVector,new File(System.getProperty("user.home")));
} catch (Exception e) {}
Enumeration fileList = fileListVector.elements();
try {
FileReader fileReader = new FileReader(args.length>0?args[0]:"TestFilter.flt");
starJar.importFilter(filter, fileReader);
} catch (FileNotFoundException e) {
System.out.println("Fehler beim Einlesen der Filterdatei :\n" + e);
}
catch (MalformedPatternException e) {
System.out.println("Fehler beim Parsen der Filterdatei :\n" + e);
}
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
while (fileList.hasMoreElements()) {
FileListElement file = (FileListElement)fileList.nextElement();
Enumeration filterEnum = filter.elements();
Pattern pathPattern = null;
Pattern filenamePattern = null;
while (filterEnum.hasMoreElements()) {
FilterElement filterElement = (FilterElement)filterEnum.nextElement();
try {
pathPattern = compiler.compile(filterElement.getPathPattern());
filenamePattern = compiler.compile(filterElement.getFilenamePattern());
} catch (MalformedPatternException e) {
System.out.println("Fehler im Pattern\n" + e);
}
if (matcher.matches(file.getPath(),pathPattern) && matcher.matches(file.getFilename(),filenamePattern))
file.setInclude(filterElement.isInclude());
}
}
starJar.zipFiles(fileListVector,"JarDirectoryTest.jar", "");
}