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 ones 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 public String
getLibraryName() {
53 return host
+ ":" + port
;
57 protected List
<MetaData
> getMetas(Progress pg
) {
61 metas
= new ArrayList
<MetaData
>();
64 new ConnectActionClient(host
, port
, true, null) {
66 public void action(Version serverVersion
) throws Exception
{
68 Object rep
= send("GET_METADATA *");
69 for (MetaData meta
: (MetaData
[]) rep
) {
72 } catch (Exception e
) {
77 } catch (IOException e
) {
86 public synchronized File
getFile(final String luid
) {
87 File file
= lib
.getFile(luid
);
89 final File
[] tmp
= new File
[1];
91 new ConnectActionClient(host
, port
, true, null) {
93 public void action(Version serverVersion
) throws Exception
{
95 Object rep
= send("GET_STORY " + luid
);
96 Story story
= (Story
) rep
;
98 lib
.save(story
, luid
, null);
99 tmp
[0] = lib
.getFile(luid
);
101 } catch (Exception e
) {
106 } catch (IOException e
) {
114 MetaData meta
= getInfo(luid
);
122 public BufferedImage
getCover(String luid
) {
123 // Retrieve it from the network if needed:
124 if (lib
.getInfo(luid
) == null) {
128 return lib
.getCover(luid
);
132 protected void clearCache() {
138 public synchronized Story
save(Story story
, String luid
, Progress pg
)
140 throw new java
.lang
.InternalError(
141 "No write support allowed on remote Libraries");
145 public synchronized void delete(String luid
) throws IOException
{
146 throw new java
.lang
.InternalError(
147 "No write support allowed on remote Libraries");
151 public void setSourceCover(String source
, String luid
) {
152 throw new java
.lang
.InternalError(
153 "No write support allowed on remote Libraries");
156 // All the following methods are only used by Save and Delete in
160 protected int getNextId() {
161 throw new java
.lang
.InternalError("Should not have been called");
165 protected void doDelete(String luid
) throws IOException
{
166 throw new java
.lang
.InternalError("Should not have been called");
170 protected Story
doSave(Story story
, Progress pg
) throws IOException
{
171 throw new java
.lang
.InternalError("Should not have been called");