weblib: allow /version without login
[fanfix.git] / src / be / nikiroo / fanfix / library / WebLibraryServerHtml.java
index 6489fdf75880e6d3488803d88fa4722091811ecc..8895fb83a07b0eb6ff7116b3998a7a89a2acfb15 100644 (file)
@@ -47,15 +47,36 @@ abstract class WebLibraryServerHtml implements Runnable {
 
        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;
 
+       abstract protected Response setCover(String uri, String luid,
+                       WLoginResult login) throws IOException;
+
        abstract protected List<MetaData> metas(WLoginResult login)
                        throws IOException;
 
        abstract protected Story story(String luid, WLoginResult login)
                        throws IOException;
 
+       protected abstract Response imprt(String uri, String url,
+                       WLoginResult login) throws IOException;
+
+       protected abstract Response imprtProgress(String uri, WLoginResult login);
+
+       protected abstract Response delete(String uri, WLoginResult login)
+                       throws IOException;
+
+       /**
+        * Wait until all operations are done and stop the server.
+        * <p>
+        * All the new R/W operations will be refused after a call to stop.
+        */
+       protected abstract Response stop(WLoginResult login);
+
        public WebLibraryServerHtml(boolean secure) throws IOException {
                Integer port = Instance.getInstance().getConfig()
                                .getInteger(Config.SERVER_PORT);
@@ -152,13 +173,14 @@ abstract class WebLibraryServerHtml implements Runnable {
                                }
 
                                Response rep = null;
-                               if (!login.isSuccess() && WebLibraryUrls.isSupportedUrl(uri)) {
+                               if (!login.isSuccess()
+                                               && WebLibraryUrls.isSupportedUrl(uri, true)) {
                                        rep = loginPage(login, uri);
                                }
 
                                if (rep == null) {
                                        try {
-                                               if (WebLibraryUrls.isSupportedUrl(uri)) {
+                                               if (WebLibraryUrls.isSupportedUrl(uri, false)) {
                                                        if (WebLibraryUrls.INDEX_URL.equals(uri)) {
                                                                rep = root(session, cookies, login);
                                                        } else if (WebLibraryUrls.VERSION_URL.equals(uri)) {
@@ -166,17 +188,38 @@ abstract class WebLibraryServerHtml implements Runnable {
                                                                                MIME_PLAINTEXT,
                                                                                Version.getCurrentVersion().toString());
                                                        } else if (WebLibraryUrls.isCoverUrl(uri)) {
-                                                               rep = getCover(uri, login);
+                                                               String luid = params.get("luid");
+                                                               if (luid != null) {
+                                                                       rep = setCover(uri, luid, login);
+                                                               } else {
+                                                                       rep = getCover(uri, login);
+                                                               }
                                                        } 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)) {
                                                                session.getCookies().delete("cookie");
                                                                cookies.remove("cookie");
                                                                rep = loginPage(login(false, false), uri);
+                                                       } else if (WebLibraryUrls.isImprtUrl(uri)) {
+                                                               String url = params.get("url");
+                                                               if (url != null) {
+                                                                       rep = imprt(uri, url, login);
+                                                               } else {
+                                                                       rep = imprtProgress(uri, login);
+                                                               }
+                                                       } else if (WebLibraryUrls.isDeleteUrl(uri)) {
+                                                               rep = delete(uri, login);
+                                                       } else if (WebLibraryUrls.EXIT_URL.equals(uri)) {
+                                                               rep = WebLibraryServerHtml.this.stop(login);
                                                        } else {
                                                                getTraceHandler().error(
                                                                                "Supported URL was not processed: "
@@ -223,9 +266,7 @@ abstract class WebLibraryServerHtml implements Runnable {
                        }
                };
 
-               if (ssf != null)
-
-               {
+               if (ssf != null) {
                        getTraceHandler().trace("Install SSL on the web server...");
                        server.makeSecure(ssf, null);
                        getTraceHandler().trace("Done.");
@@ -241,6 +282,10 @@ abstract class WebLibraryServerHtml implements Runnable {
                }
        }
 
+       protected void doStop() {
+               server.stop();
+       }
+
        /**
         * The traces handler for this {@link WebLibraryServerHtml}.
         *