1 31 32 package org.opencms.jsp; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsRequestContext; 36 import org.opencms.flex.CmsFlexController; 37 import org.opencms.i18n.CmsMessageContainer; 38 import org.opencms.main.CmsLog; 39 import org.opencms.main.CmsRuntimeException; 40 import org.opencms.util.CmsRequestUtil; 41 42 import javax.servlet.http.HttpServletRequest ; 43 import javax.servlet.http.HttpServletResponse ; 44 import javax.servlet.jsp.PageContext ; 45 46 import org.apache.commons.logging.Log; 47 48 69 public class CmsJspBean { 70 71 72 private static final Log LOG = CmsLog.getLog(CmsJspBean.class); 73 74 75 private PageContext m_context; 76 77 78 private CmsFlexController m_controller; 79 80 81 private boolean m_isNotInitialized; 82 83 84 private boolean m_isSupressingExceptions; 85 86 87 private HttpServletRequest m_request; 88 89 90 private HttpServletResponse m_response; 91 92 95 public CmsJspBean() { 96 97 m_isSupressingExceptions = true; 99 m_isNotInitialized = true; 100 } 101 102 110 public CmsObject getCmsObject() { 111 112 if (m_isNotInitialized) { 113 return null; 114 } 115 return m_controller.getCmsObject(); 116 } 117 118 123 public PageContext getJspContext() { 124 125 return m_context; 126 } 127 128 133 public HttpServletRequest getRequest() { 134 135 return m_request; 136 } 137 138 143 public CmsRequestContext getRequestContext() { 144 145 return getCmsObject().getRequestContext(); 146 } 147 148 153 public HttpServletResponse getResponse() { 154 155 return m_response; 156 } 157 158 168 public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) { 169 170 m_controller = CmsFlexController.getController(req); 171 if (m_controller == null) { 172 throw new CmsRuntimeException(Messages.get().container( 174 Messages.ERR_MISSING_CMS_CONTROLLER_1, 175 CmsJspBean.class.getName())); 176 } 177 m_context = context; 178 m_request = req; 179 m_response = res; 180 m_isNotInitialized = false; 181 } 182 183 194 public boolean isSupressingExceptions() { 195 196 return m_isSupressingExceptions; 197 } 198 199 212 public void setContentType(String type) { 213 214 m_controller.getTopResponse().setContentType(type); 216 } 217 218 231 public void setStatus(int status) { 232 233 m_request.setAttribute(CmsRequestUtil.ATTRIBUTE_ERRORCODE, new Integer (status)); 235 } 236 237 247 public void setSupressingExceptions(boolean value) { 248 249 m_isSupressingExceptions = value; 250 } 251 252 261 protected CmsFlexController getController() { 262 263 return m_controller; 264 } 265 266 277 protected String getMessage(CmsMessageContainer container) { 278 279 CmsObject cms = getCmsObject(); 280 String result; 281 if ((cms == null) || (cms.getRequestContext().getLocale() == null)) { 282 result = container.key(); 283 } else { 284 result = container.key(cms.getRequestContext().getLocale()); 285 } 286 return result; 287 } 288 289 295 protected void handleException(Throwable t) { 296 297 if (LOG.isErrorEnabled()) { 298 LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_JSP_BEAN_0), t); 299 } 300 if (!(m_isSupressingExceptions || getRequestContext().currentProject().isOnlineProject())) { 301 if (LOG.isDebugEnabled()) { 302 LOG.debug(Messages.get().getBundle().key( 304 Messages.LOG_DEBUG_INTERRUPTED_EXCEPTION_1, 305 getClass().getName())); 306 } 307 String uri = null; 308 Throwable u = getController().getThrowable(); 309 if (u != null) { 310 uri = getController().getThrowableResourceUri(); 311 } else { 312 u = t; 313 } 314 throw new CmsRuntimeException(Messages.get().container( 315 Messages.ERR_RUNTIME_1, 316 (uri != null) ? uri : getClass().getName()), t); 317 } 318 } 319 320 325 protected boolean isNotInitialized() { 326 327 return m_isNotInitialized; 328 } 329 } | Popular Tags |