diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..456ef9e56 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [jknack] +patreon: edgarespina diff --git a/README.md b/README.md index d0571a8d1..80c4069ce 100644 --- a/README.md +++ b/README.md @@ -1058,9 +1058,6 @@ Hello {{#child}}{{this.value}}{{/child}} [Bugs, Issues and Features](https://github.com/jknack/handlebars.java/issues) -## Donate - -Buy [Edgar](https://patreon.com/edgarespina) a beer! ## Related Projects * [Handlebars.js](http://handlebarsjs.com/) diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml index 2a36a4bdc..162f55944 100644 --- a/handlebars-caffeine/pom.xml +++ b/handlebars-caffeine/pom.xml @@ -5,7 +5,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 @@ -70,7 +70,7 @@ org.antlr antlr4-runtime - 4.9.2 + 4.9.3 org.abego.treelayout diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml index f2e74817a..3450e4db4 100644 --- a/handlebars-guava-cache/pom.xml +++ b/handlebars-guava-cache/pom.xml @@ -5,7 +5,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml index fa993494c..c45581145 100644 --- a/handlebars-helpers/pom.xml +++ b/handlebars-helpers/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 @@ -30,7 +30,7 @@ joda-time joda-time - 2.10.12 + 2.12.0 true diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml index d4255c258..3aa1c9949 100644 --- a/handlebars-humanize/pom.xml +++ b/handlebars-humanize/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 @@ -54,7 +54,7 @@ org.antlr antlr4-runtime - 4.9.2 + 4.9.3 org.abego.treelayout diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml index 55a84605f..842d97c6f 100644 --- a/handlebars-jackson2/pom.xml +++ b/handlebars-jackson2/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml index 96d256d4d..aab1f9386 100644 --- a/handlebars-maven-plugin-tests/pom.xml +++ b/handlebars-maven-plugin-tests/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml index d85687f4d..6f8693e08 100644 --- a/handlebars-maven-plugin/pom.xml +++ b/handlebars-maven-plugin/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml deleted file mode 100644 index 92255d0e3..000000000 --- a/handlebars-proto/pom.xml +++ /dev/null @@ -1,200 +0,0 @@ - - - - - com.github.jknack - handlebars.java - 4.3.1-SNAPSHOT - - - 4.0.0 - com.github.jknack - handlebars-proto - - A standalone Handlebars Server - - - 9.4.43.v20210629 - - - - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - *:* - - META-INF/*.SF - META-INF/*.RSA - META-INF/*.INF - META-INF/*.sf - META-INF/*.inf - META-INF/*.rsa - - - - - - com.github.jknack.handlebars.server.HbsServer - - - - - - - - - - com.akathist.maven.plugins.launch4j - launch4j-maven-plugin - 2.1.2 - - - l4j-clui - none - - launch4j - - - console - target/handlebars.exe - target/handlebars-proto-${project.version}.jar - Handlebars.java - - com.github.jknack.handlebars.server.HbsServer - false - - - 1.6.0 - - - 0.5.4.0 - ${project.version} - Handlebars.java Server - Copyright (c) 2012 Edgar Espina - 0.5.4.0 - Handlebars.java Server - ${project.version} - handlebars - handlebars.exe - - - - - - - - - - - - org.eclipse.jetty.orbit - javax.servlet - 3.0.0.v201112011016 - - - - com.github.jknack - handlebars - ${project.version} - - - - com.github.jknack - handlebars-jackson2 - ${project.version} - - - - - - - - - - com.github.jknack - handlebars-humanize - ${project.version} - - - - commons-io - commons-io - 2.11.0 - - - - org.apache.commons - commons-lang3 - - - - com.fasterxml.jackson.core - jackson-databind - - - - org.yaml - snakeyaml - compile - - - - org.eclipse.jetty - jetty-server - ${jetty-version} - - - - org.eclipse.jetty - jetty-webapp - ${jetty-version} - - - - org.eclipse.jetty - jetty-servlet - ${jetty-version} - - - - ch.qos.logback - logback-classic - compile - - - - args4j - args4j - 2.33 - - - - - junit - junit - test - - - - - diff --git a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java b/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java deleted file mode 100644 index ffb7c8504..000000000 --- a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java +++ /dev/null @@ -1,261 +0,0 @@ -/** - * Copyright (c) 2012-2015 Edgar Espina - * - * This file is part of Handlebars.java. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jknack.handlebars.server; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; -import java.net.MalformedURLException; -import java.util.Properties; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ErrorHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener; -import org.eclipse.jetty.util.component.LifeCycle; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.jetty.webapp.WebXmlConfiguration; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.Option; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.github.jknack.handlebars.Handlebars; -import com.github.jknack.handlebars.HelperRegistry; -import com.github.jknack.handlebars.HumanizeHelper; -import com.github.jknack.handlebars.Jackson2Helper; -import com.github.jknack.handlebars.helper.StringHelpers; -import com.github.jknack.handlebars.io.FileTemplateLoader; -import com.github.jknack.handlebars.io.TemplateLoader; -import com.github.jknack.handlebars.io.URLTemplateLoader; - -/** - * A handlebars web server. - * - * @author edgar.espina - */ -public class HbsServer { - - /** - * The logging system. - */ - public static final Logger logger = LoggerFactory.getLogger(HbsServer.class); - - public static final String CONTEXT = "/"; - - public static final String CONTENT_TYPE = "text/html"; - - public static final int PORT = 6780; - - public static String version; - - static { - InputStream in = null; - try { - in = HbsServer.class.getResourceAsStream("/hbs.properties"); - Properties properties = new Properties(); - properties.load(in); - version = properties.getProperty("version"); - } catch (IOException e) { - e.printStackTrace(); - } finally { - IOUtils.closeQuietly(in); - } - - } - - public static class Options { - @Option(name = "-dir", aliases = "-d", required = true, - usage = "set the template directory", metaVar = " ") - public File dir; - - @Option(name = "-suffix", aliases = "-sx", - usage = "set the template's suffix, default is: " - + TemplateLoader.DEFAULT_SUFFIX, metaVar = " ") - public String suffix = TemplateLoader.DEFAULT_SUFFIX; - - @Option(name = "-prefix", aliases = "-px", - usage = "set the template's prefix, default is: " - + TemplateLoader.DEFAULT_PREFIX, metaVar = " ") - public String prefix = TemplateLoader.DEFAULT_PREFIX; - - @Option(name = "-context", aliases = "-c", - usage = "set the web context's path, default is: " + CONTEXT, - metaVar = " ") - public String contextPath = CONTEXT; - - @Option(name = "-port", aliases = "-p", - usage = "set the port's number, default is: " + PORT, metaVar = " ") - public int port = PORT; - - @Option(name = "-contentType", aliases = "-ct", - usage = "set the content's type header, default is: " + CONTENT_TYPE, - metaVar = " ") - public String contentType = CONTENT_TYPE; - - @Option(name = "-encoding", aliases = "-e", - usage = "set the charset used it while rendering, default is: UTF-8", - metaVar = " ") - public String encoding = "UTF-8"; - } - - public static void main(final String[] args) throws Exception { - Options arguments = new Options(); - CmdLineParser parser = new CmdLineParser(arguments); - try { - parser.parseArgument(args); - run(arguments); - } catch (CmdLineException e) { - System.err.println(e.getMessage()); - String os = System.getProperty("os.name").toLowerCase(); - System.err.println("Usage:"); - String program = "java -jar handlebars-proto-${version}.jar"; - if (os.contains("win")) { - program = "handlebars"; - } - System.err.println(" " + program + " [-option value]"); - System.err.println("Options:"); - parser.printUsage(System.err); - } - } - - /** - * Start a Handlebars server. - * - * @param args The command line arguments. - * @throws Exception If something goes wrong. - */ - public static void run(final Options args) throws Exception { - if (!args.dir.exists()) { - System.out.println("File not found: " + args.dir); - } - logger.info("Welcome to the Handlebars.java server v" + version); - - URLTemplateLoader loader = new FileTemplateLoader(args.dir); - loader.setPrefix(new File(args.dir, args.prefix).getAbsolutePath()); - loader.setSuffix(args.suffix); - Handlebars handlebars = new Handlebars(loader); - - /** - * Helper wont work in the stand-alone version, so we add a default helper - * that render the plain text. - */ - handlebars.registerHelper( - HelperRegistry.HELPER_MISSING, - (context, options) -> new Handlebars.SafeString(options.fn.text()) - ); - handlebars.registerHelper("json", Jackson2Helper.INSTANCE); -// handlebars.registerHelper("md", new MarkdownHelper()); - // String helpers - StringHelpers.register(handlebars); - // Humanize helpers - HumanizeHelper.register(handlebars); - - final Server server = new Server(args.port); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - logger.info("Hope you enjoy it! bye!"); - try { - server.stop(); - } catch (Exception ex) { - logger.info("Can't stop the server", ex); - } - })); - - server.addLifeCycleListener(new AbstractLifeCycleListener() { - @Override - public void lifeCycleStarted(final LifeCycle event) { - logger.info("Open a browser and type:"); - logger.info(" http://localhost:{}{}/[page]{}", new Object[]{ - args.port, - args.contextPath.equals(CONTEXT) ? "" : args.contextPath, - args.suffix }); - } - }); - - WebAppContext root = new WebAppContext(); - ErrorHandler errorHandler = new ErrorHandler() { - @Override - protected void writeErrorPageHead(final HttpServletRequest request, final Writer writer, - final int code, final String message) throws IOException { - writer - .write("\n"); - writer.write("{{"); - writer.write(Integer.toString(code)); - writer.write("}}"); - writer.write("\n"); - writer.write(""); - } - - @Override - protected void writeErrorPageMessage(final HttpServletRequest request, final Writer writer, - final int code, - final String message, final String uri) throws IOException { - writer.write("
"); - writer - .write("

{{"); - writer.write(Integer.toString(code)); - writer.write("}}

"); - writer.write("\n

Problem accessing "); - write(writer, uri); - writer.write(". Reason:\n

    ");
-        write(writer, message);
-        writer.write("

"); - writer.write("
"); - writer.write("
"); - } - - @Override - protected void writeErrorPageBody(final HttpServletRequest request, final Writer writer, - final int code, - final String message, final boolean showStacks) throws IOException { - String uri = request.getRequestURI(); - - writeErrorPageMessage(request, writer, code, message, uri); - } - }; - root.setErrorHandler(errorHandler); - root.setContextPath(args.contextPath); - root.setResourceBase(args.dir.getAbsolutePath()); - root.addServlet(new ServletHolder(new HbsServlet(handlebars, args)), - "*" + args.suffix); - - root.setParentLoaderPriority(true); - - // prevent jetty from loading the webapp web.xml - root.setConfigurations(new Configuration[]{new WebXmlConfiguration() { - @Override - protected Resource findWebXml(final WebAppContext context) - throws IOException, MalformedURLException { - return null; - } - } }); - - server.setHandler(root); - - server.start(); - server.join(); - } - -} diff --git a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServlet.java b/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServlet.java deleted file mode 100644 index 4f8c9e381..000000000 --- a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServlet.java +++ /dev/null @@ -1,404 +0,0 @@ -/** - * Copyright (c) 2012-2015 Edgar Espina - * - * This file is part of Handlebars.java. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.jknack.handlebars.server; - -import static org.apache.commons.io.FilenameUtils.removeExtension; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.Writer; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.Yaml; - -import com.fasterxml.jackson.core.JsonLocation; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser.Feature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jknack.handlebars.Context; -import com.github.jknack.handlebars.Handlebars; -import com.github.jknack.handlebars.HandlebarsError; -import com.github.jknack.handlebars.HandlebarsException; -import com.github.jknack.handlebars.Template; -import com.github.jknack.handlebars.context.FieldValueResolver; -import com.github.jknack.handlebars.context.JavaBeanValueResolver; -import com.github.jknack.handlebars.context.MapValueResolver; -import com.github.jknack.handlebars.helper.StringHelpers; -import com.github.jknack.handlebars.server.HbsServer.Options; - -/** - * Prepare, compile and merge handlebars templates. - * - * @author edgar.espina - */ -public class HbsServlet extends HttpServlet { - - /** - * The default serial uid. - */ - private static final long serialVersionUID = 1L; - - /** - * The logging system. - */ - private static final Logger logger = - LoggerFactory.getLogger(HbsServlet.class); - - /** - * The handlebars object. - */ - private final Handlebars handlebars; - - /** - * The object mapper. - */ - private final ObjectMapper mapper = new ObjectMapper(); - - /** - * A yaml parser. - */ - private final Yaml yaml = new Yaml(); - - /** - * The server options. - */ - private final Options args; - - /** - * Creates a new {@link HbsServlet}. - * - * @param handlebars The handlebars object. - * @param args The server options. - */ - public HbsServlet(final Handlebars handlebars, final Options args) { - this.handlebars = handlebars; - this.args = args; - - mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - mapper.configure(Feature.ALLOW_COMMENTS, true); - } - - @Override - protected void doGet(final HttpServletRequest request, - final HttpServletResponse response) - throws ServletException, IOException { - Writer writer = null; - - try { - Template template = handlebars.compile(removeExtension(requestURI(request))); - - Object model = model(request); - - String output = template.apply(model); - response.setCharacterEncoding(args.encoding); - response.setContentType(args.contentType); - writer = response.getWriter(); - writer.write(output); - } catch (HandlebarsException ex) { - handlebarsError(ex, response); - } catch (JsonParseException ex) { - logger.error("Unexpected error", ex); - jsonError(ex, request, response); - } catch (FileNotFoundException ex) { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } catch (IOException ex) { - logger.error("Unexpected error", ex); - throw ex; - } catch (RuntimeException ex) { - logger.error("Unexpected error", ex); - throw ex; - } catch (Exception ex) { - logger.error("Unexpected error", ex); - throw new ServletException(ex); - } finally { - IOUtils.closeQuietly(writer); - } - } - - /** - * Attempt to load a json or yml file. - * - * @param request The original request. - * @return The associated model. - * @throws IOException If something goes wrong. - */ - private Object model(final HttpServletRequest request) throws IOException { - String jsonFilename = jsonFilename(request); - String ymlFilename = ymlFilename(request); - - Object data = json(jsonFilename); - if (data == null) { - data = yml(ymlFilename); - } - if (data == null) { - String errorMessage = "file not found: {}"; - logger.error(errorMessage, jsonFilename); - logger.error(errorMessage, ymlFilename); - return Collections.emptyMap(); - } - return data; - } - - /** - * Determines the data file to use from the requested URI or from the 'data' - * HTTP parameter. - * - * @param request The current request. - * @return The data file to use from the requested URI or from the 'data' - * HTTP parameter. - */ - private String dataFile(final HttpServletRequest request) { - String data = request.getParameter("data"); - String uri = StringUtils.isEmpty(data) - ? request.getRequestURI().replace(request.getContextPath(), "") - : data; - if (!HbsServer.CONTEXT.equals(args.prefix)) { - uri = args.prefix + uri; - } - if (!uri.startsWith("/")) { - uri = "/" + uri; - } - return uri; - } - - /** - * Remove context path from the request's URI. - * - * @param request The current request. - * @return Same as {@link HttpServletRequest#getRequestURI()} without context - * path. - */ - private String requestURI(final HttpServletRequest request) { - String requestURI = - request.getRequestURI().replace(request.getContextPath(), ""); - return requestURI; - } - - /** - * Deal with a {@link HandlebarsException}. - * - * @param ex The handlebars exception. - * @param response The http response. - * @throws IOException If something goes wrong. - */ - private void handlebarsError(final HandlebarsException ex, - final HttpServletResponse response) throws IOException { - - HandlebarsError error = ex.getError(); - int firstLine = 1; - if (error != null) { - if (ex.getCause() != null) { - firstLine = error.line; - } else { - firstLine = Math.max(1, error.line - 1); - } - } - fancyError(ex, firstLine, "Xml", response); - } - - /** - * Deal with a {@link HandlebarsException}. - * - * @param ex The handlebars exception. - * @param request The http request. - * @param response The http response. - * @throws IOException If something goes wrong. - */ - private void jsonError(final JsonParseException ex, final HttpServletRequest request, - final HttpServletResponse response) throws IOException { - - Map root = new HashMap(); - Map error = new HashMap(); - String filename = jsonFilename(request); - JsonLocation location = ex.getLocation(); - String reason = ex.getMessage(); - int atIdx = reason.lastIndexOf(" at "); - if (atIdx > 0) { - reason = reason.substring(0, atIdx); - } - error.put("filename", filename); - error.put("line", location.getLineNr()); - error.put("column", location.getColumnNr()); - error.put("reason", reason); - error.put("type", "JSON error"); - String json = read(filename); - StringBuilder evidence = new StringBuilder(); - int i = (int) location.getCharOffset(); - int nl = 0; - while (i >= 0 && nl < 2) { - char ch = json.charAt(i); - if (ch == '\n') { - nl++; - } - evidence.insert(0, ch); - i--; - } - i = (int) location.getCharOffset() + 1; - nl = 0; - while (i < json.length() && nl < 2) { - char ch = json.charAt(i); - if (ch == '\n') { - nl++; - } - evidence.append(ch); - i++; - } - error.put("evidence", evidence); - - root.put("error", error); - int firstLine = Math.max(1, ex.getLocation().getLineNr() - 1); - fancyError(root, firstLine, "JScript", response); - } - - /** - * Deal with a fancy errors. - * - * @param error An error. - * @param firstLine The first line to report. - * @param lang The lang to use. - * @param response The http response. - * @throws IOException If something goes wrong. - */ - private void fancyError(final Object error, final int firstLine, final String lang, - final HttpServletResponse response) throws IOException { - - Handlebars handlebars = new Handlebars(); - StringHelpers.register(handlebars); - - Template template = handlebars.compile("/error-pages/error"); - - PrintWriter writer = response.getWriter(); - template.apply( - Context - .newBuilder(error) - .resolver(MapValueResolver.INSTANCE, FieldValueResolver.INSTANCE, - JavaBeanValueResolver.INSTANCE) - .combine("lang", lang) - .combine("version", HbsServer.version) - .combine("firstLine", firstLine).build(), - writer); - - IOUtils.closeQuietly(writer); - } - - /** - * Try to load a json file that matches the given request. - * - * @return The associated data. - * @throws IOException If the file isn't found. - * @param filename the filename to read - */ - private Object json(final String filename) throws IOException { - try { - String json = read(filename); - if (json.trim().startsWith("[")) { - return mapper.readValue(json, List.class); - } - return mapper.readValue(json, Map.class); - } catch (FileNotFoundException ex) { - return null; - } - } - - /** - * Try to load a yml file that matches the given request. - * - * @return A yaml map. - * @throws IOException If the file isn't found. - * @param filename the filename to read - */ - private Object yml(final String filename) throws IOException { - try { - String yml = read(filename); - Object data = yaml.load(yml); - return data; - } catch (FileNotFoundException ex) { - return null; - } - } - - /** - * Construct the filename to parse json data from. - * @param request the current request - * @return filename to load json from - */ - private String jsonFilename(final HttpServletRequest request) { - return dataFilename(request, ".json"); - } - - /** - * Construct the filename to parse yml data from. - * @param request the current request - * @return filename to load yml from - */ - private String ymlFilename(final HttpServletRequest request) { - return dataFilename(request, ".yml"); - } - - /** - * Construct the filename to parse data from. - * @param request the current request - * @param extension the file extension to use, e.g. ".json" - * @return filename to load data from - */ - private String dataFilename(final HttpServletRequest request, final String extension) { - return removeExtension(dataFile(request)) + extension; - } - - /** - * Read a file from the servlet context. - * - * @param uri The requested file. - * @return The string content. - * @throws IOException If the file is not found. - */ - private String read(final String uri) throws IOException { - InputStream input = null; - try { - input = getServletContext().getResourceAsStream(uri); - if (input == null) { - throw new FileNotFoundException(args.dir + uri); - } - return IOUtils.toString(input); - } finally { - IOUtils.closeQuietly(input); - } - } - - @Override - protected void doPost(final HttpServletRequest req, - final HttpServletResponse resp) - throws ServletException, IOException { - doGet(req, resp); - } - -} diff --git a/handlebars-proto/src/main/resources/error-pages/error.hbs b/handlebars-proto/src/main/resources/error-pages/error.hbs deleted file mode 100644 index 9d8cd831c..000000000 --- a/handlebars-proto/src/main/resources/error-pages/error.hbs +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - -Handlebars.java - - - - - - - - - - - - -
- {{#if error.type}} - {{error.type}} - {{^}} - {{=<% %>=}} - {{ - Handlebars error - }} - <%={{ }}=%> - {{/if}} -
-
- {{#if error}} - - {{^}} - - {{/if}} -
- - {{#if error.type}} - {{^}} - - {{/if}} - - diff --git a/handlebars-proto/src/main/resources/hbs.properties b/handlebars-proto/src/main/resources/hbs.properties deleted file mode 100644 index defbd4820..000000000 --- a/handlebars-proto/src/main/resources/hbs.properties +++ /dev/null @@ -1 +0,0 @@ -version=${project.version} diff --git a/handlebars-proto/src/main/resources/logback.xml b/handlebars-proto/src/main/resources/logback.xml deleted file mode 100644 index f83051a1b..000000000 --- a/handlebars-proto/src/main/resources/logback.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - %msg%n - - - - - - - - - \ No newline at end of file diff --git a/handlebars-proto/src/main/resources/try.html b/handlebars-proto/src/main/resources/try.html deleted file mode 100644 index d1096a452..000000000 --- a/handlebars-proto/src/main/resources/try.html +++ /dev/null @@ -1,20 +0,0 @@ - - - -Try {{Handlebars.java}}! - - - - - -
-
-
- - \ No newline at end of file diff --git a/handlebars-proto/src/test/resources/logback-test.xml b/handlebars-proto/src/test/resources/logback-test.xml deleted file mode 100644 index 9b33dd724..000000000 --- a/handlebars-proto/src/test/resources/logback-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - %msg%n - - - - - - - - - \ No newline at end of file diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml index d19c95884..e0a6d3500 100644 --- a/handlebars-springmvc/pom.xml +++ b/handlebars-springmvc/pom.xml @@ -4,7 +4,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 @@ -67,7 +67,7 @@ org.antlr antlr4-runtime - 4.9.2 + 4.9.3 org.abego.treelayout diff --git a/handlebars/pom.xml b/handlebars/pom.xml index 12f3b44db..31557d284 100644 --- a/handlebars/pom.xml +++ b/handlebars/pom.xml @@ -6,7 +6,7 @@ com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT 4.0.0 @@ -33,20 +33,10 @@ true - org.apache.commons:commons-lang3 - org.apache.commons:commons-text org.antlr:antlr4-runtime - - org.apache.commons.lang3 - com.github.jknack.handlebars.internal.lang3 - - - org.apache.commons.text - com.github.jknack.handlebars.internal.text - org.antlr.v4.runtime com.github.jknack.handlebars.internal.antlr @@ -150,13 +140,11 @@ org.apache.commons commons-lang3 - true org.apache.commons commons-text - true @@ -228,7 +216,7 @@ - 4.9.2 + 4.9.3 15.3 diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java index 9bd3b252f..d20026a98 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java @@ -22,8 +22,11 @@ import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import org.junit.Ignore; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import com.github.jknack.handlebars.context.JavaBeanValueResolver; @@ -57,28 +60,29 @@ public String getBody() { .build(); } - @Ignore + @Test public void eachKeyWithString() throws IOException { - String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String"); + Set result = Stream.of(StringUtils.split( + compile("{{#each this}}{{@key}} {{/each}}").apply(configureContext("String")), " ")) + .collect(Collectors.toSet()); - String expected1 = "empty bytes "; - String expected2 = "bytes empty "; - assertTrue(result.equals(expected1) || result.equals(expected2)); + Set expected = Stream.of("empty", "bytes").collect(Collectors.toSet()); + assertTrue(result.containsAll(expected)); } - @Ignore + @Test public void eachKeyWithInt() throws IOException { - shouldCompileTo("{{#each this}}{{@key}} {{/each}}", 7, ""); + shouldCompileTo("{{#each this}}{{@key}} {{/each}}", configureContext(7), ""); } @Test public void eachKeyWithJavaBean() throws IOException { Blog blog = new Blog("Handlebars.java", "..."); - String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(configureContext(blog)); + Set result = Stream.of(StringUtils.split(compile("{{#each this}}{{@key}}:{{this}} {{/each}}").apply(configureContext(blog)), " ")).collect( + Collectors.toSet()); - String expected1 = "body: ... title: Handlebars.java "; - String expected2 = "title: Handlebars.java body: ... "; - assertTrue(result.equals(expected1) || result.equals(expected2)); + Set expected = Stream.of("body:...", "title:Handlebars.java").collect(Collectors.toSet()); + assertTrue(result.containsAll(expected)); } @Test diff --git a/pom.xml b/pom.xml index 8d678f2b3..ade3bd377 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.github.jknack handlebars.java - 4.3.1-SNAPSHOT + 5.0.0-SNAPSHOT pom Handlebars.java @@ -18,7 +18,6 @@ handlebars-springmvc handlebars-jackson2 handlebars-humanize - handlebars-proto handlebars-guava-cache handlebars-caffeine handlebars-maven-plugin @@ -71,13 +70,13 @@ org.apache.commons commons-text - 1.9 + 1.10.0 org.springframework spring-webmvc - 5.3.10 + 5.3.23 @@ -133,7 +132,7 @@ ch.qos.logback logback-classic - 1.2.6 + 1.4.4 test @@ -147,14 +146,14 @@ org.yaml snakeyaml - 1.29 + 1.31 test org.mockito mockito-core - 4.0.0 + 4.8.0 test @@ -394,7 +393,7 @@ UTF-8 - 2.13.0 + 2.14.0-rc2 1.2.2 0.8.7 yyyy-MM-dd HH:mm:ssa