aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/JuickApplication.java
diff options
context:
space:
mode:
authorGravatar Alex Bitney2016-02-07 00:00:41 +0200
committerGravatar Alex Bitney2016-02-07 00:00:41 +0200
commitc2d316449f85bd2b74ae9ffaa3d08b7a5ee282cf (patch)
treece808c6d65e4a61913497f5d397473f75fadc701 /src/main/java/com/juick/JuickApplication.java
parent1fffebc18bbdbe87b456e2b3bd66e9ce5a6afcb8 (diff)
added tags when posting new message
added templates engine (rythm engine) and moved something to it. WARNING: textext plugin does not work when minimized, and also I fixed bug in it.
Diffstat (limited to 'src/main/java/com/juick/JuickApplication.java')
-rw-r--r--src/main/java/com/juick/JuickApplication.java56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/main/java/com/juick/JuickApplication.java b/src/main/java/com/juick/JuickApplication.java
index ce242222..e546f5a8 100644
--- a/src/main/java/com/juick/JuickApplication.java
+++ b/src/main/java/com/juick/JuickApplication.java
@@ -4,6 +4,7 @@ import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.s2s.S2SComponent;
+import org.rythmengine.Rythm;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
@@ -12,9 +13,7 @@ import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.Channels;
import java.nio.channels.CompletionHandler;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
@@ -32,17 +31,34 @@ public class JuickApplication {
private JdbcTemplate sql;
private JdbcTemplate sqlSearch;
private List<JuickComponent> components = new ArrayList<>();
+ private String applicationPath;
- public JuickApplication(Properties conf) throws IOException {
+ public JuickApplication(Properties conf, String applicationPath) throws IOException {
+ this.applicationPath = applicationPath;
executorService = Executors.newWorkStealingPool();
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(conf.getProperty("datasource_url"));
- sql = new JdbcTemplate(dataSource);
- DriverManagerDataSource searchDatasource = new DriverManagerDataSource();
- searchDatasource.setDriverClassName("com.mysql.jdbc.Driver");
- searchDatasource.setUrl("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000");
- sqlSearch = new JdbcTemplate(searchDatasource);
+ initDataSources(conf);
+ initSockets(conf);
+ initComponents(conf);
+ initRythm(conf);
+ }
+
+ private void initRythm(Properties conf) {
+ String rythmMode = conf.getProperty("rythm_mode", "prod");
+ Map<String, Object> map = new HashMap<>();
+ map.put("home.template", applicationPath+"/WEB-INF/classes/templates");
+ map.put("rythm.engine.mode", rythmMode);
+ Rythm.init(map);
+ }
+
+ private void initComponents(Properties conf) {
+ if (!isHttpDevMode()) {
+ addComponent(new S2SComponent(this, conf));
+ addComponent(new CrosspostComponent(sql, conf));
+ addComponent(new PushComponent(sql, conf));
+ }
+ }
+
+ private void initSockets(final Properties conf) throws IOException {
AsynchronousSocketChannel socket = AsynchronousSocketChannel.open();
socket.connect(new InetSocketAddress("localhost", 5347), socket,
new CompletionHandler<Void, AsynchronousSocketChannel>() {
@@ -60,11 +76,17 @@ public class JuickApplication {
}
}
});
- if (!isHttpDevMode()) {
- addComponent(new S2SComponent(this, conf));
- addComponent(new CrosspostComponent(sql, conf));
- addComponent(new PushComponent(sql, conf));
- }
+ }
+
+ private void initDataSources(Properties conf) {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSource.setUrl(conf.getProperty("datasource_url"));
+ sql = new JdbcTemplate(dataSource);
+ DriverManagerDataSource searchDatasource = new DriverManagerDataSource();
+ searchDatasource.setDriverClassName("com.mysql.jdbc.Driver");
+ searchDatasource.setUrl("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000");
+ sqlSearch = new JdbcTemplate(searchDatasource);
}
public static boolean isHttpDevMode() {