Update of /cvsroot/phpslash/phpslash-dev/public_html/scripts/fckeditor/_jsp/src/com/fredck/FCKeditor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6026/phpslash-dev/public_html/scripts/fckeditor/_jsp/src/com/fredck/FCKeditor
Added Files:
FCKeditor.java FCKeditorConfigurations.java package.html
Log Message:
complete fckeditor addition
--- NEW FILE: FCKeditor.java ---
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: FCKeditor.java
* FCKeditor control class.
*
* Version: 2.0 Beta 1
* Modified: 2004-05-30 21:25:54
*
* File Authors:
* Simone Chiaretta (si...@pi...)
*/
package com.fredck.FCKeditor;
import javax.servlet.http.HttpServletRequest;
/**
* The main class of the class lib.<br>
* It's the container for all properties and the class that generate the output based on browser capabilities and configurations passed by the developer.
*
* @author Simone Chiaretta (si...@pi...)
*/
public class FCKeditor {
private FCKeditorConfigurations oConfig;
private String instanceName;
private String value = "";
private String basePath;
private String toolbarSet = "Default";
private String width = "100%";
private String height = "200";
private Boolean canUpload = null;
private Boolean canBrowse = null;
HttpServletRequest request;
/**
* Get the unique name of the editor
*
* @return name
*/
public String getInstanceName() {
return instanceName;
}
/**
* Set the unique name of the editor
*
* @param value name
*/
public void setInstanceName(String value) {
instanceName=value;
}
/**
* Get the initial value to be edited.<br>
* In HTML code
*
* @return value
*/
public String getValue() {
return value;
}
/**
* Set the initial value to be edited.<br>
* In HTML code
*
* @param value value
*/
public void setValue(String value) {
this.value=value;
}
/**
* Get the dir where the FCKeditor files reside on the server
*
* @return path
*/
public String getBasePath() {
return basePath;
}
/**
* Set the dir where the FCKeditor files reside on the server
*Remarks:<br>
*Avoid using relative paths. It is preferable to set the base path starting from the root (/).
*Always finish the path with a slash (/).
*
* @param value path
*/
public void setBasePath(String value) {
basePath=value;
}
/**
* Get the name of the toolbar to display
*
* @return toolbar name
*/
public String getToolbarSet() {
return toolbarSet;
}
/**
* Set the name of the toolbar to display
*
* @param value toolbar name
*/
public void setToolbarSet(String value) {
toolbarSet=value;
}
/**
* Get the width of the textarea
*
* @return width
*/
public String getWidth() {
return width;
}
/**
* Set the width of the textarea
*
* @param value width
*/
public void setWidth(String value) {
width=value;
}
/**
* Get the height of the textarea
*
* @return height
*/
public String getHeight() {
return height;
}
/**
* Set the height of the textarea
*
* @param value height
*/
public void setHeight(String value) {
height=value;
}
/**
* Get the capability to upload files or images from inside the editor.
*
* @return true/false
* @see #setCanUpload
* @deprecated use getConfig().get("LinkUpload") and getConfig().get("ImageUpload") instead
*/
public boolean getCanUpload() {
return canUpload.booleanValue();
}
/**
* Set the capability to upload files or images from inside the editor.
*
* @param value true/false
* @see #getCanUpload
* @deprecated use getConfig().put("LinkUpload",...) and getConfig().put("ImageUpload",...) instead
*/
public void setCanUpload(boolean value) {
canUpload=Boolean.valueOf(value);
getConfig().put("LinkUpload",canUpload);
getConfig().put("ImageUpload",canUpload);
}
/**
* Get the capability to browse files or images from inside the editor.
*
* @return true/false
* @see #setCanBrowse
* @deprecated use getConfig().get("LinkBrowser") and getConfig().get("ImageBrowser") instead
*/
public boolean getCanBrowse() {
return canBrowse.booleanValue();
}
/**
* Set the capability to browse files or images from inside the editor.
*
* @param value true/false
* @see #getCanBrowse
* @deprecated use getConfig().put("LinkBrowser",...) and getConfig().put("ImageBrowser",...) instead
*/
public void setCanBrowse(boolean value) {
canBrowse=Boolean.valueOf(value);
getConfig().put("LinkBrowser",canBrowse);
getConfig().put("ImageBrowser",canBrowse);
}
/**
* Get the advanced configuation set.<br>
* Adding element to this collection you can override the settings specified in the config.js file.
*
* @return configuration collection
*/
public FCKeditorConfigurations getConfig() {
return oConfig;
}
/**
* Set the advanced configuation set.
*
* @param value configuration collection
*/
public void setConfig(FCKeditorConfigurations value) {
oConfig=value;
}
/**
* Initialize the object setting all value to the default ones.
* <p>
* <ul>
* <li>width: 100%</li>
* <li>height: 200</li>
* <li>toolbar name: Default</li>
* <li>basePath: context root + "/FCKeditor/"</li>
* </ul>
* </p>
*
* @param req request object
*/
public FCKeditor(HttpServletRequest req){
request=req;
basePath = request.getContextPath() + "/FCKeditor/";
oConfig = new FCKeditorConfigurations() ;
}
/**
* Initialize the object setting the unique name and then all value to the default ones.
* <p>
* <ul>
* <li>width: 100%</li>
* <li>height: 200</li>
* <li>toolbar name: Default</li>
* <li>basePath: context root + "/FCKeditor/"</li>
* </ul>
* </p>
*
* @param req request object
* @param parInstanceName unique name
*/
public FCKeditor(HttpServletRequest req, String parInstanceName){
request=req;
basePath = request.getContextPath() + "/FCKeditor/";
instanceName=parInstanceName;
oConfig = new FCKeditorConfigurations() ;
}
/**
* Initialize the object setting all basic configurations.<br>
*
* The basePath is context root + "/FCKeditor/"
*
* @param req request object
* @param parInstanceName unique name
* @param parWidth width
* @param parHeight height
* @param parToolbarSet toolbarSet name
* @param parValue initial value
*/
public FCKeditor(HttpServletRequest req, String parInstanceName, String parWidth, String parHeight, String parToolbarSet, String parValue){
request=req;
basePath = request.getContextPath() + "/FCKeditor/";
instanceName=parInstanceName;
width=parWidth;
height=parHeight;
toolbarSet=parToolbarSet;
value=parValue;
oConfig = new FCKeditorConfigurations() ;
}
private boolean isCompatible() {
String userAgent=request.getHeader("user-agent").toLowerCase();
if(userAgent==null)
return false;
if ((userAgent.indexOf("msie") !=-1) && (userAgent.indexOf("mac") == -1) && (userAgent.indexOf("Opera") == -1)) {
if(retrieveBrowserVersion(userAgent)>=5.5)
return true;
}
else if (userAgent.indexOf("gecko") !=-1){
if(retrieveBrowserVersion(userAgent)>=20030210)
return true;
}
return false;
}
private double retrieveBrowserVersion(String userAgent) {
if(userAgent.indexOf("msie")>-1) {
String str = userAgent.substring(userAgent.indexOf("msie") + 5);
return Double.parseDouble(str.substring(0, str.indexOf(";")));
}
else {
String str = userAgent.substring(userAgent.indexOf("gecko") + 6);
return Double.parseDouble(str.substring(0, str.indexOf(" ")));
}
}
private String HTMLEncode(String txt) {
txt=txt.replaceAll("&","&");
txt=txt.replaceAll("<","<");
txt=txt.replaceAll(">",">");
txt=txt.replaceAll("\"",""");
txt=txt.replaceAll("'","’");
return txt;
}
/**
* Generate the HTML Code for the editor.
* <br>
* Evalute the browser capabilities and generate the editor if IE 5.5 or Gecko 20030210 or greater,
* or a simple textarea otherwise.
*
* @return html code
*/
public String create() {
StringBuffer strEditor=new StringBuffer();
strEditor.append("<div>");
value=HTMLEncode(value);
if(isCompatible()) {
strEditor.append("<input type=\"hidden\" id=\"" + instanceName + "\" name=\"" + instanceName + "\" value=\"" + value + "\">");
strEditor.append(createConfigHTML());
strEditor.append(createIFrameHTML());
}
else{
strEditor.append("<TEXTAREA name=\"" + instanceName + "\" rows=\"4\" cols=\"40\" style=\"WIDTH: " + width + "; HEIGHT: " + height + "\" wrap=\"virtual\">"+value+"</TEXTAREA>");
}
strEditor.append("</div>");
return strEditor.toString();
}
private String createConfigHTML() {
String configStr=oConfig.getUrlParams();
if (!toolbarSet.equals(""))
configStr+="&Toolbar=" + toolbarSet;
if(!configStr.equals(""))
configStr=configStr.substring(1);
return "<input type=\"hidden\" id=\"" + instanceName + "___Config\" value=\"" + configStr + "\">" ;
}
private String createIFrameHTML() {
StringBuffer sLink=new StringBuffer(basePath + "editor/fckeditor.html?InstanceName=" + instanceName);
return "<iframe id=\"" + instanceName + "___Frame\" src=\"" + sLink + "\" width=\"" + width + "\" height=\"" + height + "\" frameborder=\"no\" scrolling=\"no\"></iframe>";
}
}
--- NEW FILE: FCKeditorConfigurations.java ---
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: FCKeditorConfigurations.java
* FCKeditor configurations container.
*
* Version: 2.0 Beta 1
* Modified: 2004-05-30 21:26:18
*
* File Authors:
* Simone Chiaretta (si...@pi...)
*/
package com.fredck.FCKeditor;
import java.util.*;
/**
* Contains the configuration settings for the FCKEditor.<br>
* Adding element to this collection you can override the settings specified in the config.js file.
*
* @author Simone Chiaretta (si...@pi...)
*/
public class FCKeditorConfigurations extends HashMap{
/**
* Initialize the configuration collection
*/
public FCKeditorConfigurations() {
super();
}
/**
* Generate the url parameter sequence used to pass this configuration to the editor.
*
*
*@return html endocode sequence of configuration parameters
*/
public String getUrlParams() {
StringBuffer osParams = new StringBuffer();
for(Iterator i=this.entrySet().iterator();i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
osParams.append("&"+HTMLEncode(entry.getKey().toString())+"="+HTMLEncode(entry.getValue().toString()));
}
return osParams.toString();
}
private String HTMLEncode(String txt) {
txt=txt.replaceAll("&","&");
txt=txt.replaceAll("<","<");
txt=txt.replaceAll(">",">");
txt=txt.replaceAll("\"",""");
txt=txt.replaceAll("'","’");
return txt;
}
}
--- NEW FILE: package.html ---
<!--
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: package.html
* FCKeditor package description
*
* Version: 2.0 Beta 1
* Modified: 2004-05-31 23:12:46
*
* File Authors:
* Simone Chiaretta (si...@pi...)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.60 98/01/27
Copyright 1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This software is the confidential and proprietary information of Sun
Microsystems, Inc. ("Confidential Information"). You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into
with Sun.
CopyrightVersion 1.2
-->
</head>
<body bgcolor="white">
Core objects to manage the FCKeditor text input form.
Java Intergration Module 2.0.
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://www.fckeditor.net/">Official page of FCKeditor</a>
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
|