1 2 24 25 package org.enhydra.tool.codegen; 27 28 import org.enhydra.tool.ToolBoxInfo; 30 import org.enhydra.tool.common.Template; 31 import org.enhydra.tool.common.TemplateTool; 32 import org.enhydra.tool.common.TemplateFilter; 33 import org.enhydra.tool.common.PathHandle; 34 35 public class ProjectTemplateFilter implements TemplateFilter, Constants { 37 private TemplateTool tool = null; 38 private String destPath = null; 39 private String [] includes = new String [0]; 40 private String [] excludes = new String [0]; 41 private boolean tempIn = true; 42 43 public ProjectTemplateFilter(TemplateTool t, String dest) { 44 final String [] initExts = { 45 TYPE_TEMPLATE 46 }; 47 48 tool = t; 49 tool.setInitExtensions(initExts); 50 tool.setInitDestination(dest); 51 } 52 53 public String getDestination() { 54 return tool.getInitDestination(); 55 } 56 57 public boolean isIncludeTemplate() { 58 return tempIn; 59 } 60 61 public void setIncludeTemplate(boolean b) { 62 tempIn = b; 63 } 64 65 public TemplateTool getTemplateTool() { 66 return tool; 67 } 68 69 public String [] getOutputExcludes() { 70 return excludes; 71 } 72 73 public void setOutputExcludes(String [] ex) { 74 excludes = ex; 75 } 76 77 public void setInputIncludes(String [] in) { 78 includes = in; 79 } 80 81 public String [] getInputIncludes() { 82 return includes; 83 } 84 85 public boolean accept(Template template) { 86 int index = -1; 87 boolean include = false; 88 boolean dir = false; 89 PathHandle path = null; 90 String ext = new String (); 91 92 if (template.isDirectory()) { 93 include = tempIn; 94 dir = true; 95 } else { 96 path = PathHandle.createPathHandle(template.toString()); 97 ext = path.getExtension(); 98 if (tempIn) { 99 include = ext.startsWith(TYPE_TEMPLATE) && includeInput(ext); 100 } else { 101 include = (!ext.startsWith(TYPE_TEMPLATE)) 102 && includeInput(ext); 103 } 104 } 105 if (include) { 106 path = PathHandle.createPathHandle(template.getOutput()); 107 if (path.getPath() == null) { 108 tool.initOutput(template); 109 path = PathHandle.createPathHandle(template.getOutput()); 110 } 111 ext = path.getExtension(); 112 index = ext.indexOf('-'); 113 if (index > -1) { 114 path.setExtension(ext.substring(0, index)); 115 template.setOutput(path.getFile()); 116 } 117 include = (!path.endsWith(getOutputExcludes())); 118 } 119 return include; 120 } 121 122 private boolean includeInput(String input) { 123 boolean include = false; 124 int index = -1; 125 String suffix = new String (); 126 127 if (input == null) { 128 include = false; 129 } else { 130 index = input.indexOf('-'); 131 if (index > 0) { 132 suffix = input.substring(index); 133 for (int i = 0; i < getInputIncludes().length; i++) { 134 if (suffix.equalsIgnoreCase('-' 135 + getInputIncludes()[i])) { 136 include = true; 137 break; 138 } 139 } 140 } else { 141 include = true; 142 } 143 } 144 return include; 145 } 146 147 } 148 | Popular Tags |