1 31 32 package org.opencms.workplace.editors.directedit; 33 34 import org.opencms.db.CmsUserSettings; 35 import org.opencms.file.CmsObject; 36 import org.opencms.flex.CmsFlexController; 37 import org.opencms.flex.CmsFlexResponse; 38 import org.opencms.i18n.CmsEncoder; 39 import org.opencms.jsp.CmsJspTagInclude; 40 import org.opencms.loader.I_CmsResourceLoader; 41 import org.opencms.util.CmsStringUtil; 42 43 import java.io.IOException ; 44 import java.util.HashMap ; 45 import java.util.Map ; 46 47 import javax.servlet.ServletException ; 48 import javax.servlet.ServletRequest ; 49 import javax.servlet.ServletResponse ; 50 import javax.servlet.jsp.JspException ; 51 import javax.servlet.jsp.PageContext ; 52 53 74 public class CmsDirectEditJspIncludeProvider extends A_CmsDirectEditProvider implements I_CmsDirectEditProvider { 75 76 77 public static final String DIRECT_EDIT_AREA_END = "end_directedit"; 78 79 80 public static final String DIRECT_EDIT_AREA_START = "start_directedit"; 81 82 83 public static final String DIRECT_EDIT_INCLUDE_FILE_URI_DEFAULT = "/system/workplace/editors/direct_edit.jsp"; 84 85 86 public static final String DIRECT_EDIT_INCLUDES = "directedit_includes"; 87 88 89 public static final String DIRECT_EDIT_PARAM_BUTTONSTYLE = "__directEditButtonStyle"; 90 91 92 public static final String DIRECT_EDIT_PARAM_ELEMENT = "__directEditElement"; 93 94 95 public static final String DIRECT_EDIT_PARAM_LOCALE = "__directEditLocale"; 96 97 98 public static final String DIRECT_EDIT_PARAM_NEWLINK = "__directEditNewLink"; 99 100 101 public static final String DIRECT_EDIT_PARAM_OPTIONS = "__directEditOptions"; 102 103 104 public static final String DIRECT_EDIT_PARAM_TARGET = "__directEditTarget"; 105 106 107 protected String m_editElement; 108 109 110 protected String m_editTarget; 111 112 113 protected String m_permissions; 114 115 132 public static String includeDirectEditElement( 133 PageContext context, 134 String jspIncludeFile, 135 String element, 136 String editTarget, 137 String editElement, 138 String editOptions, 139 String editPermissions, 140 String createLink) throws JspException { 141 142 if (editPermissions == null) { 143 return null; 145 } 146 147 ServletRequest req = context.getRequest(); 148 ServletResponse res = context.getResponse(); 149 CmsFlexController controller = CmsFlexController.getController(req); 150 151 element = element + "_" + editPermissions; 153 154 Map parameterMap = new HashMap (); 156 CmsJspTagInclude.addParameter(parameterMap, I_CmsResourceLoader.PARAMETER_ELEMENT, element, true); 157 CmsJspTagInclude.addParameter(parameterMap, DIRECT_EDIT_PARAM_TARGET, editTarget, true); 158 CmsJspTagInclude.addParameter( 159 parameterMap, 160 DIRECT_EDIT_PARAM_LOCALE, 161 controller.getCmsObject().getRequestContext().getLocale().toString(), 162 true); 163 CmsUserSettings settings = new CmsUserSettings(controller.getCmsObject()); 164 CmsJspTagInclude.addParameter( 165 parameterMap, 166 DIRECT_EDIT_PARAM_BUTTONSTYLE, 167 String.valueOf(settings.getDirectEditButtonStyle()), 168 true); 169 if (editElement != null) { 170 CmsJspTagInclude.addParameter(parameterMap, DIRECT_EDIT_PARAM_ELEMENT, editElement, true); 171 } 172 if (editOptions != null) { 173 CmsJspTagInclude.addParameter(parameterMap, DIRECT_EDIT_PARAM_OPTIONS, editOptions, true); 174 } 175 if (createLink != null) { 176 CmsJspTagInclude.addParameter(parameterMap, DIRECT_EDIT_PARAM_NEWLINK, CmsEncoder.encode(createLink), true); 177 } 178 179 Map oldParameterMap = controller.getCurrentRequest().getParameterMap(); 181 182 try { 183 184 controller.getCurrentRequest().addParameterMap(parameterMap); 185 context.getOut().print(CmsFlexResponse.FLEX_CACHE_DELIMITER); 186 controller.getCurrentResponse().addToIncludeList(jspIncludeFile, parameterMap); 187 controller.getCurrentRequest().getRequestDispatcher(jspIncludeFile).include(req, res); 188 189 } catch (ServletException e) { 190 191 Throwable t; 192 if (e.getRootCause() != null) { 193 t = e.getRootCause(); 194 } else { 195 t = e; 196 } 197 t = controller.setThrowable(t, jspIncludeFile); 198 throw new JspException (t); 199 } catch (IOException e) { 200 201 Throwable t = controller.setThrowable(e, jspIncludeFile); 202 throw new JspException (t); 203 } finally { 204 205 if (oldParameterMap != null) { 207 controller.getCurrentRequest().setParameterMap(oldParameterMap); 208 } 209 } 210 211 return editPermissions; 212 } 213 214 217 public void init(CmsObject cms, CmsDirectEditMode mode, String fileName) { 218 219 m_cms = cms; 220 m_fileName = fileName; 221 if (CmsStringUtil.isEmpty(m_fileName)) { 222 m_fileName = DIRECT_EDIT_INCLUDE_FILE_URI_DEFAULT; 223 } 224 m_mode = mode != null ? mode : CmsDirectEditMode.AUTO; 225 } 226 227 230 public void insertDirectEditEnd(PageContext context) throws JspException { 231 232 if (m_editTarget != null) { 233 includeDirectEditElement( 235 context, 236 m_fileName, 237 DIRECT_EDIT_AREA_END, 238 m_editTarget, 239 m_editElement, 240 null, 241 m_permissions, 242 null); 243 m_editTarget = null; 244 m_permissions = null; 245 m_editElement = null; 246 } 247 } 248 249 252 public void insertDirectEditIncludes(PageContext context, CmsDirectEditParams params) throws JspException { 253 254 try { 255 CmsJspTagInclude.includeTagAction( 256 context, 257 m_fileName, 258 DIRECT_EDIT_INCLUDES, 259 false, 260 null, 261 context.getRequest(), 262 context.getResponse()); 263 } catch (Throwable t) { 264 throw new JspException (t); 266 } 267 } 268 269 272 public boolean insertDirectEditStart(PageContext context, CmsDirectEditParams params) throws JspException { 273 274 String result = null; 275 CmsDirectEditPermissions permissions = getResourceInfo(params.getResourceName()).getPermissions(); 276 if (permissions.getPermission() > 0) { 277 m_permissions = permissions.toString(); 279 m_editTarget = params.getResourceName(); 280 m_editElement = params.getElement(); 281 282 result = includeDirectEditElement( 283 context, 284 m_fileName, 285 DIRECT_EDIT_AREA_START, 286 m_editTarget, 287 m_editElement, 288 params.getButtonSelection().toString(), 289 m_permissions, 290 params.getLinkForNew()); 291 292 } else { 293 m_editTarget = null; 295 m_permissions = null; 296 m_editElement = null; 297 } 298 return result != null; 299 } 300 301 306 public boolean isManual(CmsDirectEditMode mode) { 307 308 return false; 309 } 310 311 314 public I_CmsDirectEditProvider newInstance() { 315 316 CmsDirectEditJspIncludeProvider result = new CmsDirectEditJspIncludeProvider(); 317 result.m_configurationParameters = m_configurationParameters; 318 return result; 319 } 320 } | Popular Tags |