1 31 32 package org.opencms.workplace.editors; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsResourceFilter; 36 import org.opencms.i18n.CmsEncoder; 37 import org.opencms.jsp.CmsJspActionElement; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsLog; 40 import org.opencms.util.CmsStringUtil; 41 import org.opencms.workplace.CmsWorkplaceSettings; 42 43 import java.io.IOException ; 44 import java.io.UnsupportedEncodingException ; 45 46 import javax.servlet.ServletException ; 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.jsp.JspException ; 49 50 import org.apache.commons.logging.Log; 51 52 69 public class CmsSimpleEditor extends CmsEditor { 70 71 72 private static final String EDITOR_TYPE = "simple"; 73 74 75 private static final Log LOG = CmsLog.getLog(CmsSimpleEditor.class); 76 77 82 public CmsSimpleEditor(CmsJspActionElement jsp) { 83 84 super(jsp); 85 } 86 87 90 public void actionClear(boolean forceUnlock) { 91 92 boolean modified = Boolean.valueOf(getParamModified()).booleanValue(); 93 if (forceUnlock || !modified) { 94 try { 96 getCms().unlockResource(getParamResource()); 97 } catch (CmsException e) { 98 if (LOG.isInfoEnabled()) { 100 LOG.info(e); 101 } 102 } 103 } 104 } 105 106 111 public void actionExit() throws IOException , JspException , ServletException { 112 113 if (getAction() == ACTION_CANCEL) { 114 return; 116 } 117 118 actionClear(false); 120 121 actionClose(); 123 } 124 125 130 public void actionSave() throws JspException { 131 132 CmsFile editFile = null; 133 try { 134 editFile = getCms().readFile(getParamResource(), CmsResourceFilter.ALL); 135 String decodedContent = CmsEncoder.adjustHtmlEncoding(decodeContent(getParamContent()), getFileEncoding()); 137 138 try { 139 editFile.setContents(decodedContent.getBytes(getFileEncoding())); 140 } catch (UnsupportedEncodingException e) { 141 throw new CmsException( 142 Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()), 143 e); 144 } 145 CmsFile writtenFile = getCms().writeFile(editFile); 147 try { 148 decodedContent = new String (writtenFile.getContents(), getFileEncoding()); 149 } catch (UnsupportedEncodingException e) { 150 throw new CmsException( 151 Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()), 152 e); 153 } 154 setParamContent(encodeContent(decodedContent)); 155 setParamModified(Boolean.TRUE.toString()); 157 } catch (CmsException e) { 158 showErrorPage(e); 159 } 160 161 if (getAction() != ACTION_CANCEL) { 162 setAction(ACTION_SAVE); 164 } 165 } 166 167 170 public String getEditorResourceUri() { 171 172 return getSkinUri() + "editors/" + EDITOR_TYPE + "/"; 173 } 174 175 178 protected void initContent() { 179 180 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 182 String content = getParamContent(); 184 if (CmsStringUtil.isNotEmpty(content)) { 185 setParamContent(decodeContent(content)); 187 return; 188 } else { 189 content = ""; 190 } 191 192 try { 193 checkLock(getParamResource()); 195 CmsFile editFile = getCms().readFile(getParamResource(), CmsResourceFilter.ALL); 196 try { 197 content = new String (editFile.getContents(), getFileEncoding()); 198 } catch (UnsupportedEncodingException e) { 199 throw new CmsException( 200 Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()), 201 e); 202 } 203 } catch (CmsException e) { 204 try { 206 showErrorPage(this, e); 207 } catch (JspException exc) { 208 if (LOG.isInfoEnabled()) { 210 LOG.info(exc); 211 } 212 } 213 } 214 setParamContent(content); 215 } 216 217 220 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 221 222 fillParamValues(request); 224 setParamDialogtype(EDITOR_TYPE); 226 227 if (EDITOR_SAVE.equals(getParamAction())) { 229 setAction(ACTION_SAVE); 230 } else if (EDITOR_SAVEEXIT.equals(getParamAction())) { 231 setAction(ACTION_SAVEEXIT); 232 } else if (EDITOR_EXIT.equals(getParamAction())) { 233 setAction(ACTION_EXIT); 234 } else if (EDITOR_SHOW.equals(getParamAction())) { 235 setAction(ACTION_SHOW); 236 } else if (EDITOR_SHOW_ERRORMESSAGE.equals(getParamAction())) { 237 setAction(ACTION_SHOW_ERRORMESSAGE); 238 } else { 239 setAction(ACTION_DEFAULT); 241 initContent(); 242 } 243 244 setParamContent(encodeContent(getParamContent())); 245 } 246 } 247 | Popular Tags |