Merge from master
[nikiroo-utils.git] / library / WebLibraryUrls.java
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 static private final String STORY_URL_METADATA = STORY_URL_BASE
21 + "{luid}/metadata";
22
23 // GET/SET ("value" param -> set STA to this value)
24 static private final String STORY_URL_SOURCE = STORY_URL_BASE
25 + "{luid}/source";
26 static private final String STORY_URL_TITLE = STORY_URL_BASE
27 + "{luid}/title";
28 static private final String STORY_URL_AUTHOR = STORY_URL_BASE
29 + "{luid}/author";
30
31 static private final String LIST_URL_BASE = "/list/";
32
33 static public final String LIST_URL_METADATA = LIST_URL_BASE + "metadata";
34
35 // "import" requires param "url" and return an luid, "/{luid}" return
36 // progress status as a JSON Progress or 404 if none (done or failed)
37 static private final String IMPRT_URL_BASE = "/import/";
38 static private final String IMPRT_URL_PROGRESS = IMPRT_URL_BASE + "{luid}";
39 static public final String IMPRT_URL_IMPORT = IMPRT_URL_BASE + "import";
40
41 // GET/SET ("luid" param -> set cover to the cover of this story -- not ok
42 // for /cover/story/)
43 static private final String COVER_URL_BASE = "/cover/";
44 static private final String COVER_URL_STORY = COVER_URL_BASE
45 + "story/{luid}";
46 static private final String COVER_URL_AUTHOR = COVER_URL_BASE
47 + "author/{author}";
48 static private final String COVER_URL_SOURCE = COVER_URL_BASE
49 + "source/{source}";
50
51 static public String getViewUrl(String luid, Integer chap, Integer para) {
52 return VIEWER_URL //
53 .replace("{luid}", luid) //
54 .replace("/{chap}", chap == null ? "" : "/" + chap) //
55 .replace("/{para}",
56 (chap == null || para == null) ? "" : "/" + para);
57 }
58
59 static public String getStoryUrl(String luid, int chap, Integer para) {
60 return STORY_URL //
61 .replace("{luid}", luid) //
62 .replace("{chap}", Integer.toString(chap)) //
63 .replace("{para}", para == null ? "" : Integer.toString(para));
64 }
65
66 static public String getStoryUrlCover(String luid) {
67 return STORY_URL_COVER //
68 .replace("{luid}", luid);
69 }
70
71 static public String getStoryUrlJson(String luid) {
72 return STORY_URL_JSON //
73 .replace("{luid}", luid);
74 }
75
76 static public String getStoryUrlSource(String luid) {
77 return STORY_URL_SOURCE //
78 .replace("{luid}", luid);
79 }
80
81 static public String getStoryUrlTitle(String luid) {
82 return STORY_URL_TITLE//
83 .replace("{luid}", luid);
84 }
85
86 static public String getStoryUrlAuthor(String luid) {
87 return STORY_URL_AUTHOR //
88 .replace("{luid}", luid);
89 }
90
91 static public String getStoryUrlMetadata(String luid) {
92 return STORY_URL_METADATA //
93 .replace("{luid}", luid);
94 }
95
96 static public String getImprtProgressUrl(String luid) {
97 return IMPRT_URL_PROGRESS //
98 .replace("{luid}", luid);
99 }
100
101 static public boolean isSupportedUrl(String url) {
102 return INDEX_URL.equals(url) || VERSION_URL.equals(url)
103 || LOGOUT_URL.equals(url) || isViewUrl(url) || isStoryUrl(url)
104 || isListUrl(url) || isCoverUrl(url) || isImprtUrl(url);
105 }
106
107 static public String getCoverUrlStory(String luid) {
108 return COVER_URL_STORY //
109 .replace("{luid}", luid);
110 }
111
112 static public String getCoverUrlSource(String source) {
113 return COVER_URL_SOURCE //
114 .replace("{source}", source);
115 }
116
117 static public String getCoverUrlAuthor(String author) {
118 return COVER_URL_AUTHOR //
119 .replace("{author}", author);
120 }
121
122 static public boolean isViewUrl(String url) {
123 return url != null && url.startsWith(VIEWER_URL_BASE);
124 }
125
126 static public boolean isStoryUrl(String url) {
127 return url != null && url.startsWith(STORY_URL_BASE);
128 }
129
130 static public boolean isListUrl(String url) {
131 return url != null && url.startsWith(LIST_URL_BASE);
132 }
133
134 static public boolean isCoverUrl(String url) {
135 return url != null && url.startsWith(COVER_URL_BASE);
136 }
137
138 static public boolean isImprtUrl(String url) {
139 return url != null && url.startsWith(IMPRT_URL_BASE);
140 }
141 }