aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/MainModule.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-11 08:28:41 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-11 08:28:41 -0700
commita401b40ee3b69d5679031a1e1d7287a0a56f4160 (patch)
tree30b0a1dfdc6b396dcb12947f19307b749e531446 /src/main/java/org/traccar/MainModule.java
parent5b269c0e309b70866ad167fb148eafcbad5a8b26 (diff)
downloadtrackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.gz
trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.tar.bz2
trackermap-server-a401b40ee3b69d5679031a1e1d7287a0a56f4160.zip
Inject velocity engine
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;
+ }
+
}