Switch to unified view

a/tool/run/plugins/basic/pluginSearch.java b/tool/run/plugins/basic/pluginSearch.java
...
...
12
 */
12
 */
13
13
14
package basic;
14
package basic;
15
15
16
import definitions.Messages;
16
import definitions.Messages;
17
import definitions.definition;
17
import definitions.is;
18
import definitions.is;
18
import java.io.File;
19
import java.io.File;
19
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import main.controller;
20
import script.Plugin;
23
import script.Plugin;
21
import script.log;
24
import script.log;
22
import spdxlib.FileInfo;
25
import spdxlib.FileInfo;
23
import spdxlib.SPDXfile;
26
import spdxlib.SPDXfile;
24
import ssdeep.SpamSumSignature;
27
import ssdeep.SpamSumSignature;
25
import ssdeep.ssdeep;
28
import ssdeep.ssdeep;
26
import main.core;
29
import main.core;
27
import utils.html;
30
import utils.html;
31
import www.RequestOrigin;
32
import www.WebRequest;
28
33
29
34
30
/**
35
/**
31
 *
36
 *
32
 * @author Nuno Brito, 8th of November 2013 in Darmstadt, Germany.
37
 * @author Nuno Brito, 8th of November 2013 in Darmstadt, Germany.
...
...
49
        log.hooks.addAction(Messages.SearchBoxPressedKey,
54
        log.hooks.addAction(Messages.SearchBoxPressedKey,
50
               thisFile, "doKeyPress");
55
               thisFile, "doKeyPress");
51
        
56
        
52
        // whenever a search happens, trigger this method
57
        // whenever a search happens, trigger this method
53
        log.hooks.addAction("Search: %1",
58
        log.hooks.addAction("Search: %1",
54
               thisFile, "launchNewSearch");        
59
               thisFile, "launchNewSearch");
60
        
61
        // prepare a smart feature that we love!
62
        prepareFileLauncher();
63
        
55
    }
64
    }
56
    
65
    
57
   
66
   
67
    /**
68
     * We use the search bar to launch our internal pages. Might seem hard
69
     * to understand what is the fuzz but we love to type something like
70
     * "server" and see it in front of us right away.
71
     */
72
    private void prepareFileLauncher(){
73
        // get all the java files that we are ready to launch if needed
74
        ArrayList<File> files = utils.files.findFilesFiltered(core.getPluginsFolder(), 
75
                ".java", 25);
76
        
77
        // we need some filtering
78
        HashMap list = new HashMap();
79
        // go through all the files we found
80
        for(File file : files){
81
            String name = file.getName();
82
            // avoid cases like .java.old
83
            if(name.endsWith(".java")){
84
                // remove the .java portion, transform to lower case
85
                name = name.replace(".java", "").toLowerCase();
86
                // put it on our list, if duplicate just overwrite we don't care
87
                list.put(name, file);
88
            }
89
        }
90
        
91
        // place the list available for the future
92
        core.temp.put(definition.searchList, list);
93
    }
58
    
94
    
59
    /**
95
    /**
60
     * Reacts to the case when users press the ENTER key
96
     * Reacts to the case when users press the ENTER key
61
     */
97
     */
62
    void doKeyPress(){
98
    void doKeyPress(){
...
...
371
            System.out.println(helpFile.getAbsoluteFile());
407
            System.out.println(helpFile.getAbsoluteFile());
372
            output = utils.files.readAsString(helpFile);
408
            output = utils.files.readAsString(helpFile);
373
            //System.out.println(output);
409
            //System.out.println(output);
374
            return true;
410
            return true;
375
        }
411
        }
412
        // check for internal pages we can run
413
        HashMap list = 
414
                (HashMap) core.temp.get(definition.searchList);
415
416
        // no need to continue if empty
417
        if(list == null){
418
            return false;
419
        }
420
        
421
        // files matching this search? let's process
422
        if(list.containsKey(searchTerm)){
423
            File file = (File) list.get(searchTerm);
424
            System.err.println("Matched " + searchTerm);
425
            // an action happened and needs a reply
426
            WebRequest request = new WebRequest();
427
            // signal that this request is coming from the user interface
428
            request.requestOrigin = RequestOrigin.GUI;
429
            request.BaseFolder = file.getParentFile();
430
            request.scriptFile = file;
431
            request.scriptMethod = is.methodDefault;
432
            // submit the request to be executed
433
            controller.process(request);
434
            // all done, hope for the best.. :-)
435
            return true;
436
        }
437
        
438
        
439
        
376
        return false;
440
        return false;
377
    }
441
    }
378
    
442
    
379
    
443
    
380
  
444