1 package be
.nikiroo
.fanfix
.library
;
3 import java
.awt
.image
.BufferedImage
;
5 import java
.io
.IOException
;
6 import java
.util
.ArrayList
;
9 import be
.nikiroo
.fanfix
.Instance
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
11 import be
.nikiroo
.fanfix
.data
.Story
;
12 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
13 import be
.nikiroo
.utils
.Progress
;
14 import be
.nikiroo
.utils
.Version
;
15 import be
.nikiroo
.utils
.serial
.ConnectActionClient
;
18 * This {@link BasicLibrary} will access a remote server to list the available
19 * stories, and download the one you try to load to the local directory
20 * specified in the configuration.
24 public class RemoteLibrary
extends BasicLibrary
{
29 private LocalLibrary lib
;
30 private List
<MetaData
> metas
;
33 * Create a {@link RemoteLibrary} linked to the given server.
36 * the host to contact or NULL for localhost
38 * the port to contact it on
40 public RemoteLibrary(String host
, int port
) {
44 this.baseDir
= Instance
.getRemoteDir(host
);
45 this.baseDir
.mkdirs();
47 this.lib
= new LocalLibrary(baseDir
, OutputType
.INFO_TEXT
,
52 protected List
<MetaData
> getMetas(Progress pg
) {
56 metas
= new ArrayList
<MetaData
>();
59 new ConnectActionClient(host
, port
, true, null) {
60 public void action(Version serverVersion
) throws Exception
{
62 Object rep
= send("GET_METADATA *");
63 for (MetaData meta
: (MetaData
[]) rep
) {
66 } catch (Exception e
) {
71 } catch (IOException e
) {
80 public synchronized File
getFile(final String luid
) {
81 File file
= lib
.getFile(luid
);
83 final File
[] tmp
= new File
[1];
85 new ConnectActionClient(host
, port
, true, null) {
86 public void action(Version serverVersion
) throws Exception
{
88 Object rep
= send("GET_STORY " + luid
);
89 Story story
= (Story
) rep
;
91 lib
.save(story
, luid
, null);
92 tmp
[0] = lib
.getFile(luid
);
94 } catch (Exception e
) {
99 } catch (IOException e
) {
107 MetaData meta
= getInfo(luid
);
115 public BufferedImage
getCover(String luid
) {
116 // Retrieve it from the network if needed:
117 if (lib
.getInfo(luid
) == null) {
121 return lib
.getCover(luid
);
125 protected void clearCache() {
131 public synchronized Story
save(Story story
, String luid
, Progress pg
)
133 throw new java
.lang
.InternalError(
134 "No write support allowed on remote Libraries");
138 protected int getNextId() {
139 throw new java
.lang
.InternalError(
140 "No write support allowed on remote Libraries");
144 protected void doDelete(String luid
) throws IOException
{
145 throw new java
.lang
.InternalError(
146 "No write support allowed on remote Libraries");
150 protected Story
doSave(Story story
, Progress pg
) throws IOException
{
151 throw new java
.lang
.InternalError(
152 "No write support allowed on remote Libraries");