| 1 | package be.nikiroo.fanfix.library; |
| 2 | |
| 3 | class WebLibraryUrls { |
| 4 | static public final String INDEX_URL = "/"; |
| 5 | |
| 6 | static public final String VERSION_URL = "/version"; |
| 7 | |
| 8 | static public final String LOGOUT_URL = "/logout"; |
| 9 | |
| 10 | static public final String EXIT_URL = "/exit"; |
| 11 | |
| 12 | static private final String VIEWER_URL_BASE = "/view/story/"; |
| 13 | static private final String VIEWER_URL = VIEWER_URL_BASE |
| 14 | + "{luid}/{chap}/{para}"; |
| 15 | |
| 16 | static private final String STORY_URL_BASE = "/story/"; |
| 17 | static private final String STORY_URL = STORY_URL_BASE |
| 18 | + "{luid}/{chap}/{para}"; |
| 19 | static private final String STORY_URL_COVER = STORY_URL_BASE |
| 20 | + "{luid}/cover"; |
| 21 | static private final String STORY_URL_JSON = STORY_URL_BASE + "{luid}/json"; |
| 22 | static private final String STORY_URL_METADATA = STORY_URL_BASE |
| 23 | + "{luid}/metadata"; |
| 24 | |
| 25 | // GET/SET ("value" param -> set STA to this value) |
| 26 | static private final String STORY_URL_SOURCE = STORY_URL_BASE |
| 27 | + "{luid}/source"; |
| 28 | static private final String STORY_URL_TITLE = STORY_URL_BASE |
| 29 | + "{luid}/title"; |
| 30 | static private final String STORY_URL_AUTHOR = STORY_URL_BASE |
| 31 | + "{luid}/author"; |
| 32 | |
| 33 | static private final String LIST_URL_BASE = "/list/"; |
| 34 | |
| 35 | static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata"; |
| 36 | |
| 37 | // "import" requires param "url" and return an luid, "/{luid}" return |
| 38 | // progress status as a JSON Progress or 404 if none (done or failed) |
| 39 | static private final String IMPRT_URL_BASE = "/import/"; |
| 40 | static private final String IMPRT_URL_PROGRESS = IMPRT_URL_BASE + "{luid}"; |
| 41 | static public final String IMPRT_URL_IMPORT = IMPRT_URL_BASE + "import"; |
| 42 | |
| 43 | static private final String DELETE_URL_BASE = "/delete/"; |
| 44 | static private final String DELETE_URL_STORY = DELETE_URL_BASE + "{luid}"; |
| 45 | |
| 46 | // GET/SET ("luid" param -> set cover to the cover of this story -- not ok |
| 47 | // for /cover/story/) |
| 48 | static private final String COVER_URL_BASE = "/cover/"; |
| 49 | static private final String COVER_URL_STORY = COVER_URL_BASE |
| 50 | + "story/{luid}"; |
| 51 | static private final String COVER_URL_AUTHOR = COVER_URL_BASE |
| 52 | + "author/{author}"; |
| 53 | static private final String COVER_URL_SOURCE = COVER_URL_BASE |
| 54 | + "source/{source}"; |
| 55 | |
| 56 | static public String getViewUrl(String luid, Integer chap, Integer para) { |
| 57 | return VIEWER_URL // |
| 58 | .replace("{luid}", luid) // |
| 59 | .replace("/{chap}", chap == null ? "" : "/" + chap) // |
| 60 | .replace("/{para}", |
| 61 | (chap == null || para == null) ? "" : "/" + para); |
| 62 | } |
| 63 | |
| 64 | static public String getStoryUrl(String luid, int chap, Integer para) { |
| 65 | return STORY_URL // |
| 66 | .replace("{luid}", luid) // |
| 67 | .replace("{chap}", Integer.toString(chap)) // |
| 68 | .replace("{para}", para == null ? "" : Integer.toString(para)); |
| 69 | } |
| 70 | |
| 71 | static public String getStoryUrlCover(String luid) { |
| 72 | return STORY_URL_COVER // |
| 73 | .replace("{luid}", luid); |
| 74 | } |
| 75 | |
| 76 | static public String getStoryUrlJson(String luid) { |
| 77 | return STORY_URL_JSON // |
| 78 | .replace("{luid}", luid); |
| 79 | } |
| 80 | |
| 81 | static public String getStoryUrlSource(String luid) { |
| 82 | return STORY_URL_SOURCE // |
| 83 | .replace("{luid}", luid); |
| 84 | } |
| 85 | |
| 86 | static public String getStoryUrlTitle(String luid) { |
| 87 | return STORY_URL_TITLE// |
| 88 | .replace("{luid}", luid); |
| 89 | } |
| 90 | |
| 91 | static public String getStoryUrlAuthor(String luid) { |
| 92 | return STORY_URL_AUTHOR // |
| 93 | .replace("{luid}", luid); |
| 94 | } |
| 95 | |
| 96 | static public String getStoryUrlMetadata(String luid) { |
| 97 | return STORY_URL_METADATA // |
| 98 | .replace("{luid}", luid); |
| 99 | } |
| 100 | |
| 101 | static public String getImprtProgressUrl(String luid) { |
| 102 | return IMPRT_URL_PROGRESS // |
| 103 | .replace("{luid}", luid); |
| 104 | } |
| 105 | |
| 106 | static public boolean isSupportedUrl(String url, |
| 107 | boolean requiresLoginOnly) { |
| 108 | if (requiresLoginOnly) { |
| 109 | return INDEX_URL.equals(url) || LOGOUT_URL.equals(url) |
| 110 | || EXIT_URL.equals(url) || isViewUrl(url) || isStoryUrl(url) |
| 111 | || isListUrl(url) || isCoverUrl(url) || isImprtUrl(url) |
| 112 | || isDeleteUrl(url); |
| 113 | } |
| 114 | |
| 115 | return isSupportedUrl(url, true) || VERSION_URL.equals(url); |
| 116 | } |
| 117 | |
| 118 | static public String getCoverUrlStory(String luid) { |
| 119 | return COVER_URL_STORY // |
| 120 | .replace("{luid}", luid); |
| 121 | } |
| 122 | |
| 123 | static public String getCoverUrlSource(String source) { |
| 124 | return COVER_URL_SOURCE // |
| 125 | .replace("{source}", source); |
| 126 | } |
| 127 | |
| 128 | static public String getCoverUrlAuthor(String author) { |
| 129 | return COVER_URL_AUTHOR // |
| 130 | .replace("{author}", author); |
| 131 | } |
| 132 | |
| 133 | static public String getDeleteUrlStory(String luid) { |
| 134 | return DELETE_URL_STORY // |
| 135 | .replace("{luid}", luid); |
| 136 | } |
| 137 | |
| 138 | static public boolean isViewUrl(String url) { |
| 139 | return url != null && url.startsWith(VIEWER_URL_BASE); |
| 140 | } |
| 141 | |
| 142 | static public boolean isStoryUrl(String url) { |
| 143 | return url != null && url.startsWith(STORY_URL_BASE); |
| 144 | } |
| 145 | |
| 146 | static public boolean isListUrl(String url) { |
| 147 | return url != null && url.startsWith(LIST_URL_BASE); |
| 148 | } |
| 149 | |
| 150 | static public boolean isCoverUrl(String url) { |
| 151 | return url != null && url.startsWith(COVER_URL_BASE); |
| 152 | } |
| 153 | |
| 154 | static public boolean isImprtUrl(String url) { |
| 155 | return url != null && url.startsWith(IMPRT_URL_BASE); |
| 156 | } |
| 157 | |
| 158 | static public boolean isDeleteUrl(String url) { |
| 159 | return url != null && url.startsWith(DELETE_URL_BASE); |
| 160 | } |
| 161 | } |