1 31 32 package org.opencms.workplace.editors; 33 34 import org.opencms.file.CmsResourceFilter; 35 import org.opencms.file.CmsVfsResourceNotFoundException; 36 import org.opencms.i18n.CmsEncoder; 37 import org.opencms.jsp.CmsJspActionElement; 38 import org.opencms.lock.CmsLock; 39 import org.opencms.main.CmsException; 40 import org.opencms.main.CmsLog; 41 import org.opencms.main.OpenCms; 42 import org.opencms.util.CmsStringUtil; 43 import org.opencms.workplace.CmsWorkplaceSettings; 44 import org.opencms.workplace.galleries.A_CmsGallery; 45 import org.opencms.xml.page.CmsXmlPageFactory; 46 47 import java.util.ArrayList ; 48 import java.util.Collections ; 49 import java.util.HashMap ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Map ; 53 import java.util.Properties ; 54 55 import javax.servlet.http.HttpServletRequest ; 56 import javax.servlet.jsp.JspException ; 57 58 import org.apache.commons.logging.Log; 59 60 75 public class CmsSimplePageEditor extends CmsDefaultPageEditor { 76 77 78 private static final String EDITOR_TYPE = "simplehtml"; 79 80 81 private static final Log LOG = CmsLog.getLog(CmsSimplePageEditor.class); 82 83 88 public CmsSimplePageEditor(CmsJspActionElement jsp) { 89 90 super(jsp); 91 } 92 93 96 public String buildGalleryButtons(CmsEditorDisplayOptions options, int buttonStyle, Properties displayOptions) { 97 98 StringBuffer result = new StringBuffer (); 99 Map galleryMap = OpenCms.getWorkplaceManager().getGalleries(); 100 List galleries = new ArrayList (galleryMap.size()); 101 Map typeMap = new HashMap (galleryMap.size()); 102 103 Iterator i = galleryMap.keySet().iterator(); 104 while (i.hasNext()) { 105 String key = (String )i.next(); 106 A_CmsGallery currGallery = (A_CmsGallery)galleryMap.get(key); 107 galleries.add(currGallery); 108 typeMap.put(currGallery, key); 110 } 111 112 Collections.sort(galleries); 114 115 for (int k = 0; k < galleries.size(); k++) { 116 A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k); 117 String galleryType = (String )typeMap.get(currGallery); 118 String galleryName = CmsStringUtil.substitute(galleryType, "gallery", ""); 119 if (options.showElement("gallery." + galleryName, displayOptions)) { 120 result.append(button( 122 "javascript:openGallery(\'" + galleryType + "\');", 123 null, 124 galleryType, 125 Messages.getGalleryKey(galleryName), 126 buttonStyle)); 127 } 128 } 129 130 return result.toString(); 131 } 132 133 136 public String getEditorResourceUri() { 137 138 return getSkinUri() + "editors/" + EDITOR_TYPE + "/"; 139 } 140 141 144 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 145 146 fillParamValues(request); 148 149 setParamDialogtype(EDITOR_TYPE); 151 152 if (getParamTempfile() != null && !"null".equals(getParamTempfile())) { 154 try { 155 m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL); 156 m_page = CmsXmlPageFactory.unmarshal(getCms(), m_file); 157 } catch (CmsException e) { 158 if (e instanceof CmsVfsResourceNotFoundException) { 159 try { 162 setParamTempfile(createTempFile()); 163 m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL); 164 m_page = CmsXmlPageFactory.unmarshal(getCms(), m_file); 165 } catch (CmsException e1) { 166 try { 168 showErrorPage(this, e1); 169 } catch (JspException exc) { 170 if (LOG.isInfoEnabled()) { 172 LOG.info(exc); 173 } 174 } 175 } 176 } else { 177 try { 179 showErrorPage(this, e); 180 } catch (JspException exc) { 181 if (LOG.isInfoEnabled()) { 183 LOG.info(exc); 184 } 185 } 186 } 187 } 188 } 189 190 if (EDITOR_SAVE.equals(getParamAction())) { 192 setAction(ACTION_SAVE); 193 } else if (EDITOR_SAVEEXIT.equals(getParamAction())) { 194 setAction(ACTION_SAVEEXIT); 195 } else if (EDITOR_SAVEACTION.equals(getParamAction())) { 196 setAction(ACTION_SAVEACTION); 197 try { 198 actionDirectEdit(); 199 } catch (Exception e) { 200 if (LOG.isInfoEnabled()) { 202 LOG.info(e); 203 } 204 } 205 setAction(ACTION_EXIT); 206 } else if (EDITOR_EXIT.equals(getParamAction())) { 207 setAction(ACTION_EXIT); 208 } else if (EDITOR_CLOSEBROWSER.equals(getParamAction())) { 209 actionClear(true); 211 return; 212 } else if (EDITOR_DELETELOCALE.equals(getParamAction())) { 213 setAction(ACTION_DELETELOCALE); 214 } else if (EDITOR_CHANGE_ELEMENT.equals(getParamAction())) { 215 setAction(ACTION_SHOW); 216 actionChangeBodyElement(); 217 prepareContent(false); 219 } else if (EDITOR_CLEANUP.equals(getParamAction())) { 220 setAction(ACTION_SHOW); 221 actionCleanupBodyElement(); 222 prepareContent(false); 224 } else if (EDITOR_SHOW.equals(getParamAction())) { 225 setAction(ACTION_SHOW); 226 prepareContent(false); 228 } else if (EDITOR_PREVIEW.equals(getParamAction())) { 229 setAction(ACTION_PREVIEW); 230 } else { 231 setAction(ACTION_DEFAULT); 233 try { 234 if (Boolean.valueOf(getParamDirectedit()).booleanValue()) { 236 checkLock(getParamResource(), CmsLock.TEMPORARY); 238 } else { 239 checkLock(getParamResource()); 241 } 242 setParamTempfile(createTempFile()); 244 m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL); 246 m_page = CmsXmlPageFactory.unmarshal(getCms(), m_file); 247 } catch (CmsException e) { 248 try { 250 showErrorPage(this, e); 251 return; 252 } catch (JspException exc) { 253 if (LOG.isInfoEnabled()) { 255 LOG.info(exc); 256 } 257 } 258 } 259 if (getParamElementlanguage() == null) { 261 initBodyElementLanguage(); 262 } 263 if (getParamElementname() == null) { 264 initBodyElementName(null); 265 } 266 initContent(); 268 prepareContent(false); 270 } 271 } 272 273 279 protected String prepareContent(boolean save) { 280 281 String content = getParamContent().trim(); 282 content = CmsEncoder.adjustHtmlEncoding(content, getFileEncoding()); 284 if (!save) { 285 setParamContent(content); 286 } 287 return content; 288 } 289 290 } 291 | Popular Tags |