1 package be
.nikiroo
.fanfix
.library
;
3 import java
.io
.UnsupportedEncodingException
;
4 import java
.net
.URLEncoder
;
7 static public final String INDEX_URL
= "/";
9 static public final String VERSION_URL
= "/version";
11 static public final String LOGOUT_URL
= "/logout";
13 static public final String EXIT_URL
= "/exit";
15 static private final String VIEWER_URL_BASE
= "/view/story/";
16 static private final String VIEWER_URL
= VIEWER_URL_BASE
17 + "{luid}/{chap}/{para}";
19 static private final String STORY_URL_BASE
= "/story/";
20 static private final String STORY_URL
= STORY_URL_BASE
21 + "{luid}/{chap}/{para}";
22 static private final String STORY_URL_COVER
= STORY_URL_BASE
24 static private final String STORY_URL_JSON
= STORY_URL_BASE
+ "{luid}/json";
25 static private final String STORY_URL_METADATA
= STORY_URL_BASE
28 // GET/SET ("value" param -> set STA to this value)
29 static private final String STORY_URL_SOURCE
= STORY_URL_BASE
31 static private final String STORY_URL_TITLE
= STORY_URL_BASE
33 static private final String STORY_URL_AUTHOR
= STORY_URL_BASE
36 static private final String LIST_URL_BASE
= "/list/";
38 static public final String LIST_URL_METADATA
= LIST_URL_BASE
+ "metadata";
40 // "import" requires param "url" and return an luid, "/{luid}" return
41 // progress status as a JSON Progress or 404 if none (done or failed)
42 static private final String IMPRT_URL_BASE
= "/import/";
43 static private final String IMPRT_URL_PROGRESS
= IMPRT_URL_BASE
+ "{luid}";
44 static public final String IMPRT_URL_IMPORT
= IMPRT_URL_BASE
+ "import";
46 static private final String DELETE_URL_BASE
= "/delete/";
47 static private final String DELETE_URL_STORY
= DELETE_URL_BASE
+ "{luid}";
49 // GET/SET ("luid" param -> set cover to the cover of this story -- not ok
51 static private final String COVER_URL_BASE
= "/cover/";
52 static private final String COVER_URL_STORY
= COVER_URL_BASE
54 static private final String COVER_URL_AUTHOR
= COVER_URL_BASE
56 static private final String COVER_URL_SOURCE
= COVER_URL_BASE
59 static public String
getViewUrl(String luid
, Integer chap
, Integer para
) {
61 .replace("{luid}", luid
) //
62 .replace("/{chap}", chap
== null ?
"" : "/" + chap
) //
64 (chap
== null || para
== null) ?
"" : "/" + para
);
67 static public String
getStoryUrl(String luid
, int chap
, Integer para
) {
69 .replace("{luid}", luid
) //
70 .replace("{chap}", Integer
.toString(chap
)) //
71 .replace("{para}", para
== null ?
"" : Integer
.toString(para
));
74 static public String
getStoryUrlCover(String luid
) {
75 return STORY_URL_COVER
//
76 .replace("{luid}", luid
);
79 static public String
getStoryUrlJson(String luid
) {
80 return STORY_URL_JSON
//
81 .replace("{luid}", luid
);
84 static public String
getStoryUrlSource(String luid
) {
85 return STORY_URL_SOURCE
//
86 .replace("{luid}", luid
);
89 static public String
getStoryUrlTitle(String luid
) {
90 return STORY_URL_TITLE
//
91 .replace("{luid}", luid
);
94 static public String
getStoryUrlAuthor(String luid
) {
95 return STORY_URL_AUTHOR
//
96 .replace("{luid}", luid
);
99 static public String
getStoryUrlMetadata(String luid
) {
100 return STORY_URL_METADATA
//
101 .replace("{luid}", luid
);
104 static public String
getImprtProgressUrl(String luid
) {
105 return IMPRT_URL_PROGRESS
//
106 .replace("{luid}", luid
);
109 static public boolean isSupportedUrl(String url
,
110 boolean requiresLoginOnly
) {
111 if (requiresLoginOnly
) {
112 return INDEX_URL
.equals(url
) || LOGOUT_URL
.equals(url
)
113 || EXIT_URL
.equals(url
) || isViewUrl(url
) || isStoryUrl(url
)
114 || isListUrl(url
) || isCoverUrl(url
) || isImprtUrl(url
)
118 return isSupportedUrl(url
, true) || VERSION_URL
.equals(url
);
121 static public String
getCoverUrlStory(String luid
) {
122 return COVER_URL_STORY
//
123 .replace("{luid}", luid
);
126 static public String
getCoverUrlSource(String source
) {
127 return COVER_URL_SOURCE
//
128 .replace("{source}", url(source
));
131 static public String
getCoverUrlAuthor(String author
) {
132 return COVER_URL_AUTHOR
//
133 .replace("{author}", url(author
));
136 static public String
getDeleteUrlStory(String luid
) {
137 return DELETE_URL_STORY
//
138 .replace("{luid}", luid
);
141 static public boolean isViewUrl(String url
) {
142 return url
!= null && url
.startsWith(VIEWER_URL_BASE
);
145 static public boolean isStoryUrl(String url
) {
146 return url
!= null && url
.startsWith(STORY_URL_BASE
);
149 static public boolean isListUrl(String url
) {
150 return url
!= null && url
.startsWith(LIST_URL_BASE
);
153 static public boolean isCoverUrl(String url
) {
154 return url
!= null && url
.startsWith(COVER_URL_BASE
);
157 static public boolean isImprtUrl(String url
) {
158 return url
!= null && url
.startsWith(IMPRT_URL_BASE
);
161 static public boolean isDeleteUrl(String url
) {
162 return url
!= null && url
.startsWith(DELETE_URL_BASE
);
165 static private String
url(String value
) {
167 return URLEncoder
.encode(value
, "UTF-8");
168 } catch (UnsupportedEncodingException e
) {
169 // UTF-8 is always supported