1 18 19 package org.apache.roller.ui.rendering.model; 20 21 import java.net.MalformedURLException ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import javax.servlet.jsp.PageContext ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.roller.RollerException; 28 import org.apache.roller.config.RollerRuntimeConfig; 29 import org.apache.roller.pojos.WebsiteData; 30 import org.apache.roller.ui.core.RequestConstants; 31 import org.apache.roller.ui.rendering.util.WeblogRequest; 32 import org.apache.roller.util.URLUtilities; 33 import org.apache.struts.util.RequestUtils; 34 35 36 49 public class URLModel implements Model { 50 51 private static Log log = LogFactory.getLog(URLModel.class); 52 53 private WebsiteData weblog = null; 54 private String locale = null; 55 56 57 private PageContext pageContext = null; 58 59 60 public URLModel() {} 61 62 public String getModelName() { 63 return "url"; 64 } 65 66 public void init(Map initData) throws RollerException { 67 68 WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest"); 70 if(weblogRequest == null) { 71 throw new RollerException("Expected 'weblogRequest' init param!"); 72 } 73 74 this.weblog = weblogRequest.getWeblog(); 75 this.locale = weblogRequest.getLocale(); 76 77 pageContext = (PageContext ) initData.get("pageContext"); 79 } 80 81 82 83 public String getSite() { 84 return RollerRuntimeConfig.getRelativeContextURL(); 85 } 86 87 88 89 public String getAbsoluteSite() { 90 return RollerRuntimeConfig.getAbsoluteContextURL(); 91 } 92 93 94 95 public String getLogin() { 96 String returnURL = null; 97 try { 98 returnURL = RequestUtils.computeURL(pageContext, 99 "login-redirect", null, null, null, null, null, false); 100 } catch (MalformedURLException mue) { 101 log.error("ERROR forming Struts URL: ", mue); 102 } 103 return returnURL; 104 } 105 106 107 108 public String getLogout() { 109 String returnURL = null; 110 try { 111 returnURL = RequestUtils.computeURL(pageContext, 112 "logout-redirect", null, null, null, null, null, false); 113 } catch (MalformedURLException mue) { 114 log.error("ERROR forming Struts URL: ", mue); 115 } 116 return returnURL; 117 } 118 119 120 public String getCommentAuthenticator() { 121 return getSite()+"/CommentAuthenticatorServlet"; 122 } 123 124 125 public String themeResource(String theme, String filePath) { 126 return getSite()+RollerRuntimeConfig.getProperty("users.themes.path")+"/"+theme+"/"+filePath; 127 } 128 129 public String themeResource(String theme, String filePath, boolean absolute) { 130 if (absolute) { 131 return getAbsoluteSite()+RollerRuntimeConfig.getProperty("users.themes.path")+"/"+theme+"/"+filePath; 132 } 133 return themeResource(theme, filePath); 134 } 135 136 public String getHome() { 137 return URLUtilities.getWeblogCollectionURL(weblog, locale, null, null, -1, true); 138 } 139 140 141 public String home(int pageNum) { 142 return URLUtilities.getWeblogCollectionURL(weblog, locale, null, null, pageNum, true); 143 } 144 145 146 public String home(String customLocale) { 147 return URLUtilities.getWeblogCollectionURL(weblog, customLocale, null, null, -1, true); 148 } 149 150 151 public String home(String customLocale, int pageNum) { 152 return URLUtilities.getWeblogCollectionURL(weblog, customLocale, null, null, pageNum, true); 153 } 154 155 156 public String entry(String anchor) { 157 return URLUtilities.getWeblogEntryURL(weblog, locale, anchor, true); 158 } 159 160 public String comment(String anchor, String timeStamp) { 161 return URLUtilities.getWeblogCommentURL(weblog, locale, anchor, timeStamp, true); 162 } 163 164 165 public String comments(String anchor) { 166 return URLUtilities.getWeblogCommentsURL(weblog, locale, anchor, true); 167 } 168 169 170 public String trackback(String anchor) { 171 return URLUtilities.getWeblogEntryURL(weblog, locale, anchor, true); 172 } 173 174 175 public String date(String dateString) { 176 return URLUtilities.getWeblogCollectionURL(weblog, locale, null, dateString, -1, true); 177 } 178 179 180 public String date(String dateString, int pageNum) { 181 return URLUtilities.getWeblogCollectionURL(weblog, locale, null, dateString, pageNum, true); 182 } 183 184 185 public String category(String catPath) { 186 return URLUtilities.getWeblogCollectionURL(weblog, locale, catPath, null, -1, true); 187 } 188 189 190 public String category(String catPath, int pageNum) { 191 return URLUtilities.getWeblogCollectionURL(weblog, locale, catPath, null, pageNum, true); 192 } 193 194 195 public String collection(String dateString, String catPath) { 196 return URLUtilities.getWeblogCollectionURL(weblog, locale, catPath, dateString, -1, true); 197 } 198 199 200 public String collection(String dateString, String catPath, int pageNum) { 201 return URLUtilities.getWeblogCollectionURL(weblog, locale, catPath, dateString, pageNum, true); 202 } 203 204 205 public String getSearch() { 206 return URLUtilities.getWeblogSearchURL(weblog, locale, null, null, -1, false); 207 } 208 209 210 public String search(String query, int pageNum) { 211 return URLUtilities.getWeblogSearchURL(weblog, locale, query, null, pageNum, false); 212 } 213 214 215 public String search(String query, String catPath, int pageNum) { 216 return URLUtilities.getWeblogSearchURL(weblog, locale, query, catPath, pageNum, false); 217 } 218 219 220 public String page(String pageLink) { 221 return URLUtilities.getWeblogPageURL(weblog, locale, pageLink, null, null, null, -1, true); 222 } 223 224 225 public String page(String pageLink, String dateString, String catPath, int pageNum) { 226 return URLUtilities.getWeblogPageURL(weblog, locale, pageLink, null, catPath, dateString, pageNum, true); 227 } 228 229 230 public String resource(String filePath) { 231 return URLUtilities.getWeblogResourceURL(weblog, filePath, true); 232 } 233 234 235 public String getRsd() { 236 return URLUtilities.getWeblogRsdURL(weblog, true); 237 } 238 239 240 public FeedURLS getFeed() { 241 return new FeedURLS(); 242 } 243 244 245 246 public String editEntry(String anchor) { 247 String ret = null; 248 Map params = new HashMap (); 249 params.put(RequestConstants.ANCHOR, anchor); 250 params.put(RequestConstants.WEBLOG, weblog.getHandle()); 251 try { 252 ret = RequestUtils.computeURL(pageContext, 253 "weblogEdit", null, null, null, params, null, false); 254 } catch (MalformedURLException mue) { 255 log.error("ERROR forming Struts URL: ", mue); 256 } 257 return ret; 258 } 259 260 261 262 public String getCreateEntry() { 263 String returnURL = null; 264 Map params = new HashMap (); 265 params.put(RequestConstants.WEBLOG, weblog.getHandle()); 266 try { 267 returnURL = RequestUtils.computeURL(pageContext, 268 "weblogCreate", null, null, null, params, null, false); 269 } catch (MalformedURLException mue) { 270 log.error("ERROR forming Struts URL: ", mue); 271 } 272 return returnURL; 273 } 274 275 276 277 public String getEditSettings() { 278 String returnURL = null; 279 Map params = new HashMap (); 280 params.put(RequestConstants.WEBLOG, weblog.getHandle()); 281 try { 282 returnURL = RequestUtils.computeURL(pageContext, 283 "editWebsite", null, null, null, params, null, false); 284 } catch (MalformedURLException mue) { 285 log.error("ERROR forming Struts URL: ", mue); 286 } 287 return returnURL; 288 } 289 290 291 293 public class FeedURLS { 294 295 public EntryFeedURLS getEntries() { 296 return new EntryFeedURLS(); 297 } 298 299 public CommentFeedURLS getComments() { 300 return new CommentFeedURLS(); 301 } 302 } 303 304 public class EntryFeedURLS { 305 306 public String getRss() { 307 return URLUtilities.getWeblogFeedURL(weblog, locale, "entries", "rss", null, false, true); 308 } 309 310 public String rss(String catPath, boolean excerpts) { 311 return URLUtilities.getWeblogFeedURL(weblog, locale, "entries", "rss", catPath, excerpts, true); 312 } 313 314 public String getAtom() { 315 return URLUtilities.getWeblogFeedURL(weblog, locale, "entries", "atom", null, false, true); 316 } 317 318 public String atom(String catPath, boolean excerpts) { 319 return URLUtilities.getWeblogFeedURL(weblog, locale, "entries", "atom", catPath, excerpts, true); 320 } 321 } 322 323 public class CommentFeedURLS { 324 325 public String getRss() { 326 return URLUtilities.getWeblogFeedURL(weblog, locale, "comments", "rss", null, false, true); 327 } 328 329 public String rss(String catPath, boolean excerpts) { 330 return URLUtilities.getWeblogFeedURL(weblog, locale, "comments", "rss", catPath, excerpts, true); 331 } 332 333 public String getAtom() { 334 return URLUtilities.getWeblogFeedURL(weblog, locale, "comments", "atom", null, false, true); 335 } 336 337 public String atom(String catPath, boolean excerpts) { 338 return URLUtilities.getWeblogFeedURL(weblog, locale, "comments", "atom", catPath, excerpts, true); 339 } 340 341 } 342 343 } 344 | Popular Tags |