View Javadoc
1   package gboat2.example.action;
2   
3   import gboat2.base.bridge.GboatAppContext;
4   import gboat2.base.core.web.BaseActionSupport;
5   import gboat2.example.vo.Language;
6   
7   import java.util.ArrayList;
8   import java.util.Arrays;
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  import org.apache.commons.lang3.RandomStringUtils;
14  import org.apache.commons.lang3.StringUtils;
15  
16  public class AutocompleterAction extends BaseActionSupport {
17      
18      private static final long serialVersionUID = 1L;
19  
20      private static final String[] ALL_LANGUAGES = { "Actionscript (Flash)",
21          "ABAP Objects", "Ada", "Aleph", "AppleScript", "Beta", "BlitzMax",
22          "Boo", "C++", "C#", "Cecil", "Clarion", "Cobol ISO 2002",
23          "CoDeSys", "CFML (ColdFusion Markup Language)",
24          "Common Lisp Object System (CLOS)", "Component Pascal",
25          "CorbaScript", "D", "Delphi", "Eiffel", "Fpii",
26          "Fortran - ab Fortran 2003", "Gambas", "IDL", "IDLscript",
27          "incr Tcl", "Java", "JavaScript / ECMAScript", "Lexico", "Lingo",
28          "Modula-3", "Modelica", "NewtonScript", "Oberon", "Objective-C",
29          "Objective CAML", "Object Pascal", "Perl", "PHP", "PowerBuilder",
30          "Progress OpenEdge", "Python", "Ruby", "R", "Sather", "Scala",
31          "Seed7", "Self", "Simula", "Smalltalk", "SuperCollider",
32          "Superx++", "STOOOP", "Visual Basic", "Visual Basic .NET (VB.NET)",
33          "Visual Basic Script", "Visual Objects", "XBase", "XOTcl", "Zonnon" };
34  
35      private String term;
36      private List<String> languages;
37      
38      /**
39       * 自动提示
40       * @return
41       */
42      @Override
43      public String execute() {
44          languages = Arrays.asList(ALL_LANGUAGES);
45          return "jqueryui/autocompleter";
46      }
47      
48      public void queryArray() {
49          term = StringUtils.trimToNull(term);
50          List<String> list = new ArrayList<String>();
51          for (String language : ALL_LANGUAGES) {
52              if(term == null || StringUtils.containsIgnoreCase(language, term)) {
53                  list.add(language);
54              }
55          }
56          GboatAppContext.output(list);
57      }
58      
59      public void queryMap() {
60          term = StringUtils.trimToNull(term);
61          Map<Integer, String> map = new HashMap<Integer, String>();
62          for (int i = 0; i < ALL_LANGUAGES.length; i++) {
63              if(term == null || StringUtils.containsIgnoreCase(ALL_LANGUAGES[i], term)) {
64                  map.put(i, ALL_LANGUAGES[i]);
65              }
66          }
67          GboatAppContext.output(map);
68      }
69      
70      public void queryObjectList(){
71          term = StringUtils.trimToNull(term);
72          List<Language> list = new ArrayList<Language>();
73          for (int i = 0; i < ALL_LANGUAGES.length; i++) {
74              if(term == null || StringUtils.containsIgnoreCase(ALL_LANGUAGES[i], term)) {
75                  list.add(new Language(i, ALL_LANGUAGES[i], RandomStringUtils.randomAscii(5)));
76              }
77          }
78          GboatAppContext.output(list);
79      }
80  
81      public void setTerm(String term) {
82          this.term = term;
83      }
84  
85      public List<String> getLanguages() {
86          return languages;
87      }
88  }