本文整理匯總了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);
}
}