implemented finde transl
This commit is contained in:
2
resources/js/jquery-3.5.1.min.js
vendored
Normal file
2
resources/js/jquery-3.5.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -10,6 +10,11 @@ function addTile(tile,x,y){
|
|||||||
console.log("addTile:",tile.id,x,y);
|
console.log("addTile:",tile.id,x,y);
|
||||||
x = Math.floor(x/SQUARE);
|
x = Math.floor(x/SQUARE);
|
||||||
y = Math.floor(y/SQUARE);
|
y = Math.floor(y/SQUARE);
|
||||||
|
$.ajax({
|
||||||
|
url : 'plan',
|
||||||
|
method: 'POST',
|
||||||
|
data : {mode:mode,tile:tile.id,x:x,y:y}
|
||||||
|
});
|
||||||
var id = 'tile-'+x+'-'+y;
|
var id = 'tile-'+x+'-'+y;
|
||||||
$('#'+id).remove();
|
$('#'+id).remove();
|
||||||
var tile = $(tile).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
|
var tile = $(tile).clone().css({left:(30*x)+'px',top:(30*y)+'px','border':''}).attr('id',id);
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -33,6 +36,7 @@ public class Application {
|
|||||||
private static Plan plan;
|
private static Plan plan;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
|
||||||
private static final String PORT = "port";
|
private static final String PORT = "port";
|
||||||
|
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
||||||
@@ -79,16 +83,26 @@ public class Application {
|
|||||||
client.sendResponseHeaders(code, msg.length());
|
client.sendResponseHeaders(code, msg.length());
|
||||||
LOG.error(msg);
|
LOG.error(msg);
|
||||||
OutputStream out = client.getResponseBody();
|
OutputStream out = client.getResponseBody();
|
||||||
out.write(msg.getBytes(StandardCharsets.UTF_8));
|
out.write(msg.getBytes(UTF8));
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String t(String text, Object...fills) {
|
private static HashMap<String, String> inflate(byte[] data) {
|
||||||
return Translation.get(Application.class, text, fills);
|
return inflate(new String(data,UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendPlan(HttpExchange client) throws IOException {
|
private static HashMap<String, String> inflate(String data) {
|
||||||
send(client,plan.html().style("css/style.css").js("js/jquery-3.5.1.slim.min.js").js("js/plan.js"));
|
LOG.debug("inflate({})",data);
|
||||||
|
HashMap<String, String> params = new HashMap<String, String>();
|
||||||
|
if (data == null || data.trim().isEmpty()) return params;
|
||||||
|
String[] parts = data.split("&");
|
||||||
|
|
||||||
|
for (String part : parts) {
|
||||||
|
String[] entry = part.split("=", 2);
|
||||||
|
params.put(URLDecoder.decode(entry[0],UTF8),URLDecoder.decode(entry[1], UTF8));
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void send(HttpExchange client, Page response) throws IOException {
|
private static void send(HttpExchange client, Page response) throws IOException {
|
||||||
@@ -97,7 +111,23 @@ public class Application {
|
|||||||
client.getResponseHeaders().add("content-type", "text/html");
|
client.getResponseHeaders().add("content-type", "text/html");
|
||||||
client.sendResponseHeaders(200, html.length());
|
client.sendResponseHeaders(200, html.length());
|
||||||
OutputStream os = client.getResponseBody();
|
OutputStream os = client.getResponseBody();
|
||||||
os.write(html.toString().getBytes(StandardCharsets.UTF_8));
|
os.write(html.toString().getBytes(UTF8));
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendPlan(HttpExchange client) throws IOException {
|
||||||
|
HashMap<String, String> params = inflate(client.getRequestBody().readAllBytes());
|
||||||
|
try {
|
||||||
|
if (!params.isEmpty()) {
|
||||||
|
send(client,plan.process(params));
|
||||||
|
} else send(client,plan.html().style("css/style.css").js("js/jquery-3.5.1.min.js").js("js/plan.js"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Error during sendPlan(): {}",e);
|
||||||
|
send(client,new Page().append(e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String t(String text, Object...fills) {
|
||||||
|
return Translation.get(Application.class, text, fills);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package de.srsoftware.web4rail;
|
package de.srsoftware.web4rail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.tiles.DiagES;
|
import de.srsoftware.web4rail.tiles.DiagES;
|
||||||
import de.srsoftware.web4rail.tiles.DiagNE;
|
import de.srsoftware.web4rail.tiles.DiagNE;
|
||||||
@@ -19,18 +24,24 @@ import de.srsoftware.web4rail.tiles.TurnoutSW;
|
|||||||
import de.srsoftware.web4rail.tiles.TurnoutWS;
|
import de.srsoftware.web4rail.tiles.TurnoutWS;
|
||||||
|
|
||||||
public class Plan {
|
public class Plan {
|
||||||
|
private static final String MODE = "mode";
|
||||||
|
private static final String MODE_ADD = "1";
|
||||||
|
private static final String TILE = "tile";
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(Plan.class);
|
||||||
|
private static final String X = "x";
|
||||||
|
private static final String Y = "y";
|
||||||
|
|
||||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||||
|
|
||||||
public Tile set(int x,int y,Tile tile) {
|
private Tile addTile(String clazz, String xs, String ys) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
Tile old = null;
|
int x = Integer.parseInt(xs);
|
||||||
HashMap<Integer, Tile> column = tiles.get(x);
|
int y = Integer.parseInt(ys);
|
||||||
if (column == null) {
|
if (clazz == null) throw new NullPointerException(TILE+" must not be null!");
|
||||||
column = new HashMap<Integer,Tile>();
|
Class<Tile> tc = Tile.class;
|
||||||
tiles.put(x, column);
|
clazz = tc.getName().replace(".Tile", "."+clazz);
|
||||||
}
|
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||||
old = column.get(y);
|
set(x, y, tile);
|
||||||
column.put(y,tile.position(x, y));
|
return tile;
|
||||||
return old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile get(int x, int y) {
|
public Tile get(int x, int y) {
|
||||||
@@ -72,4 +83,39 @@ public class Plan {
|
|||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Page process(HashMap<String, String> params) {
|
||||||
|
Page page = new Page();
|
||||||
|
try {
|
||||||
|
String mode = params.get(MODE);
|
||||||
|
|
||||||
|
if (mode == null) throw new NullPointerException(MODE+" should not be null!");
|
||||||
|
switch (mode) {
|
||||||
|
case MODE_ADD:
|
||||||
|
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y));
|
||||||
|
return page.append(t("Added {}",tile.getClass().getSimpleName()));
|
||||||
|
default:
|
||||||
|
LOG.warn("Unknown mode: {}",mode);
|
||||||
|
}
|
||||||
|
return page.append("unknown "+MODE+": "+mode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return page.append(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile set(int x,int y,Tile tile) {
|
||||||
|
Tile old = null;
|
||||||
|
HashMap<Integer, Tile> column = tiles.get(x);
|
||||||
|
if (column == null) {
|
||||||
|
column = new HashMap<Integer,Tile>();
|
||||||
|
tiles.put(x, column);
|
||||||
|
}
|
||||||
|
old = column.get(y);
|
||||||
|
column.put(y,tile.position(x, y));
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String t(String message, Object...fills) {
|
||||||
|
return Translation.get(Application.class, message, fills);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user