Fixed date format and introduced an encoding error
This commit is contained in:
parent
f5deb2243c
commit
cc6fdf38ce
14 changed files with 11991 additions and 27 deletions
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//pages/js/moment-with-locales.js=UTF-8
|
|
@ -1,12 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<title>ChatServer</title>
|
||||
<meta charset="UTF-8"/>
|
||||
<script src="js/jquery-3.1.0.js"></script>
|
||||
<script src="js/moment-with-locales.js" charset="UTF-8"></script>
|
||||
<script src="js/utils.js"></script>
|
||||
<script src="js/message.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
<script src="js/register.js"></script>
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="stylesheet" href="css/style.css"/>
|
||||
<script src="js/index.js"></script>
|
||||
</head>
|
||||
|
|
|
@ -5,10 +5,19 @@
|
|||
$(document).ready(function () {
|
||||
var cmsgs = document.getElementById("channelmessages");
|
||||
if (cmsgs != null && cmsgs.childElementCount > 0) {
|
||||
cmsgs.forEach(function (item) {
|
||||
var ctime = item.getElementById("converttime");
|
||||
ctime.innerText = new Date(ctime.innerText * 1).toDateString();
|
||||
});
|
||||
var nodes = cmsgs.children;
|
||||
for (var x = 0; x < nodes.length; x++) {
|
||||
var item = nodes[x];
|
||||
console.log(item);
|
||||
var spans = item.getElementsByTagName("span");
|
||||
var ctime = null;
|
||||
for (var i = 0; i < spans.length; i++)
|
||||
if (spans[i].className.split(' ').indexOf("converttime") > -1)
|
||||
ctime = spans[i];
|
||||
if (ctime != null)
|
||||
ctime.innerText = moment(ctime.innerText).format("lll");
|
||||
//ctime.innerText = new Date(ctime.innerText * 1).toDateString();
|
||||
}
|
||||
cmsgs.lastElementChild.scrollIntoView(false);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -9,8 +9,9 @@ var sendmsg = function sendmsg(msginputta) {
|
|||
var respfunc = function respfunc(result) {
|
||||
if (result != "Success") { //on success result is string
|
||||
var msginput = document.getElementById("msginput");
|
||||
if (result.responseText == "JSONERROR") {
|
||||
if (result.responseText.indexOf("JSONERROR") != -1) {
|
||||
console.log("Got JSON error. Retrying...");
|
||||
console.log(result.responseText);
|
||||
sendmsg(msginput);
|
||||
}
|
||||
else {
|
||||
|
|
11954
pages/js/moment-with-locales.js
Normal file
11954
pages/js/moment-with-locales.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,6 @@ import org.reflections.util.ConfigurationBuilder;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.norbipeti.chat.server.data.*;
|
||||
import io.github.norbipeti.chat.server.db.domain.*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.github.norbipeti.chat.server.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package io.github.norbipeti.chat.server.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class LoaderRefSerializer extends TypeAdapter<LoaderRef<?>> {
|
|||
in.nextName();
|
||||
long id = in.nextLong();
|
||||
if (!in.nextName().equals("class")) {
|
||||
new Exception("Error: Next isn't \"class\"").printStackTrace(); // TODO: Same as at LoaderCollectionSerializer
|
||||
new Exception("Error: Next isn't \"class\"").printStackTrace();
|
||||
return null;
|
||||
}
|
||||
Class<? extends SavedData> cl;
|
||||
|
@ -48,12 +48,11 @@ public class LoaderRefSerializer extends TypeAdapter<LoaderRef<?>> {
|
|||
}
|
||||
LoaderRef<? extends SavedData> ref;
|
||||
try {
|
||||
ref = LoaderRef.class.getDeclaredConstructor(Class.class).newInstance(cl);
|
||||
ref = LoaderRef.class.getDeclaredConstructor(Class.class, Long.class).newInstance(cl, id);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
ref.id = id;
|
||||
in.endObject();
|
||||
return ref;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.github.norbipeti.chat.server.io;
|
|||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -15,6 +14,7 @@ import java.util.Map.Entry;
|
|||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -62,8 +62,8 @@ public class IOHelper {
|
|||
}
|
||||
|
||||
public static String ReadFile(File file) throws FileNotFoundException, IOException {
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
LogManager.getLogger().debug(content); // TODO: FIx UTF-8 file reading
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package io.github.norbipeti.chat.server.page;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -61,8 +63,10 @@ public class IndexPage extends Page {
|
|||
for (Message message : chunk.getMessages()) {
|
||||
Element msgelement = channelmessages.appendElement("div");
|
||||
Element header = msgelement.appendElement("p");
|
||||
header.text(message.getSender().get().getName() + " - <span id=\"converttime\">"
|
||||
+ message.getTime().getTime() + "</span>");
|
||||
header.text(message.getSender().get().getName() + " - ");
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
header.appendElement("span").addClass("converttime").text(isoFormat.format(message.getTime()));
|
||||
Element body = msgelement.appendElement("p");
|
||||
body.text(message.getMessage()); // TODO: Use JavaScript to convert time
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import io.github.norbipeti.chat.server.io.IOHelper;
|
|||
|
||||
/**
|
||||
* Add to {@link Main}.Pages
|
||||
*
|
||||
*/
|
||||
public abstract class Page implements HttpHandler {
|
||||
public abstract String GetName();
|
||||
|
@ -42,7 +41,7 @@ public abstract class Page implements HttpHandler {
|
|||
str.print("</pre>");
|
||||
IOHelper.SendResponse(500, baos.toString(StandardCharsets.ISO_8859_1), exchange);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace(); //TODO: Message listener JS
|
||||
e1.printStackTrace(); // TODO: Message listener JS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ import io.github.norbipeti.chat.server.db.domain.User;
|
|||
import io.github.norbipeti.chat.server.io.IOHelper;
|
||||
|
||||
public class ReceiveMessageAjaxPage extends Page {
|
||||
|
||||
// http://stackoverflow.com/questions/9242404/javascript-listen-to-server
|
||||
@Override
|
||||
public String GetName() {
|
||||
return "receivemessage"; // TODO: Update cookie every once in a while
|
||||
return "receivemessage";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,10 +32,7 @@ public class ReceiveMessageAjaxPage extends Page {
|
|||
}
|
||||
JsonObject obj = IOHelper.GetPOSTJSON(exchange);
|
||||
if (obj == null) {
|
||||
/*
|
||||
* IOHelper.SendResponse(400, "<h1>400 Bad request</h1><p>Not a JSON string!</p><p>" + IOHelper.GetPOST(exchange) + "</p>", exchange);
|
||||
*/
|
||||
IOHelper.SendResponse(400, "JSONERROR", exchange);
|
||||
IOHelper.SendResponse(400, "JSONERROR: " + IOHelper.GetPOST(exchange), exchange);
|
||||
return;
|
||||
}
|
||||
if (!obj.has("message") || !obj.has("conversation")) {
|
||||
|
|
|
@ -29,7 +29,10 @@ public class ScriptsPage extends Page {
|
|||
if (!jsfile.exists())
|
||||
IOHelper.SendResponse(404, "<h1>JavaScript file not found</h1>", exchange);
|
||||
else
|
||||
{
|
||||
exchange.getResponseHeaders().add("Content-Type", "application/javascript; charset=UTF-8");
|
||||
IOHelper.SendResponse(200, IOHelper.ReadFile(jsfile), exchange);
|
||||
}
|
||||
} else
|
||||
LogManager.getLogger().log(Level.DEBUG, exchange.getRequestURI().getPath());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue