Dependency fix + Local/Remote Library support
[fanfix.git] / src / be / nikiroo / fanfix / RemoteLibraryServer.java
1 package be.nikiroo.fanfix;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.List;
6 import java.util.Map;
7
8 import be.nikiroo.fanfix.data.MetaData;
9 import be.nikiroo.utils.Version;
10 import be.nikiroo.utils.serial.ConnectActionServer;
11 import be.nikiroo.utils.serial.Server;
12
13 public class RemoteLibraryServer extends Server {
14
15 public RemoteLibraryServer(int port) throws IOException {
16 super(Version.getCurrentVersion(), port, true);
17 }
18
19 @Override
20 protected Object onRequest(ConnectActionServer action,
21 Version clientVersion, Object data) throws Exception {
22 String command = null;
23 String args = null;
24 if (data instanceof String) {
25 command = (String) data;
26 int pos = command.indexOf(" ");
27 if (pos >= 0) {
28 args = command.substring(pos + 1);
29 command = command.substring(0, pos);
30 }
31 }
32
33 System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command,
34 args));
35
36 if (command != null) {
37 if (command.equals("GET_METADATA")) {
38 if (args != null && args.equals("*")) {
39 List<MetaData> metas = Instance.getLibrary().getMetas(null);
40 return metas.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 }