Code cleanup: Libraries/Readers
[fanfix.git] / src / be / nikiroo / fanfix / library / RemoteLibraryServer.java
CommitLineData
e42573a0 1package be.nikiroo.fanfix.library;
b0e88ebd 2
b0e88ebd 3import java.io.IOException;
68e2c6d2 4import java.util.List;
b0e88ebd 5
e42573a0 6import be.nikiroo.fanfix.Instance;
b0e88ebd
NR
7import be.nikiroo.fanfix.data.MetaData;
8import be.nikiroo.utils.Version;
9import be.nikiroo.utils.serial.ConnectActionServer;
10import be.nikiroo.utils.serial.Server;
11
12public class RemoteLibraryServer extends Server {
13
14 public RemoteLibraryServer(int port) throws IOException {
15 super(Version.getCurrentVersion(), port, true);
16 }
17
18 @Override
19 protected Object onRequest(ConnectActionServer action,
20 Version clientVersion, Object data) throws Exception {
21 String command = null;
22 String args = null;
23 if (data instanceof String) {
24 command = (String) data;
25 int pos = command.indexOf(" ");
26 if (pos >= 0) {
27 args = command.substring(pos + 1);
28 command = command.substring(0, pos);
29 }
30 }
31
32 System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command,
33 args));
34
35 if (command != null) {
36 if (command.equals("GET_METADATA")) {
37 if (args != null && args.equals("*")) {
68e2c6d2
NR
38 List<MetaData> metas = Instance.getLibrary().getMetas(null);
39 return metas.toArray(new MetaData[] {});
b0e88ebd
NR
40 }
41 } else if (command.equals("GET_STORY")) {
42 if (args != null) {
43 return Instance.getLibrary().getStory(args, null);
44 }
45 }
46 }
47
48 return null;
49 }
50}