From 19b119b997c3bac4377e0dad949bc05d4a25293a Mon Sep 17 00:00:00 2001 From: Riduidel Date: Mon, 1 Sep 2014 16:07:46 +0200 Subject: [PATCH] fixes #132 by moving all config keys into a constant interface. It's not yet optimal (as there is not yet any separation between the various rendering engines), but at least it's a good start, no ? --- src/main/java/org/jbake/app/ConfigUtil.java | 108 +++++++++++++++++- src/main/java/org/jbake/app/Crawler.java | 6 +- src/main/java/org/jbake/app/Oven.java | 32 +++--- src/main/java/org/jbake/app/Parser.java | 9 +- src/main/java/org/jbake/app/Renderer.java | 14 ++- src/main/java/org/jbake/launcher/Init.java | 7 +- src/main/java/org/jbake/launcher/Main.java | 7 +- .../org/jbake/parser/AsciidoctorEngine.java | 12 +- .../template/DelegatingTemplateEngine.java | 4 +- .../template/FreemarkerTemplateEngine.java | 5 +- .../jbake/template/GroovyTemplateEngine.java | 6 +- .../template/ThymeleafTemplateEngine.java | 6 +- .../java/org/jbake/app/ConfigUtilTest.java | 3 +- src/test/java/org/jbake/app/CrawlerTest.java | 5 +- .../org/jbake/app/GroovyRendererTest.java | 3 +- src/test/java/org/jbake/app/InitTest.java | 3 +- src/test/java/org/jbake/app/RendererTest.java | 3 +- .../org/jbake/app/ThymeleafRendererTest.java | 3 +- 18 files changed, 184 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/jbake/app/ConfigUtil.java b/src/main/java/org/jbake/app/ConfigUtil.java index 0dbec8a00..e2f60a765 100644 --- a/src/main/java/org/jbake/app/ConfigUtil.java +++ b/src/main/java/org/jbake/app/ConfigUtil.java @@ -12,8 +12,114 @@ * @author Jonathan Bullock */ public class ConfigUtil { + /** + * Set of config keys used by JBake + * @author ndx + * + */ + public static interface Keys { - public final static String DATE_FORMAT = "date.format"; + /** + * Path of archived file. Should only be used when {@link #RENDER_ARCHIVE} is true. + */ + static final String ARCHIVE_FILE = "archive.file"; + static final String ASCIIDOCTOR_ATTRIBUTES = "asciidoctor.attributes"; + static final String ASCIIDOCTOR_ATTRIBUTES_EXPORT = "asciidoctor.attributes.export"; + static final String ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX = "asciidoctor.attributes.export.prefix"; + static final String ASCIIDOCTOR_OPTION = "asciidoctor.option"; + /** + * Folder where assets are stored. Assets are copied directly in output folder and not processed by JBake. + */ + static final String ASSET_FOLDER = "asset.folder"; + /** + * Timestamp that will be output when generation start. + */ + static final String BUILD_TIMESTAMP = "build.timestamp"; + /** + * Folder where content (that's to say files to be transformed) resides in + */ + static final String CONTENT_FOLDER = "content.folder"; + /** + * How date is formated + */ + final static String DATE_FORMAT = "date.format"; + static final String DB_PATH = "db.path"; + static final String DB_STORE = "db.store"; + /** + * Default status to use (in roder to avoid putting it in all files + */ + static final String DEFAULT_STATUS = "default.status"; + /** + * Path where html files are generated in. + */ + static final String DESTINATION_FOLDER = "destination.folder"; + /** + * Suffix used to identify draft files + */ + static final String DRAFT_SUFFIX = "draft.suffix"; + /** + * Feed template file. IS required only when {@link #RENDER_FEED} is set to true + */ + static final String FEED_FILE = "feed.file"; + /** + * Index template file. Required only when {@link #RENDER_INDEX} is set to true + */ + static final String INDEX_FILE = "index.file"; + /** + * Common extension for all output files + */ + static final String OUTPUT_EXTENSION = "output.extension"; + /** + * Flag indicating if archive file should be generated. + */ + static final String RENDER_ARCHIVE = "render.archive"; + /** + * Encoding used to render files. + */ + static final String RENDER_ENCODING = "render.encoding"; + /** + * Flag indicating if feed file should be generated. + */ + static final String RENDER_FEED = "render.feed"; + /** + * Flag indicating if index file should be generated. + */ + static final String RENDER_INDEX = "render.index"; + /** + * Flag indicating if sitemap file should be generated. + */ + static final String RENDER_SITEMAP = "render.sitemap"; + /** + * Flag indicating if tags file should be generated. + */ + static final String RENDER_TAGS = "render.tags"; + /** + * Port used when running Jetty server + */ + static final String SERVER_PORT = "server.port"; + /** + * Sitemap template file name. Used only when {@link #RENDER_SITEMAP} is set to true + */ + static final String SITEMAP_FILE = "sitemap.file"; + /** + * tags template file name. Used only when {@link #RENDER_TAGS} is set to true + */ + static final String TAG_PATH = "tag.path"; + /** + * Ecoding for template files + */ + static final String TEMPLATE_ENCODING = "template.encoding"; + /** + * Folder where template files are looked for + */ + static final String TEMPLATE_FOLDER = "template.folder"; + /** + * Locale used for thymeleaf template rendering + */ + public static final String THYMELEAF_LOCALE = "thymeleaf.locale"; + static final String VERSION = "version"; + + } public static CompositeConfiguration load(File source) throws ConfigurationException { CompositeConfiguration config = new CompositeConfiguration(); diff --git a/src/main/java/org/jbake/app/Crawler.java b/src/main/java/org/jbake/app/Crawler.java index e44c706f7..e6d0bb320 100644 --- a/src/main/java/org/jbake/app/Crawler.java +++ b/src/main/java/org/jbake/app/Crawler.java @@ -3,7 +3,9 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; + import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.model.DocumentStatus; import org.jbake.model.DocumentTypes; import org.slf4j.Logger; @@ -39,7 +41,7 @@ public class Crawler { public Crawler(ODatabaseDocumentTx db, File source, CompositeConfiguration config) { this.db = db; this.config = config; - this.contentPath = source.getPath() + separator + config.getString("content.folder"); + this.contentPath = source.getPath() + separator + config.getString(ConfigUtil.Keys.CONTENT_FOLDER); this.parser = new Parser(config, contentPath); } @@ -108,7 +110,7 @@ private String buildURI(final File sourceFile) { if (uri.startsWith("/")) { uri = uri.substring(1, uri.length()); } - uri = uri.substring(0, uri.lastIndexOf(".")) + config.getString("output.extension"); + uri = uri.substring(0, uri.lastIndexOf(".")) + config.getString(Keys.OUTPUT_EXTENSION); return uri; } diff --git a/src/main/java/org/jbake/app/Oven.java b/src/main/java/org/jbake/app/Oven.java index 7f424f587..19f894099 100644 --- a/src/main/java/org/jbake/app/Oven.java +++ b/src/main/java/org/jbake/app/Oven.java @@ -13,7 +13,9 @@ import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; + import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.model.DocumentTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +76,7 @@ private void ensureSource() throws Exception { private void ensureDestination() throws Exception { if (null == destination) { - destination = new File(config.getString("destination.folder")); + destination = new File(config.getString(Keys.DESTINATION_FOLDER)); } if (!destination.exists()) { destination.mkdirs(); @@ -91,9 +93,9 @@ private void ensureDestination() throws Exception { */ public void setupPaths() throws Exception { ensureSource(); - templatesPath = setupRequiredFolderFromConfig("template.folder"); - contentsPath = setupRequiredFolderFromConfig("content.folder"); - assetsPath = setupPathFromConfig("asset.folder"); + templatesPath = setupRequiredFolderFromConfig(Keys.TEMPLATE_FOLDER); + contentsPath = setupRequiredFolderFromConfig(Keys.CONTENT_FOLDER); + assetsPath = setupPathFromConfig(Keys.ASSET_FOLDER); if (!assetsPath.exists()) { LOGGER.warn("No asset folder was found!"); } @@ -118,7 +120,7 @@ private File setupRequiredFolderFromConfig(String key) throws Exception { * @throws Exception */ public void bake() throws Exception { - ODatabaseDocumentTx db = DBUtil.createDB(config.getString("db.store"), config.getString("db.path")); + ODatabaseDocumentTx db = DBUtil.createDB(config.getString(Keys.DB_STORE), config.getString(Keys.DB_PATH)); updateDocTypesFromConfiguration(); DBUtil.updateSchema(db); try { @@ -148,45 +150,45 @@ public void bake() throws Exception { } // write index file - if (config.getBoolean("render.index")) { + if (config.getBoolean(Keys.RENDER_INDEX)) { try { - renderer.renderIndex(config.getString("index.file")); + renderer.renderIndex(config.getString(Keys.INDEX_FILE)); } catch (Exception e) { errors.add(e.getMessage()); } } // write feed file - if (config.getBoolean("render.feed")) { + if (config.getBoolean(Keys.RENDER_FEED)) { try { - renderer.renderFeed(config.getString("feed.file")); + renderer.renderFeed(config.getString(Keys.FEED_FILE)); } catch (Exception e) { errors.add(e.getMessage()); } } // write sitemap file - if (config.getBoolean("render.sitemap")) { + if (config.getBoolean(Keys.RENDER_SITEMAP)) { try { - renderer.renderSitemap(config.getString("sitemap.file")); + renderer.renderSitemap(config.getString(Keys.SITEMAP_FILE)); } catch (Exception e) { errors.add(e.getMessage()); } } // write master archive file - if (config.getBoolean("render.archive")) { + if (config.getBoolean(Keys.RENDER_ARCHIVE)) { try { - renderer.renderArchive(config.getString("archive.file")); + renderer.renderArchive(config.getString(Keys.ARCHIVE_FILE)); } catch (Exception e) { errors.add(e.getMessage()); } } // write tag files - if (config.getBoolean("render.tags")) { + if (config.getBoolean(Keys.RENDER_TAGS)) { try { - renderer.renderTags(crawler.getTags(), config.getString("tag.path")); + renderer.renderTags(crawler.getTags(), config.getString(Keys.TAG_PATH)); } catch (Exception e) { errors.add(e.getMessage()); } diff --git a/src/main/java/org/jbake/app/Parser.java b/src/main/java/org/jbake/app/Parser.java index bde200e9f..4c9f0dc5a 100644 --- a/src/main/java/org/jbake/app/Parser.java +++ b/src/main/java/org/jbake/app/Parser.java @@ -2,6 +2,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.io.IOUtils; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.parser.Engines; import org.jbake.parser.MarkupEngine; import org.jbake.parser.ParserContext; @@ -52,7 +53,7 @@ public Map processFile(File file) { List fileContents = null; try { is = new FileInputStream(file); - fileContents = IOUtils.readLines(is, config.getString("render.encoding")); + fileContents = IOUtils.readLines(is, config.getString(Keys.RENDER_ENCODING)); } catch (IOException e) { LOGGER.error("Error while opening file {}: {}", file, e); @@ -84,11 +85,11 @@ public Map processFile(File file) { // then read engine specific headers engine.processHeader(context); - if (config.getString("default.status") != null) { + if (config.getString(Keys.DEFAULT_STATUS) != null) { // default status has been set if (content.get("status") == null) { // file hasn't got status so use default - content.put("status", config.getString("default.status")); + content.put("status", config.getString(Keys.DEFAULT_STATUS)); } } @@ -173,7 +174,7 @@ private void processHeader(List contents, final Map cont String[] parts = line.split("="); if (parts.length == 2) { if (parts[0].equalsIgnoreCase("date")) { - DateFormat df = new SimpleDateFormat(config.getString(ConfigUtil.DATE_FORMAT)); + DateFormat df = new SimpleDateFormat(config.getString(Keys.DATE_FORMAT)); Date date = null; try { date = df.parse(parts[1]); diff --git a/src/main/java/org/jbake/app/Renderer.java b/src/main/java/org/jbake/app/Renderer.java index a5448d6db..97cec57e7 100644 --- a/src/main/java/org/jbake/app/Renderer.java +++ b/src/main/java/org/jbake/app/Renderer.java @@ -1,7 +1,9 @@ package org.jbake.app; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; + import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.template.DelegatingTemplateEngine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,19 +63,19 @@ public void render(Map content) throws Exception { outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf(".")); // delete existing versions if they exist in case status has changed either way - File draftFile = new File(outputFilename + config.getString("draft.suffix") + config.getString("output.extension")); + File draftFile = new File(outputFilename + config.getString(Keys.DRAFT_SUFFIX) + config.getString(Keys.OUTPUT_EXTENSION)); if (draftFile.exists()) { draftFile.delete(); } - File publishedFile = new File(outputFilename + config.getString("output.extension")); + File publishedFile = new File(outputFilename + config.getString(Keys.OUTPUT_EXTENSION)); if (publishedFile.exists()) { publishedFile.delete(); } if (content.get("status").equals("draft")) { - outputFilename = outputFilename + config.getString("draft.suffix"); + outputFilename = outputFilename + config.getString(Keys.DRAFT_SUFFIX); } - File outputFile = new File(outputFilename + config.getString("output.extension")); + File outputFile = new File(outputFilename + config.getString(Keys.OUTPUT_EXTENSION)); StringBuilder sb = new StringBuilder(); sb.append("Rendering [").append(outputFile).append("]... "); @@ -101,7 +103,7 @@ private Writer createWriter(File file) throws IOException { file.createNewFile(); } - return new OutputStreamWriter(new FileOutputStream(file), config.getString("render.encoding")); + return new OutputStreamWriter(new FileOutputStream(file), config.getString(ConfigUtil.Keys.RENDER_ENCODING)); } /** @@ -230,7 +232,7 @@ public void renderTags(Set tags, String tagPath) throws Exception { model.put("content", Collections.singletonMap("type","tag")); tag = tag.trim().replace(" ", "-"); - File outputFile = new File(destination.getPath() + File.separator + tagPath + File.separator + tag + config.getString("output.extension")); + File outputFile = new File(destination.getPath() + File.separator + tagPath + File.separator + tag + config.getString(Keys.OUTPUT_EXTENSION)); StringBuilder sb = new StringBuilder(); sb.append("Rendering tags [").append(outputFile).append("]... "); diff --git a/src/main/java/org/jbake/launcher/Init.java b/src/main/java/org/jbake/launcher/Init.java index ec242c2aa..95bc462d2 100644 --- a/src/main/java/org/jbake/launcher/Init.java +++ b/src/main/java/org/jbake/launcher/Init.java @@ -4,6 +4,7 @@ import java.io.FileInputStream; import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.ZipUtil; /** @@ -37,13 +38,13 @@ public void run(File outputFolder, File templateLocationFolder, String templateT if (contents != null) { for (File content : contents) { if (content.isDirectory()) { - if (content.getName().equalsIgnoreCase(config.getString("template.folder"))) { + if (content.getName().equalsIgnoreCase(config.getString(Keys.TEMPLATE_FOLDER))) { safe = false; } - if (content.getName().equalsIgnoreCase(config.getString("content.folder"))) { + if (content.getName().equalsIgnoreCase(config.getString(Keys.CONTENT_FOLDER))) { safe = false; } - if (content.getName().equalsIgnoreCase(config.getString("asset.folder"))) { + if (content.getName().equalsIgnoreCase(config.getString(Keys.ASSET_FOLDER))) { safe = false; } } diff --git a/src/main/java/org/jbake/launcher/Main.java b/src/main/java/org/jbake/launcher/Main.java index e57ad4f61..541ef083b 100644 --- a/src/main/java/org/jbake/launcher/Main.java +++ b/src/main/java/org/jbake/launcher/Main.java @@ -8,6 +8,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; import org.jbake.app.ConfigUtil; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.FileUtil; import org.jbake.app.Oven; import org.kohsuke.args4j.CmdLineException; @@ -66,7 +67,7 @@ private void run(String[] args) { System.exit(1); } - System.out.println("JBake " + config.getString("version") + " (" + config.getString("build.timestamp") + ") [http://jbake.org]"); + System.out.println("JBake " + config.getString(Keys.VERSION) + " (" + config.getString(Keys.BUILD_TIMESTAMP) + ") [http://jbake.org]"); System.out.println(); if (res.isHelpNeeded()) { @@ -90,9 +91,9 @@ private void run(String[] args) { if (res.isRunServer()) { if (res.getSource().getPath().equals(".")) { // use the default destination folder - runServer(config.getString("destination.folder"), config.getString("server.port")); + runServer(config.getString(Keys.DESTINATION_FOLDER), config.getString(Keys.SERVER_PORT)); } else { - runServer(res.getSource().getPath(), config.getString("server.port")); + runServer(res.getSource().getPath(), config.getString(Keys.SERVER_PORT)); } } diff --git a/src/main/java/org/jbake/parser/AsciidoctorEngine.java b/src/main/java/org/jbake/parser/AsciidoctorEngine.java index e598d69b0..fc4fa58ef 100644 --- a/src/main/java/org/jbake/parser/AsciidoctorEngine.java +++ b/src/main/java/org/jbake/parser/AsciidoctorEngine.java @@ -7,7 +7,7 @@ import org.asciidoctor.AttributesBuilder; import org.asciidoctor.ast.DocumentHeader; import org.asciidoctor.Options; -import org.jbake.app.ConfigUtil; +import org.jbake.app.ConfigUtil.Keys; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,7 +87,7 @@ public void processHeader(final ParserContext context) { if (key.equals("revdate")) { if (attributes.get(key) != null && attributes.get(key) instanceof String) { - DateFormat df = new SimpleDateFormat(context.getConfig().getString(ConfigUtil.DATE_FORMAT)); + DateFormat df = new SimpleDateFormat(context.getConfig().getString(Keys.DATE_FORMAT)); Date date = null; try { date = df.parse((String)attributes.get(key)); @@ -127,9 +127,9 @@ private void processAsciiDoc(ParserContext context) { private Options getAsciiDocOptionsAndAttributes(ParserContext context) { CompositeConfiguration config = context.getConfig(); - final AttributesBuilder attributes = attributes(config.getStringArray("asciidoctor.attributes")); - if (config.getBoolean("asciidoctor.attributes.export", false)) { - final String prefix = config.getString( "asciidoctor.attributes.export.prefix", ""); + final AttributesBuilder attributes = attributes(config.getStringArray(Keys.ASCIIDOCTOR_ATTRIBUTES)); + if (config.getBoolean(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT, false)) { + final String prefix = config.getString( Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX, ""); for (final Iterator it = config.getKeys(); it.hasNext();) { final String key = it.next(); if (!key.startsWith("asciidoctor")) { @@ -137,7 +137,7 @@ private Options getAsciiDocOptionsAndAttributes(ParserContext context) { } } } - final Configuration optionsSubset = config.subset("asciidoctor.option"); + final Configuration optionsSubset = config.subset(Keys.ASCIIDOCTOR_OPTION); final Options options = options().attributes(attributes.get()).get(); for (final Iterator iterator = optionsSubset.getKeys(); iterator.hasNext();) { final String name = iterator.next(); diff --git a/src/main/java/org/jbake/template/DelegatingTemplateEngine.java b/src/main/java/org/jbake/template/DelegatingTemplateEngine.java index 3e80406f7..dbf20925d 100644 --- a/src/main/java/org/jbake/template/DelegatingTemplateEngine.java +++ b/src/main/java/org/jbake/template/DelegatingTemplateEngine.java @@ -1,7 +1,9 @@ package org.jbake.template; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; + import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.FileUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +32,7 @@ public DelegatingTemplateEngine(final CompositeConfiguration config, final OData @Override public void renderDocument(final Map model, String templateName, final Writer writer) throws RenderingException { - model.put("version", config.getString("version")); + model.put("version", config.getString(Keys.VERSION)); Map configModel = new HashMap(); Iterator configKeys = config.getKeys(); while (configKeys.hasNext()) { diff --git a/src/main/java/org/jbake/template/FreemarkerTemplateEngine.java b/src/main/java/org/jbake/template/FreemarkerTemplateEngine.java index b1ffe2b18..8c363ecc6 100644 --- a/src/main/java/org/jbake/template/FreemarkerTemplateEngine.java +++ b/src/main/java/org/jbake/template/FreemarkerTemplateEngine.java @@ -3,6 +3,7 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; + import freemarker.template.Configuration; import freemarker.template.DefaultObjectWrapper; import freemarker.template.SimpleCollection; @@ -15,7 +16,9 @@ import freemarker.template.TemplateHashModel; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; + import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.DBUtil; import org.jbake.app.DocumentList; import org.jbake.model.DocumentTypes; @@ -49,7 +52,7 @@ public FreemarkerTemplateEngine(final CompositeConfiguration config, final OData private void createTemplateConfiguration(final CompositeConfiguration config, final File templatesPath) { templateCfg = new Configuration(); - templateCfg.setDefaultEncoding(config.getString("render.encoding")); + templateCfg.setDefaultEncoding(config.getString(Keys.RENDER_ENCODING)); try { templateCfg.setDirectoryForTemplateLoading(templatesPath); } catch (IOException e) { diff --git a/src/main/java/org/jbake/template/GroovyTemplateEngine.java b/src/main/java/org/jbake/template/GroovyTemplateEngine.java index d60da64c5..2613cb857 100644 --- a/src/main/java/org/jbake/template/GroovyTemplateEngine.java +++ b/src/main/java/org/jbake/template/GroovyTemplateEngine.java @@ -3,20 +3,24 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; + import groovy.lang.GString; import groovy.lang.Writable; import groovy.text.SimpleTemplateEngine; import groovy.text.Template; import groovy.text.TemplateEngine; import groovy.text.XmlTemplateEngine; + import org.apache.commons.configuration.CompositeConfiguration; import org.codehaus.groovy.runtime.MethodClosure; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.DBUtil; import org.jbake.app.DocumentList; import org.jbake.model.DocumentTypes; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; + import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.File; @@ -66,7 +70,7 @@ private Template findTemplate(final String templateName) throws SAXException, Pa File sourceTemplate = new File(templatesPath, templateName); Template template = cachedTemplates.get(templateName); if (template == null) { - template = ste.createTemplate(new InputStreamReader(new BufferedInputStream(new FileInputStream(sourceTemplate)), config.getString("template.encoding"))); + template = ste.createTemplate(new InputStreamReader(new BufferedInputStream(new FileInputStream(sourceTemplate)), config.getString(Keys.TEMPLATE_ENCODING))); cachedTemplates.put(templateName, template); } return template; diff --git a/src/main/java/org/jbake/template/ThymeleafTemplateEngine.java b/src/main/java/org/jbake/template/ThymeleafTemplateEngine.java index c7269af5d..3ae3629e7 100644 --- a/src/main/java/org/jbake/template/ThymeleafTemplateEngine.java +++ b/src/main/java/org/jbake/template/ThymeleafTemplateEngine.java @@ -3,8 +3,10 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; + import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.lang.LocaleUtils; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.app.DBUtil; import org.jbake.app.DocumentList; import org.jbake.model.DocumentTypes; @@ -54,14 +56,14 @@ public ThymeleafTemplateEngine(final CompositeConfiguration config, final ODatab private void initializeTemplateEngine() { templateResolver = new FileTemplateResolver(); templateResolver.setPrefix(templatesPath.getAbsolutePath() + File.separatorChar); - templateResolver.setCharacterEncoding(config.getString("template.encoding")); + templateResolver.setCharacterEncoding(config.getString(Keys.TEMPLATE_ENCODING)); templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(templateResolver); } @Override public void renderDocument(final Map model, final String templateName, final Writer writer) throws RenderingException { - String localeString = config.getString("thymeleaf.locale"); + String localeString = config.getString(Keys.THYMELEAF_LOCALE); Locale locale = localeString != null ? LocaleUtils.toLocale(localeString) : Locale.getDefault(); Context context = new Context(locale, wrap(model)); lock.lock(); diff --git a/src/test/java/org/jbake/app/ConfigUtilTest.java b/src/test/java/org/jbake/app/ConfigUtilTest.java index 76bc3d8d6..63cee9e83 100644 --- a/src/test/java/org/jbake/app/ConfigUtilTest.java +++ b/src/test/java/org/jbake/app/ConfigUtilTest.java @@ -5,6 +5,7 @@ import junit.framework.Assert; import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.junit.Test; public class ConfigUtilTest { @@ -14,7 +15,7 @@ public void load() throws Exception { CompositeConfiguration config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile())); // check default.properties values exist - Assert.assertEquals("output", config.getString("destination.folder")); + Assert.assertEquals("output", config.getString(Keys.DESTINATION_FOLDER)); // check custom.properties values exist Assert.assertEquals("testing123", config.getString("test.property")); diff --git a/src/test/java/org/jbake/app/CrawlerTest.java b/src/test/java/org/jbake/app/CrawlerTest.java index 6cfab81f2..4321a604b 100644 --- a/src/test/java/org/jbake/app/CrawlerTest.java +++ b/src/test/java/org/jbake/app/CrawlerTest.java @@ -15,6 +15,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; +import org.jbake.app.ConfigUtil.Keys; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -37,7 +38,7 @@ public void setup() throws Exception, IOException, URISyntaxException { } config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile())); - Assert.assertEquals(".html", config.getString("output.extension")); + Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION)); db = DBUtil.createDB("memory", "documents"+System.currentTimeMillis()); } @@ -49,7 +50,7 @@ public void cleanup() throws InterruptedException { @Test public void crawl() throws ConfigurationException { Crawler crawler = new Crawler(db, sourceFolder, config); - crawler.crawl(new File(sourceFolder.getPath() + File.separator + config.getString("content.folder"))); + crawler.crawl(new File(sourceFolder.getPath() + File.separator + config.getString(Keys.CONTENT_FOLDER))); Assert.assertEquals(2, crawler.getPostCount()); Assert.assertEquals(3, crawler.getPageCount()); diff --git a/src/test/java/org/jbake/app/GroovyRendererTest.java b/src/test/java/org/jbake/app/GroovyRendererTest.java index cfa4842c4..677cfb270 100644 --- a/src/test/java/org/jbake/app/GroovyRendererTest.java +++ b/src/test/java/org/jbake/app/GroovyRendererTest.java @@ -6,6 +6,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.io.FileUtils; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.model.DocumentTypes; import org.junit.After; import org.junit.Assert; @@ -58,7 +59,7 @@ public void setup() throws Exception, IOException, URISyntaxException { config.setProperty(key, old.substring(0, old.length()-4)+".gsp"); } } - Assert.assertEquals(".html", config.getString("output.extension")); + Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION)); db = DBUtil.createDB("memory", "documents"+System.currentTimeMillis()); } diff --git a/src/test/java/org/jbake/app/InitTest.java b/src/test/java/org/jbake/app/InitTest.java index 8d1c411f4..3bb4be614 100644 --- a/src/test/java/org/jbake/app/InitTest.java +++ b/src/test/java/org/jbake/app/InitTest.java @@ -6,6 +6,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.launcher.Init; import org.junit.Before; import org.junit.Rule; @@ -47,7 +48,7 @@ public void initOK() throws Exception { public void initFailDestinationContainsContent() throws IOException{ Init init = new Init(config); File initPath = folder.newFolder("init"); - File contentFolder = new File(initPath.getPath() + File.separatorChar + config.getString("content.folder")); + File contentFolder = new File(initPath.getPath() + File.separatorChar + config.getString(Keys.CONTENT_FOLDER)); contentFolder.mkdir(); try { init.run(initPath, rootPath, "freemarker"); diff --git a/src/test/java/org/jbake/app/RendererTest.java b/src/test/java/org/jbake/app/RendererTest.java index a87142e33..958e7ea28 100644 --- a/src/test/java/org/jbake/app/RendererTest.java +++ b/src/test/java/org/jbake/app/RendererTest.java @@ -3,6 +3,7 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import org.apache.commons.configuration.CompositeConfiguration; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.model.DocumentTypes; import org.junit.After; import org.junit.Assert; @@ -59,7 +60,7 @@ public void setup() throws Exception, IOException, URISyntaxException { } config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile())); - Assert.assertEquals(".html", config.getString("output.extension")); + Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION)); db = DBUtil.createDB("memory", "documents"+System.currentTimeMillis()); } diff --git a/src/test/java/org/jbake/app/ThymeleafRendererTest.java b/src/test/java/org/jbake/app/ThymeleafRendererTest.java index 14ca564e9..a5666cf5c 100644 --- a/src/test/java/org/jbake/app/ThymeleafRendererTest.java +++ b/src/test/java/org/jbake/app/ThymeleafRendererTest.java @@ -6,6 +6,7 @@ import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.io.FileUtils; +import org.jbake.app.ConfigUtil.Keys; import org.jbake.model.DocumentTypes; import org.junit.After; import org.junit.Assert; @@ -58,7 +59,7 @@ public void setup() throws Exception, IOException, URISyntaxException { config.setProperty(key, old.substring(0, old.length()-4)+".thyme"); } } - Assert.assertEquals(".html", config.getString("output.extension")); + Assert.assertEquals(".html", config.getString(Keys.OUTPUT_EXTENSION)); db = DBUtil.createDB("memory", "documents"+System.currentTimeMillis()); }