Bug 12231 fixed: In SciNotes, a whole word was searched when the expression was not... 27/10527/2
Calixte DENIZET [Tue, 19 Feb 2013 10:35:51 +0000 (11:35 +0100)]
Change-Id: Ia2f7cf8b1b506e8ffbe203ee460b3decbee776f1

scilab/CHANGES_5.4.X
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/ScilabXMLUtilities.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SearchManager.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SearchWordInFilesAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SearchFile.java

index 2f4c6cc..97d1c41 100644 (file)
@@ -349,6 +349,9 @@ Bug fixes
 
 * Bug #12219 fixed - delete("all") does not recreate a basic axe within cleaned figure.
 
+* Bug #12231 fixed - In SciNotes, a whole word was searched when the expression
+                     was not a word.
+
 * Bug #12232 fixed - There were several memleaks in various fillers.
 
 * Bug #12235 fixed - Matplot did not update on color_map change.
index 8dea0f6..768c252 100644 (file)
@@ -483,4 +483,55 @@ public class ScilabXMLUtilities {
         }
         return length;
     }
+
+    /**
+     * Replace classical XML reserved chars by their XML equivalent entities
+     * @param str the String to parse and transform
+     * @return a String with the XML entities.
+     */
+    public static String getXMLString(String str) {
+        if (str != null && !str.isEmpty()) {
+            StringBuilder buf = new StringBuilder();
+            char[] chars = str.toCharArray();
+            int last = 0;
+            for (int i = 0; i < chars.length; i++) {
+                switch (chars[i]) {
+                case '\'' :
+                    buf.append(chars, last, i - last).append("&apos;");
+                    last = i + 1;
+                    break;
+                case '\"' :
+                    buf.append(chars, last, i - last).append("&quot;");
+                    last = i + 1;
+                    break;
+                case '<' :
+                    buf.append(chars, last, i - last).append("&lt;");
+                    last = i + 1;
+                    break;
+                case '>' :
+                    buf.append(chars, last, i - last).append("&gt;");
+                    last = i + 1;
+                    break;
+                case '&' :
+                    buf.append(chars, last, i - last).append("&amp;");
+                    last = i + 1;
+                    break;
+                default :
+                    break;
+                }
+            }
+
+            if (last == 0) {
+                return str;
+            }
+
+            if (last < chars.length) {
+                buf.append(chars, last, chars.length - last);
+            }
+
+            return buf.toString();
+        }
+
+        return str;
+    }
 }
index 27da77b..5b668ff 100644 (file)
@@ -32,6 +32,7 @@ import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 import javax.swing.tree.DefaultMutableTreeNode;
 
+import org.scilab.modules.commons.xml.ScilabXMLUtilities;
 import org.scilab.modules.gui.utils.ScilabSwingUtilities;
 import org.scilab.modules.scinotes.utils.SciNotesMessages;
 import org.w3c.dom.Element;
