<%@page language="java"%>
<%@page import="java.io.*"%>
<%@page import="java.util.Enumeration"%>
<%
String osName = System.getProperty("os.name");
String s = null;
//The following variables values must reflect your installation needs.
//convert from php to jsp by windu gata (windu_gata@yahoo.com) 11 October 2007, universitas Budi Luhur, universitas Nusa Mandiri
//String aspell_prog = "C:\\Program Files\\Aspell\\bin\\aspell.exe"; //windows
String aspell_prog = "/usr/bin/aspell"; //linux
//String aspell_prog = "/opt/local/bin/aspell"; //apple
String aspell_opts = "-a --lang=en_US --encoding=utf-8 -H --rem-sgml-check=alt";
String spellercss = "../spellerStyle.css";
String word_win_src = "../wordWindow.js";
String input_separator = "A";
String escape_char[] = {"%20", "%27", "%3C", "%3E", "%3B", "%26nbsp","%2F","br"};
String replace_char[]= {" ", "\'" , "" , "" , "" , "" , "" ," " };
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="<%=spellercss %>" />
<script language="javascript" src="<%=word_win_src %>"></script>
<script language="javascript">
var suggs = new Array();
var words = new Array();
var textinputs = new Array();
var error;
<%
//get parameter
String textinputs = request.getParameter("textinputs[]");
out.write("textinputs[0] = decodeURIComponent(\"" + textinputs + "\");\n");
//delete escape character
for (int i=0; i<escape_char.length;i++) {
textinputs = textinputs.replace(escape_char[i],replace_char[i]);
}
//get temporary servlet directory
ServletContext context=request.getSession().getServletContext();
File tmpdir=(File)context.getAttribute("javax.servlet.context.tempdir");
String tmpfile="/aspell_data_";
try {
//save temporary file
PrintWriter printout = new PrintWriter (new BufferedWriter (new FileWriter (tmpdir.getPath() + tmpfile)));
printout.print (textinputs);
printout.flush ();
printout.close ();
}
catch (IOException e) {
out.write("Cannot Create File Temporary " + e.toString()) ;
}
try {
// Windows Nt or XP, change "cmd " t0 "command" on windows 98
// String[] cmd = {
// "cmd",
// "-c",
// aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
// };
String[] cmd = {
"/bin/sh",
"-c",
aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
};
Process p1 = Runtime.getRuntime().exec(cmd);
int exitValue = p1.waitFor();
if (exitValue == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p1.getInputStream()));
int index = 0;
int text_input_idx = -1;
int line=0;
while ((s = stdInput.readLine()) != null) {
if (!s.startsWith("@") && s.length() > 0) {
if (s.startsWith("*")) {
text_input_idx++;
out.write("words[" + text_input_idx + "] = [];\n");
out.write("suggs[" + text_input_idx + "] = [];\n");
index=0;
}else if (s.startsWith("&") || s.startsWith("#")) {
if (text_input_idx == -1) {
text_input_idx++;
out.write("words[" + text_input_idx + "] = [];\n");
out.write("suggs[" + text_input_idx + "] = [];\n");
}
String word[] = s.replace("\'", "\\'").split(":");
String wordleft[] = word[0].split(" ");
out.write ("words[" + text_input_idx + "][" + index + "] = '" + wordleft[1].replace("\'", "\\'") + "';\n");
if ( word.length > 1) {
String suggs[] = word[1].split(", ");
out.write("suggs[" + text_input_idx + "][" + index + "] = [");
for (int i=0; i< suggs.length ; i++) {
out.write( "'" + suggs[i].trim().replace("\'","") + "'");
if (i < suggs.length-1 ) {
out.write(",");
}
}
out.write("];\n");
}
index++;
}
line++;
}
}
}
}
catch (Exception e) {
//System.out.println(e.toString());
}
%>
var wordWindowObj = new wordWindow();
wordWindowObj.originalSpellings = words;
wordWindowObj.suggestions = suggs;
wordWindowObj.textInputs = textinputs;
function init_spell() {
// check if any error occured during server-side processing
if( error ) {
alert( error );
} else {
// call the init_spell() function in the parent frameset
if (parent.frames.length) {
parent.init_spell( wordWindowObj );
} else {
alert('This page was loaded outside of a frameset. It might not display properly');
}
}
}
</script>
</head>
<!-- <body onLoad="init_spell();"> by FredCK -->
<body onLoad="init_spell();" bgcolor="#ffffff">
<script type="text/javascript">
wordWindowObj.writeBody();
</script>
</body>
</html>
Thu, 10/11/2007 - 10:37
#1
Re: The Newest spellchecker.jsp For JAva Programmer
hmm.. still error but i have fixed this code, test it
<%@page language="java"%>
<%@page import="java.io.*"%>
<%@page import="java.util.Enumeration"%>
<%
String osName = System.getProperty("os.name");
String s = null;
//The following variables values must reflect your installation needs.
//convert from php to jsp by windu gata 10 October 2007 budi luhur university
//fixed 17 october 2007
//String aspell_prog = "C:\\Program Files\\Aspell\\bin\\aspell.exe"; //windows
//String aspell_prog = "/usr/bin/aspell"; //linux
String aspell_prog = "/opt/local/bin/aspell"; //apple
String aspell_opts = "-a --lang=en_US --encoding=utf-8 -H --rem-sgml-check=alt";
String spellercss = "../spellerStyle.css";
String word_win_src = "../wordWindow.js";
String input_separator = "A";
//java has no decode html so u acan add character
String escape_char[] = {"%3Cb%3E", "%3C%2Fb%3E", "%20", " %3Cbr%3E", "%0A", "%2C", "%22", "%27", "%3C", "a href%3D\"mailto%A", "%3C%2Fa%3E", "%40", "%3A", "%3D", "_fcksavedurl=", "<%2Fa%3E", "%3E", "%26nbsp", "%3B", "<br"};
String replace_char[]= {" " , " " , " " , " " , " " , "," , " " , " " , "<" , " " , " " , "@" , ":" , "=" , " " , " " , " " , " " , " " , " " };
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="<%=spellercss %>" />
<script language="javascript" src="<%=word_win_src %>"></script>
<script language="javascript">
var suggs = new Array();
var words = new Array();
var textinputs = new Array();
var error;
<%
//get parameter
String textinputs = request.getParameter("textinputs[]");
//out.write("textinputs[0] = decodeURIComponent(\"\");\n");
out.write("textinputs[0] = decodeURIComponent(\"" + textinputs + "\");\n");
System.out.println(textinputs);
//delete escape character
for (int i=0; i<escape_char.length;i++) {
textinputs = textinputs.replace(escape_char[i],replace_char[i]);
}
//get temporary servlet directory
ServletContext context=request.getSession().getServletContext();
File tmpdir=(File)context.getAttribute("javax.servlet.context.tempdir");
String tmpfile="/aspell_data_";
try {
//save temporary file
PrintWriter printout = new PrintWriter (new BufferedWriter (new FileWriter (tmpdir.getPath() + tmpfile)));
printout.print (textinputs);
printout.flush ();
printout.close ();
}
catch (IOException e) {
out.write("Cannot Create File Temporary " + e.toString()) ;
}
try {
// Windows Nt or XP, change "cmd " t0 "command" on windows 98
// String[] cmd = {
// "cmd",
// "-c",
// aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
// };
String[] cmd = {
"/bin/sh",
"-c",
aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
};
Process p1 = Runtime.getRuntime().exec(cmd);
int exitValue = p1.waitFor();
//System.out.println("jalan " + exitValue);
if (exitValue == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p1.getInputStream()));
int index = 0;
int text_input_idx = -1;
int line=0;
while ((s = stdInput.readLine()) != null) {
if (!s.startsWith("@") && s.length() > 0) {
if (s.startsWith("&") || s.startsWith("#")) {
if (text_input_idx == -1) {
text_input_idx++;
out.write("words[" + text_input_idx + "] = [];\n");
out.write("suggs[" + text_input_idx + "] = [];\n");
}
//System.out.println(" nilai " + s.replace("\'", "\\'"));
String word[] = s.replace("\'", "").split(":");
String wordleft[] = word[0].split(" ");
out.write ("words[" + text_input_idx + "][" + index + "] = '" + wordleft[1].replace("\'", "\\'") + "';\n");
if ( word.length > 1) {
String suggs[] = word[1].split(", ");
out.write("suggs[" + text_input_idx + "][" + index + "] = [");
for (int i=0; i< suggs.length ; i++) {
out.write( "'" + suggs[i].trim().replace("\'","") + "'");
if (i < suggs.length-1 ) {
out.write(",");
}
}
out.write("];\n");
}
index++;
}
line++;
}
}
}
}
catch (Exception e) {
System.out.println(e.toString());
}
%>
var wordWindowObj = new wordWindow();
wordWindowObj.originalSpellings = words;
wordWindowObj.suggestions = suggs;
wordWindowObj.textInputs = textinputs;
function init_spell() {
// check if any error occured during server-side processing
if( error ) {
alert( error );
} else {
// call the init_spell() function in the parent frameset
if (parent.frames.length) {
parent.init_spell( wordWindowObj );
} else {
alert('This page was loaded outside of a frameset. It might not display properly');
}
}
}
</script>
</head>
<!-- <body onLoad="init_spell();"> by FredCK -->
<body onLoad="init_spell();" bgcolor="#ffffff">
<script type="text/javascript">
wordWindowObj.writeBody();
</script>
</body>
</html>
Re: The Newest spellchecker.jsp For JAva Programmer
First of all, thanks a lot for the code of this jsp.
I try to use it on windows XP ans WAS6 (I decommented the correct lines), but at the execution time, it seems like p1.waitfor() loops eternally ...
Has anybody an idea of what causes that ? Thanks a lot !
I've seen that cmd -c doesn't seem to use the third argument so I tried without it but that's the same.
Re: The Newest spellchecker.jsp For JAva Programmer
Cheers,
Vincent
Re: The Newest spellchecker.jsp For JAva Programmer
I would recommend posting your code attached to a ticket at http://dev.fckeditor.net.
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
I love FckEditor and I use it with PHP too. but i was sad why there is no SpellChecker.jsp on your project. So I learned your PHP code and convert to JSP Code. I thought so many java developer had same problem with me.
I have tested this code to my project and still running till now and my clients love it. and have tested using windows xp, windows 98, linux, and apple as server. my web server is tomcat and my jdk was jdk1.4 and now using Jdk 1.5
you can asked me to windu_gata@yahoo.com
regards,
windu
Re: The Newest spellchecker.jsp For JAva Programmer
Thank you for the JSP file !
I added it in fckez.jar in fckez\web\js\ext\FCKeditor\editor\dialog\fck_spellerpages\spellerpages\server-scripts
Then, in my FCKEditor config file, I added :
But when I click on spell check button in FCKEditor, it displays the spellchecker.jsp source file and doesn't run it.
Could you help me ?
Thank you.
Re: The Newest spellchecker.jsp For JAva Programmer
I am using the linux with tomcat server, I tried including the jsp code for spell check.
When I click the spell check link in FCK editor, the pop-up window open, but the data are not loading and moreover I didn't able to type anything in that page.
If I click on any button it shows me alert message stating that "Error:"Not in dictionary" text is missing".
Can you please help me out to fix the issue.
Thanks in advance,
Karthi
Re: The Newest spellchecker.jsp For JAva Programmer
Hi, All
easy to use this stuff,
please follow these steps
1. make sure that aspell has installed on your computer.
I think linux already has it.
linux : ftp://ftp.gnu.org/gnu/aspell/dict/0index.html
windows : https://support.kayako.com/index.php?_m ... icleid=125
apple : http://osdir.com/ml/os.apple.fink.cvs/2 ... index.html
2. find aspell (aspell.exe) directory
windows : C:\Program Files\Aspell\bin\aspell.exe
linux : /usr/bin/aspell (find it)
apple : /opt/local/bin/aspell
3. Change fckconfig.js
FCKConfig.spellChecker = "spellerPages";
.......
FCKConfig.SpellerPagesServerScript = 'server-scripts/spellchecker.jsp' ; // Available extension: .php .cfm .pl now jsp
4. Copy second Script above
viewtopic.php?f=5&t=7219&p=23279#p19347
(i do not use fckez.jar)
and save as spellchecker.jsp to directory
fckeditor\editor\dialog\fck_spellerpages\spellerpages\server-scripts
5. run on your computer
I hope u like it and have fun .........
regards,
Windu Gata
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
I tried all the day to modify speelchecker.jsp for Windows XP :
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
When I use the code from the second post with the proper commented sections I get the following error:
this.originalSpellings[...].length is null or not an object
and then two:
Object does not support this method or property errors
I can't figure out where/why that is happening, wondered if anyone else had encountered and fixed it. Or at least had an idea how to.
Re: The Newest spellchecker.jsp For JAva Programmer
The problem is still in missing java support for redirects and pipes (for Windows) in the method Runtime.getRuntime().exec() and the need to handle the Input/Output Streams in more threads.
The possible solution for this problem is to write some code which use more threads for input/output stream handling (based on)/(uses the code from) the prety code from OpenSource JeditSpellCheckPlugin http://plugins.jedit.org/plugins/?SpellCheck
I have opened Ticket #2090 for FCK http://dev.fckeditor.net/ticket/2090
Re: The Newest spellchecker.jsp For JAva Programmer
Hi, great stuff by Wendy !!! thanks for posting
I am however facing the same problem as mentioned above, the top frame of the spellcheck window (pop up), keeps display the "spell check in progress" message, and then nothing happens.
Has anyone found a solution for this ?
thnks
Re: The Newest spellchecker.jsp For JAva Programmer
I wonder how it works with UTF-8 symbols especially 3-byte's when they are part of misspeled word. I have had troubles with it. But I couldn't use this jsp as it is anyway because I use InDesign server for spellchecking instead of aspell. So I had to write it all differently but at least I suggest setting
response.setCharacterEncoding("UTF-8"); somewere before using out.write().
Re: The Newest spellchecker.jsp For JAva Programmer
Hi,
I followed your suggestion and it was working fine. But, now suddenly, the spellchecker window is blank. The output window contains the following (All the content in between is the content of my text file) -
08/07/11 23:18:39
%20%20%20%20%20%20%20%20%20%20%20%20%20%20http%3A%2F%2F130.35.74.28%2Fidc%2Fidcplg%3FIdcService%3DGET_SOAP_WSDL_LISTsysadmin%2Fidc%20as%20username%2Fpasswordhttp%3A%2F%2Femsprod.us.oracle.com%2FEMS%2FForms%2FViewEnvInfo%2Fprocess_form%3Fenv_info_file%3D%2Fnfs%2Femsnet%2Fadc1003nap-ems_34270_1482%2Fems%2Fconf%2Fcm2yd550_info.xml%26amp%3Benv_name%3DEE_CM2YD550_MKT_FUSION_DEVhttp%3A%2F%2Fap6015fses%3A8997%2FLeadsForerunnerUI%0A%20%20%20%20%20%20%20%20%20%20%20%20
Any pointers would be useful.
Thanks,
Vish
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
Thanks,
Vish
Re: The Newest spellchecker.jsp For JAva Programmer
strange issue. please help.
satya
Re: The Newest spellchecker.jsp For JAva Programmer
Thanks
satya
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
Here is the spellchecker.jsp that works in IE as well as Firefox
<%@page language="java"%>
<%@page import="java.io.*"%>
<%@page import="java.util.Enumeration"%>
<%@page import="org.apache.commons.lang.*"%>
<%
String osName = System.getProperty("os.name");
String s = null;
//The following variables values must reflect your installation needs.
//convert from php to jsp by windu gata 10 October 2007 budi luhur university
//fixed 17 october 2007
//String aspell_prog = "C:\\Program Files\\Aspell\\bin\\aspell.exe"; //windows
String aspell_prog = "/usr/local/bin/aspell"; //linux
//String aspell_prog = "/opt/local/bin/aspell"; //apple
String aspell_opts = "-a --lang=en_US --encoding=utf-8 -H --rem-sgml-check=alt";
String spellercss = "../spellerStyle.css";
String word_win_src = "../wordWindow.js";
String input_separator = "A";
//java has no decode html so u acan add character
//String escape_char[] = {"%0D%0A" , "%3Cp%3E" , "%3C%2Fp%3E", "%3Cb%3E", "%3C%2Fb%3E", "%20", " %3Cbr%3E", "%0A", "%2C", "%22", "%27", "%3C", "a href%3D\"mailto%A", "%3C%2Fa%3E", "%40", "%3A", "%3D", "_fcksavedurl=", "<%2Fa%3E", "%3E", "%26nbsp", "%3B", "<br"};
//String replace_char[]= {" " , " " , " " , " " , " " , " " , " " , " " , "," , " " , " " , "<" , " " , " " , "@" , ":" , "=" , " " , " " , " " , " " , " " , " " };
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="<%=spellercss %>" />
<script language="javascript" src="<%=word_win_src %>"></script>
<script language="javascript">
var suggs = new Array();
var words = new Array();
var textinputs = new Array();
var error;
<%
//get parameter
String textinputs = request.getParameter("textinputs[]");
//out.write("textinputs[0] = decodeURIComponent(\"\");\n");
out.write("textinputs[0] = decodeURIComponent(\"" + textinputs + "\");\n");
System.out.println(textinputs);
//delete escape character
//for (int i=0; i<escape_char.length;i++) {
//textinputs = textinputs.replace(escape_char[i],replace_char[i]);
//}
textinputs=java.net.URLDecoder.decode(textinputs,"UTF-8");
//get temporary servlet directory
ServletContext context=request.getSession().getServletContext();
File tmpdir=(File)context.getAttribute("javax.servlet.context.tempdir");
String tmpfile="/aspell_data_"+new java.util.Random().nextLong();
//Replace newline characters
System.out.println("Before newline char replace: " + textinputs);
textinputs=textinputs.replaceAll("\n","");
textinputs=textinputs.replaceAll("\r","");
System.out.println("After newline char replace: " + textinputs);
try {
//save temporary file
PrintWriter printout = new PrintWriter (new BufferedWriter (new FileWriter (tmpdir.getPath() + tmpfile)));
printout.print (textinputs);
printout.flush ();
printout.close ();
}
catch (IOException e) {
out.write("Cannot Create File Temporary " + e.toString()) ;
}
try {
// Windows Nt or XP, change "cmd " t0 "command" on windows 98
// String[] cmd = {
// "cmd",
// "-c",
// aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
// };
//Test
//tmpfile="/aspell_data_-4239128009781966915";
//End Test
String[] cmd = {
"/bin/sh",
"-c",
aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
};
Process p1 = Runtime.getRuntime().exec(cmd);
int exitValue = p1.waitFor();
System.out.println("jalan " + exitValue);
if (exitValue == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p1.getInputStream()));
int index = 0;
int text_input_idx = -1;
int line=0;
//boolean noMispelled = false;
while ((s = stdInput.readLine()) != null) {
if (text_input_idx == -1) {
text_input_idx++;
out.write("words[" + text_input_idx + "] = [];\n");
out.write("suggs[" + text_input_idx + "] = [];\n");
}
if (!s.startsWith("@") && s.length() > 0) {
if (s.startsWith("&") || s.startsWith("#")) {
//if (text_input_idx == -1) {
// text_input_idx++;
// out.write("words[" + text_input_idx + "] = [];\n");
// out.write("suggs[" + text_input_idx + "] = [];\n");
//}
System.out.println(" nilai " + s.replace("\'", "\\'"));
String word[] = s.replace("\'", "").split(":");
String wordleft[] = word[0].split(" ");
out.write ("words[" + text_input_idx + "][" + index + "] = '" + wordleft[1].replace("\'", "\\'") + "';\n");
if ( word.length > 1) {
String suggs[] = word[1].split(", ");
out.write("suggs[" + text_input_idx + "][" + index + "] = [");
for (int i=0; i< suggs.length ; i++) {
out.write( "'" + suggs[i].trim().replace("\'","") + "'");
if (i < suggs.length-1 ) {
out.write(",");
}
}
out.write("];\n");
}
//noMispelled = true;
index++;
} else if (s.startsWith("*") ) {
//text_input_idx++;
//if(noMispelled) {
//out.write("words[" + text_input_idx + "] = [];\n");
//out.write("suggs[" + text_input_idx + "] = [];\n");
//index = 0;
//}
}
line++;
}
}
}
}
catch (Exception e) {
System.out.println(e.toString());
}
File f1 = new File(tmpdir.getPath() + tmpfile );
boolean success = f1.delete();
if (!success){
System.out.println("Deletion failed.");
}
%>
var wordWindowObj = new wordWindow();
wordWindowObj.originalSpellings = words;
wordWindowObj.suggestions = suggs;
wordWindowObj.textInputs = textinputs;
function init_spell() {
// check if any error occured during server-side processing
if( error ) {
alert( error );
} else {
// call the init_spell() function in the parent frameset
if (parent.frames.length) {
parent.init_spell( wordWindowObj );
} else {
alert('This page was loaded outside of a frameset. It might not display properly');
}
}
}
</script>
</head>
<!-- <body onLoad="init_spell();"> by FredCK -->
<body onLoad="init_spell();" bgcolor="#ffffff">
<script type="text/javascript">
wordWindowObj.writeBody();
</script>
</body>
</html>
Re: The Newest spellchecker.jsp For JAva Programmer
I've tried the file you posted with the obvious changes for Windows, but am still having no joy!
String aspell_prog = "C:\\Program Files\\Aspell\\bin\\aspell.exe"; //windows
//String aspell_prog = "/usr/local/bin/aspell"; //linux
//String aspell_prog = "/opt/local/bin/aspell"; //apple
.....
// Windows Nt or XP, change "cmd " t0 "command" on windows 98
String[] cmd = {
"cmd",
"-c",
aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
};
//Test
//tmpfile="/aspell_data_-4239128009781966915";
//End Test
//String[] cmd = {
//"/bin/sh",
//"-c",
//aspell_prog + " " + aspell_opts + "<" + tmpdir.getPath() + tmpfile + " 2>&1"
//};
Thanks
Re: The Newest spellchecker.jsp For JAva Programmer
Re: The Newest spellchecker.jsp For JAva Programmer
i made a few modifications, hopefully it will help someone.. only made one minor change
Re: The Newest spellchecker.jsp For JAva Programmer
here is a port of windu's code for windows and unix
Tested on windows xp / solaris 10
---------------------------------------------------------------------
Re: The Newest spellchecker.jsp For JAva Programmer
I would like to show my appreciation. words can't really express it. but here it goes. THANKS so much for the JSP file. it's a big help.
-------------------------
fishing gears
Re: The Newest spellchecker.jsp For JAva Programmer
Dear All,
Nice to help you all, I am glad to know you all.
and say hello ... from Indonesia
Regards,
windu
http://windu1976.multiply.com/
Attachments: