git://git.nikiroo.be
/
nikiroo-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add get custom covers
[nikiroo-utils.git]
/
src
/
be
/
nikiroo
/
fanfix
/
library
/
RemoteLibrary.java
diff --git
a/src/be/nikiroo/fanfix/library/RemoteLibrary.java
b/src/be/nikiroo/fanfix/library/RemoteLibrary.java
index 4d8d5123bc787bcf65167bc29dd2d8d840200083..3a60e02c9ed6fc845193574f897c3bd9b0ecc60a 100644
(file)
--- a/
src/be/nikiroo/fanfix/library/RemoteLibrary.java
+++ b/
src/be/nikiroo/fanfix/library/RemoteLibrary.java
@@
-21,6
+21,8
@@
import be.nikiroo.utils.serial.server.ConnectActionClientObject;
* This {@link BasicLibrary} will access a remote server to list the available
* stories, and download the ones you try to load to the local directory
* specified in the configuration.
* This {@link BasicLibrary} will access a remote server to list the available
* stories, and download the ones you try to load to the local directory
* specified in the configuration.
+ * <p>
+ * This remote library uses a custom fanfix:// protocol.
*
* @author niki
*/
*
* @author niki
*/
@@
-35,18
+37,13
@@
public class RemoteLibrary extends BasicLibrary {
}
@Override
}
@Override
- public Object send(Object data)
throws IOException,
- NoSuchFieldException, NoSuchMethodException,
+ public Object send(Object data)
+
throws IOException,
NoSuchFieldException, NoSuchMethodException,
ClassNotFoundException {
Object rep = super.send(data);
if (rep instanceof RemoteLibraryException) {
RemoteLibraryException remoteEx = (RemoteLibraryException) rep;
ClassNotFoundException {
Object rep = super.send(data);
if (rep instanceof RemoteLibraryException) {
RemoteLibraryException remoteEx = (RemoteLibraryException) rep;
- IOException cause = remoteEx.getCause();
- if (cause == null) {
- cause = new IOException("IOException");
- }
-
- throw cause;
+ throw remoteEx.unwrapException();
}
return rep;
}
return rep;
@@
-65,7
+62,7
@@
public class RemoteLibrary extends BasicLibrary {
* Create a {@link RemoteLibrary} linked to the given server.
* <p>
* Note that the key is structured:
* Create a {@link RemoteLibrary} linked to the given server.
* <p>
* Note that the key is structured:
- * <tt><b><i>xxx</i></b>(|<b><i>yyy</i></b>
|<b>w
l</b>)(|<b>rw</b>)</tt>
+ * <tt><b><i>xxx</i></b>(|<b><i>yyy</i></b>
(|<b>wl</b>)(|<b>b
l</b>)(|<b>rw</b>)</tt>
* <p>
* Note that anything before the first pipe (<tt>|</tt>) character is
* considered to be the encryption key, anything after that character is
* <p>
* Note that anything before the first pipe (<tt>|</tt>) character is
* considered to be the encryption key, anything after that character is
@@
-80,16
+77,16
@@
public class RemoteLibrary extends BasicLibrary {
* <li><b><i>yyy</i></b>: the secondary key</li>
* <li><b>rw</b>: flag to allow read and write access if it is not the
* default on this server</li>
* <li><b><i>yyy</i></b>: the secondary key</li>
* <li><b>rw</b>: flag to allow read and write access if it is not the
* default on this server</li>
- * <li><b>
wl</b>: flag to allow access to all the stories (bypassing the
- *
whitelist if it exists)
</li>
+ * <li><b>
bl</b>: flag to bypass the blacklist (if it exists)</li>
+ *
<li><b>wl</b>: flag to bypass the whitelist if it exists
</li>
* </ul>
* </ul>
- *
+ *
<p>
* Some examples:
* <ul>
* <li><b>my_key</b>: normal connection, will take the default server
* options</li>
* Some examples:
* <ul>
* <li><b>my_key</b>: normal connection, will take the default server
* options</li>
- * <li><b>my_key|agzyzz|wl
</b>: will ask to bypass the white list (if it
- * exists)</li>
+ * <li><b>my_key|agzyzz|wl
|bl</b>: will ask to bypass the black list and the
+ *
white list (if it
exists)</li>
* <li><b>my_key|agzyzz|rw</b>: will ask read-write access (if the default
* is read-only)</li>
* <li><b>my_key|agzyzz|wl|rw</b>: will ask both read-write access and white
* <li><b>my_key|agzyzz|rw</b>: will ask read-write access (if the default
* is read-only)</li>
* <li><b>my_key|agzyzz|wl|rw</b>: will ask both read-write access and white
@@
-118,28
+115,33
@@
public class RemoteLibrary extends BasicLibrary {
this.subkey = "";
}
this.subkey = "";
}
+ if (host.startsWith("fanfix://")) {
+ host = host.substring("fanfix://".length());
+ }
+
this.host = host;
this.port = port;
}
@Override
public String getLibraryName() {
this.host = host;
this.port = port;
}
@Override
public String getLibraryName() {
- return (rw ? "[READ-ONLY] " : "") + host + ":" + port;
+ return (rw ? "[READ-ONLY] " : "") +
"fanfix://" +
host + ":" + port;
}
@Override
public Status getStatus() {
}
@Override
public Status getStatus() {
- Instance.getTraceHandler().trace("Getting remote lib status...");
+ Instance.getInstance().getTraceHandler()
+ .trace("Getting remote lib status...");
Status status = getStatusDo();
Status status = getStatusDo();
- Instance.getTraceHandler().trace("Remote lib status: " + status);
+ Instance.getInstance().getTraceHandler()
+ .trace("Remote lib status: " + status);
return status;
}
private Status getStatusDo() {
final Status[] result = new Status[1];
return status;
}
private Status getStatusDo() {
final Status[] result = new Status[1];
- result[0] = Status.INVALID;
-
+ result[0] = null;
try {
new RemoteConnectAction() {
@Override
try {
new RemoteConnectAction() {
@Override
@@
-185,8
+187,8
@@
public class RemoteLibrary extends BasicLibrary {
@Override
public void action(ConnectActionClientObject action)
throws Exception {
@Override
public void action(ConnectActionClientObject action)
throws Exception {
- Object rep = action
.send(new Object[] { subkey, "GET_COVER",
- luid });
+ Object rep = action
+
.send(new Object[] { subkey, "GET_COVER",
luid });
result[0] = (Image) rep;
}
});
result[0] = (Image) rep;
}
});
@@
-237,8
+239,8
@@
public class RemoteLibrary extends BasicLibrary {
pg = new Progress();
}
pg = new Progress();
}
- Object rep = action
.send(new Object[] { subkey, "GET_STORY",
- luid });
+ Object rep = action
+
.send(new Object[] { subkey, "GET_STORY",
luid });
MetaData meta = null;
if (rep instanceof MetaData) {
MetaData meta = null;
if (rep instanceof MetaData) {
@@
-357,8
+359,9
@@
public class RemoteLibrary extends BasicLibrary {
@Override
// Could work (more slowly) without it
@Override
// Could work (more slowly) without it
- public
Story
imprt(final URL url, Progress pg) throws IOException {
+ public
MetaData
imprt(final URL url, Progress pg) throws IOException {
// Import the file locally if it is actually a file
// Import the file locally if it is actually a file
+
if (url == null || url.getProtocol().equalsIgnoreCase("file")) {
return super.imprt(url, pg);
}
if (url == null || url.getProtocol().equalsIgnoreCase("file")) {
return super.imprt(url, pg);
}
@@
-369,13
+372,7
@@
public class RemoteLibrary extends BasicLibrary {
pg = new Progress();
}
pg = new Progress();
}
- pg.setMinMax(0, 2);
- Progress pgImprt = new Progress();
- Progress pgGet = new Progress();
- pg.addProgress(pgImprt, 1);
- pg.addProgress(pgGet, 1);
-
- final Progress pgF = pgImprt;
+ final Progress pgF = pg;
final String[] luid = new String[1];
connectRemoteAction(new RemoteAction() {
final String[] luid = new String[1];
connectRemoteAction(new RemoteAction() {
@@
-384,8
+381,8
@@
public class RemoteLibrary extends BasicLibrary {
throws Exception {
Progress pg = pgF;
throws Exception {
Progress pg = pgF;
- Object rep = action.send(
new Object[] { subkey, "IMPORT",
- url.toString() });
+ Object rep = action.send(
+
new Object[] { subkey, "IMPORT",
url.toString() });
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {
@@
-404,11
+401,8
@@
public class RemoteLibrary extends BasicLibrary {
throw new IOException("Remote failure");
}
throw new IOException("Remote failure");
}
- Story story = getStory(luid[0], pgGet);
- pgGet.done();
-
pg.done();
pg.done();
- return
story
;
+ return
getInfo(luid[0])
;
}
@Override
}
@Override
@@
-439,26
+433,32
@@
public class RemoteLibrary extends BasicLibrary {
}
@Override
}
@Override
- public
synchronized
File getFile(final String luid, Progress pg) {
+ public File getFile(final String luid, Progress pg) {
throw new java.lang.InternalError(
"Operation not supportorted on remote Libraries");
}
/**
* Stop the server.
throw new java.lang.InternalError(
"Operation not supportorted on remote Libraries");
}
/**
* Stop the server.
+ *
+ * @throws IOException
+ * in case of I/O errors
+ * @throws SSLException
+ * when the key was not accepted
*/
*/
- public void exit() throws IOException {
+ public void exit() throws IOException
, SSLException
{
connectRemoteAction(new RemoteAction() {
@Override
public void action(ConnectActionClientObject action)
throws Exception {
action.send(new Object[] { subkey, "EXIT" });
connectRemoteAction(new RemoteAction() {
@Override
public void action(ConnectActionClientObject action)
throws Exception {
action.send(new Object[] { subkey, "EXIT" });
+ Thread.sleep(100);
}
});
}
@Override
}
});
}
@Override
- public
synchronized
MetaData getInfo(String luid) throws IOException {
+ public MetaData getInfo(String luid) throws IOException {
List<MetaData> metas = getMetasList(luid, null);
if (!metas.isEmpty()) {
return metas.get(0);
List<MetaData> metas = getMetasList(luid, null);
if (!metas.isEmpty()) {
return metas.get(0);
@@
-531,8
+531,8
@@
public class RemoteLibrary extends BasicLibrary {
pg = new Progress();
}
pg = new Progress();
}
- Object rep = action
.send(new Object[] { subkey, "GET_METADATA",
- luid });
+ Object rep = action
+
.send(new Object[] { subkey, "GET_METADATA",
luid });
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {
@@
-569,7
+569,7
@@
public class RemoteLibrary extends BasicLibrary {
@Override
protected void onError(Exception e) {
if (!(e instanceof IOException)) {
@Override
protected void onError(Exception e) {
if (!(e instanceof IOException)) {
- Instance.getTraceHandler().error(e);
+ Instance.get
Instance().get
TraceHandler().error(e);
return;
}
return;
}