1 package be
.nikiroo
.fanfix
;
3 import java
.awt
.image
.BufferedImage
;
5 import java
.io
.IOException
;
6 import java
.util
.ArrayList
;
9 import be
.nikiroo
.fanfix
.data
.MetaData
;
10 import be
.nikiroo
.fanfix
.data
.Story
;
11 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
12 import be
.nikiroo
.utils
.Progress
;
13 import be
.nikiroo
.utils
.Version
;
14 import be
.nikiroo
.utils
.serial
.ConnectActionClient
;
17 * This {@link BasicLibrary} will access a remote server to list the available
18 * stories, and download the one you try to load to the local directory
19 * specified in the configuration.
23 public class RemoteLibrary
extends BasicLibrary
{
28 private LocalLibrary lib
;
29 private List
<MetaData
> metas
;
32 * Create a {@link RemoteLibrary} linked to the given server.
35 * the host to contact or NULL for localhost
37 * the port to contact it on
39 public RemoteLibrary(String host
, int port
) {
43 this.baseDir
= Instance
.getRemoteDir(host
);
44 this.baseDir
.mkdirs();
46 this.lib
= new LocalLibrary(baseDir
, OutputType
.INFO_TEXT
,
51 protected List
<MetaData
> getMetas(Progress pg
) {
55 metas
= new ArrayList
<MetaData
>();
58 new ConnectActionClient(host
, port
, true, null) {
59 public void action(Version serverVersion
) throws Exception
{
61 Object rep
= send("GET_METADATA *");
62 for (MetaData meta
: (MetaData
[]) rep
) {
65 } catch (Exception e
) {
70 } catch (IOException e
) {
79 public synchronized File
getFile(final String luid
) {
80 File file
= lib
.getFile(luid
);
82 final File
[] tmp
= new File
[1];
84 new ConnectActionClient(host
, port
, true, null) {
85 public void action(Version serverVersion
) throws Exception
{
87 Object rep
= send("GET_STORY " + luid
);
88 Story story
= (Story
) rep
;
90 lib
.save(story
, luid
, null);
91 tmp
[0] = lib
.getFile(luid
);
93 } catch (Exception e
) {
98 } catch (IOException e
) {
106 MetaData meta
= getInfo(luid
);
114 public BufferedImage
getCover(String luid
) {
115 // Retrieve it from the network if needed:
116 if (lib
.getInfo(luid
) == null) {
120 return lib
.getCover(luid
);
124 protected void clearCache() {
130 public synchronized Story
save(Story story
, String luid
, Progress pg
)
132 throw new java
.lang
.InternalError(
133 "No write support allowed on remote Libraries");
137 protected int getNextId() {
138 throw new java
.lang
.InternalError(
139 "No write support allowed on remote Libraries");
143 protected void doDelete(String luid
) throws IOException
{
144 throw new java
.lang
.InternalError(
145 "No write support allowed on remote Libraries");
149 protected Story
doSave(Story story
, Progress pg
) throws IOException
{
150 throw new java
.lang
.InternalError(
151 "No write support allowed on remote Libraries");