001package org.avaje.freemarker; 002 003import freemarker.cache.TemplateLoader; 004import freemarker.template.Configuration; 005import freemarker.template.ObjectWrapper; 006import freemarker.template.TemplateExceptionHandler; 007 008/** 009 * Bean used to build a Freemarker Configuration object. 010 */ 011public class ConfigurationBuilder { 012 013 private ObjectWrapper wrapper = ObjectWrapper.DEFAULT_WRAPPER; 014 015 private String encoding = "UTF-8"; 016 017 private String numberFormat = "0.######"; 018 019 private boolean localizedLookup; 020 021 private int templateUpdateDelay; 022 023 private boolean useExceptionHandler; 024 025 private TemplateLoader templateLoader; 026 027 public Configuration build() { 028 029 try { 030 Configuration config = new Configuration(); 031 config.setObjectWrapper(wrapper); 032 config.setLocalizedLookup(localizedLookup); 033 config.setDefaultEncoding(encoding); 034 config.setTemplateUpdateDelay(templateUpdateDelay); 035 config.setNumberFormat(numberFormat); 036 037 if (useExceptionHandler) { 038 config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); 039 } 040 041 config.setTemplateLoader(templateLoader); 042 043 return config; 044 045 } catch (Exception e) { 046 throw new RuntimeException(e); 047 } 048 } 049 050 public ObjectWrapper getWrapper() { 051 return wrapper; 052 } 053 054 public void setWrapper(ObjectWrapper wrapper) { 055 this.wrapper = wrapper; 056 } 057 058 public String getEncoding() { 059 return encoding; 060 } 061 062 public void setEncoding(String encoding) { 063 this.encoding = encoding; 064 } 065 066 public int getTemplateUpdateDelay() { 067 return templateUpdateDelay; 068 } 069 070 public void setTemplateUpdateDelay(int templateUpdateDelay) { 071 this.templateUpdateDelay = templateUpdateDelay; 072 } 073 074 public boolean isUseExceptionHandler() { 075 return useExceptionHandler; 076 } 077 078 public void setUseExceptionHandler(boolean useExceptionHandler) { 079 this.useExceptionHandler = useExceptionHandler; 080 } 081 082 public boolean isLocalizedLookup() { 083 return localizedLookup; 084 } 085 086 public void setLocalizedLookup(boolean localizedLookup) { 087 this.localizedLookup = localizedLookup; 088 } 089 090 public TemplateLoader getTemplateLoader() { 091 return templateLoader; 092 } 093 094 public void setTemplateLoader(TemplateLoader templateLoader) { 095 this.templateLoader = templateLoader; 096 } 097 098}