1 21 22 package org.opensubsystems.blog.www; 23 24 import java.io.IOException ; 25 import java.util.List ; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import javax.servlet.ServletConfig ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import org.opensubsystems.blog.logic.BlogController; 35 import org.opensubsystems.core.error.OSSException; 36 import org.opensubsystems.core.logic.ControllerManager; 37 import org.opensubsystems.core.util.Log; 38 import org.opensubsystems.core.www.WebUIServlet; 39 import org.opensubsystems.core.www.WebUtils; 40 41 52 public class BlogBrowserServlet extends WebUIServlet 53 { 54 56 60 public static final String BLOGBROWSER_BLOG_INDEX_PAGE = "blogbrowser.blog.index.page"; 61 62 65 public static final String BLOGBROWSER_BLOG_VIEWER_PAGE = "blogbrowser.blog.viewer.page"; 66 67 70 public static final String BLOGBROWSER_BLOGENTRY_VIEWER_PAGE 71 = "blogbrowser.entry.viewer.page"; 72 73 75 78 public static final int FORM_COUNT_BLOGBROWSER = FORM_COUNT_WEBUI; 79 80 82 85 private static Logger s_logger = Log.getInstance(BlogBrowserServlet.class); 86 87 89 92 private static final long serialVersionUID = 3131866602964809055L; 93 94 96 99 public void init( 100 ServletConfig scConfig 101 ) throws ServletException 102 { 103 super.init(scConfig); 104 105 cacheUIPath(scConfig, BLOGBROWSER_BLOG_INDEX_PAGE, 108 "Path to main index page is not set in property " 109 + BLOGBROWSER_BLOG_INDEX_PAGE); 110 111 cacheUIPath(scConfig, BLOGBROWSER_BLOG_VIEWER_PAGE, 113 "Path to blog viewer page is not set in property " 114 + BLOGBROWSER_BLOG_INDEX_PAGE); 115 116 cacheUIPath(scConfig, BLOGBROWSER_BLOGENTRY_VIEWER_PAGE, 118 "Path to entry viewer page is not set in property " 119 + BLOGBROWSER_BLOGENTRY_VIEWER_PAGE); 120 } 121 122 125 protected void doGet( 126 HttpServletRequest hsrqRequest, 127 HttpServletResponse hsrpResponse 128 ) throws ServletException , 129 IOException 130 { 131 if (WebUtils.isIndexPage(hsrqRequest)) 132 { 133 if (WebUtils.isMainIndexPage(hsrqRequest)) 134 { 135 createMainIndexPage(hsrqRequest, hsrpResponse); 137 } 138 else 139 { 140 createIndexPage(hsrqRequest, hsrpResponse); 142 } 143 } 144 else 145 { 146 if (WebUtils.isStaticWebPage(hsrqRequest)) 147 { 148 createBlogEntryPage(hsrqRequest, hsrpResponse); 150 } 151 else 152 { 153 hsrpResponse.sendError(HttpServletResponse.SC_NOT_FOUND); 154 } 155 } 156 } 157 158 161 public String getServletInfo( 162 ) 163 { 164 return this.getClass().getName(); 165 } 166 167 169 177 protected void createMainIndexPage( 178 HttpServletRequest hsrqRequest, 179 HttpServletResponse hsrpResponse 180 ) throws IOException , 181 ServletException 182 { 183 s_logger.entering(this.getClass().getName(), "createMainIndexPage"); 184 185 try 186 { 187 List lstBlogs; 188 189 lstBlogs = getController().getAll(); 190 if (lstBlogs != null) 191 { 192 hsrqRequest.setAttribute("blogs", lstBlogs); 193 } 194 hsrqRequest.setAttribute("blognavigator", getNavigator(hsrqRequest)); 195 displayUI(BLOGBROWSER_BLOG_INDEX_PAGE, hsrqRequest, hsrpResponse); 196 } 197 catch (Exception eExc) 198 { 199 s_logger.log(Level.WARNING, 200 "An error has occured while retrieving list of blogs.", 201 eExc); 202 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 203 getNavigator(hsrqRequest).getRootURL(), 204 eExc.getCause()); 205 } 206 finally 207 { 208 s_logger.exiting(this.getClass().getName(), "createMainIndexPage"); 209 } 210 } 211 212 220 protected void createIndexPage( 221 HttpServletRequest hsrqRequest, 222 HttpServletResponse hsrpResponse 223 ) throws IOException , 224 ServletException 225 { 226 s_logger.entering(this.getClass().getName(), "createIndexPage"); 227 228 try 229 { 230 Object objBlogIdentification; 231 Object [] arObjects; 232 BlogNavigator navigator; 233 234 navigator = getNavigator(hsrqRequest); 235 objBlogIdentification = navigator.getBlogIdentification(hsrqRequest); 236 arObjects = getController().getWithEntries((String )objBlogIdentification); 237 238 if ((arObjects != null) && (arObjects[0] != null)) 239 { 240 hsrqRequest.setAttribute("blog", arObjects[0]); 241 if (arObjects[1] != null) 243 { 244 hsrqRequest.setAttribute("blogentries", arObjects[1]); 245 } 246 hsrqRequest.setAttribute("blognavigator", navigator); 247 displayUI(BLOGBROWSER_BLOG_VIEWER_PAGE, hsrqRequest, hsrpResponse); 248 } 249 else 250 { 251 hsrpResponse.sendError(HttpServletResponse.SC_NOT_FOUND); 254 } 255 } 256 catch (Exception eExc) 257 { 258 s_logger.log(Level.WARNING, "An error has occured while retrieving blog.", 259 eExc); 260 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 261 getNavigator(hsrqRequest).getRootURL(), 262 eExc.getCause()); 263 } 264 finally 265 { 266 s_logger.exiting(this.getClass().getName(), "createIndexPage"); 267 } 268 } 269 270 278 protected void createBlogEntryPage( 279 HttpServletRequest hsrqRequest, 280 HttpServletResponse hsrpResponse 281 ) throws IOException , 282 ServletException 283 { 284 s_logger.entering(this.getClass().getName(), "createBlogEntryPage"); 285 286 try 287 { 288 BlogEntryIdentification entryIdentification; 289 Object [] arObjects = null; 290 BlogNavigator navigator; 291 292 navigator = getNavigator(hsrqRequest); 293 entryIdentification = navigator.getBlogEntryIdentification(hsrqRequest); 294 if (entryIdentification != null) 295 { 296 arObjects = getController().getWithEntry( 297 (String )entryIdentification.getBlogIdentification(), 298 entryIdentification.getBlogEntryIdentification()); 299 } 300 301 if ((arObjects != null) && (arObjects[0] != null) 302 && (arObjects[1] != null)) 303 { 304 hsrqRequest.setAttribute("blog", arObjects[0]); 305 hsrqRequest.setAttribute("blogentry", arObjects[1]); 306 hsrqRequest.setAttribute("blognavigator", navigator); 307 displayUI(BLOGBROWSER_BLOGENTRY_VIEWER_PAGE, hsrqRequest, hsrpResponse); 308 } 309 else 310 { 311 hsrpResponse.sendError(HttpServletResponse.SC_NOT_FOUND); 314 } 315 } 316 catch (Exception eExc) 317 { 318 s_logger.log(Level.WARNING, 319 "An error has occured while retrieving blog entry.", 320 eExc); 321 messageBoxPage(hsrqRequest, hsrpResponse, "Error", eExc.getMessage(), 322 getNavigator(hsrqRequest).getRootURL(), eExc.getCause()); 323 } 324 finally 325 { 326 s_logger.exiting(this.getClass().getName(), "createBlogEntryPage"); 327 } 328 } 329 330 332 338 protected BlogNavigator getNavigator( 339 HttpServletRequest hsrqRequest 340 ) 341 { 342 return new BlogNavigator(hsrqRequest); 343 } 344 345 351 protected BlogController getController( 352 ) throws OSSException 353 { 354 BlogController controller; 355 356 controller = (BlogController)ControllerManager.getInstance( 357 BlogController.class); 358 359 return controller; 360 } 361 } 362 | Popular Tags |