Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. DataCls dc = new DataCls();
  2. dc.ExeComm("DROP TABLE IF EXISTS tblError;"
  3. + "CREATE TABLE tblError("
  4. + "FILE VARCHAR(255), "
  5. + "WORD VARCHAR(255), "
  6. + "LINE INT(10)"
  7. + ")");
  8. String[] col = new String[]{"File","Word","Line"};
  9. p.dtm.addColumn(col[0]);
  10. p.dtm.addColumn(col[1]);
  11. p.dtm.addColumn(col[2]);
  12. for(int i = 0; i < lstFile.getSize(); i++) {
  13. SpellChecker splChkr = new SpellChecker(dict);
  14. spellCheck splChk = p.new spellCheck();
  15. splChk.file = lstFile.getElementAt(i).toString();
  16. splChk.counter = 0;
  17. splChkr.addSpellCheckListener(splChk);
  18. String toCheck = p.readXHTML(new File(lstFile.getElementAt(i).toString()));
  19. splChkr.checkSpelling(new StringWordTokenizer(toCheck));
  20. }
  21. ResultSet rs = dc.ExeQuery("SELECT * FROM tblError");
  22. try {
  23. while (rs.next()) {
  24. String cont[] = new String[rs.getMetaData().getColumnCount()];
  25. for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
  26. cont[i] = rs.getString(rs.getMetaData().getColumnName(i + 1).toString());
  27. }
  28. p.dtm.addRow(cont);
  29. }
  30. rs.close();
  31. tblView.setModel(p.dtm);
  32. }
  33. catch (SQLException e) {
  34. JOptionPane.showMessageDialog(rootPane, e);
  35. }
  36. JOptionPane.showMessageDialog(rootPane, "Spell checking completed.");
  37. this.setCursor(Cursor.DEFAULT_CURSOR);
  38. }
  39. catch(FileNotFoundException e) {
  40. JOptionPane.showMessageDialog(rootPane, "File loading error. rnrn" + e, "Error Occured.", JOptionPane.WARNING_MESSAGE);
  41. }
  42. catch(IOException f) {
  43. JOptionPane.showMessageDialog(rootPane, "File loading error. rnrn" + f, "Error Occured.", JOptionPane.WARNING_MESSAGE);
  44. }
  45. }
  46.  
  47. public class spellCheck implements SpellCheckListener {
  48. String file = "";
  49. String lst = "";
  50. String[] rValue = {"","",""};
  51. int counter;
  52. String find = "";
  53. DataCls dat = new DataCls();
  54. @Override
  55. public void spellingError(SpellCheckEvent svt) {
  56.  
  57. lst ="";
  58. lstError.addElement(svt.getInvalidWord().replace("'", "\'"));
  59.  
  60. try {
  61. ResultSet rChk = dat.ExeQuery("SELECT MAX(LINE) FROM tblError WHERE FILE='" + new File(file).getName() + "'AND WORD='" + svt.getInvalidWord().replace("'", "''") + "'");
  62. int rwCnt = 0;
  63. while(rChk.next()) {rwCnt++;}
  64. if (rwCnt == 0) {
  65. try {
  66. BufferedReader br = new BufferedReader(new FileReader(file));
  67. int i = 0;
  68. String line;
  69. while((line = br.readLine()) != null) {
  70. i++;
  71. int index = line.indexOf(svt.getInvalidWord().replace("'", "\'"));
  72. if (index >= 0) {
  73. dat.ExeComm("INSERT INTO tblError(FILE,WORD,LINE) "
  74. + "VALUES ('" + new File(file).getName() +"','" + svt.getInvalidWord().replace("'", "\'") + "','" + i + "')");
  75. break;
  76. }
  77. }
  78. } catch (IOException e){
  79. System.out.println(e);
  80. }
  81.  
  82. } else if (rwCnt > 0){
  83. ResultSet rs = dat.ExeQuery("SELECT MAX(LINE) FROM tblError WHERE FILE='" + new File(file).getName() + "' AND WORD='" + svt.getInvalidWord().replace("'", "''") + "'");
  84. rs.next();
  85. try {
  86. int iline = rs.getInt(1);
  87. try {
  88. BufferedReader br = new BufferedReader(new FileReader(file));
  89. int i = 0;
  90. String line;
  91. while((line = br.readLine()) != null){
  92. i++;
  93. int index = line.indexOf(svt.getInvalidWord().replace("'", "\'"));
  94. if (i > iline) {
  95. if (index >= 0) {
  96. dat.ExeComm("INSERT INTO tblError(FILE,WORD,LINE) "
  97. + "VALUES ('" + new File(file).getName() +"','" + svt.getInvalidWord().replace("'", "\'") + "','" + i + "')");
  98. break;
  99. }
  100. }
  101. }
  102.  
  103. }
  104. catch (IOException e) {
  105. JOptionPane.showMessageDialog(null, e);
  106. }
  107. } catch (SQLException ex) {
  108. JOptionPane.showMessageDialog(null, ex);
  109. }
  110. }
  111. } catch (SQLException ex) {
  112. JOptionPane.showConfirmDialog(null, ex);
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement