| | |
| | | import com.github.mustachejava.MustacheFactory; |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.httpserver.base.HttpHelper; |
| | | import de.uhilger.httpserver.base.HttpResponder; |
| | | import de.uhilger.httpserver.base.handler.FileHandler; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.StringWriter; |
| | | import java.util.Map; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * Der TemplateActor rendert den Inhalt einer Map in |
| | |
| | | * @version 1, 04.07.2021 |
| | | */ |
| | | public class TemplateActor { |
| | | |
| | | private static final Logger logger = Logger.getLogger(TemplateActor.class.getName()); |
| | | |
| | | public static final String STR_DOT = "."; |
| | | public static final String STR_EMPTY = ""; |
| | |
| | | Map attributes = exchange.getHttpContext().getAttributes(); |
| | | String fileBase = helper.getAttrStr(attributes, FileHandler.ATTR_FILE_BASE, STR_EMPTY); |
| | | File fileRoot = new File(fileBase); |
| | | logger.fine("fileRoot: " + fileRoot.getAbsolutePath()); |
| | | //logger.fine("fileRoot: " + fileRoot.getAbsolutePath()); |
| | | //String template = helper.getAttrStr(attributes, ATTR_TEMPLATE, STR_EMPTY); |
| | | File templateFile = new File(fileRoot, template); |
| | | if(templateFile.exists()) { |
| | | logger.fine("using template " + templateFile.getAbsolutePath()); |
| | | //logger.fine("using template " + templateFile.getAbsolutePath()); |
| | | mf = new NeonMustacheFactory(fileRoot); |
| | | m = mf.compile(template); |
| | | } else { |
| | | logger.fine("template " + templateFile.getAbsolutePath() + " not found"); |
| | | //logger.fine("template " + templateFile.getAbsolutePath() + " not found"); |
| | | mf = new NeonMustacheFactory(); |
| | | m = mf.compile(template); |
| | | } |