001 002package org.opencms.editors.tinymce; 003 004import org.opencms.jsp.CmsJspActionElement; 005import org.opencms.util.CmsHtmlConverter; 006import org.opencms.util.CmsStringUtil; 007import org.opencms.workplace.CmsWorkplaceSettings; 008import org.opencms.workplace.editors.CmsSimplePageEditor; 009 010import javax.servlet.http.HttpServletRequest; 011 012/** 013 * The tinyMCE based editor.<p> 014 */ 015public class CmsTinyMCE extends CmsSimplePageEditor { 016 017 /** String constant separator for button groups. */ 018 public static final String GROUP_SEPARATOR = "|"; 019 020 /** Suffix for the style file that is added to the used template styles file name. */ 021 public static final String SUFFIX_STYLE = "_style"; 022 023 /** Constant for the editor type, must be the same as the editors sub folder name in the VFS. */ 024 private static final String EDITOR_TYPE = "tinymce"; 025 026 /** 027 * Public constructor.<p> 028 * 029 * @param jsp an initialized JSP action element 030 */ 031 public CmsTinyMCE(CmsJspActionElement jsp) { 032 033 super(jsp); 034 } 035 036 /** 037 * Builds toolbar javascript file for TinyMCE.<p> 038 * 039 * @param buttonString button names and block separators delimited by comma 040 * 041 * @return returns the toolbar buttons 042 */ 043 public static String buildToolbar(String buttonString) { 044 045 StringBuilder toolbar = new StringBuilder(); 046 String[] buttons = buttonString.split("\\,"); 047 048 String button; 049 for (int i = 0; i < buttons.length; i++) { 050 button = buttons[i]; 051 toolbar.append(button + " "); 052 } 053 return toolbar.toString(); 054 } 055 056 /** 057 * @see org.opencms.workplace.editors.CmsEditor#getEditorResourceUri() 058 */ 059 @Override 060 public String getEditorResourceUri() { 061 062 return getSkinUri() + "editors/" + EDITOR_TYPE + "/jscripts/tinymce/"; 063 } 064 065 /** 066 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest) 067 */ 068 @Override 069 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 070 071 if (CmsStringUtil.isNotEmpty(request.getParameter(PARAM_RESOURCE))) { 072 super.initWorkplaceRequestValues(settings, request); 073 } 074 } 075 076 /** 077 * @see org.opencms.workplace.editors.CmsSimplePageEditor#prepareContent(boolean) 078 */ 079 @Override 080 protected String prepareContent(boolean save) { 081 082 if (save) { 083 String conversionSetting = CmsHtmlConverter.getConversionSettings(getCms(), m_file); 084 if (CmsStringUtil.isEmptyOrWhitespaceOnly(conversionSetting)) { 085 // by default we want to pretty-print and XHTML format when saving the content in TinyMCE 086 String content = getParamContent(); 087 CmsHtmlConverter converter = new CmsHtmlConverter(getEncoding(), CmsHtmlConverter.PARAM_XHTML); 088 content = converter.convertToStringSilent(content); 089 setParamContent(content); 090 } 091 } 092 // do further processing with super class 093 return super.prepareContent(true); 094 } 095}