1 31 32 package org.opencms.editors.fckeditor; 33 34 import org.opencms.jsp.CmsJspActionElement; 35 import org.opencms.main.OpenCms; 36 import org.opencms.util.CmsHtmlConverter; 37 import org.opencms.util.CmsStringUtil; 38 import org.opencms.workplace.CmsWorkplaceSettings; 39 import org.opencms.workplace.editors.CmsEditorDisplayOptions; 40 import org.opencms.workplace.editors.CmsSimplePageEditor; 41 import org.opencms.workplace.galleries.A_CmsGallery; 42 43 import java.util.ArrayList ; 44 import java.util.Collections ; 45 import java.util.HashMap ; 46 import java.util.Iterator ; 47 import java.util.List ; 48 import java.util.Map ; 49 import java.util.Properties ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 53 77 public class CmsFCKEditor extends CmsSimplePageEditor { 78 79 80 public static final String SUFFIX_STYLESXML = "_style.xml"; 81 82 83 private static final String EDITOR_TYPE = "fckeditor"; 84 85 90 public CmsFCKEditor(CmsJspActionElement jsp) { 91 92 super(jsp); 93 } 94 95 102 public String buildGalleryButtonRow(CmsEditorDisplayOptions options, Properties displayOptions) { 103 104 StringBuffer result = new StringBuffer (); 105 Map galleryMap = OpenCms.getWorkplaceManager().getGalleries(); 106 List galleries = new ArrayList (galleryMap.size()); 107 Map typeMap = new HashMap (galleryMap.size()); 108 109 Iterator i = galleryMap.keySet().iterator(); 110 while (i.hasNext()) { 111 String key = (String )i.next(); 112 A_CmsGallery currGallery = (A_CmsGallery)galleryMap.get(key); 113 galleries.add(currGallery); 114 typeMap.put(currGallery, key); 116 } 117 118 Collections.sort(galleries); 120 121 for (int k = 0; k < galleries.size(); k++) { 122 A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k); 123 String galleryType = (String )typeMap.get(currGallery); 124 if (options.showElement("gallery." + CmsStringUtil.substitute(galleryType, "gallery", ""), displayOptions)) { 125 if (result.length() == 0) { 127 result.append(", \'-\'"); 128 } 129 result.append(", \'oc-" + galleryType + "\'"); 130 } 131 } 132 return result.toString(); 133 } 134 135 138 public String buildGalleryButtons(CmsEditorDisplayOptions options, int buttonStyle, Properties displayOptions) { 139 140 StringBuffer result = new StringBuffer (1024); 141 Iterator i = OpenCms.getWorkplaceManager().getGalleries().keySet().iterator(); 142 143 while (i.hasNext()) { 144 String galleryType = (String )i.next(); 145 String galleryName = CmsStringUtil.substitute(galleryType, "gallery", ""); 146 147 result.append("\n\nvar ").append(galleryType).append("Command = function() { this.Name = \"").append( 148 galleryType).append("\"; }\n"); 149 result.append(galleryType).append("Command.prototype.GetState = function() { return FCK_TRISTATE_OFF ; }\n"); 150 result.append(galleryType).append("Command.prototype.Execute = function() {\n"); 151 result.append("\topenGallery(\"").append(galleryType).append("\");\n"); 152 153 result.append("}\n"); 154 result.append("FCKCommands.RegisterCommand(\"oc-").append(galleryType).append("\", new ").append( 155 galleryType).append("Command());\n"); 156 result.append("FCKToolbarItems.RegisterItem(\"oc-").append(galleryType).append("\", "); 157 result.append("new FCKToolbarButton(\"oc-").append(galleryType).append("\", \""); 158 result.append(key(org.opencms.workplace.editors.Messages.getGalleryKey(galleryName))).append("\"));"); 159 } 160 161 return result.toString(); 162 } 163 164 167 public String getEditorResourceUri() { 168 169 return getSkinUri() + "editors/" + EDITOR_TYPE + "/"; 170 } 171 172 175 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 176 177 if (CmsStringUtil.isNotEmpty(request.getParameter(PARAM_RESOURCE))) { 178 super.initWorkplaceRequestValues(settings, request); 179 } 180 } 181 182 185 protected String prepareContent(boolean save) { 186 187 if (save) { 188 String conversionSetting = CmsHtmlConverter.getConversionSettings(getCms(), m_file); 189 if (CmsStringUtil.isEmptyOrWhitespaceOnly(conversionSetting)) { 190 String content = getParamContent(); 192 CmsHtmlConverter converter = new CmsHtmlConverter(getEncoding(), CmsHtmlConverter.PARAM_XHTML); 193 content = converter.convertToStringSilent(content); 194 setParamContent(content); 195 } 196 } 197 return super.prepareContent(true); 199 } 200 } | Popular Tags |