Index: lams_central/conf/xdoclet/taglib-tag.xml =================================================================== diff -u --- lams_central/conf/xdoclet/taglib-tag.xml (revision 0) +++ lams_central/conf/xdoclet/taglib-tag.xml (revision 4cbe6aa5e34abb7af38710fd0aa50624c951211e) @@ -0,0 +1,179 @@ + + STRUTS-textarea + org.lamsfoundation.lams.web.tag.MultiLinesTextareaTag + + accesskey + false + true + + + alt + false + true + + + altKey + false + true + + + bundle + false + true + + + cols + false + true + + + disabled + false + true + + + errorKey + false + true + + + errorStyle + false + true + + + errorStyleClass + false + true + + + errorStyleId + false + true + + + indexed + false + true + + + name + false + true + + + onblur + false + true + + + onchange + false + true + + + onclick + false + true + + + ondblclick + false + true + + + onfocus + false + true + + + onkeydown + false + true + + + onkeypress + false + true + + + onkeyup + false + true + + + onmousedown + false + true + + + onmousemove + false + true + + + onmouseout + false + true + + + onmouseover + false + true + + + onmouseup + false + true + + + property + true + true + + + readonly + false + true + + + rows + false + true + + + style + false + true + + + styleClass + false + true + + + styleId + false + true + + + tabindex + false + true + + + title + false + true + + + titleKey + false + true + + + value + false + true + + Index: lams_central/src/java/org/lamsfoundation/lams/web/tag/MultiLinesTextareaTag.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/tag/MultiLinesTextareaTag.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/tag/MultiLinesTextareaTag.java (revision 4cbe6aa5e34abb7af38710fd0aa50624c951211e) @@ -0,0 +1,141 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.web.tag; + + +import javax.servlet.jsp.JspException; + +import org.apache.struts.taglib.html.TextareaTag; +/** + * Customerized HTML textarea tag. This tag must used with /lams_web_root/includes/javascript/common.js. + * This Tag is 100% compatiable with STRUTS HTML:textarea tag. But this tag can save break line character into + * HTML <BR>. Any specified string for characters that are sensitive to HTML interpreters will be replace + * as well. So the content saved into database thru this tag will 100% compatiable with FCKEditor content. + * + * @author Steve.Ni + * + * @version $Revision$ + */ +public class MultiLinesTextareaTag extends TextareaTag { + private static String os = (String) System.getProperties().get("os.name"); + /** + * + */ + private static final long serialVersionUID = -2282473095816882899L; + + /** + * Generate an HTML <textarea> tag. + * @override + * @throws JspException + */ + protected String renderTextareaElement() throws JspException { + if(this.property == null) + return super.renderTextareaElement(); + String tagName = prepareName(); + + //add Javascript event handler + String chbr ="filterData(this,document.getElementById('" + tagName + "'));"; + String onChange = this.getOnchange(); + if(onChange == null) + onChange = chbr; + else if(onChange.indexOf(chbr) == -1){ + if(onChange.endsWith(";")) + onChange += chbr; + else + onChange = onChange + ";" + chbr; + } + this.setOnchange(onChange); + + //reset some values to another in order to use them in hidden field. + String oldProperty= this.property; + String oldValue = this.value; + + this.value=getDataNoBr(this.value); + this.property +="__textarea"; + StringBuffer results = new StringBuffer(super.renderTextareaElement()); + this.property = oldProperty; + + //construct hidden variable + results.append(""); + + this.value = oldValue; + + return results.toString(); + } + /** + * Change input string <BR> tag into \n or \r\n (dependent on OS). + * @param data + * @return + * @throws JspException + */ + private String getDataNoBr(String data) throws JspException{ + if (data == null) { + data = this.lookupProperty(this.name, this.property); + } + if(data != null){ + //change back + if(os.toLowerCase().indexOf("win") != -1) + data = data.replaceAll("
","\r\n"); + else + data = data.replaceAll("
","\n"); + } + return data == null?"":data; + } + /** + * Change input string \n or \r\n (dependent on OS) into <BR> tag. + * @param data + * @return + * @throws JspException + */ + private String getDataWithBr(String data) throws JspException{ + + if(data != null){ + //change back + if(os.toLowerCase().indexOf("win") != -1) + data = data.replaceAll("\r\n","
"); + else + data = data.replaceAll("\n","
"); + } + return data; + } + + /** + * Renders the value displayed in the <textarea> tag. + * @override + * @throws JspException + */ + protected String renderData() throws JspException { + String data = this.value; + + if (data == null) { + data = this.lookupProperty(this.name, this.property); + } + + return (data == null) ? "":data; + } +} Index: lams_central/web/WEB-INF/lams.tld =================================================================== diff -u -r8ba43ae6cd465e24431866147a53ae7e43102efd -r4cbe6aa5e34abb7af38710fd0aa50624c951211e --- lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) +++ lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision 4cbe6aa5e34abb7af38710fd0aa50624c951211e) @@ -32,17 +32,197 @@ - css - org.lamsfoundation.lams.web.tag.CssTag - + WebAppURL + org.lamsfoundation.lams.web.tag.WebAppURLTag + - WebAppURL - org.lamsfoundation.lams.web.tag.WebAppURLTag - + css + org.lamsfoundation.lams.web.tag.CssTag + + + STRUTS-textarea + org.lamsfoundation.lams.web.tag.MultiLinesTextareaTag + + accesskey + false + true + + + alt + false + true + + + altKey + false + true + + + bundle + false + true + + + cols + false + true + + + disabled + false + true + + + errorKey + false + true + + + errorStyle + false + true + + + errorStyleClass + false + true + + + errorStyleId + false + true + + + indexed + false + true + + + name + false + true + + + onblur + false + true + + + onchange + false + true + + + onclick + false + true + + + ondblclick + false + true + + + onfocus + false + true + + + onkeydown + false + true + + + onkeypress + false + true + + + onkeyup + false + true + + + onmousedown + false + true + + + onmousemove + false + true + + + onmouseout + false + true + + + onmouseover + false + true + + + onmouseup + false + true + + + property + true + true + + + readonly + false + true + + + rows + false + true + + + style + false + true + + + styleClass + false + true + + + styleId + false + true + + + tabindex + false + true + + + title + false + true + + + titleKey + false + true + + + value + false + true + + + Index: lams_central/web/includes/javascript/common.js =================================================================== diff -u -rffbc47494b72d5222b6fc95db0347f7732d93310 -r4cbe6aa5e34abb7af38710fd0aa50624c951211e --- lams_central/web/includes/javascript/common.js (.../common.js) (revision ffbc47494b72d5222b6fc95db0347f7732d93310) +++ lams_central/web/includes/javascript/common.js (.../common.js) (revision 4cbe6aa5e34abb7af38710fd0aa50624c951211e) @@ -15,4 +15,25 @@ instructionsWindow = window.open(url,'instructions','resizable,width=796,height=570,scrollbars'); instructionsWindow.window.focus(); // } + } + + function filterData(src,target){ + if(src.value != null){ + //replace specified string for characters that are sensitive to HTML interpreters + var srcV = src.value; + //must replace & first, otherwise, this will conflict with others. + srcV = srcV.replace(/&/g,"&"); + srcV = srcV.replace(//g,">"); + srcV = srcV.replace(/"/g,"""); + srcV = srcV.replace(/\\/g,"'"); + target.value = srcV; + //for windows system + if(src.value.indexOf("\r\n") != -1) + target.value=srcV.replace(/\r\n/g,"
"); + //for *nix system + else if(src.value.indexOf("\n") != -1) + target.value=srcV.replace(/\n/g,"
"); + + } } \ No newline at end of file