protected synchronized void changeSTA(final String luid,
final String newSource, final String newTitle,
final String newAuthor, Progress pg) throws IOException {
- // TODO
- super.changeSTA(luid, newSource, newTitle, newAuthor, pg);
+ MetaData meta = getInfo(luid);
+ if (meta != null) {
+ if (!meta.getSource().equals(newSource)) {
+ Map<String, String> post = new HashMap<String, String>();
+ post.put("value", newSource);
+ post(WebLibraryUrls.getStoryUrlSource(luid), post).close();
+ }
+ if (!meta.getTitle().equals(newTitle)) {
+ Map<String, String> post = new HashMap<String, String>();
+ post.put("value", newTitle);
+ post(WebLibraryUrls.getStoryUrlTitle(luid), post).close();
+ }
+ if (!meta.getAuthor().equals(newAuthor)) {
+ Map<String, String> post = new HashMap<String, String>();
+ post.put("value", newAuthor);
+ post(WebLibraryUrls.getStoryUrlAuthor(luid), post).close();
+ }
+ }
}
@Override
return newInputStreamResponse(mimeType, in);
}
+ // /story/luid/source
+ // /story/luid/title
+ // /story/luid/author
+ @Override
+ protected Response setStoryPart(String uri, String value,
+ WLoginResult login) throws IOException {
+ String[] uriParts = uri.split("/");
+ int off = 2; // "" and "story"
+
+ if (uriParts.length < off + 2) {
+ return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
+ NanoHTTPD.MIME_PLAINTEXT, "Invalid story part request");
+ }
+
+ String luid = uriParts[off + 0];
+ String type = uriParts[off + 1];
+
+ if (!Arrays.asList("source", "title", "author").contains(type)) {
+ return NanoHTTPD.newFixedLengthResponse(Status.BAD_REQUEST,
+ NanoHTTPD.MIME_PLAINTEXT,
+ "Invalid SET story part: " + type);
+ }
+
+ if (meta(luid, login) != null) {
+ BasicLibrary lib = Instance.getInstance().getLibrary();
+ if ("source".equals(type)) {
+ lib.changeSource(luid, value, null);
+ } else if ("title".equals(type)) {
+ lib.changeTitle(luid, value, null);
+ } else if ("author".equals(type)) {
+ lib.changeAuthor(luid, value, null);
+ }
+ }
+
+ return newInputStreamResponse(NanoHTTPD.MIME_PLAINTEXT, null);
+ }
+
@Override
protected Response getCover(String uri, WLoginResult login)
throws IOException {
abstract protected Response getStoryPart(String uri, WLoginResult login);
+ abstract protected Response setStoryPart(String uri, String value,
+ WLoginResult login) throws IOException;
+
abstract protected Response getCover(String uri, WLoginResult login)
throws IOException;
} else if (WebLibraryUrls.isListUrl(uri)) {
rep = getList(uri, login);
} else if (WebLibraryUrls.isStoryUrl(uri)) {
- rep = getStoryPart(uri, login);
+ String value = params.get("value");
+ if (value != null) {
+ rep = setStoryPart(uri, value, login);
+ } else {
+ rep = getStoryPart(uri, login);
+ }
} else if (WebLibraryUrls.isViewUrl(uri)) {
rep = getViewer(cookies, uri, login);
} else if (WebLibraryUrls.LOGOUT_URL.equals(uri)) {
+ "{luid}/cover";
static private final String STORY_URL_JSON = STORY_URL_BASE + "{luid}/json";
+ // GET/SET ("value" param -> set STA to this value)
+ static private final String STORY_URL_SOURCE = STORY_URL_BASE
+ + "{luid}/source";
+ static private final String STORY_URL_TITLE = STORY_URL_BASE
+ + "{luid}/title";
+ static private final String STORY_URL_AUTHOR = STORY_URL_BASE
+ + "{luid}/author";
+
static private final String LIST_URL_BASE = "/list/";
static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata";
.replace("{luid}", luid);
}
+ static public String getStoryUrlSource(String luid) {
+ return STORY_URL_SOURCE //
+ .replace("{luid}", luid);
+ }
+
+ static public String getStoryUrlTitle(String luid) {
+ return STORY_URL_TITLE//
+ .replace("{luid}", luid);
+ }
+
+ static public String getStoryUrlAuthor(String luid) {
+ return STORY_URL_AUTHOR //
+ .replace("{luid}", luid);
+ }
+
static public boolean isSupportedUrl(String url) {
return INDEX_URL.equals(url) || VERSION_URL.equals(url)
|| LOGOUT_URL.equals(url) || isViewUrl(url) || isStoryUrl(url)