/Users/lyon/j4p/src/futils/WordPrintMerge.java

1    package futils; 
2     
3    import gui.In; 
4    import utils.StringUtils; 
5    import utils.SystemUtils; 
6     
7    import java.io.File; 
8    import java.io.FileWriter; 
9    import java.io.IOException; 
10   import java.io.PrintWriter; 
11    
12   /** 
13    * Copyright DocJava, inc. User: lyon 
14    * <p/> 
15    * Date: Dec 5, 2004 
16    * <p/> 
17    * Time: 9:36:58 AM 
18    */ 
19   public class WordPrintMerge { 
20       public static void main(String[] args) { 
21           try { 
22               wordPrintMerge(); 
23           } catch (IOException e) { 
24               e.printStackTrace(); 
25    
26           } 
27       } 
28    
29    
30       public static void wordPrintMerge() throws IOException { 
31           File f =Futil.getReadFile("select a file to be merged") ; 
32           String fn = f.getName(); 
33           int index =  fn.indexOf('.'); 
34           String wild = fn.substring(index+1); 
35           boolean b = In.getBoolean("is "+wild+" the file suffix of interest?"); 
36           if (!b) 
37             wild = In.getString("enter a suffix for a file name search"); 
38           File files[] = Ls.getWildFiles(f, 
39                           wild); 
40           wordPrintMerge(files); 
41    
42           if (In.getBoolean("Done! Want to go again?")) wordPrintMerge(); 
43           System.exit(0); 
44       } 
45    
46       public static void wordPrintMerge(File[] files) throws IOException { 
47           FileWriter fw = WriterUtil.getFileWriter("enter output file"); 
48           PrintWriter pw = new PrintWriter(fw); 
49           final String directorySeparator = SystemUtils.getDirectorySeparator(); 
50    
51           for (int i = 0; i < files.length; i++) { 
52               final String str = "ÇINCLUDE "+ 
53                                   files[i].getCanonicalPath() + 
54                       "È" + 
55                       "Figure  " + 
56                       files[i].getName() + 
57                       "\r\f"; 
58               pw.print(StringUtils.replaceAll(str, directorySeparator, ":")); 
59           } 
60    
61           try { 
62    
63               fw.close(); 
64           } catch (IOException e) { 
65               e.printStackTrace(); 
66           } 
67       } 
68    
69       public static void lsWordPrintMerge() { 
70           String wild = In.getString("enter a suffix for a file name search"); 
71    
72           File files[] = Ls.getWildFiles(wild); 
73    
74           System.out.println(files.length + " file(s):"); 
75    
76           for (int i = 0; i < files.length; i++) 
77               System.out.println("\t" + files[i]); 
78    
79       } 
80   } 
81