/*
 * Copyright 2014 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

package io.vertx.ext.web.templ.jte.impl;

import gg.jte.CodeResolver;
import io.vertx.core.Vertx;
import io.vertx.ext.web.common.WebEnvironment;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author <a href="mailto:andy@mazebert.com">Andreas Hager</a>
 */
public class VertxDirectoryCodeResolver implements CodeResolver {
  private final Vertx vertx;
  private final String templateRootDirectory;
  private final ConcurrentMap<String, Long> modificationTimes;

  public VertxDirectoryCodeResolver(Vertx vertx, String templateRootDirectory) {
    this.vertx = vertx;
    this.templateRootDirectory = templateRootDirectory.endsWith("/") ? templateRootDirectory : templateRootDirectory + "/";

    if (WebEnvironment.development()) {
      modificationTimes = new ConcurrentHashMap<>();
    } else {
      modificationTimes = null;
    }
  }

  public String resolve(String name) {
    name = templateRootDirectory + name;

    String templateCode = vertx.fileSystem().readFileBlocking(name).toString();
    if (templateCode == null) {
      return null;
    }

    if (modificationTimes != null) {
      modificationTimes.put(name, this.getLastModified(name));
    }

    return templateCode;
  }

  public boolean hasChanged(String name) {
    if (modificationTimes == null) {
      return false;
    }

    name = templateRootDirectory + name;

    Long lastResolveTime = this.modificationTimes.get(name);
    if (lastResolveTime == null) {
      return true;
    } else {
      long lastModified = this.getLastModified(name);
      return lastModified != lastResolveTime;
    }
  }

  private long getLastModified(String name) {
    return vertx.fileSystem().propsBlocking(name).lastModifiedTime();
  }
}

@@ -665,16 +665,71 @@
 nment;%0A%0A
+import java.nio.file.Path;%0Aimport java.nio.file.Paths;%0A
 import j
@@ -767,16 +767,16 @@
 ashMap;%0A
-
 import j
@@ -994,22 +994,20 @@
 e final 
-String
+Path
  templat
@@ -1228,97 +1228,40 @@
 y = 
-templateRootDirectory.endsWith(%22/%22) ? templateRootDirectory : templateRootDirectory + %22/%22
+Paths.get(templateRootDirectory)
 ;%0A%0A 
@@ -1475,31 +1475,49 @@
 ootDirectory
- + name
+.resolve(name).toString()
 ;%0A%0A    Strin
@@ -1925,15 +1925,33 @@
 tory
- + name
+.resolve(name).toString()
 ;%0A%0A 

Use Path API instead of String concatenation