FileDocCategorySizeDatePackage
FreemarkerExample.javaAPI DocExample4289Wed May 18 09:39:02 BST 2005com.discursive.jccook.template.freemarker

FreemarkerExample

public class FreemarkerExample extends Object
Include a table of the Values in DateFormatUtils

Fields Summary
private static Logger
logger
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] pArgs)

     
        LogInit.init();
    
        FreemarkerExample example = new FreemarkerExample();
        example.testSimpleTemplate();
    
private EnrollmenttestEnrollment()


        Enrollment enroll = new Enrollment();
        enroll.setSection(2);

        Course course = new Course();
        course.setDept("ECON");
        course.setNum(201);
        course.setName("Macroeconomics");
        course.setProfessor("Elzinger K.");
        enroll.setCourse(course);

        Student stud = new Student();
        stud.setFirstName("Stefan");
        stud.setLastName("Winz");
        enroll.setStudent(stud);

        List exams = new ArrayList();

        Calendar cal = new GregorianCalendar(2003, 1, 5);

        Exam e1 = new Exam();
        e1.setName("T01");
        e1.setDate(cal.getTime());
        e1.setScore(90.0);
        e1.setWeight(1.00);
        exams.add(e1);

        cal.add(Calendar.WEEK_OF_YEAR, 2);
        Exam e2 = new Exam();
        e2.setName("T02");
        e2.setDate(cal.getTime());
        e2.setScore(84.5);
        e2.setWeight(1.50);
        exams.add(e2);

        cal.add(Calendar.WEEK_OF_YEAR, 2);
        Exam e3 = new Exam();
        e3.setName("MID");
        e3.setDate(cal.getTime());
        e3.setScore(79.0);
        e3.setWeight(2.00);
        exams.add(e3);

        cal.add(Calendar.WEEK_OF_YEAR, 2);
        Exam e4 = new Exam();
        e4.setName("T03");
        e4.setDate(cal.getTime());
        e4.setScore(99.0);
        e4.setWeight(1.00);
        exams.add(e4);

        cal.add(Calendar.WEEK_OF_YEAR, 2);
        Exam e5 = new Exam();
        e5.setName("T04");
        e5.setDate(cal.getTime());
        e5.setScore(65.0);
        e5.setWeight(1.75);
        exams.add(e5);

        cal.add(Calendar.WEEK_OF_YEAR, 2);
        Exam e6 = new Exam();
        e6.setName("FIN");
        e6.setDate(cal.getTime());
        e6.setScore(83.0);
        e6.setWeight(4.00);
        exams.add(e6);

        enroll.setExams(exams);
        return enroll;

    
public voidtestSimpleTemplate()


        Configuration cfg = Configuration.getDefaultConfiguration();
        cfg.setTemplateLoader(new ClassTemplateLoader(getClass()));
        cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);

        logger.debug("Template Loader: " + cfg.getTemplateLoader());

        Map root = new HashMap();
        root.put("enrollment", testEnrollment());

        Template template = cfg.getTemplate("template.ftl");

        StringWriter writer = new StringWriter();
        template.process(root, writer);

        logger.debug("output: \n" + writer.toString());