1 package com.genimen.djeneric.tools.generator.util; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 import java.util.StringTokenizer ; 6 7 import com.genimen.djeneric.util.DjFileFilter; 8 9 public class TemplateSetManager 10 { 11 ArrayList _knownTemplateSets = new ArrayList (); 12 13 public final static String TEMPLATE_SET_EXTENSION = "dts"; 14 public final static String TEMPLATE_EXTENSION = "tpl"; 15 16 public TemplateSetManager() 17 { 18 } 19 20 public void rescanTemplateSets(String paths) 21 { 22 StringTokenizer tok = new StringTokenizer (paths, ";"); 23 _knownTemplateSets = new ArrayList (); 24 25 while (tok.hasMoreElements()) 26 { 27 String path = tok.nextToken(); 28 scanPath(path, _knownTemplateSets); 29 } 30 } 31 32 public TemplateSet[] getTemplateSets() 33 { 34 return (TemplateSet[]) _knownTemplateSets.toArray(new TemplateSet[0]); 35 } 36 37 public Template[] getTemplates(String [] templateSetNames) 38 { 39 ArrayList result = new ArrayList (); 40 41 for (int t = 0; t < templateSetNames.length; t++) 42 for (int i = 0; i < _knownTemplateSets.size(); i++) 43 { 44 TemplateSet ts = (TemplateSet) _knownTemplateSets.get(i); 45 46 if (ts.getName().equalsIgnoreCase(templateSetNames[t])) 47 { 48 Template[] subset = ts.getTemplates(); 49 for (int s = 0; s < subset.length; s++) 50 result.add(subset[s]); 51 } 52 } 53 return (Template[]) result.toArray(new Template[0]); 54 } 55 56 public String [] getTemplatesWithErrors() 57 { 58 ArrayList result = new ArrayList (); 59 60 for (int i = 0; i < _knownTemplateSets.size(); i++) 61 { 62 TemplateSet ts = (TemplateSet) _knownTemplateSets.get(i); 63 String [] subset = ts.getTemplatesWithErrors(); 64 for (int s = 0; s < subset.length; s++) 65 result.add(subset[s]); 66 } 67 return (String []) result.toArray(new String [0]); 68 } 69 70 public String getLoadLog() 71 { 72 StringBuffer log = new StringBuffer (); 73 74 for (int i = 0; i < _knownTemplateSets.size(); i++) 75 { 76 TemplateSet ts = (TemplateSet) _knownTemplateSets.get(i); 77 log.append(ts.getLoadLog()); 78 } 79 return log.toString().trim(); 80 } 81 82 private void scanPath(String path, ArrayList known) 83 { 84 File file = new File (path); 85 if (!file.isDirectory()) return; 86 87 File [] sets = file.listFiles(new DjFileFilter(TEMPLATE_SET_EXTENSION)); 88 for (int i = 0; i < sets.length; i++) 89 { 90 if (sets[i].isDirectory()) scanPath(sets[i].getAbsolutePath(), known); 91 else known.add(new TemplateSet(sets[i].getAbsolutePath())); 92 } 93 } 94 95 } | Popular Tags |