Dict Files are usually specified by their server path in RapidSpellWebLauncher tag's attribute "dictFile". It is not possible to specify a Dict File in this manner if it resides in a WAR file, instead the Dict File should be set directly as a stream.
Please see the attached WAR file, for a runnable demo.
As of v2.3 of RapidSpell Web Java it is possible to set Dict Files as streams, the example below first creates a custom instance of RapidSpellChecker (the core spell checker class - note, if the license key has expired and you are evaluating, then a new one should be obtained from the Key Generator/ and set in all files.). The code below then goes on to copy the Dict File from the war file, into memory.
Note: getResource("/test.dict") specifies the location of the Dict File inside the WAR, in our demo test.dict is in the root of the WAR.
The code sets the dict file as an input stream in the RapidSpellChecker object, and instructs the RapidSpellWeb Tag to use our RapidSpellChecker instance.
Eg (in the popup page);
<% //construct an instance of the core spell checker com.keyoti.rapidSpell.RapidSpellChecker rapidSpellChecker = new com.keyoti.rapidSpell.RapidSpellChecker("544F645B6157635C655667665E5763354D524E3E353A3D383D3D3B4140414640484D494E0");
//obtain a stream to the resource in the WAR file java.io.BufferedInputStream resStream = new java.io.BufferedInputStream(application.getResource("/test.dict").openStream()); //construct a byte array stream to store a copy of the Dict file java.io.ByteArrayOutputStream memoryOutputStream = new java.io.ByteArrayOutputStream(1000000);
//copy from the resource stream to the byte array byte[] buffer = new byte[10000]; int count = resStream.read(buffer, 0, 10000); while (count > 0){ memoryOutputStream.write(buffer, 0, count); count=resStream.read(buffer, 0, count); }
//create an input stream from the byte array stream java.io.ByteArrayInputStream memoryDictInputStream = new java.io.ByteArrayInputStream(memoryOutputStream.toByteArray()); //reset the position of the byte array stream memoryDictInputStream.reset();
//set the dict file steam rapidSpellChecker.setDictFileStream(memoryDictInputStream);
%>
<RapidSpellWeb:rapidSpellWeb checkerEngine="<%= rapidSpellChecker %>"/>
These are all the changes that need to be made. Note, that if the Dict File is not successfully loaded, then the dictionary contained in the RapidSpellMDict.jar file is used as default - to aid debugging it is advisable to add a word to your Dict File and try spell checking that word. In the attached example we have added the word "keyoti".
|