1 31 32 package org.opencms.jsp; 33 34 import org.opencms.file.CmsBackupResourceHandler; 35 import org.opencms.file.CmsObject; 36 import org.opencms.flex.CmsFlexController; 37 import org.opencms.main.CmsLog; 38 import org.opencms.main.OpenCms; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.workplace.editors.directedit.CmsDirectEditJspIncludeProvider; 41 import org.opencms.workplace.editors.directedit.CmsDirectEditMode; 42 import org.opencms.workplace.editors.directedit.CmsDirectEditParams; 43 import org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider; 44 45 import javax.servlet.ServletRequest ; 46 import javax.servlet.jsp.JspException ; 47 import javax.servlet.jsp.PageContext ; 48 import javax.servlet.jsp.tagext.BodyTagSupport ; 49 50 import org.apache.commons.logging.Log; 51 52 78 public class CmsJspTagEditable extends BodyTagSupport { 79 80 81 private static final Log LOG = CmsLog.getLog(CmsJspTagEditable.class); 82 83 84 private static final long serialVersionUID = 4137789622146499225L; 85 86 87 protected String m_file; 88 89 90 protected CmsDirectEditMode m_mode; 91 92 93 protected String m_provider; 94 95 96 private boolean m_firstOnPage; 97 98 99 private boolean m_manualPlacement; 100 101 111 public static void editableTagAction(PageContext context, String provider, CmsDirectEditMode mode, String fileName) 112 throws JspException { 113 114 if (mode == CmsDirectEditMode.FALSE) { 115 return; 117 } 118 119 ServletRequest req = context.getRequest(); 120 if (CmsBackupResourceHandler.isBackupRequest(req)) { 121 return; 123 } 124 125 CmsFlexController controller = CmsFlexController.getController(req); 126 CmsObject cms = controller.getCmsObject(); 127 128 if (!cms.getRequestContext().currentProject().isOnlineProject()) { 129 I_CmsDirectEditProvider eb = getDirectEditProvider(context); 131 if (eb == null) { 132 if (CmsStringUtil.isNotEmpty(fileName) && CmsStringUtil.isEmpty(provider)) { 133 provider = CmsDirectEditJspIncludeProvider.class.getName(); 135 } 136 if (CmsStringUtil.isNotEmpty(provider)) { 138 try { 139 eb = (I_CmsDirectEditProvider)Class.forName(provider).newInstance(); 141 } catch (Exception e) { 142 LOG.error(Messages.get().getBundle().key(Messages.ERR_DIRECT_EDIT_PROVIDER_1, provider), e); 144 } 145 } 146 if (eb == null) { 147 eb = OpenCms.getWorkplaceManager().getDirectEditProvider(); 149 } 150 if (mode == null) { 151 mode = CmsDirectEditMode.AUTO; 153 } 154 eb.init(cms, mode, fileName); 155 setDirectEditProvider(context, eb); 157 } 158 if (eb.isManual(mode)) { 159 CmsDirectEditParams params = getDirectEditProviderParams(context); 161 if (params != null) { 162 eb.insertDirectEditStart(context, params); 164 } else { 165 eb.insertDirectEditEnd(context); 167 } 168 } else { 169 eb.insertDirectEditIncludes(context, new CmsDirectEditParams(cms.getRequestContext().getUri())); 171 } 172 } 173 } 174 175 182 public static void endDirectEdit(PageContext context) throws JspException { 183 184 I_CmsDirectEditProvider eb = getDirectEditProvider(context); 186 187 if (eb != null) { 188 eb.insertDirectEditEnd(context); 190 } 191 } 192 193 200 public static I_CmsDirectEditProvider getDirectEditProvider(PageContext context) { 201 202 return (I_CmsDirectEditProvider)context.getRequest().getAttribute( 204 I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER); 205 } 206 207 218 public static boolean startDirectEdit(PageContext context, CmsDirectEditParams params) throws JspException { 219 220 I_CmsDirectEditProvider eb = getDirectEditProvider(context); 222 223 boolean result = false; 224 if (eb != null) { 225 if (eb.isManual(params.getMode())) { 227 setDirectEditProviderParams(context, params); 229 } else { 230 result = eb.insertDirectEditStart(context, params); 232 } 233 } 234 235 return result; 236 } 237 238 247 protected static CmsDirectEditParams getDirectEditProviderParams(PageContext context) { 248 249 ServletRequest req = context.getRequest(); 251 CmsDirectEditParams result = (CmsDirectEditParams)req.getAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS); 253 if (result != null) { 254 req.removeAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS); 255 } 256 return result; 257 } 258 259 266 protected static void setDirectEditProvider(PageContext context, I_CmsDirectEditProvider provider) { 267 268 context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER, provider); 270 } 271 272 278 protected static void setDirectEditProviderParams(PageContext context, CmsDirectEditParams params) { 279 280 context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS, params); 282 } 283 284 291 public int doEndTag() throws JspException { 292 293 if (m_firstOnPage || m_manualPlacement) { 294 editableTagAction(pageContext, m_provider, m_mode, m_file); 296 } 297 release(); 298 299 return EVAL_PAGE; 300 } 301 302 310 public int doStartTag() throws JspException { 311 312 if (!CmsFlexController.isCmsOnlineRequest(pageContext.getRequest())) { 313 I_CmsDirectEditProvider eb = getDirectEditProvider(pageContext); 315 m_firstOnPage = (eb == null); 317 m_manualPlacement = false; 318 if (m_mode == CmsDirectEditMode.MANUAL) { 319 if (!m_firstOnPage && (eb != null)) { 321 if (eb.isManual(m_mode)) { 323 m_manualPlacement = true; 325 editableTagAction(pageContext, m_provider, m_mode, m_file); 326 } 327 } 328 } 329 } else { 330 m_firstOnPage = false; 332 m_manualPlacement = false; 333 } 334 return EVAL_BODY_INCLUDE; 335 } 336 337 342 public String getFile() { 343 344 return m_file != null ? m_file : ""; 345 } 346 347 352 public String getMode() { 353 354 return m_mode != null ? m_mode.toString() : ""; 355 } 356 357 362 public String getProvider() { 363 364 return m_provider != null ? m_provider : ""; 365 } 366 367 370 public void release() { 371 372 super.release(); 373 m_file = null; 374 m_provider = null; 375 m_mode = null; 376 m_firstOnPage = false; 377 m_manualPlacement = true; 378 } 379 380 385 public void setFile(String file) { 386 387 if (file != null) { 388 m_file = file; 389 } 390 } 391 392 397 public void setMode(String mode) { 398 399 m_mode = CmsDirectEditMode.valueOf(mode); 400 } 401 402 407 public void setProvider(String provider) { 408 409 if (provider != null) { 410 m_provider = provider; 411 } 412 } 413 } | Popular Tags |