| 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 private final String VIEWER_URL_BASE = "/view/story/"; |
| 11 | static private final String VIEWER_URL = VIEWER_URL_BASE |
| 12 | + "{luid}/{chap}/{para}"; |
| 13 | |
| 14 | static private final String STORY_URL_BASE = "/story/"; |
| 15 | static private final String STORY_URL = STORY_URL_BASE |
| 16 | + "{luid}/{chap}/{para}"; |
| 17 | static private final String STORY_URL_COVER = STORY_URL_BASE |
| 18 | + "{luid}/cover"; |
| 19 | static private final String STORY_URL_JSON = STORY_URL_BASE + "{luid}/json"; |
| 20 | |
| 21 | // GET/SET ("value" param -> set STA to this value) |
| 22 | static private final String STORY_URL_SOURCE = STORY_URL_BASE |
| 23 | + "{luid}/source"; |
| 24 | static private final String STORY_URL_TITLE = STORY_URL_BASE |
| 25 | + "{luid}/title"; |
| 26 | static private final String STORY_URL_AUTHOR = STORY_URL_BASE |
| 27 | + "{luid}/author"; |
| 28 | |
| 29 | static private final String LIST_URL_BASE = "/list/"; |
| 30 | |
| 31 | static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata"; |
| 32 | |
| 33 | // GET/SET ("luid" param -> set cover to the cover of this story -- not ok |
| 34 | // for /cover/story/) |
| 35 | static private final String COVER_URL_BASE = "/cover/"; |
| 36 | static private final String COVER_URL_STORY = COVER_URL_BASE |
| 37 | + "story/{luid}"; |
| 38 | static private final String COVER_URL_AUTHOR = COVER_URL_BASE |
| 39 | + "author/{author}"; |
| 40 | static private final String COVER_URL_SOURCE = COVER_URL_BASE |
| 41 | + "source/{source}"; |
| 42 | |
| 43 | static public String getViewUrl(String luid, Integer chap, Integer para) { |
| 44 | return VIEWER_URL // |
| 45 | .replace("{luid}", luid) // |
| 46 | .replace("/{chap}", chap == null ? "" : "/" + chap) // |
| 47 | .replace("/{para}", |
| 48 | (chap == null || para == null) ? "" : "/" + para); |
| 49 | } |
| 50 | |
| 51 | static public String getStoryUrl(String luid, int chap, Integer para) { |
| 52 | return STORY_URL // |
| 53 | .replace("{luid}", luid) // |
| 54 | .replace("{chap}", Integer.toString(chap)) // |
| 55 | .replace("{para}", para == null ? "" : Integer.toString(para)); |
| 56 | } |
| 57 | |
| 58 | static public String getStoryUrlCover(String luid) { |
| 59 | return STORY_URL_COVER // |
| 60 | .replace("{luid}", luid); |
| 61 | } |
| 62 | |
| 63 | static public String getStoryUrlJson(String luid) { |
| 64 | return STORY_URL_JSON // |
| 65 | .replace("{luid}", luid); |
| 66 | } |
| 67 | |
| 68 | static public String getStoryUrlSource(String luid) { |
| 69 | return STORY_URL_SOURCE // |
| 70 | .replace("{luid}", luid); |
| 71 | } |
| 72 | |
| 73 | static public String getStoryUrlTitle(String luid) { |
| 74 | return STORY_URL_TITLE// |
| 75 | .replace("{luid}", luid); |
| 76 | } |
| 77 | |
| 78 | static public String getStoryUrlAuthor(String luid) { |
| 79 | return STORY_URL_AUTHOR // |
| 80 | .replace("{luid}", luid); |
| 81 | } |
| 82 | |
| 83 | static public boolean isSupportedUrl(String url) { |
| 84 | return INDEX_URL.equals(url) || VERSION_URL.equals(url) |
| 85 | || LOGOUT_URL.equals(url) || isViewUrl(url) || isStoryUrl(url) |
| 86 | || isListUrl(url) || isCoverUrl(url); |
| 87 | } |
| 88 | |
| 89 | static public String getCoverUrlStory(String luid) { |
| 90 | return COVER_URL_STORY // |
| 91 | .replace("{luid}", luid); |
| 92 | } |
| 93 | |
| 94 | static public String getCoverUrlSource(String source) { |
| 95 | return COVER_URL_SOURCE // |
| 96 | .replace("{source}", source); |
| 97 | } |
| 98 | |
| 99 | static public String getCoverUrlAuthor(String author) { |
| 100 | return COVER_URL_AUTHOR // |
| 101 | .replace("{author}", author); |
| 102 | } |
| 103 | |
| 104 | static public boolean isViewUrl(String url) { |
| 105 | return url != null && url.startsWith(VIEWER_URL_BASE); |
| 106 | } |
| 107 | |
| 108 | static public boolean isStoryUrl(String url) { |
| 109 | return url != null && url.startsWith(STORY_URL_BASE); |
| 110 | } |
| 111 | |
| 112 | static public boolean isListUrl(String url) { |
| 113 | return url != null && url.startsWith(LIST_URL_BASE); |
| 114 | } |
| 115 | |
| 116 | static public boolean isCoverUrl(String url) { |
| 117 | return url != null && url.startsWith(COVER_URL_BASE); |
| 118 | } |
| 119 | } |