Templates mit jdk.httpserver nutzen
ulrich
2021-07-07 73eed012df8d842738f64dc45ce5f13aad788b5e
Template als Parameter anstelle eines Attributes des HttpContext
1 files modified
6 ■■■■ changed files
src/de/uhilger/httpserver/template/TemplateActor.java 6 ●●●● patch | view | raw | blame | history
src/de/uhilger/httpserver/template/TemplateActor.java
@@ -45,7 +45,7 @@
  public static final String STR_EMPTY = "";
  public static final String STR_SLASH = "/";
  
  public static final String ATTR_TEMPLATE = "template";
  //public static final String ATTR_TEMPLATE = "template";
  
  //public static final String WELCOME_FILE = "index.htmi";
  
@@ -63,7 +63,7 @@
   * @return das ausgefuellte Template
   * @throws IOException 
   */
  public String render(HttpExchange exchange, Map data) throws IOException {
  public String render(HttpExchange exchange, Map data, String template) throws IOException {
    MustacheFactory mf;
    Mustache m;
    HttpHelper helper = new HttpHelper();
@@ -71,7 +71,7 @@
    String fileBase = helper.getAttrStr(attributes, FileHandler.ATTR_FILE_BASE, STR_EMPTY);
    File fileRoot = new File(fileBase);    
    logger.fine("fileRoot: " + fileRoot.getAbsolutePath());
    String template = helper.getAttrStr(attributes, ATTR_TEMPLATE, STR_EMPTY);
    //String template = helper.getAttrStr(attributes, ATTR_TEMPLATE, STR_EMPTY);
    File templateFile = new File(fileRoot, template);
    if(templateFile.exists()) {
      logger.fine("using template " + templateFile.getAbsolutePath());