| 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.data.DataConstant; 32 import org.opensubsystems.core.util.Log; 33 import org.opensubsystems.core.www.WebCommonConstants; 34 import org.opensubsystems.core.www.WebUtils; 35 import org.opensubsystems.patterns.listdata.data.DataCondition; 36 import org.opensubsystems.patterns.listdata.www.ListBrowserServlet; 37 38 48 public class DynamicBlogNavigator extends BlogNavigator 49 { 50 52 56 public static final String DYNAMIC_LOGIN_WEB_PAGE = "logindynamic.html"; 57 58 62 public static final String DYNAMIC_LOGOUT_WEB_PAGE = "logoutdynamic.html"; 63 64 70 public static final String DYNAMIC_POST_WEB_PAGE = "dynamic.html"; 71 72 74 77 private static Logger s_logger = Log.getInstance(DynamicBlogNavigator.class); 78 79 81 86 public DynamicBlogNavigator( 87 HttpServletRequest hsrqRequest 88 ) 89 { 90 super(hsrqRequest); 91 } 92 93 95 98 public boolean getIsDynamic() 99 { 100 return true; 101 } 102 103 106 public String getPostURL( 107 ) 108 { 109 return DYNAMIC_POST_WEB_PAGE; 113 } 114 115 118 public String getRootURL( 119 ) 120 { 121 StringBuffer sbURL; 122 123 sbURL = new StringBuffer (m_strBlogDirectoryURL); 124 sbURL.append("blogs"); 125 126 return sbURL.toString(); 127 } 128 129 132 public String getURL( 133 Blog blog 134 ) 135 { 136 return getBlogURL(blog.getIdAsObject()); 137 } 138 139 142 public String getBlogURL( 143 Object objBlogIdentification 144 ) 145 { 146 String strURL; 147 148 if (objBlogIdentification instanceof Integer ) 149 { 150 StringBuffer sbURL; 153 154 161 162 sbURL = new StringBuffer (m_strBlogDirectoryURL); 163 sbURL.append("entries"); 164 sbURL.append(WebCommonConstants.URL_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE); 166 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(DataConstant.BLOG_DATA_TYPE); 168 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER); 170 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(((Integer )objBlogIdentification).intValue()); 172 173 strURL = sbURL.toString(); 174 } 175 else 176 { 177 strURL = super.getBlogURL(objBlogIdentification); 178 } 179 180 return strURL; 181 } 182 183 186 public String getURL( 187 Blog blog, 188 Entry entry 189 ) 190 { 191 return getURL(entry); 192 } 193 194 197 public String getURL( 198 Entry entry 199 ) 200 { 201 BlogEntryIdentification entryIdentification = new BlogEntryIdentification(); 202 203 entryIdentification.m_objBlogIdentification = new Integer (entry.getParentId()); 204 entryIdentification.m_iBlogEntryIdentification = entry.getId(); 205 206 return getURL(entryIdentification); 207 } 208 209 212 public String getURL( 213 BlogEntryIdentification entryIdentification 214 ) 215 { 216 StringBuffer sbURL; 217 218 237 238 sbURL = new StringBuffer (m_strBlogDirectoryURL); 239 sbURL.append("entries"); 240 sbURL.append(WebCommonConstants.URL_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE); 242 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(DataConstant.BLOG_DATA_TYPE); 244 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER); 246 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(((Integer )entryIdentification.m_objBlogIdentification).intValue()); 248 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE); 250 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(Entry.COL_BLOGENTRY_ID); 252 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_OPERAND); 254 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(DataCondition.OPERAND_EQUALS); 256 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE); 258 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(DataCondition.VALUE_TYPE_ID); 260 sbURL.append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); sbURL.append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE); 262 sbURL.append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); sbURL.append(entryIdentification.m_iBlogEntryIdentification); 264 265 return sbURL.toString(); 266 } 267 268 271 public Object getBlogIdentification( 272 HttpServletRequest hsrqRequest 273 ) 274 { 275 Object objReturn; 276 Integer iBlogId; 277 278 iBlogId = getBlogId(hsrqRequest); 279 if (iBlogId == null) 280 { 281 objReturn = super.getBlogIdentification(hsrqRequest); 282 } 283 else 284 { 285 objReturn = iBlogId; 286 } 287 288 return objReturn; 289 } 290 291 294 public BlogEntryIdentification getBlogEntryIdentification( 295 HttpServletRequest hsrqRequest 296 ) 297 { 298 BlogEntryIdentification entryIdentification = null; 299 Object objBlogId; 300 Integer iEntryId; 301 302 objBlogId = getBlogId(hsrqRequest); 303 iEntryId = getBlogEntryId(hsrqRequest); 304 305 if ((objBlogId != null) && (iEntryId != null)) 306 { 307 entryIdentification = new BlogEntryIdentification(); 308 entryIdentification.m_objBlogIdentification = objBlogId; 309 entryIdentification.m_iBlogEntryIdentification = iEntryId.intValue(); 310 } 311 else 312 { 313 s_logger.log(Level.FINEST, 314 "The request doesn't identify valid Blog entry."); 315 } 317 318 return entryIdentification; 319 } 320 321 324 public int isIndexPage( 325 ) 326 { 327 throw new UnsupportedOperationException ( 330 "Application should never call this method for dynamic navigation"); 331 } 332 333 336 public boolean isBlogIndexPage( 337 ) 338 { 339 throw new UnsupportedOperationException ( 342 "Application should never call this method for dynamic navigation"); 343 } 344 345 346 352 public boolean isLoginPage( 353 ) 354 { 355 String strPath; 356 357 strPath = WebUtils.getFullRequestPath(m_hsrqRequest); 358 359 return strPath.endsWith(DYNAMIC_LOGIN_WEB_PAGE); 360 } 361 362 368 public boolean isLogoutPage( 369 ) 370 { 371 String strPath; 372 373 strPath = WebUtils.getFullRequestPath(m_hsrqRequest); 374 375 return strPath.endsWith(DYNAMIC_LOGOUT_WEB_PAGE); 376 } 377 380 public String getFirstPageURL( 381 ) 382 { 383 throw new UnsupportedOperationException ( 386 "Application should never call this method for dynamic navigation"); 387 } 388 389 392 public String getLastPageURL( 393 ) 394 { 395 throw new UnsupportedOperationException ( 398 "Application should never call this method for dynamic navigation"); 399 } 400 401 403 410 protected Integer getBlogId( 411 HttpServletRequest hsrqRequest 412 ) 413 { 414 Integer iBlogId = null; 415 String strTemp; 416 417 strTemp = hsrqRequest.getParameter("BLOG_ID"); 419 if (strTemp != null) 420 { 421 try 422 { 423 iBlogId = new Integer (strTemp); 424 } 425 catch (NumberFormatException nfeExc) 426 { 427 } 429 } 430 431 if (iBlogId == null) 432 { 433 strTemp = hsrqRequest.getParameter("BLOGENTRY_BLOG_ID"); 434 if (strTemp != null) 435 { 436 try 437 { 438 iBlogId = new Integer (strTemp); 439 } 440 catch (NumberFormatException nfeExc) 441 { 442 } 444 } 445 } 446 447 if (iBlogId == null) 448 { 449 int iParentDataType = DataConstant.NO_DATA_TYPE; 450 451 strTemp = hsrqRequest.getParameter( 452 ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE); 453 if (strTemp != null) 454 { 455 try 456 { 457 iParentDataType = Integer.parseInt(strTemp); 458 if (iParentDataType == DataConstant.BLOG_DATA_TYPE) 459 { 460 strTemp = hsrqRequest.getParameter( 461 ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER); 462 if (strTemp != null) 463 { 464 iBlogId = new Integer (strTemp); 465 } 466 } 467 } 468 catch (NumberFormatException nfeExc) 469 { 470 } 472 } 473 } 474 475 return iBlogId; 476 } 477 478 485 protected Integer getBlogEntryId( 486 HttpServletRequest hsrqRequest 487 ) 488 { 489 Integer iBlogEntryId = null; 490 String strTemp; 491 492 strTemp = hsrqRequest.getParameter("BLOGENTRY_ID"); 494 if (strTemp != null) 495 { 496 try 497 { 498 iBlogEntryId = new Integer (strTemp); 499 } 500 catch (NumberFormatException nfeExc) 501 { 502 } 504 } 505 506 return iBlogEntryId; 507 } 508 } 509 | Popular Tags |