Java tutorial
/* * @(#)TmpRender.java 2011-11-22 * ?us?? 2008-2011, Inc. All rights reserved. * s.server. Use is subject to license terms. */ package com.tools.bi; import java.io.File; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import org.apache.commons.io.FileUtils; import com.us.util.DateUtil; import com.us.util.FileHelper; import com.us.util.FtlUtil; /** * :? * * @author <a href="mailto:monlyu.hong@gmail.com">monlyu</a> * @version --0.0.1--, 2011-11-22 * @since JDK6.0 */ public class TmpRender { private TmpRender() { } // public static TmpRender instance() { return new TmpRender(); } /** * action? * @param clazz * @param src ? * @throws Exception */ public void createAction(Class<?> clazz, String src) throws Exception { Map<String, Object> data = getEachHas(clazz); InputStream stream_tmp = FileHelper.getFileInPackage("com.tools.bi.ftl", "ActionTmp.ftl"); String javaStream = FtlUtil.render2Str(data, stream_tmp); File file = FileHelper.getClassFile(src, String.format("com.us.action.%s", data.get("className"))); FileUtils.write(FileHelper.getFile(file, String.format("%sHandle.java", data.get("ClassName"))), javaStream, "UTF-8"); } // ? private Map<String, Object> getEachHas(Class<?> clazz) { Map<String, Object> defaults = new HashMap<String, Object>(); defaults.put("today", DateUtil.format(DateUtil.now())); defaults.put("year", DateUtil.format(DateUtil.now(), "yyyy")); String className = clazz.getSimpleName(); defaults.put("ClassName", className); defaults.put("className", Character.toLowerCase(className.charAt(0)) + className.substring(1)); return defaults; } public void createBo(Class<?> clazz, String srcPath) throws Exception { Map<String, Object> data = getEachHas(clazz); InputStream stream_tmp = FileHelper.getFileInPackage("com.tools.bi.ftl", "BoTmp.ftl"); String javaStream = FtlUtil.render2Str(data, stream_tmp); File file = FileHelper.getClassFile(srcPath, "com.us.bo"); FileUtils.write(FileHelper.getFile(file, String.format("%sBo.java", data.get("ClassName"))), javaStream, "UTF-8"); } public void createDao(Class<?> clazz, String srcPath) throws Exception { Map<String, Object> data = getEachHas(clazz); InputStream stream_tmp = FileHelper.getFileInPackage("com.tools.bi.ftl", "DaoTmp.ftl"); String javaStream = FtlUtil.render2Str(data, stream_tmp); File file = FileHelper.getClassFile(srcPath, "com.us.dao"); FileUtils.write(FileHelper.getFile(file, String.format("%sDao.java", data.get("ClassName"))), javaStream, "UTF-8"); } }