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
weblib: set custom covers
[nikiroo-utils.git]
/
src
/
be
/
nikiroo
/
fanfix
/
library
/
WebLibrary.java
diff --git
a/src/be/nikiroo/fanfix/library/WebLibrary.java
b/src/be/nikiroo/fanfix/library/WebLibrary.java
index 7f775830edf8c7641eeb3303abdddf3fcdb48fbd..796533080fba899b60a553f5ac90b80d71d56f58 100644
(file)
--- a/
src/be/nikiroo/fanfix/library/WebLibrary.java
+++ b/
src/be/nikiroo/fanfix/library/WebLibrary.java
@@
-22,6
+22,7
@@
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.Image;
import be.nikiroo.utils.Progress;
+import be.nikiroo.utils.Version;
/**
* This {@link BasicLibrary} will access a remote server to list the available
/**
* This {@link BasicLibrary} will access a remote server to list the available
@@
-107,16
+108,30
@@
public class WebLibrary extends BasicLibrary {
this.rw = false;
}
this.rw = false;
}
+ public Version getVersion() {
+ try {
+ InputStream in = post(WebLibraryUrls.VERSION_URL);
+ try {
+ return new Version(IOUtils.readSmallStream(in));
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ }
+
+ return new Version();
+ }
+
@Override
public Status getStatus() {
try {
@Override
public Status getStatus() {
try {
-
download("/"
);
+
post(WebLibraryUrls.INDEX_URL).close(
);
} catch (IOException e) {
try {
} catch (IOException e) {
try {
-
download("/style.css"
);
+
post("/style.css").close(
);
return Status.UNAUTHORIZED;
} catch (IOException ioe) {
return Status.UNAUTHORIZED;
} catch (IOException ioe) {
- return Status.
INVALID
;
+ return Status.
UNAVAILABLE
;
}
}
}
}
@@
-125,41
+140,52
@@
public class WebLibrary extends BasicLibrary {
@Override
public String getLibraryName() {
@Override
public String getLibraryName() {
- return (rw ? "[READ-ONLY] " : "") + host + ":" + port;
+ return (rw ? "[READ-ONLY] " : "") + host + ":" + port + " ("
+ + getVersion() + ")";
}
@Override
public Image getCover(String luid) throws IOException {
}
@Override
public Image getCover(String luid) throws IOException {
- InputStream in =
download("/story/" + luid + "/cover"
);
-
if (in != null)
{
+ InputStream in =
post(WebLibraryUrls.getStoryUrlCover(luid)
);
+
try
{
return new Image(in);
return new Image(in);
+ } finally {
+ in.close();
}
}
-
- return null;
}
@Override
}
@Override
- public Image getCustomSourceCover(final String source) throws IOException {
- // TODO maybe global system in BasicLib ?
- return null;
+ public Image getCustomSourceCover(String source) throws IOException {
+ InputStream in = post(WebLibraryUrls.getCoverUrlSource(source));
+ try {
+ return new Image(in);
+ } finally {
+ in.close();
+ }
}
@Override
}
@Override
- public Image getCustomAuthorCover(final String author) throws IOException {
- // TODO maybe global system in BasicLib ?
- return null;
+ public Image getCustomAuthorCover(String author) throws IOException {
+ InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author));
+ try {
+ return new Image(in);
+ } finally {
+ in.close();
+ }
}
@Override
public void setSourceCover(String source, String luid) throws IOException {
}
@Override
public void setSourceCover(String source, String luid) throws IOException {
- // TODO Auto-generated method stub
- throw new IOException("Not implemented yet");
+ Map<String, String> post = new HashMap<String, String>();
+ post.put("luid", luid);
+ post(WebLibraryUrls.getCoverUrlSource(source), post).close();
}
@Override
public void setAuthorCover(String author, String luid) throws IOException {
}
@Override
public void setAuthorCover(String author, String luid) throws IOException {
- // TODO Auto-generated method stub
- throw new IOException("Not implemented yet");
+ Map<String, String> post = new HashMap<String, String>();
+ post.put("luid", luid);
+ post(WebLibraryUrls.getCoverUrlAuthor(author), post).close();
}
@Override
}
@Override
@@
-169,7
+195,7
@@
public class WebLibrary extends BasicLibrary {
// TODO: pg
Story story;
// TODO: pg
Story story;
- InputStream in =
download("/story/" + luid + "/json"
);
+ InputStream in =
post(WebLibraryUrls.getStoryUrlJson(luid)
);
try {
JSONObject json = new JSONObject(IOUtils.readSmallStream(in));
story = JsonIO.toStory(json);
try {
JSONObject json = new JSONObject(IOUtils.readSmallStream(in));
story = JsonIO.toStory(json);
@@
-183,8
+209,8
@@
public class WebLibrary extends BasicLibrary {
int number = 1;
for (Paragraph para : chap) {
if (para.getType() == ParagraphType.IMAGE) {
int number = 1;
for (Paragraph para : chap) {
if (para.getType() == ParagraphType.IMAGE) {
- InputStream subin =
download
(
-
"/story/" + luid + "/" + chapNum + "/" + number
);
+ InputStream subin =
post
(
+
WebLibraryUrls.getStoryUrl(luid, chapNum, number)
);
try {
para.setContentImage(new Image(subin));
} finally {
try {
para.setContentImage(new Image(subin));
} finally {
@@
-204,7
+230,7
@@
public class WebLibrary extends BasicLibrary {
@Override
protected List<MetaData> getMetas(Progress pg) throws IOException {
List<MetaData> metas = new ArrayList<MetaData>();
@Override
protected List<MetaData> getMetas(Progress pg) throws IOException {
List<MetaData> metas = new ArrayList<MetaData>();
- InputStream in =
download("/list/luids"
);
+ InputStream in =
post(WebLibraryUrls.LIST_URL_METADATA
);
JSONArray jsonArr = new JSONArray(IOUtils.readSmallStream(in));
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject json = jsonArr.getJSONObject(i);
JSONArray jsonArr = new JSONArray(IOUtils.readSmallStream(in));
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject json = jsonArr.getJSONObject(i);
@@
-276,11
+302,19
@@
public class WebLibrary extends BasicLibrary {
"Operation not supportorted on remote Libraries");
}
"Operation not supportorted on remote Libraries");
}
- // starts with "/"
- private InputStream download(String path) throws IOException {
+ // starts with "/", never NULL
+ private InputStream post(String path) throws IOException {
+ return post(path, null);
+ }
+
+ // starts with "/", never NULL
+ private InputStream post(String path, Map<String, String> post)
+ throws IOException {
URL url = new URL(host + ":" + port + path);
URL url = new URL(host + ":" + port + path);
- Map<String, String> post = new HashMap<String, String>();
+ if (post == null) {
+ post = new HashMap<String, String>();
+ }
post.put("login", subkey);
post.put("password", key);
post.put("login", subkey);
post.put("password", key);