@@ -139,7 +140,7 @@ public class SearchManager {
             if (!useRegexp) {
                 word = word.replace("\\E", "\\E\\\\E\\Q");
                 word = "\\Q" + word + "\\E";
-                if (wholeWord) {
+                if (wholeWord && exp.matches("\\b.*\\b")) {
                     word = "\\b" + word + "\\b";
                 }
             }
@@ -172,8 +173,8 @@ public class SearchManager {
      * @return infos with the matching positions
      */
     public static MatchingPositions searchInFiles(final BackgroundSearch bgs, String base, final boolean recursive, final boolean ignoreCR,
-            String filePattern, boolean fileCaseSensitive,
-            String wordPattern, boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
+                                                  String filePattern, boolean fileCaseSensitive,
+                                                  String wordPattern, boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
         final File dir = new File(base);
         Pattern word = null;
         if (wordPattern != null && wordPattern.length() != 0) {
@@ -226,12 +227,12 @@ public class SearchManager {
             pos = new MatchingPositions(base.getAbsolutePath(), list);
             int occurences = 0;
             File[] files = base.listFiles(new FilenameFilter() {
-                @Override
-                public boolean accept(File dir, String name) {
-                    File f = new File(dir, name);
-                    return f.isFile() && f.canRead() && file.matcher(name).matches();
-                }
-            });
+                    @Override
+                    public boolean accept(File dir, String name) {
+                        File f = new File(dir, name);
+                        return f.isFile() && f.canRead() && file.matcher(name).matches();
+                    }
+                });
             Arrays.sort(files);
 
             if (word != null) {
@@ -256,12 +257,12 @@ public class SearchManager {
 
             if (recursive) {
                 files = base.listFiles(new FilenameFilter() {
-                    @Override
-                    public boolean accept(File dir, String name) {
-                        File d = new File(dir, name);
-                        return d.isDirectory() && d.canRead();
-                    }
-                });
+                        @Override
+                        public boolean accept(File dir, String name) {
+                            File d = new File(dir, name);
+                            return d.isDirectory() && d.canRead();
+                        }
+                    });
                 Arrays.sort(files);
 
                 for (int i = 0; i < files.length && !killed[0]; i++) {
@@ -365,17 +366,17 @@ public class SearchManager {
      */
     private static void countFiles(File base, final Pattern pat, final int[] count) {
         File[] files = base.listFiles(new FilenameFilter() {
-            @Override
-            public boolean accept(File dir, String name) {
-                File f = new File(dir, name);
-                if (f.isFile() && f.canRead() && pat.matcher(name).matches()) {
-                    count[0]++;
-                } else if (f.isDirectory() && f.canRead()) {
-                    countFiles(f, pat, count);
+                @Override
+                public boolean accept(File dir, String name) {
+                    File f = new File(dir, name);
+                    if (f.isFile() && f.canRead() && pat.matcher(name).matches()) {
+                        count[0]++;
+                    } else if (f.isDirectory() && f.canRead()) {
+                        countFiles(f, pat, count);
+                    }
+                    return false;
                 }
-                return false;
-            }
-        });
+            });
     }
 
     /**
@@ -572,7 +573,7 @@ public class SearchManager {
          */
         public void toXML(BufferedWriter buffer, int level) throws IOException {
             indent(buffer, level);
-            buffer.append("<Position file=\"" + file + "\" isRoot=\"" + isRoot + "\" occurences=\"" + occurences + "\"");
+            buffer.append("<Position file=\"" + ScilabXMLUtilities.getXMLString(file) + "\" isRoot=\"" + isRoot + "\" occurences=\"" + occurences + "\"");
             if (children != null && !children.isEmpty()) {
                 buffer.append(">\n");
                 for (int i = 0; i < children.size(); i++) {
@@ -692,7 +693,7 @@ public class SearchManager {
          */
         public void toXML(BufferedWriter buffer, int level) throws IOException {
             indent(buffer, level);
-            buffer.append("<Line content=\"" + content.replaceAll("\"", "&quot;") + "\" number=\"" + number + "\"/>\n");
+            buffer.append("<Line content=\"" + ScilabXMLUtilities.getXMLString(content) + "\" number=\"" + number + "\"/>\n");
         }
 
         /**
index 3294d3f..846e2f4 100644 (file)
@@ -221,11 +221,11 @@ public class SearchWordInFilesAction extends DefaultAction implements WindowFocu
         mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         mainFrame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE , 0), ESCAPE);
         mainFrame.getRootPane().getActionMap().put(ESCAPE, new AbstractAction() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                closeWindow();
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    closeWindow();
+                }
+            });
         mainFrame.setTitle(SciNotesMessages.SEARCHINFILES);
         mainFrame.setIconImage(new ImageIcon(ScilabSwingUtilities.findIcon("system-search", "32x32")).getImage());
 
@@ -248,6 +248,13 @@ public class SearchWordInFilesAction extends DefaultAction implements WindowFocu
         JLabel wordPatternLabel = new JLabel(SciNotesMessages.WORDPATTERN + ":");
         comboWordPattern = new JComboBox();
         comboWordPattern.setEditable(true);
+        comboWordPattern.getEditor().addActionListener(new ActionListener() {
+
+                public void actionPerformed(ActionEvent e) {
+                    updateCombos();
+                    startSearch();
+                }
+            });
         ((JTextField) comboWordPattern.getEditor().getEditorComponent()).setColumns(32);
         NORMALCOLOR = ((JTextField) comboWordPattern.getEditor().getEditorComponent()).getForeground();
 
@@ -370,244 +377,244 @@ public class SearchWordInFilesAction extends DefaultAction implements WindowFocu
         mainFrame.setContentPane(panelFrame);
 
         mainFrame.addWindowListener(new WindowListener() {
-            @Override
-            public void windowClosed(WindowEvent arg0) { }
-            @Override
-            public void windowDeiconified(WindowEvent arg0) { }
-            @Override
-            public void windowActivated(WindowEvent arg0) { }
-
-            @Override
-            public void windowClosing(WindowEvent arg0) {
-                closeWindow();
-            }
+                @Override
+                public void windowClosed(WindowEvent arg0) { }
+                @Override
+                public void windowDeiconified(WindowEvent arg0) { }
+                @Override
+                public void windowActivated(WindowEvent arg0) { }
+
+                @Override
+                public void windowClosing(WindowEvent arg0) {
+                    closeWindow();
+                }
 
-            @Override
-            public void windowDeactivated(WindowEvent arg0) { }
-            @Override
-            public void windowIconified(WindowEvent arg0) { };
-            @Override
-            public void windowOpened(WindowEvent arg0) { }
-        });
+                @Override
+                public void windowDeactivated(WindowEvent arg0) { }
+                @Override
+                public void windowIconified(WindowEvent arg0) { };
+                @Override
+                public void windowOpened(WindowEvent arg0) { }
+            });
 
         checkWordCase.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveCaseSensitive(checkWordCase.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveCaseSensitive(checkWordCase.isSelected());
+                }
+            });
 
         checkFileCase.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveFileCase(checkFileCase.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveFileCase(checkFileCase.isSelected());
+                }
+            });
 
         checkWhole.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveWholeWord(checkWhole.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveWholeWord(checkWhole.isSelected());
+                }
+            });
 
         checkRecursive.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveRecursive(checkRecursive.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveRecursive(checkRecursive.isSelected());
+                }
+            });
 
         checkRegular.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveRegularExpression(checkRegular.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveRegularExpression(checkRegular.isSelected());
+                }
+            });
 
         checkLineByLine.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                ConfigSciNotesManager.saveLineByLine(checkLineByLine.isSelected());
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ConfigSciNotesManager.saveLineByLine(checkLineByLine.isSelected());
+                }
+            });
 
         chooseBaseDirButton.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                SwingScilabFileChooser fileChooser = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
-                fileChooser.setDialogTitle(SciNotesMessages.CHOOSEBASEDIR);
-                fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
-                fileChooser.setAcceptAllFileFilterUsed(false);
-                if (fileChooser.showOpenDialog(getEditor()) == JFileChooser.APPROVE_OPTION) {
-                    File path = fileChooser.getSelectedFile();
-                    if (path == null || path.isFile()) {
-                        path = fileChooser.getCurrentDirectory();
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    SwingScilabFileChooser fileChooser = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
+                    fileChooser.setDialogTitle(SciNotesMessages.CHOOSEBASEDIR);
+                    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+                    fileChooser.setAcceptAllFileFilterUsed(false);
+                    if (fileChooser.showOpenDialog(getEditor()) == JFileChooser.APPROVE_OPTION) {
+                        File path = fileChooser.getSelectedFile();
+                        if (path == null || path.isFile()) {
+                            path = fileChooser.getCurrentDirectory();
+                        }
+                        comboBaseDir.getEditor().setItem(path.toString());
+                        updateFindButtonStatus(true);
                     }
-                    comboBaseDir.getEditor().setItem(path.toString());
-                    updateFindButtonStatus(true);
                 }
-            }
-        });
+            });
 
         buttonFind.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                updateCombos();
-                startSearch();
-            }
-        });
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    updateCombos();
+                    startSearch();
+                }
+            });
 
         buttonStop.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                stopSearch();
-            }
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    stopSearch();
+                }
 
-        });
+            });
 
         buttonStop.addPropertyChangeListener(new PropertyChangeListener() {
-            @Override
-            public void propertyChange(PropertyChangeEvent e) {
-                if (mainFrame.isVisible() && e.getPropertyName().equals(SearchFile.SEARCHDONE)) {
-                    boolean newValue = (Boolean) e.getNewValue();
-                    buttonFind.setEnabled(newValue);
-                    buttonStop.setEnabled(!newValue);
-                } else if (e.getPropertyName().equals(ENABLED)) {
-                    boolean newValue = (Boolean) e.getNewValue();
-                    comboBaseDir.setEnabled(!newValue);
-                    comboFilePattern.setEnabled(!newValue);
-                    chooseBaseDirButton.setEnabled(!newValue);
+                @Override
+                public void propertyChange(PropertyChangeEvent e) {
+                    if (mainFrame.isVisible() && e.getPropertyName().equals(SearchFile.SEARCHDONE)) {
+                        boolean newValue = (Boolean) e.getNewValue();
+                        buttonFind.setEnabled(newValue);
+                        buttonStop.setEnabled(!newValue);
+                    } else if (e.getPropertyName().equals(ENABLED)) {
+                        boolean newValue = (Boolean) e.getNewValue();
+                        comboBaseDir.setEnabled(!newValue);
+                        comboFilePattern.setEnabled(!newValue);
+                        chooseBaseDirButton.setEnabled(!newValue);
+                    }
                 }
-            }
-        });
+            });
 
         buttonClose.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                closeWindow();
-            }
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    closeWindow();
+                }
 
-        });
+            });
 
         comboBaseDir.addItemListener(new ItemListener() {
-            @Override
-            public void itemStateChanged(ItemEvent e) {
-                updateFindButtonStatus(true);
-            }
-        });
+                @Override
+                public void itemStateChanged(ItemEvent e) {
+                    updateFindButtonStatus(true);
+                }
+            });
 
         comboBaseDir.addPopupMenuListener(new PopupMenuListener() {
-            @Override
-            public void popupMenuCanceled(PopupMenuEvent e) {
-                comboBaseDirCanceled = true;
-            }
+                @Override
+                public void popupMenuCanceled(PopupMenuEvent e) {
+                    comboBaseDirCanceled = true;
+                }
 
-            @Override
-            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
+                @Override
+                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
 
-            @Override
-            public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
-        });
+                @Override
+                public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
+            });
 
         comboBaseDir.getEditor().getEditorComponent().addKeyListener(new KeyListener() {
-            @Override
-            public void keyTyped(KeyEvent e) { }
-            @Override
-            public void keyReleased(KeyEvent e) {
-                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
-                    if (comboBaseDirCanceled) {
-                        comboBaseDirCanceled = false;
-                    } else {
-                        closeWindow();
+                @Override
+                public void keyTyped(KeyEvent e) { }
+                @Override
+                public void keyReleased(KeyEvent e) {
+                    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+                        if (comboBaseDirCanceled) {
+                            comboBaseDirCanceled = false;
+                        } else {
+                            closeWindow();
+                        }
                     }
+                    updateFindButtonStatus(true);
                 }
-                updateFindButtonStatus(true);
-            }
 
-            @Override
-            public void keyPressed(KeyEvent e) { }
-        });
+                @Override
+                public void keyPressed(KeyEvent e) { }
+            });
 
         comboFilePattern.addItemListener(new ItemListener() {
-            @Override
-            public void itemStateChanged(ItemEvent e) {
-                updateFindButtonStatus(false);
-            }
-        });
+                @Override
+                public void itemStateChanged(ItemEvent e) {
+                    updateFindButtonStatus(false);
+                }
+            });
 
         comboFilePattern.addPopupMenuListener(new PopupMenuListener() {
-            @Override
-            public void popupMenuCanceled(PopupMenuEvent e) {
-                comboFilePatternCanceled = true;
-            }
+                @Override
+                public void popupMenuCanceled(PopupMenuEvent e) {
+                    comboFilePatternCanceled = true;
+                }
 
-            @Override
-            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
+                @Override
+                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
 
-            @Override
-            public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
-        });
+                @Override
+                public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
+            });
 
         comboFilePattern.getEditor().getEditorComponent().addKeyListener(new KeyListener() {
-            @Override
-            public void keyTyped(KeyEvent e) { }
-            @Override
-            public void keyReleased(KeyEvent e) {
-                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
-                    if (comboFilePatternCanceled) {
-                        comboFilePatternCanceled = false;
-                    } else {
-                        closeWindow();
+                @Override
+                public void keyTyped(KeyEvent e) { }
+                @Override
+                public void keyReleased(KeyEvent e) {
+                    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+                        if (comboFilePatternCanceled) {
+                            comboFilePatternCanceled = false;
+                        } else {
+                            closeWindow();
+                        }
                     }
+                    updateFindButtonStatus(false);
                 }
-                updateFindButtonStatus(false);
-            }
 
-            @Override
-            public void keyPressed(KeyEvent e) { }
-        });
+                @Override
+                public void keyPressed(KeyEvent e) { }
+            });
 
         comboWordPattern.addPopupMenuListener(new PopupMenuListener() {
-            @Override
-            public void popupMenuCanceled(PopupMenuEvent e) {
-                comboWordPatternCanceled = true;
-            }
+                @Override
+                public void popupMenuCanceled(PopupMenuEvent e) {
+                    comboWordPatternCanceled = true;
+                }
 
-            @Override
-            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
+                @Override
+                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
 
-            @Override
-            public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
-        });
+                @Override
+                public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
+            });
 
         comboWordPattern.getEditor().getEditorComponent().addKeyListener(new KeyListener() {
-            @Override
-            public void keyTyped(KeyEvent e) { }
-            @Override
-            public void keyReleased(KeyEvent e) {
-                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
-                    if (comboWordPatternCanceled) {
-                        comboWordPatternCanceled = false;
-                    } else {
-                        closeWindow();
+                @Override
+                public void keyTyped(KeyEvent e) { }
+                @Override
+                public void keyReleased(KeyEvent e) {
+                    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+                        if (comboWordPatternCanceled) {
+                            comboWordPatternCanceled = false;
+                        } else {
+                            closeWindow();
+                        }
                     }
-                }
-                if (checkRegular.isSelected()) {
-                    try {
-                        Pattern.compile((String) comboWordPattern.getEditor().getItem());
-                        ((JTextField) comboWordPattern.getEditor().getEditorComponent()).setForeground(NORMALCOLOR);
-                        buttonFind.setEnabled(true);
-                    } catch (PatternSyntaxException pse) {
-                        ((JTextField) comboWordPattern.getEditor().getEditorComponent()).setForeground(ERRORCOLOR);
-                        buttonFind.setEnabled(false);
+                    if (checkRegular.isSelected()) {
+                        try {
+                            Pattern.compile((String) comboWordPattern.getEditor().getItem());
+                            ((JTextField) comboWordPattern.getEditor().getEditorComponent()).setForeground(NORMALCOLOR);
+                            buttonFind.setEnabled(true);
+                        } catch (PatternSyntaxException pse) {
+                            ((JTextField) comboWordPattern.getEditor().getEditorComponent()).setForeground(ERRORCOLOR);
+                            buttonFind.setEnabled(false);
+                        }
                     }
                 }
-            }
 
-            @Override
-            public void keyPressed(KeyEvent e) { }
-        });
+                @Override
+                public void keyPressed(KeyEvent e) { }
+            });
 
         mainFrame.pack();
         mainFrame.setResizable(false);
index f96bf36..952448b 100644 (file)
@@ -216,10 +216,10 @@ public class SearchFile extends SwingScilabTab {
                 buffer.append(" base=\"" + mySearch.base + "\"");
                 buffer.append(" recursive=\"" + mySearch.recursive + "\"");
                 buffer.append(" ignoreCR=\"" + mySearch.ignoreCR + "\"");
-                buffer.append(" filePattern=\"" + mySearch.filePattern.replaceAll("\"", "&quot;") + "\"");
+                buffer.append(" filePattern=\"" + ScilabXMLUtilities.getXMLString(mySearch.filePattern) + "\"");
                 buffer.append(" fileCaseSensitive=\"" + mySearch.fileCaseSensitive + "\"");
                 if (mySearch.wordPattern != null && !mySearch.wordPattern.isEmpty()) {
-                    buffer.append(" wordPattern=\"" + mySearch.wordPattern.replaceAll("\"", "&quot;") + "\"");
+                    buffer.append(" wordPattern=\"" + ScilabXMLUtilities.getXMLString(mySearch.wordPattern) + "\"");
                 }
                 buffer.append(" wordCaseSensitive=\"" + mySearch.wordCaseSensitive + "\"");
                 buffer.append(" wholeWord=\"" + mySearch.wholeWord + "\"");
@@ -306,16 +306,16 @@ public class SearchFile extends SwingScilabTab {
         updateUI();
 
         CommonCallBack callback = new CommonCallBack(null) {
-            @Override
-            public void callBack() {
-                ClosingOperationsManager.startClosingOperation((SwingScilabTab) SearchFile.this);
-            }
+                @Override
+                public void callBack() {
+                    ClosingOperationsManager.startClosingOperation((SwingScilabTab) SearchFile.this);
+                }
 
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                callBack();
-            }
-        };
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    callBack();
+                }
+            };
 
         setCallback(callback);
         MenuBar menubar = ScilabMenuBar.createMenuBar();
@@ -376,53 +376,53 @@ public class SearchFile extends SwingScilabTab {
         files.setRoot();
         final JTree tree = new JTree(files.toDefaultMutableTreeNode());
         MouseListener ml = new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
-                int row = tree.getRowForLocation(e.getX(), e.getY());
-                if (row != -1) {
-                    if (e.getClickCount() == 2) {
-                        validNode(editor, p, tree.getPathForRow(row));
+                @Override
+                public void mousePressed(MouseEvent e) {
+                    int row = tree.getRowForLocation(e.getX(), e.getY());
+                    if (row != -1) {
+                        if (e.getClickCount() == 2) {
+                            validNode(editor, p, tree.getPathForRow(row));
+                        }
                     }
                 }
-            }
-        };
+            };
         tree.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "toggle");
         tree.addKeyListener(new KeyAdapter() {
-            public void keyTyped(KeyEvent e) {
-                if (e.getKeyChar() == '\n') {
-                    int row = tree.getMinSelectionRow();
-                    if (row != -1) {
-                        validNode(editor, p, tree.getPathForRow(row));
+                public void keyTyped(KeyEvent e) {
+                    if (e.getKeyChar() == '\n') {
+                        int row = tree.getMinSelectionRow();
+                        if (row != -1) {
+                            validNode(editor, p, tree.getPathForRow(row));
+                        }
                     }
                 }
-            }
-        });
+            });
         tree.addMouseListener(ml);
         DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
-            @Override
-            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
-            boolean expanded, boolean leaf, int row, boolean hasFocus) {
-                super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
-                DefaultMutableTreeNode mtn = (DefaultMutableTreeNode) value;
-                SearchManager.Iconable pos = (SearchManager.Iconable) mtn.getUserObject();
-                this.setIcon(pos.getIcon());
-                return this;
-            }
-        };
+                @Override
+                public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
+                                                              boolean expanded, boolean leaf, int row, boolean hasFocus) {
+                    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
+                    DefaultMutableTreeNode mtn = (DefaultMutableTreeNode) value;
+                    SearchManager.Iconable pos = (SearchManager.Iconable) mtn.getUserObject();
+                    this.setIcon(pos.getIcon());
+                    return this;
+                }
+            };
         if (statusbar != null) {
             tree.addTreeSelectionListener(new TreeSelectionListener() {
-                @Override
-                public void valueChanged(TreeSelectionEvent e) {
-                    TreePath path = e.getNewLeadSelectionPath();
-                    Object userObj = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
-                    if (userObj instanceof SearchManager.MatchingPositions) {
-                        statusbar.setText(((SearchManager.MatchingPositions) userObj).getFileName());
-                    } else if (userObj instanceof SearchManager.Line) {
-                        userObj = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) path.getLastPathComponent()).getParent()).getUserObject();
-                        statusbar.setText(((SearchManager.MatchingPositions) userObj).getFileName());
+                    @Override
+                    public void valueChanged(TreeSelectionEvent e) {
+                        TreePath path = e.getNewLeadSelectionPath();
+                        Object userObj = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
+                        if (userObj instanceof SearchManager.MatchingPositions) {
+                            statusbar.setText(((SearchManager.MatchingPositions) userObj).getFileName());
+                        } else if (userObj instanceof SearchManager.Line) {
+                            userObj = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) path.getLastPathComponent()).getParent()).getUserObject();
+                            statusbar.setText(((SearchManager.MatchingPositions) userObj).getFileName());
+                        }
                     }
-                }
-            });
+                });
         }
         tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
         tree.setCellRenderer(renderer);
@@ -446,9 +446,9 @@ public class SearchFile extends SwingScilabTab {
      * @return a key, can be used to stop the search
      */
     public static Object getSearchResultsWindow(JComponent component, SciNotes editor, String base,
-            boolean recursive, boolean ignoreCR,
-            String filePattern, boolean fileCaseSensitive,
-            String wordPattern, boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
+                                                boolean recursive, boolean ignoreCR,
+                                                String filePattern, boolean fileCaseSensitive,
+                                                String wordPattern, boolean wordCaseSensitive, boolean wholeWord, boolean regexp) {
         MyBackgroundSearch searcher = new MyBackgroundSearch(component, editor, base, recursive, ignoreCR, filePattern, fileCaseSensitive, wordPattern, wordCaseSensitive, wholeWord, regexp);
         searcher.start();
         return searcher;
@@ -508,14 +508,14 @@ public class SearchFile extends SwingScilabTab {
                 final ScilabEditorPane sep = editor.getTextPane();
                 if (sep.getName().equals(fileName)) {
                     SwingUtilities.invokeLater(new Runnable() {
-                        @Override
-                        public void run() {
-                            sep.highlightWords(pat, fline);
-                            if (ln != 0) {
-                                sep.scrollTextToLineNumber(ln, false, false, true);
+                            @Override
+                            public void run() {
+                                sep.highlightWords(pat, fline);
+                                if (ln != 0) {
+                                    sep.scrollTextToLineNumber(ln, false, false, true);
+                                }
                             }
-                        }
-                    });
+                        });
                 }
             }
         }
@@ -614,15 +614,15 @@ public class SearchFile extends SwingScilabTab {
             sf.setMyBackgroundSearch(this);
 
             SwingUtilities.invokeLater(new Runnable() {
-                @Override
-                public void run() {
-                    sf.getJTree().addSelectionRow(0);
-                    sf.getJTree().requestFocus();
-                    long time = getElapsedTime();
+                    @Override
+                    public void run() {
+                        sf.getJTree().addSelectionRow(0);
+                        sf.getJTree().requestFocus();
+                        long time = getElapsedTime();
 
-                    sf.getInfoBar().setText(String.format(SciNotesMessages.ELAPSEDTIME, ((double) time) / 1000));
-                }
-            });
+                        sf.getInfoBar().setText(String.format(SciNotesMessages.ELAPSEDTIME, ((double) time) / 1000));
+                    }
+                });
 
             if (component != null) {
                 component.firePropertyChange(SEARCHDONE, false, true);