File Source: MultiWeblogURLStrategy.java
/*
P/P * Method: org.apache.roller.weblogger.business.MultiWeblogURLStrategy__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.business;
20
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
26 import org.apache.roller.weblogger.pojos.WeblogTheme;
27 import org.apache.roller.weblogger.pojos.Weblog;
28 import org.apache.roller.weblogger.util.URLUtilities;
29
30
31 /**
32 * A Weblogger URLStrategy which builds urls for a multi-weblog environment.
33 */
34 public class MultiWeblogURLStrategy extends AbstractURLStrategy {
35
/*
P/P * Method: void org.apache.roller.weblogger.business.MultiWeblogURLStrategy()
*/
36 public MultiWeblogURLStrategy() {}
37
38
39 /**
40 * @inheritDoc
41 */
42 public URLStrategy getPreviewURLStrategy(String previewTheme) {
/*
P/P * Method: URLStrategy getPreviewURLStrategy(String)
*
* Postconditions:
* return_value == &new PreviewURLStrategy(getPreviewURLStrategy#1)
* new PreviewURLStrategy(getPreviewURLStrategy#1) num objects == 1
* return_value.previewTheme == previewTheme
* init'ed(return_value.previewTheme)
*/
43 return new PreviewURLStrategy(previewTheme);
44 }
45
46
47 /**
48 * Get root url for a given weblog. Optionally for a certain locale.
49 */
50 public String getWeblogURL(Weblog weblog,
51 String locale,
52 boolean absolute) {
53
/*
P/P * Method: String getWeblogURL(Weblog, String, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuffer:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuffer:toString(...)}
*
* Test Vectors:
* absolute: {0}, {1}
* locale: Addr_Set{null}, Inverse{null}
* weblog: Inverse{null}, Addr_Set{null}
*/
54 if(weblog == null) {
55 return null;
56 }
57
58 StringBuffer url = new StringBuffer();
59
60 if(absolute) {
61 url.append(WebloggerRuntimeConfig.getAbsoluteContextURL());
62 } else {
63 url.append(WebloggerRuntimeConfig.getRelativeContextURL());
64 }
65
66 url.append("/").append(weblog.getHandle()).append("/");
67
68 if(locale != null) {
69 url.append(locale).append("/");
70 }
71
72 return url.toString();
73 }
74
75
76 /**
77 * Get url for a single weblog entry on a given weblog.
78 */
79 public String getWeblogEntryURL(Weblog weblog,
80 String locale,
81 String entryAnchor,
82 boolean absolute) {
83
/*
P/P * Method: String getWeblogEntryURL(Weblog, String, String, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuffer:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuffer:toString(...)}
*
* Test Vectors:
* entryAnchor: Inverse{null}, Addr_Set{null}
* weblog: Addr_Set{null}, Inverse{null}
*/
84 if(weblog == null || entryAnchor == null) {
85 return null;
86 }
87
88 StringBuffer url = new StringBuffer();
89
90 url.append(getWeblogURL(weblog, locale, absolute));
91 url.append("entry/").append(URLUtilities.encode(entryAnchor));
92
93 return url.toString();
94 }
95
96
97 /**
98 * Get url for a single weblog entry comments on a given weblog.
99 */
100 public String getWeblogCommentsURL(Weblog weblog,
101 String locale,
102 String entryAnchor,
103 boolean absolute) {
104
/*
P/P * Method: String getWeblogCommentsURL(Weblog, String, String, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*/
105 return getWeblogEntryURL(weblog, locale, entryAnchor, absolute)+"#comments";
106 }
107
108
109 /**
110 * Get url for a single weblog entry comment on a given weblog.
111 */
112 public String getWeblogCommentURL(Weblog weblog,
113 String locale,
114 String entryAnchor,
115 String timeStamp,
116 boolean absolute) {
117
/*
P/P * Method: String getWeblogCommentURL(Weblog, String, String, String, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*/
118 return getWeblogEntryURL(weblog, locale, entryAnchor, absolute)+"#comment-"+timeStamp;
119 }
120
121
122 /**
123 * Get url for a collection of entries on a given weblog.
124 */
125 public String getWeblogCollectionURL(Weblog weblog,
126 String locale,
127 String category,
128 String dateString,
129 List tags,
130 int pageNum,
131 boolean absolute) {
132
/*
P/P * Method: String getWeblogCollectionURL(Weblog, String, String, String, List, int, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* category: Addr_Set{null}, Inverse{null}
* dateString: Inverse{null}, Addr_Set{null}
* pageNum: {-231..0}, {1..232-1}
* tags: Addr_Set{null}, Inverse{null}
* weblog: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@143: {0}, {1}
* java.lang.String:startsWith(...)@145: {0}, {1}
* java.util.List:size(...)@155: {-231..0}, {1..232-1}
*/
133 if(weblog == null) {
134 return null;
135 }
136
137 StringBuffer pathinfo = new StringBuffer();
138 Map params = new HashMap();
139
140 pathinfo.append(getWeblogURL(weblog, locale, absolute));
141
142 String cat = null;
143 if(category != null && "/".equals(category)) {
144 cat = null;
145 } else if(category != null && category.startsWith("/")) {
146 cat = category.substring(1);
147 }
148
149 if(cat != null && dateString == null) {
150 pathinfo.append("category/").append(URLUtilities.encodePath(cat));
151
152 } else if(dateString != null && cat == null) {
153 pathinfo.append("date/").append(dateString);
154
155 } else if(tags != null && tags.size() > 0) {
156 pathinfo.append("tags/").append(URLUtilities.getEncodedTagsString(tags));
157 } else {
158 if(dateString != null) params.put("date", dateString);
159 if(cat != null) params.put("cat", URLUtilities.encode(cat));
160 }
161
162 if(pageNum > 0) {
163 params.put("page", Integer.toString(pageNum));
164 }
165
166 return pathinfo.toString() + URLUtilities.getQueryString(params);
167 }
168
169
170 /**
171 * Get url for a custom page on a given weblog.
172 */
173 public String getWeblogPageURL(Weblog weblog,
174 String locale,
175 String pageLink,
176 String entryAnchor,
177 String category,
178 String dateString,
179 List tags,
180 int pageNum,
181 boolean absolute) {
182
/*
P/P * Method: String getWeblogPageURL(Weblog, String, String, String, String, String, List, int, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* category: Addr_Set{null}, Inverse{null}
* dateString: Addr_Set{null}, Inverse{null}
* pageLink: Addr_Set{null}, Inverse{null}
* pageNum: {-231..0}, {1..232-1}
* tags: Addr_Set{null}, Inverse{null}
* weblog: Inverse{null}, Addr_Set{null}
* java.util.List:size(...)@202: {-231..0}, {1..232-1}
*/
183 if(weblog == null) {
184 return null;
185 }
186
187 StringBuffer pathinfo = new StringBuffer();
188 Map params = new HashMap();
189
190 pathinfo.append(getWeblogURL(weblog, locale, absolute));
191
192 if(pageLink != null) {
193 pathinfo.append("page/").append(pageLink);
194
195 // for custom pages we only allow query params
196 if(dateString != null) {
197 params.put("date", dateString);
198 }
199 if(category != null) {
200 params.put("cat", URLUtilities.encode(category));
201 }
202 if(tags != null && tags.size() > 0) {
203 params.put("tags", URLUtilities.getEncodedTagsString(tags));
204 }
205 if(pageNum > 0) {
206 params.put("page", Integer.toString(pageNum));
207 }
208 } else {
209 // if there is no page link then this is just a typical collection url
210 return getWeblogCollectionURL(weblog, locale, category, dateString, tags, pageNum, absolute);
211 }
212
213 return pathinfo.toString() + URLUtilities.getQueryString(params);
214 }
215
216
217 /**
218 * Get url for a feed on a given weblog.
219 */
220 public String getWeblogFeedURL(Weblog weblog,
221 String locale,
222 String type,
223 String format,
224 String category,
225 String term,
226 List tags,
227 boolean excerpts,
228 boolean absolute) {
229
/*
P/P * Method: String getWeblogFeedURL(Weblog, String, String, String, String, String, List, bool, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* category: Addr_Set{null}, Inverse{null}
* excerpts: {0}, {1}
* tags: Addr_Set{null}, Inverse{null}
* term: Addr_Set{null}, Inverse{null}
* weblog: Inverse{null}, Addr_Set{null}
* java.lang.String:length(...)@240: {0}, {1..232-1}
* java.lang.String:length(...)@246: {0}, {1..232-1}
* java.util.List:size(...)@243: {-231..0}, {1..232-1}
*/
230 if(weblog == null) {
231 return null;
232 }
233
234 StringBuffer url = new StringBuffer();
235
236 url.append(getWeblogURL(weblog, locale, absolute));
237 url.append("feed/").append(type).append("/").append(format);
238
239 Map params = new HashMap();
240 if(category != null && category.trim().length() > 0) {
241 params.put("cat", URLUtilities.encode(category));
242 }
243 if(tags != null && tags.size() > 0) {
244 params.put("tags", URLUtilities.getEncodedTagsString(tags));
245 }
246 if(term != null && term.trim().length() > 0) {
247 params.put("q", URLUtilities.encode(term.trim()));
248 }
249 if(excerpts) {
250 params.put("excerpts", "true");
251 }
252
253 return url.toString() + URLUtilities.getQueryString(params);
254 }
255
256
257 /**
258 * Get url to search endpoint on a given weblog.
259 */
260 public String getWeblogSearchURL(Weblog weblog,
261 String locale,
262 String query,
263 String category,
264 int pageNum,
265 boolean absolute) {
266
/*
P/P * Method: String getWeblogSearchURL(Weblog, String, String, String, int, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* category: Addr_Set{null}, Inverse{null}
* pageNum: {-231..0}, {1..232-1}
* query: Addr_Set{null}, Inverse{null}
* weblog: Inverse{null}, Addr_Set{null}
*/
267 if(weblog == null) {
268 return null;
269 }
270
271 StringBuffer url = new StringBuffer();
272
273 url.append(getWeblogURL(weblog, locale, absolute));
274 url.append("search");
275
276 Map params = new HashMap();
277 if(query != null) {
278 params.put("q", URLUtilities.encode(query));
279
280 // other stuff only makes sense if there is a query
281 if(category != null) {
282 params.put("cat", URLUtilities.encode(category));
283 }
284 if(pageNum > 0) {
285 params.put("page", Integer.toString(pageNum));
286 }
287 }
288
289 return url.toString() + URLUtilities.getQueryString(params);
290 }
291
292
293 /**
294 * Get url to a resource on a given weblog.
295 */
296 public String getWeblogResourceURL(Weblog weblog,
297 String filePath,
298 boolean absolute) {
299
/*
P/P * Method: String getWeblogResourceURL(Weblog, String, bool)
*
* Preconditions:
* (soft) filePath != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuffer:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuffer:toString(...)}
*
* Test Vectors:
* weblog: Addr_Set{null}, Inverse{null}
* java.lang.String:startsWith(...)@309: {0}, {1}
* org.apache.commons.lang.StringUtils:isEmpty(...)@300: {0}, {1}
*/
300 if(weblog == null || StringUtils.isEmpty(filePath)) {
301 return null;
302 }
303
304 StringBuffer url = new StringBuffer();
305
306 url.append(getWeblogURL(weblog, null, absolute));
307 url.append("resource/");
308
309 if(filePath.startsWith("/")) {
310 url.append(URLUtilities.encodePath(filePath.substring(1)));
311 } else {
312 url.append(URLUtilities.encodePath(filePath));
313 }
314
315 return url.toString();
316 }
317
318
319 /**
320 * Get url to rsd file on a given weblog.
321 */
322 public String getWeblogRsdURL(Weblog weblog,
323 boolean absolute) {
324
/*
P/P * Method: String getWeblogRsdURL(Weblog, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == One-of{null, &java.lang.StringBuilder:toString(...)}
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* weblog: Inverse{null}, Addr_Set{null}
*/
325 if(weblog == null) {
326 return null;
327 }
328
329 return getWeblogURL(weblog, null, absolute)+"rsd";
330 }
331
332
333 /**
334 * Get url to JSON tags service url, optionally for a given weblog.
335 */
336 public String getWeblogTagsJsonURL(Weblog weblog,
337 boolean absolute) {
338
/*
P/P * Method: String getWeblogTagsJsonURL(Weblog, bool)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.absoluteContextURL)
* (soft) org/apache/roller/weblogger/config/WebloggerRuntimeConfig.log != null
* (soft) init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.relativeContextURL)
*
* Postconditions:
* init'ed(java.lang.StringBuffer:toString(...)._tainted)
* return_value == &java.lang.StringBuffer:toString(...)
*
* Test Vectors:
* absolute: {0}, {1}
* weblog: Addr_Set{null}, Inverse{null}
*/
339 StringBuffer url = new StringBuffer();
340
341 if(absolute) {
342 url.append(WebloggerRuntimeConfig.getAbsoluteContextURL());
343 } else {
344 url.append(WebloggerRuntimeConfig.getRelativeContextURL());
345 }
346
347 // json tags service base
348 url.append("/roller-services/json/tags/");
349
350 // is this for a specific weblog or site-wide?
351 if(weblog != null) {
352 url.append(weblog.getHandle()).append("/");
353 }
354
355 return url.toString();
356 }
357
358 }
SofCheck Inspector Build Version : 2.18479
| MultiWeblogURLStrategy.java |
2009-Jan-02 14:25:42 |
| MultiWeblogURLStrategy.class |
2009-Sep-04 03:12:30 |