1 | |
package org.paneris.bibliomania; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
public class Bib { |
12 | |
private BibliomaniaDatabase db; |
13 | |
|
14 | 2 | public Bib(BibliomaniaDatabase db) { |
15 | 2 | this.db = db; |
16 | 2 | } |
17 | |
|
18 | |
public BibliomaniaDatabase getDatabase() { |
19 | 3 | return db; |
20 | |
} |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public static String bibliomaniaTemplate(String name) { |
31 | 23 | return BibliomaniaServlet.bibliomaniaTemplate(name) + ".wm"; |
32 | |
} |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public String getStaticRootURL() { |
39 | 20 | return db.getStaticRootURL(); |
40 | |
} |
41 | |
|
42 | |
public String getContentStaticRootURL() { |
43 | 0 | return db.getContentStaticRootURL(); |
44 | |
} |
45 | |
|
46 | |
public String getCacheRootURL() { |
47 | 3 | return db.getCacheRootURL(); |
48 | |
} |
49 | |
|
50 | |
public String getHomepageURL() { |
51 | 3 | return db.getHomepageURL(); |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public String getLogoURL() { |
64 | 0 | return getStaticRootURL() + "/logo.html"; |
65 | |
} |
66 | |
|
67 | |
public String getFaqURL() { |
68 | 3 | return getCacheRootURL() + "/Faq.html"; |
69 | |
} |
70 | |
|
71 | |
public String getCommentURL() { |
72 | 0 | return "mailto:comments@boards.bibliomania.com"; |
73 | |
} |
74 | |
|
75 | |
public String getTrolleyURL() { |
76 | 0 | return "/trolley"; |
77 | |
} |
78 | |
|
79 | |
public String urlPrefixedReally( |
80 | |
String prefix, |
81 | |
SectionGroup area, |
82 | |
Section section, |
83 | |
Unit object, |
84 | |
Integer page) { |
85 | 24 | if (object != null && object instanceof Chapter) { |
86 | 17 | return addPage( |
87 | |
urlDirectoryPrefixedReally(prefix, area, section, object), |
88 | |
page) |
89 | |
.toString(); |
90 | |
} else { |
91 | 7 | return urlDirectoryPrefixedReally(prefix, area, section, object) |
92 | |
.toString(); |
93 | |
} |
94 | |
|
95 | |
} |
96 | |
public StringBuffer urlDirectoryPrefixedReally( |
97 | |
String prefix, |
98 | |
SectionGroup area, |
99 | |
Section section, |
100 | |
Unit object) { |
101 | |
|
102 | |
|
103 | |
Integer authorid, bookid, chapterid; |
104 | |
|
105 | 24 | if (object == null) { |
106 | |
|
107 | 0 | authorid = bookid = chapterid = null; |
108 | |
} else { |
109 | 24 | if (object instanceof Chapter) { |
110 | 17 | Chapter chapter = (Chapter)object; |
111 | 17 | Book book = chapter.getBook(); |
112 | 17 | chapterid = chapter.troid(); |
113 | 17 | bookid = book.troid(); |
114 | 17 | authorid = book.getAuthorTroid(); |
115 | 17 | section = book.getSection(); |
116 | 17 | } else if (object instanceof Book) { |
117 | 6 | Book book = (Book)object; |
118 | 6 | chapterid = null; |
119 | 6 | bookid = book.troid(); |
120 | 6 | authorid = book.getAuthorTroid(); |
121 | 6 | section = book.getSection(); |
122 | 6 | } else if (object instanceof Author) { |
123 | 1 | Author author = (Author)object; |
124 | 1 | chapterid = null; |
125 | 1 | bookid = null; |
126 | 1 | authorid = author.troid(); |
127 | 1 | if (section == null) |
128 | 1 | if ((section = author.getSection()) == null) |
129 | 0 | section = db.getSectionTable().getSectionObject(0); |
130 | 1 | } else if (object instanceof Section) { |
131 | 0 | chapterid = null; |
132 | 0 | bookid = null; |
133 | 0 | authorid = null; |
134 | 0 | section = (Section)object; |
135 | |
} else { |
136 | 0 | chapterid = null; |
137 | 0 | bookid = null; |
138 | 0 | authorid = null; |
139 | 0 | section = null; |
140 | 0 | area = (SectionGroup)object; |
141 | |
} |
142 | |
} |
143 | |
|
144 | 24 | if (area == null) |
145 | 24 | area = section != null ? section.getGroup() : db.getReadSectionGroup(); |
146 | |
|
147 | 24 | StringBuffer it = new StringBuffer(); |
148 | 24 | it.append(prefix); |
149 | 24 | it.append('/'); |
150 | 24 | if (area.getUrlprefix() != null) { |
151 | 0 | it.append(area.getUrlprefix()); |
152 | 0 | it.append('/'); |
153 | |
} |
154 | 24 | it.append(area.troid()); |
155 | 24 | if (section != null) { |
156 | 24 | it.append('/'); |
157 | 24 | it.append(section.troid()); |
158 | 24 | if (authorid != null) { |
159 | 24 | it.append('/'); |
160 | 24 | it.append(authorid); |
161 | 24 | if (bookid != null) { |
162 | 23 | it.append('/'); |
163 | 23 | it.append(bookid); |
164 | 23 | if (chapterid != null) { |
165 | 17 | it.append('/'); |
166 | 17 | it.append(chapterid); |
167 | |
} |
168 | |
} |
169 | |
} |
170 | |
} |
171 | 24 | return it; |
172 | |
} |
173 | |
|
174 | |
private StringBuffer addPage(StringBuffer url, Integer page) { |
175 | 17 | url.append('/'); |
176 | 17 | if (page == null) { |
177 | 9 | url.append(1); |
178 | |
} else { |
179 | 8 | url.append(page.intValue()); |
180 | |
} |
181 | 17 | url.append(".html"); |
182 | 17 | return url; |
183 | |
} |
184 | |
|
185 | |
public String urlPrefixed( |
186 | |
String prefix, |
187 | |
SectionGroup area, |
188 | |
Section section, |
189 | |
Unit object, |
190 | |
Integer page) { |
191 | 24 | if (object != null && object instanceof Book) { |
192 | 6 | Book book = (Book)object; |
193 | 6 | Boolean hnfp = book.getHasnofrontpage(); |
194 | 6 | if (hnfp != null && hnfp.booleanValue()) |
195 | 0 | object = book.getChapter0(); |
196 | |
} |
197 | |
|
198 | 24 | return urlPrefixedReally(prefix, area, section, object, page); |
199 | |
} |
200 | |
|
201 | |
public String url( |
202 | |
SectionGroup area, |
203 | |
Section section, |
204 | |
Unit object, |
205 | |
Integer page) { |
206 | 24 | return urlPrefixed( |
207 | |
((BibliomaniaDatabase)object.getDatabase()).getCacheRootURL(), |
208 | |
area, |
209 | |
section, |
210 | |
object, |
211 | |
page); |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public String url(SectionGroup area, Unit object) { |
222 | 16 | return url(area, null, object, null); |
223 | |
} |
224 | |
|
225 | |
public String url(Chapter object, Integer page) { |
226 | 5 | return url(null, null, object, page); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
public String url(Chapter object, String page) { |
235 | 3 | return url(null, null, object, new Integer(page)); |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
public String url(Unit object) { |
244 | 16 | return url(null, object); |
245 | |
} |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public String framesetURL(Unit object) { |
254 | |
|
255 | 1 | String url = url(object); |
256 | 1 | if (url.endsWith(".html")) |
257 | 0 | url = url.substring(0, url.length() - 5); |
258 | |
|
259 | 1 | return url + "/frameset.html"; |
260 | |
} |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
public String framesetURL(Chapter chapter, String page) { |
269 | |
|
270 | 2 | String url = url(chapter, page); |
271 | 2 | if (url.endsWith(".html")) |
272 | 2 | url = url.substring(0, url.length() - 5); |
273 | |
|
274 | 2 | return url + "/frameset.html"; |
275 | |
} |
276 | |
|
277 | |
|
278 | |
public String urlReally(Unit object) { |
279 | 0 | return urlPrefixedReally( |
280 | |
((BibliomaniaDatabase)object.getDatabase()).getCacheRootURL(), |
281 | |
null, |
282 | |
null, |
283 | |
object, |
284 | |
null); |
285 | |
} |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
public Book book(Integer troid) { |
293 | 0 | return (Book)db.getBookTable().getObject(troid); |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
public String anchorURL(Chapter chapter, String anchor) { |
303 | 0 | Integer page = chapter.pageOfAnchor(anchor); |
304 | 0 | return page == null |
305 | |
? url(null, chapter) |
306 | |
: url(null, null, chapter, page) + "#" + anchor; |
307 | |
} |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
public Unit atMostBook(Unit object) { |
316 | 0 | return object instanceof Chapter ? ((Chapter)object).getBook() : object; |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public Unit atMostAuthor(Unit object) { |
325 | 0 | return object instanceof Chapter |
326 | |
? ((Chapter)object).getBook().getAuthor() |
327 | |
: object instanceof Book |
328 | |
? ((Book)object).getAuthor() |
329 | |
: object; |
330 | |
} |
331 | |
} |