Add a test for Library (before changing it)
[nikiroo-utils.git] / src / be / nikiroo / fanfix / RemoteLibraryServer.java
CommitLineData
b0e88ebd
NR
1package be.nikiroo.fanfix;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.Map;
6
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("*")) {
38 Map<MetaData, File> stories = Instance.getLibrary()
39 .getStories(null);
40 return stories.keySet().toArray(new MetaData[] {});
41 }
42 } else if (command.equals("GET_STORY")) {
43 if (args != null) {
44 return Instance.getLibrary().getStory(args, null);
45 }
46 }
47 }
48
49 return null;
50 }
51}