| 1 20 21 22 package com.fredck.FCKeditor; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 32 public class FCKeditor { 33 34 private FCKeditorConfigurations oConfig; 35 private String instanceName; 36 private String value = ""; 37 private String basePath; 38 private String toolbarSet = "Default"; 39 private String width = "100%"; 40 private String height = "200"; 41 42 HttpServletRequest request; 43 44 49 public String getInstanceName() { 50 return instanceName; 51 } 52 53 58 public void setInstanceName(String value) { 59 instanceName=value; 60 } 61 62 68 public String getValue() { 69 return value; 70 } 71 72 78 public void setValue(String value) { 79 this.value=value; 80 } 81 82 87 public String getBasePath() { 88 return basePath; 89 } 90 91 99 public void setBasePath(String value) { 100 basePath=value; 101 } 102 103 108 public String getToolbarSet() { 109 return toolbarSet; 110 } 111 112 117 public void setToolbarSet(String value) { 118 toolbarSet=value; 119 } 120 121 126 public String getWidth() { 127 return width; 128 } 129 130 135 public void setWidth(String value) { 136 width=value; 137 } 138 139 144 public String getHeight() { 145 return height; 146 } 147 148 153 public void setHeight(String value) { 154 height=value; 155 } 156 157 158 164 public FCKeditorConfigurations getConfig() { 165 return oConfig; 166 } 167 168 173 public void setConfig(FCKeditorConfigurations value) { 174 oConfig=value; 175 } 176 177 190 public FCKeditor(HttpServletRequest req){ 191 request=req; 192 basePath = request.getContextPath() + "/FCKeditor/"; 193 oConfig = new FCKeditorConfigurations() ; 194 } 195 196 210 public FCKeditor(HttpServletRequest req, String parInstanceName){ 211 request=req; 212 basePath = request.getContextPath() + "/FCKeditor/"; 213 instanceName=parInstanceName; 214 oConfig = new FCKeditorConfigurations() ; 215 } 216 217 229 public FCKeditor(HttpServletRequest req, String parInstanceName, String parWidth, String parHeight, String parToolbarSet, String parValue){ 230 request=req; 231 basePath = request.getContextPath() + "/FCKeditor/"; 232 instanceName=parInstanceName; 233 width=parWidth; 234 height=parHeight; 235 toolbarSet=parToolbarSet; 236 value=parValue; 237 oConfig = new FCKeditorConfigurations() ; 238 } 239 240 241 private boolean isCompatible() { 242 String userAgent=request.getHeader("user-agent"); 243 if(userAgent==null) 244 return false; 245 userAgent=userAgent.toLowerCase(); 246 if ((userAgent.indexOf("msie") !=-1) && (userAgent.indexOf("mac") == -1) && (userAgent.indexOf("opera") == -1)) { 247 if(retrieveBrowserVersion(userAgent)>=5.5) 248 return true; 249 } 250 else if (userAgent.indexOf("gecko") !=-1){ 251 if(retrieveBrowserVersion(userAgent)>=20030210) 252 return true; 253 } 254 return false; 255 } 256 257 private double retrieveBrowserVersion(String userAgent) { 258 if(userAgent.indexOf("msie")>-1) { 259 String str = userAgent.substring(userAgent.indexOf("msie") + 5); 260 return Double.parseDouble(str.substring(0, str.indexOf(";"))); 261 } 262 else { 263 String str = userAgent.substring(userAgent.indexOf("gecko") + 6); 264 return Double.parseDouble(str.substring(0, 8)); 265 } 266 } 267 268 private String HTMLEncode(String txt) { 269 txt=txt.replaceAll("&","&"); 270 txt=txt.replaceAll("<","<"); 271 txt=txt.replaceAll(">",">"); 272 txt=txt.replaceAll("\"","""); 273 txt=txt.replaceAll("'","’"); 274 return txt; 275 } 276 277 278 286 public String create() { 287 StringBuffer strEditor=new StringBuffer (); 288 289 strEditor.append("<div>"); 290 String encodedValue=HTMLEncode(value); 291 292 if(isCompatible()) { 293 294 strEditor.append("<input type=\"hidden\" id=\"" + instanceName + "\" name=\"" + instanceName + "\" value=\"" + encodedValue + "\">"); 295 296 strEditor.append(createConfigHTML()); 297 strEditor.append(createIFrameHTML()); 298 299 } 300 else{ 301 strEditor.append("<TEXTAREA name=\"" + instanceName + "\" rows=\"4\" cols=\"40\" style=\"WIDTH: " + width + "; HEIGHT: " + height + "\" wrap=\"virtual\">"+encodedValue+"</TEXTAREA>"); 302 } 303 strEditor.append("</div>"); 304 return strEditor.toString(); 305 } 306 307 private String createConfigHTML() { 308 String configStr=oConfig.getUrlParams(); 309 310 311 if(!configStr.equals("")) 312 configStr=configStr.substring(1); 313 314 return "<input type=\"hidden\" id=\"" + instanceName + "___Config\" value=\"" + configStr + "\">" ; 315 } 316 317 private String createIFrameHTML() { 318 319 String sLink=basePath + "editor/fckeditor.html?InstanceName=" + instanceName; 320 321 if (!toolbarSet.equals("")) 322 sLink+="&Toolbar=" + toolbarSet; 323 324 return "<iframe id=\"" + instanceName + "___Frame\" SRC=\"" + sLink + "\" width=\"" + width + "\" height=\"" + height + "\" frameborder=\"no\" scrolling=\"no\"></iframe>"; 325 326 } 327 328 329 } 330 | Popular Tags |