本文整理汇总了Java中org.apache.velocity.texen.util.FileUtil类的典型用法代码示例。如果您正苦于以下问题:Java FileUtil类的具体用法?Java FileUtil怎么用?Java FileUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUtil类属于org.apache.velocity.texen.util包,在下文中一共展示了FileUtil类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import org.apache.velocity.texen.util.FileUtil; //导入依赖的package包/类
public void generate(File svcFile, String codeRootPath, String resRoootPath) {
Log.info("codeRootPath=[" + codeRootPath + "]");
Log.info("resxRoootPath=[" + resRoootPath + "]");
Log.info("load service description file " + svcFile.getPath());
Document doc = getSvcXml(svcFile);
Element rootNode = doc.getRootElement();
String dtoStyle = rootNode.attributeValue("dtoStyle", "pojo");
String createHtml = rootNode.attributeValue("createHtml", "false");
String basePkg = rootNode.attributeValue("javaPackageBase", "");
String basePkgPath = FileUtil.combinePath(codeRootPath, basePkg.replace('.', File.separatorChar));
TransformerFactory txFactory = TransformerFactory.newInstance();
//
String filename = svcFile.getName();
filename = filename.substring(0, filename.indexOf('.'));
genEnum(txFactory, doc, basePkgPath);
}
示例2: generateCodeByVelocity
import org.apache.velocity.texen.util.FileUtil; //导入依赖的package包/类
/**
* 生成代码 by velocity
* @param map 变量
* @param destPath 目的地址
* @param destFile 目的文件名
* @param tmpPath 模版地址
* @param tmpFile 模版文件名
* @return
*/
public static boolean generateCodeByVelocity(Map<String, Object> map, String destPath, String destFile, String tmpPath, String tmpFile){
try {
// 1.初始化
Properties properties = new Properties();
properties.put("file.resource.loader.path", tmpPath);
properties.put("input.encoding", "UTF-8");
properties.put("output.encoding", "UTF-8");
Velocity.init(properties);
VelocityContext context = new VelocityContext(map);
// 2.生成代码
FileUtil.mkdir(destPath);
BufferedWriter sw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(destPath, destFile)), "UTF-8"));
Velocity.getTemplate(tmpFile).merge(context, sw);
sw.flush();
sw.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例3: genEnum
import org.apache.velocity.texen.util.FileUtil; //导入依赖的package包/类
private void genEnum(TransformerFactory txFactory, Document doc, String basePkgPath) {
try {
InputStream xlsInputStream = getClass().getClassLoader().getResourceAsStream("xsl/enum.xsl");
Transformer tx = txFactory.newTransformer(new StreamSource(xlsInputStream));
List enumNodes = doc.selectNodes("root/enums/enum");
for (Object n : enumNodes) {
Element enumNode = (Element) n;
for (Object n2 : enumNode.selectNodes("field")) {
Element fieldNode = (Element) n2;
fieldNode.addAttribute("name", fieldNode.attributeValue("name").toUpperCase());
// System.out.println(fieldNode.attributeValue("name"));
}
}
//
DocumentSource src = new DocumentSource(doc);
DocumentResult rzt = new DocumentResult();
tx.transform(src, rzt);
Document rztDoc = rzt.getDocument();
String filePath = FileUtil.combinePath(basePkgPath, "constant");
FileUtil.mkdir(filePath);
for (Object jn : rztDoc.selectNodes("enums/enum")) {
Element jenumNode = (Element) jn;
String enumName = jenumNode.attributeValue("name");
String jenumFilePath = FileUtil.combinePath(filePath, enumName + ".java");
Writer writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(jenumFilePath), "utf-8");
String enumCodes = jenumNode.getText();
enumCodes = enumCodes.replace(",;", ";");
writer.write(enumCodes);
} finally {
if (writer != null) {
writer.close();
}
}
Log.info("gen enum %s at %s", enumName, jenumFilePath);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}