1 2 24 package org.enhydra.tool.codegen.internal; 25 26 import org.enhydra.tool.ToolBoxInfo; 28 import org.enhydra.tool.codegen.ProjectGenerator; 29 import org.enhydra.tool.codegen.GeneratorException; 30 import org.enhydra.tool.codegen.wizard.AppOptionPanel1; 31 import org.enhydra.tool.codegen.wizard.ProjectOptionPanel2; 32 import org.enhydra.tool.codegen.wizard.ProjectOptionPanel3; 33 import org.enhydra.tool.codegen.wizard.CodeGenPanel; 34 import org.enhydra.tool.common.FileUtil; 35 import org.enhydra.tool.common.PathHandle; 36 import org.enhydra.tool.common.Replacement; 37 import org.enhydra.tool.common.ReplacementSet; 38 import org.enhydra.tool.common.ResUtil; 39 import org.enhydra.tool.common.Template; 40 import org.enhydra.tool.common.TemplateFilter; 41 import org.enhydra.tool.common.TemplateTool; 42 import org.enhydra.tool.common.ToolException; 43 import org.enhydra.tool.common.event.TemplateEvent; 44 import org.enhydra.tool.common.event.TemplateListener; 45 import org.enhydra.tool.configure.ConfigTool; 46 47 import java.io.BufferedReader ; 49 import java.io.IOException ; 50 import java.io.File ; 51 import java.io.FileNotFoundException ; 52 import java.io.FileReader ; 53 import java.io.FileWriter ; 54 import java.io.PrintWriter ; 55 import java.util.ArrayList ; 56 import java.util.Arrays ; 57 import java.util.Properties ; 58 import java.util.ResourceBundle ; 59 import java.util.StringTokenizer ; 60 import java.util.Vector ; 61 62 abstract public class AppGenerator extends ProjectGenerator { 64 private String client = null; 65 private String [][] addinMap = null; 66 private CodeGenPanel[] panels = null; 67 68 public AppGenerator() { 69 setReplacementSet(new AppReplacementSet()); 70 setOptionSet(new AppOptionSet()); 71 } 72 73 protected String [] getInputIncludes() { 75 ArrayList list = null; 76 String [] includes = new String [0]; 77 78 list = new ArrayList (Arrays.asList(super.getInputIncludes())); 79 list.add(getClient()); 80 list.trimToSize(); 81 includes = new String [list.size()]; 82 includes = (String []) list.toArray(includes); 83 list.clear(); 84 return includes; 85 } 86 87 public void initReplacementSet() throws GeneratorException { 89 super.initReplacementSet(); 90 try { 91 String content = null; 92 String app = null; 93 StringBuffer buf = new StringBuffer (); 94 95 if (getClient().equalsIgnoreCase(TYPE_WML)) { 97 content = CONTENT_WML; 98 } else { 99 100 content = CONTENT_HTML; 102 } 103 app = 104 getReplacementSet().lookup(AppReplacementSet.at_PROJECT_at).getReplaceWith()[0]; 105 buf.append(Character.toUpperCase(app.charAt(0))); 106 if (app.length() > 1) { 107 buf.append(app.substring(1)); 108 } 109 app = buf.toString(); 110 getReplacementSet().lookup(AppReplacementSet.APP).setReplaceWith(app); 111 getReplacementSet().lookup(AppReplacementSet.CLIENT).setReplaceWith(getClient().toUpperCase()); 112 getReplacementSet().lookup(AppReplacementSet.CONTENT_TYPE).setReplaceWith(content); 113 getReplacementSet().lookup(AppReplacementSet.APP).setReplaceWith(app); 114 } catch (ToolException e) { 115 e.printStackTrace(); 116 throw new GeneratorException(e, 117 res.getString("Unable_to_init_rep")); 118 } 119 } 120 121 128 public CodeGenPanel[] getWizardPanels() throws GeneratorException { 129 130 if (panels == null && isSwing()) { 132 panels = new CodeGenPanel[3]; 133 panels[0] = new AppOptionPanel1(); 134 panels[1] = new ProjectOptionPanel2(); 135 panels[2] = new ProjectOptionPanel3(); 136 for (int i = 0; i < panels.length; i++) { 137 panels[i].setOptionSet(getOptionSet()); 138 panels[i].readOptionSet(); 139 } 140 } 141 return panels; 142 } 143 144 protected String getClient() { 145 if (client == null) { 146 try { 147 client = 148 getOptionSet().lookup(AppOptionSet.CLIENT).getValue().toUpperCase(); 149 } catch (GeneratorException e) { 150 e.printStackTrace(); 151 client = null; 152 return TYPE_HTML; 153 } 154 } 155 return client; 156 } 157 158 171 public String [][] expandAddinPackageMap() throws GeneratorException { 172 String [][] exMap = new String [0][0]; 173 TemplateTool tool = null; 174 175 tool = new TemplateTool(); 176 tool.setReplacements(getReplacementSet().toArray()); 177 if (addinMap == null) { 178 initAddinPackageMap(); 179 } 180 exMap = new String [addinMap.length][addinMap[0].length]; 181 for (int i = 0; i < exMap.length; i++) { 182 for (int j = 0; j < exMap[i].length; j++) { 183 exMap[i][j] = addinMap[i][j]; 184 } 185 } 186 for (int i = 0; i < exMap.length; i++) { 187 for (int j = 0; j < exMap[i].length; j++) { 188 exMap[i][j] = tool.lineSearchAndReplace(exMap[i][j]); 189 } 190 } 191 return exMap; 192 } 193 194 public String [][] getAddinPackageMap() throws GeneratorException { 195 if (addinMap == null) { 196 initAddinPackageMap(); 197 } 198 return addinMap; 199 } 200 201 public void setAddinPackageMap(String [][] m) { 202 addinMap = m; 203 } 204 205 private void initAddinPackageMap() throws GeneratorException { 206 addinMap = new String [2][2]; 207 StringBuffer buf = new StringBuffer (); 208 209 buf.append(getDestination()); 210 buf.append(File.separator); 211 buf.append(DIR_RESOURCES); 217 addinMap[0][0] = buf.toString(); 218 buf.setLength(0); 219 buf.append("@JAVA_PACKAGE@"); buf.append('.'); 221 buf.append(DIR_PRESENTATION); 222 addinMap[0][1] = buf.toString(); 223 buf.setLength(0); 224 buf.append(getDestination()); 225 buf.append(File.separator); 226 buf.append(DIR_RESOURCES); 232 buf.append(File.separator); 233 buf.append(DIR_MEDIA); 234 addinMap[1][0] = buf.toString(); 235 addinMap[1][1] = DIR_MEDIA; 236 } 237 238 protected String [] getDefaultAddinSteps() { 239 String [] steps = new String [6]; 240 241 steps[0] = res.getString("StepsKelp0"); 242 steps[1] = res.getString("StepsKelp1"); 243 steps[2] = res.getString("StepsKelp2"); 244 steps[3] = res.getString("StepsKelp3"); 245 steps[4] = res.getString("StepsKelp4"); 246 steps[5] = res.getString("StepsKelp5"); 247 return steps; 248 } 249 250 protected String [] getDefaultShellSteps() { 251 String [] steps = new String [3]; 252 StringBuffer buf = new StringBuffer (); 253 254 buf.append(res.getString("StepsShell0a")); 255 buf.append(res.getString("StepsShell0b")); 256 buf.append(res.getString("StepsShell0c")); 257 buf.append(res.getString("StepsShell0d")); 258 buf.append(res.getString("StepsShell0e")); 259 buf.append(res.getString("StepsShell0f")); 260 buf.append(res.getString("StepsShell0g")); 261 buf.append(res.getString("StepsShell0h")); 262 steps[0] = buf.toString(); 263 steps[1] = res.getString("StepsShell1"); 264 buf.setLength(0); 265 buf.append(res.getString("StepsShell2a")); 266 buf.append(res.getString("StepsShell2b")); 267 steps[2] = buf.toString(); 268 return steps; 269 } 270 271 } 272 | Popular Tags |