outputFileName = file.getName();
// 获取模板
String tPath = file.getAbsolutePath().replace(
this.templatePath, "");
Template template = Velocity.getTemplate(tPath, "UTF-8");
if (file.getName().equalsIgnoreCase("ContextListener.java")) {
packagePath = target.getPath() + File.separator
+ this.packageNamePath + File.separator
+ "listener" + File.separator;
checkDirExist(packagePath);
} else if (file.getName().equalsIgnoreCase("Simple.java")
|| file.getName().equalsIgnoreCase("WithVelocity.java")) {
if (this.useJPA)
return;
packagePath = target.getPath() + File.separator
+ this.packageNamePath + File.separator
+ "resource" + File.separator;
checkDirExist(packagePath);
outputFileName = entityName + outputFileName;
} else if (file.getName().equalsIgnoreCase("Entity.java")) {
if (!this.useJPA)
return;
packagePath = target.getPath() + File.separator
+ this.packageNamePath + File.separator + "entity"
+ File.separator;
checkDirExist(packagePath);
outputFileName = entityName + ".java";
} else if (file.getName().equalsIgnoreCase("Resource.java")) {
if (!this.useJPA)
return;
packagePath = target.getPath() + File.separator
+ this.packageNamePath + File.separator
+ "service" + File.separator;
checkDirExist(packagePath);
outputFileName = entityName + outputFileName;
} else if (file.getName().equalsIgnoreCase("Service.java")
|| file.getName().equalsIgnoreCase("ServiceTest.java")) {
if (!this.useJPA)
return;
packagePath = target.getPath() + File.separator
+ this.packageNamePath + File.separator + "service"
+ File.separator;
checkDirExist(packagePath);
outputFileName = entityName + outputFileName;
} else
packagePath = target.getPath() + File.separator;
if (file.getName().equalsIgnoreCase("velocity.vm")) {
outputFileName = entityName + ".vm";
}
// 输出到用户端
OutputStreamWriter fileWriter = new OutputStreamWriter(
new FileOutputStream(packagePath + outputFileName),
"UTF-8");
template.merge(context, fileWriter);
fileWriter.flush();
fileWriter.close();
} catch (Exception e) {
}
}