aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/MainModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/MainModule.java')
-rw-r--r--src/main/java/org/traccar/MainModule.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index e3f693444..a6f983a6b 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -21,6 +21,9 @@ import com.google.inject.Provides;
import com.google.inject.Scopes;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.log.NullLogChute;
+import org.eclipse.jetty.util.URIUtil;
import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
@@ -70,6 +73,9 @@ import javax.annotation.Nullable;
import javax.inject.Singleton;
import javax.ws.rs.client.Client;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
public class MainModule extends AbstractModule {
@@ -278,4 +284,27 @@ public class MainModule extends AbstractModule {
return null;
}
+ @Singleton
+ @Provides
+ public static VelocityEngine provideVelocityEngine(Config config) {
+ Properties properties = new Properties();
+ properties.setProperty("file.resource.loader.path", config.getString(Keys.TEMPLATES_ROOT) + "/");
+ properties.setProperty("runtime.log.logsystem.class", NullLogChute.class.getName());
+
+ String address;
+ try {
+ address = config.getString(Keys.WEB_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (UnknownHostException e) {
+ address = "localhost";
+ }
+
+ String url = config.getString(
+ Keys.WEB_URL, URIUtil.newURI("http", address, config.getInteger(Keys.WEB_PORT), "", ""));
+ properties.setProperty("web.url", url);
+
+ VelocityEngine velocityEngine = new VelocityEngine();
+ velocityEngine.init(properties);
+ return velocityEngine;
+ }
+
}