1 21 22 package org.opensubsystems.blog.www; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import javax.servlet.http.HttpServletRequest ; 28 29 import org.opensubsystems.blog.data.Blog; 30 import org.opensubsystems.blog.data.Entry; 31 import org.opensubsystems.core.util.Log; 32 import org.opensubsystems.core.www.WebCommonConstants; 33 import org.opensubsystems.core.www.WebUtils; 34 35 50 public class BlogNavigator 51 { 52 54 57 public static final String LOGIN_WEB_PAGE = "login.html"; 58 59 62 public static final String LOGOUT_WEB_PAGE = "logout.html"; 63 64 66 69 protected String m_strBlogDirectoryURL; 70 71 74 protected HttpServletRequest m_hsrqRequest; 75 76 78 81 private static Logger s_logger = Log.getInstance(BlogNavigator.class); 82 83 85 90 public BlogNavigator( 91 HttpServletRequest hsrqRequest 92 ) 93 { 94 m_hsrqRequest = hsrqRequest; 95 96 String strBlogDirectoryURL = hsrqRequest.getContextPath(); 100 101 if (!strBlogDirectoryURL.endsWith(WebCommonConstants.URL_SEPARATOR)) 102 { 103 s_logger.finest("Optimize call to BlogNavigator constructor" + 106 " to pass fully formed URL."); 107 108 StringBuffer sbTemp = new StringBuffer (strBlogDirectoryURL); 109 sbTemp.append(WebCommonConstants.URL_SEPARATOR); 110 m_strBlogDirectoryURL = sbTemp.toString(); 111 } 112 else 113 { 114 m_strBlogDirectoryURL = strBlogDirectoryURL; 115 } 116 } 117 118 120 125 public String getPostURL( 126 ) 127 { 128 return ""; 131 } 132 133 138 public String getRootURL( 139 ) 140 { 141 StringBuffer sbURL = new StringBuffer (m_strBlogDirectoryURL); 142 143 sbURL.append(WebCommonConstants.DEFAULT_DIRECTORY_WEB_PAGE); 144 return sbURL.toString(); 145 } 146 147 153 public String getURL( 154 Blog blog 155 ) 156 { 157 return getBlogURL(blog.getFolder()); 158 } 159 160 167 public String getBlogURL( 168 Object objBlogIdentification 169 ) 170 { 171 StringBuffer sbURL; 172 173 sbURL = getBlogRootURL(objBlogIdentification.toString()); 174 sbURL.append(WebCommonConstants.DEFAULT_DIRECTORY_WEB_PAGE); 175 176 return sbURL.toString(); 177 } 178 179 186 public String getURL( 187 Blog blog, 188 Entry entry 189 ) 190 { 191 return getBlogEntryURL(blog.getFolder(), entry.getId()); 192 } 193 194 200 public String getURL( 201 BlogEntryIdentification entryIdentification 202 ) 203 { 204 return getBlogEntryURL((String )entryIdentification.m_objBlogIdentification, 205 entryIdentification.m_iBlogEntryIdentification); 206 } 207 208 217 public Object getBlogIdentification( 218 HttpServletRequest hsrqRequest 219 ) 220 { 221 String strBlogId = ""; 224 String strExtraPath; 225 String strURL; 226 227 strURL = hsrqRequest.getServletPath(); 228 strExtraPath = hsrqRequest.getPathInfo(); 229 if (strExtraPath != null) 230 { 231 strURL += strExtraPath; 232 } 233 if ((strURL != null) && (strURL.length() > 0)) 234 { 235 int iIndex = strURL.indexOf(WebCommonConstants.URL_SEPARATOR_CHAR); 236 int iLastIndex = strURL.lastIndexOf(WebCommonConstants.URL_SEPARATOR_CHAR); 237 if ((iLastIndex != -1) && (iLastIndex > iIndex)) 238 { 239 strBlogId = strURL.substring(iIndex + 1, iLastIndex); 241 } 242 } 243 244 return strBlogId; 245 } 246 247 253 public BlogEntryIdentification getBlogEntryIdentification( 254 HttpServletRequest hsrqRequest 255 ) 256 { 257 String strBlogURL; 258 String strExtraPath; 259 BlogEntryIdentification entryIdentification = null; 260 261 strBlogURL = hsrqRequest.getServletPath(); 262 strExtraPath = hsrqRequest.getPathInfo(); 263 if (strExtraPath != null) 264 { 265 strBlogURL += strExtraPath; 266 } 267 if ((strBlogURL != null) && (strBlogURL.length() > 0)) 268 { 269 int iIndex = strBlogURL.indexOf(WebCommonConstants.URL_SEPARATOR_CHAR); 270 int iLastIndex = strBlogURL.lastIndexOf(WebCommonConstants.URL_SEPARATOR_CHAR); 271 272 if ((iLastIndex != -1) && (iLastIndex > iIndex)) 273 { 274 try 275 { 276 int iEntryId; 277 278 iEntryId = Integer.parseInt( 279 strBlogURL.substring(iLastIndex + 1, 280 strBlogURL.lastIndexOf( 281 WebCommonConstants.WEB_PAGE_EXTENSION))); 282 entryIdentification = new BlogEntryIdentification(); 283 entryIdentification.m_objBlogIdentification 284 = strBlogURL.substring(strBlogURL.indexOf( 285 WebCommonConstants.URL_SEPARATOR_CHAR) + 1, iLastIndex); 286 entryIdentification.m_iBlogEntryIdentification = iEntryId; 287 288 } 289 catch (NumberFormatException nfeExc) 290 { 291 s_logger.log(Level.FINEST, 292 "The URL doesn't identify valid Blog entry.", nfeExc); 293 } 295 } 296 } 297 298 return entryIdentification; 299 } 300 301 307 public boolean isLoginPage( 308 ) 309 { 310 String strPath; 311 312 strPath = WebUtils.getFullRequestPath(m_hsrqRequest); 313 314 return strPath.endsWith(LOGIN_WEB_PAGE); 315 } 316 317 323 public boolean isLogoutPage( 324 ) 325 { 326 String strPath; 327 328 strPath = WebUtils.getFullRequestPath(m_hsrqRequest); 329 330 return strPath.endsWith(LOGOUT_WEB_PAGE); 331 } 332 333 335 341 protected StringBuffer getBlogRootURL( 342 String strId 343 ) 344 { 345 StringBuffer sbURL; 346 347 sbURL = new StringBuffer (m_strBlogDirectoryURL); 348 sbURL.append(strId); 349 sbURL.append(WebCommonConstants.URL_SEPARATOR_CHAR); 350 351 return sbURL; 352 } 353 354 361 protected String getBlogEntryURL( 362 String strFolder, 363 int iEntryId 364 ) 365 { 366 StringBuffer sbURL; 367 368 sbURL = getBlogRootURL(strFolder); 369 sbURL.append(iEntryId); 370 sbURL.append(WebCommonConstants.WEB_PAGE_EXTENSION); 371 372 return sbURL.toString(); 373 } 374 375 } 376 | Popular Tags |