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.rw = false;
}
+ public Version getVersion() {
+ try {
+ InputStream in = download(WebLibraryUrls.VERSION_URL);
+ try {
+ return new Version(IOUtils.readSmallStream(in));
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ }
+
+ return null;
+ }
+
@Override
public Status getStatus() {
try {
- download("/");
+ download(WebLibraryUrls.INDEX_URL).close();
} catch (IOException e) {
try {
- download("/style.css");
+ download(WebLibraryUrls.VERSION_URL).close();
return Status.UNAUTHORIZED;
} catch (IOException ioe) {
- return Status.INVALID;
+ return Status.UNAVAILABLE;
}
}
@Override
public Image getCover(String luid) throws IOException {
- InputStream in = download("/story/" + luid + "/cover");
- if (in != null) {
+ InputStream in = download(WebLibraryUrls.getStoryUrlCover(luid));
+ try {
return new Image(in);
+ } finally {
+ in.close();
}
-
- return null;
}
@Override
// TODO: pg
Story story;
- InputStream in = download("/story/" + luid + "/json");
+ InputStream in = download(WebLibraryUrls.getStoryUrlJson(luid));
try {
JSONObject json = new JSONObject(IOUtils.readSmallStream(in));
story = JsonIO.toStory(json);
for (Paragraph para : chap) {
if (para.getType() == ParagraphType.IMAGE) {
InputStream subin = download(
- "/story/" + luid + "/" + chapNum + "/" + number);
+ WebLibraryUrls.getStoryUrl(luid, chapNum, number));
try {
para.setContentImage(new Image(subin));
} finally {
@Override
protected List<MetaData> getMetas(Progress pg) throws IOException {
List<MetaData> metas = new ArrayList<MetaData>();
- InputStream in = download("/list/luids");
+ InputStream in = download(WebLibraryUrls.LIST_URL_METADATA);
JSONArray jsonArr = new JSONArray(IOUtils.readSmallStream(in));
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject json = jsonArr.getJSONObject(i);
"Operation not supportorted on remote Libraries");
}
- // starts with "/"
+ // starts with "/", never NULL
private InputStream download(String path) throws IOException {
URL url = new URL(host + ":" + port + path);