1
4
19package com.borneo.util;
20
21import java.io.File;
22import java.text.SimpleDateFormat;
23import java.text.ParseException;
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.Collection;
27import java.util.Date;
28import java.util.TimeZone;
29
30import javax.xml.namespace.QName;
31
32import org.apache.axis.encoding.ser.DateDeserializer;
33import org.apache.log4j.Logger;
34import org.apache.log4j.PropertyConfigurator;
35
36
39public class FileSelector
40{
41
42 public FileSelector()
43 {
44 }
45
46 public static Collection getFiles(String pattern)
47 {
48 return Arrays.asList((new File(POProperty.get("data.source.sourcedirectory"))).listFiles(new MyFileFilter(pattern)));
49 }
50
51 public static Collection getFiles(File fil, String pattern)
52 {
53 return Arrays.asList(fil.listFiles(new MyFileFilter(pattern)));
54 }
55
56 public static Collection getFiles(File fil, String pattern, Date adate)
57 {
58 MyFileFilter myFF = new MyFileFilter(pattern) ;
59 myFF.setModDate(adate);
60 if (fil.exists())
61 return Arrays.asList(fil.listFiles(myFF));
62 return new ArrayList();
63 }
64
65 public static Collection getFiles(String filenm, String pattern)
66 {
67 return getFiles(new File(filenm), pattern);
68 }
69
70 public static Collection getFiles(String filenm, String pattern, String value)
73 {
74 if(value.equalsIgnoreCase("") ){
75 return getFiles(new File(filenm), pattern);
76 }
77 else
78 {return getFiles(new File(filenm), pattern, Dates.getISODate(value));}
79 }
80
89 public static Collection getFilesFromProps (){
90 MyFileFilter myFF = new MyFileFilter(PropertyCompar()) ;
91
92 if(! POProperty.get(
93 "data.source.lastfile"
94 ).equalsIgnoreCase("")){
95 myFF.setModDate(
96 Dates.getISODate(
97 POProperty.get(
98 "data.source.lastfile"
99 )
00 )
01 );}
02 if(! POProperty.get(
03 "data.source.filesize.filter"
04 ).equalsIgnoreCase("")){
05 myFF.setSize(
06 new Long(
07 POProperty.get(
08 "data.source.filesize.filter"
09 )
10 ).longValue()
11 );}
12
13 return Arrays.asList(
15 new File (
16 POProperty.get(
17 "data.source.sourcedirectory"
18 )
19 ).listFiles(myFF)
20 );
21 }
22 private static String PropertyCompar (){
23 if (
24 ! POProperty.get("data.source.regex").equalsIgnoreCase("")
25 &&
26 POProperty.get("data.source.filename").equalsIgnoreCase("")
27 ){return POProperty.get("data.source.regex") ;}
28 else {
29 if (
30 POProperty.get("data.source.regex").equalsIgnoreCase("")
31 &&
32 ! POProperty.get("data.source.filename").equalsIgnoreCase("")
33 ){return POProperty.get("data.source.filename");}
34 }
35
36 return null;
37 }
38 public static void main(String args1[])
39 {System.out.println("convertd : "
40 + Dates.getISODate(args1[0]).toString()
41);
42 }
43
44 protected static Logger log;
45
46 static
47 {
48 log = Logger.getLogger(com.borneo.util.FileSelector.class.getName());
49 PropertyConfigurator.configure(com.borneo.util.FileSelector.class.getClassLoader().getResource("config/log4j.properties"));
50 }
51}
52