fix STOP server
[fanfix.git] / src / be / nikiroo / fanfix / library / WebLibraryUrls.java
CommitLineData
5ee0fc14
NR
1package be.nikiroo.fanfix.library;
2
33d40b9f 3class WebLibraryUrls {
5ee0fc14
NR
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
09c2396e
NR
10 static public final String EXIT_URL = "/exit";
11
5ee0fc14
NR
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";
f70bcacf
NR
22 static private final String STORY_URL_METADATA = STORY_URL_BASE
23 + "{luid}/metadata";
5ee0fc14 24
089e354e
NR
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
5ee0fc14
NR
33 static private final String LIST_URL_BASE = "/list/";
34
d5581157 35 static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata";
5ee0fc14 36
f70bcacf
NR
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
a1226ce0
NR
43 static private final String DELETE_URL_BASE = "/delete/";
44 static private final String DELETE_URL_STORY = DELETE_URL_BASE + "{luid}";
45
e4b1b70c
NR
46 // GET/SET ("luid" param -> set cover to the cover of this story -- not ok
47 // for /cover/story/)
6673ec59
NR
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
5ee0fc14
NR
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);
089e354e
NR
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);
5ee0fc14
NR
94 }
95
f70bcacf
NR
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
5ee0fc14
NR
106 static public boolean isSupportedUrl(String url) {
107 return INDEX_URL.equals(url) || VERSION_URL.equals(url)
09c2396e
NR
108 || LOGOUT_URL.equals(url) || EXIT_URL.equals(url)
109 || isViewUrl(url) || isStoryUrl(url) || isListUrl(url)
110 || isCoverUrl(url) || isImprtUrl(url) || isDeleteUrl(url);
6673ec59
NR
111 }
112
113 static public String getCoverUrlStory(String luid) {
114 return COVER_URL_STORY //
115 .replace("{luid}", luid);
116 }
117
118 static public String getCoverUrlSource(String source) {
119 return COVER_URL_SOURCE //
120 .replace("{source}", source);
121 }
122
123 static public String getCoverUrlAuthor(String author) {
124 return COVER_URL_AUTHOR //
125 .replace("{author}", author);
5ee0fc14
NR
126 }
127
a1226ce0
NR
128 static public String getDeleteUrlStory(String luid) {
129 return DELETE_URL_STORY //
130 .replace("{luid}", luid);
131 }
132
5ee0fc14
NR
133 static public boolean isViewUrl(String url) {
134 return url != null && url.startsWith(VIEWER_URL_BASE);
135 }
136
137 static public boolean isStoryUrl(String url) {
138 return url != null && url.startsWith(STORY_URL_BASE);
139 }
140
141 static public boolean isListUrl(String url) {
142 return url != null && url.startsWith(LIST_URL_BASE);
143 }
6673ec59
NR
144
145 static public boolean isCoverUrl(String url) {
146 return url != null && url.startsWith(COVER_URL_BASE);
147 }
f70bcacf
NR
148
149 static public boolean isImprtUrl(String url) {
150 return url != null && url.startsWith(IMPRT_URL_BASE);
151 }
a1226ce0
NR
152
153 static public boolean isDeleteUrl(String url) {
154 return url != null && url.startsWith(DELETE_URL_BASE);
155 }
5ee0fc14 156}