001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.common;
017
018 import java.io.File;
019 import java.io.InputStream;
020 import java.util.Properties;
021
022 import freemarker.cache.ClassTemplateLoader;
023 import freemarker.cache.TemplateLoader;
024 import freemarker.template.Configuration;
025 import sun.applet.Main;
026
027 /**
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public class FreemarkerSTTmplMthdGenerator {
031 private static Configuration cfg = new Configuration();
032
033 // Templates for File Generation
034 private static String DIR_TMPL = "/Gen/";
035
036 //Configuration
037 private static TemplateLoader templateLoader = new ClassTemplateLoader(FreemarkerSTTmplMthdGenerator.class, DIR_TMPL);
038
039 public static void main(String[] args) throws Exception {
040 cfg.setTemplateLoader(templateLoader);
041
042 String propLocation = "/GenFiles/MainTmplMthdSTNavBase.properties";
043 String template = "TmplMthdSTNavBase.ftl";
044
045 createFile(propLocation, template);
046 }
047
048 private static void createFile(String propLocation, String template) throws Exception {
049 try {
050 InputStream in = FreemarkerSTTmplMthdGenerator.class.getResourceAsStream(propLocation);
051 File f1 = new File("src" + File.separatorChar + "it" + File.separatorChar + "resources"
052 + File.separatorChar + "GenFiles" + File.separatorChar
053 + propLocation.substring(propLocation.lastIndexOf("/"), propLocation.lastIndexOf("."))
054 + template.substring(0, template.length() - 4) + ".java");
055 FreemarkerUtil.ftlWrite(f1, cfg.getTemplate(template), in);
056
057 } catch (Exception e) {
058 e.printStackTrace();
059 throw new Exception("Unable to generate files", e);
060 }
061 }
062 }