View Javadoc

1   /***
2    Copyright (C) 2005 The Java Community
3   
4    This program is free software; you can redistribute it and/or modify  it under
5    the terms of the GNU General Public License as published by  the Free Software
6    Foundation; either version 2 of the License, or  (at your option) any later
7    version.
8   
9    This program is distributed in the hope that it will be useful,  but WITHOUT
10   ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13   You should have received a copy of the GNU General Public License  along with
14   this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15   Place, Suite 330, Boston, MA 02111-1307 USA.
16   */
17  package org.bejug.javacareers.common.ajax;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.List;
25  
26  /***
27   * Class which gathers completion results from event handlers
28   *
29   * @author Tor Norbye
30   * @author Bavo Bruylandt (Last modified by $Author: shally $)
31   * $Revision: 1.12 $ - $Date: 2005/12/20 15:36:46 $
32   */
33  public class CompletionResult {
34  
35      /***
36       * The maximum results collection.
37       */
38      private final List results = new ArrayList(PhaseListener.MAX_RESULTS_RETURNED);
39  
40      /***
41       * The logger.
42       */
43      private static final Log LOG = LogFactory.getLog(CompletionResult.class);
44  
45      /***
46       * Creates a new instance of CompletionResult
47       */
48      CompletionResult() {
49      }
50  
51      /***
52       * Add the given String into the set of completion items returned
53       * to the browser.
54       *
55       * @param item The item to be added to the completion result
56       */
57      public void addItem(final String item) {
58          // Todo: check the replace all argument (is this correct ?)
59          String cleaned = item.replaceAll("[//\"//'?]*", "");
60          if (cleaned.trim().length() < 1) {
61              LOG.debug("Debug: Item had no length, not adding");
62          }
63  
64          results.add(cleaned);
65          LOG.debug("Debug: Added item: " + cleaned);
66      }
67  
68      /***
69       * Add all the items in the given String artray into
70       * the set of completion items returned to the browser.
71       *
72       * @param items The item array to be added to the completion result
73       */
74      public void addItems(final String[]  items) {
75          if (items != null) {
76              for (int i = 0; i < items.length; i++) {
77                  results.add(items[i]);
78              }
79          }
80      }
81  
82      /***
83       * Add all the items in the given collection <b>of Strings</b> into
84       * the set of completion items returned to the browser.
85       *
86       * @param items The collection of Strings to be added
87       */
88      public void addItems(final Collection items) {
89          results.addAll(items);
90      }
91  
92      /***
93       * Provide the results to other ajax textfield classes such that the results
94       * can be encoded and returned to the browser.
95       *
96       * @return A list of completion results.
97       */
98      public List getItems() {
99          return results;
100     }
101 }
102 
103 /***
104  * $Log: CompletionResult.java,v $
105  * Revision 1.12  2005/12/20 15:36:46  shally
106  * CheckStyle and PMD changes.
107  *
108  * Revision 1.11  2005/12/09 10:46:56  shally
109  * Opkuis voor checkstyle en PMD
110  *
111  * Revision 1.10  2005/11/15 15:36:19  someysf
112  * Regular expression hersteld naar het oude [//\"//'?]. In het kort de karakters \, ", ' en ? moeten gematched en verwijderd worden om problemen met de client side parser te voorkomen.
113  * Het probleem zat hem echter niet in de client side parser or invalid output maar dat er een foutieve regex gespecificeerd stond.
114  *
115  * Revision 1.9  2005/10/11 09:16:41  stephan_janssen
116  * Cleanup + todo added.
117  *
118  * Revision 1.8  2005/09/30 14:38:07  bavo_jcs
119  * Fixed URL
120  *
121  * Revision 1.7  2005/09/13 08:11:06  schauwvliege
122  * organize imports
123  *
124  * Revision 1.6  2005/08/10 12:07:42  bavo_jcs
125  * Optimized imports according to checkstyle
126  *
127  * Revision 1.5  2005/08/10 09:04:45  bavo_jcs
128  * Optimized imports according to checkstyle
129  *
130  * Revision 1.4  2005/08/09 12:59:50  bavo_jcs
131  * Optimized imports
132  *
133  * Revision 1.3  2005/08/05 06:25:09  bme_jcs
134  * resolved checkstyle errors
135  *
136  * Revision 1.2  2005/07/13 11:42:08  bavo_jcs
137  * Ajax rename and test-cleanup
138  *
139  * Revision 1.1  2005/07/13 11:16:53  bavo_jcs
140  * Moved Ajax files
141  *
142  * Revision 1.2  2005/07/08 14:02:25  bavo_jcs
143  * PDF Ajax integration
144  *
145  * Revision 1.1  2005/07/06 14:15:30  bavo_jcs
146  * Ajax integration
147  *
148  */