1 12 13 package com.openedit.modules.edit; 14 15 import java.io.FileNotFoundException ; 16 import java.io.IOException ; 17 import java.net.URLDecoder ; 18 import java.util.List ; 19 20 import com.openedit.OpenEditException; 21 import com.openedit.WebPageRequest; 22 import com.openedit.modules.BaseModule; 23 import com.openedit.modules.html.EditorSession; 24 import com.openedit.modules.spell.WebSpellChecker; 25 import com.openedit.page.Page; 26 27 28 33 public class SpellCheckerModule extends BaseModule 34 { 35 36 public SpellCheckerModule() 37 { 38 super(); 39 } 40 41 public void checkAllSpellings(WebPageRequest inReq) throws Exception  42 { 43 44 String content = inReq.getRequestParameter("textinputs[]"); 45 46 String text = URLDecoder.decode(content); 47 48 WebSpellChecker checker = getSpellChecker( inReq ); 49 List allwords = checker.checkAllWords(text); 50 51 inReq.putPageValue("errors",allwords); 52 String javascript = new EditorSession().createVariable(text); 53 54 inReq.putPageValue("textinputs",javascript); 55 } 56 57 58 protected WebSpellChecker getSpellChecker( WebPageRequest inContext ) throws OpenEditException 59 { 60 WebSpellChecker spellChecker = (WebSpellChecker)inContext.getSessionValue( WebSpellChecker.KEY ); 61 if (spellChecker == null) 62 { 63 try 64 { 65 Page dic = getPageManager().getPage("/openedit/editors/spell/dictionary/all.dic"); 67 spellChecker = new WebSpellChecker( 68 getRoot().getAbsolutePath() + dic.getContentItem().getPath() ); 69 inContext.putSessionValue( WebSpellChecker.KEY, spellChecker ); 70 } 71 catch (FileNotFoundException e) 72 { 73 throw new OpenEditException("Spellchecker dictionary file not found.", e); 74 } 75 catch (IOException e) 76 { 77 throw new OpenEditException("Failed to load spellchecker dictionary.", e); 78 } 79 } 80 81 return spellChecker; 82 } 83 84 } 85 | Popular Tags |