File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\search\SearchIndexBuilder.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.search;
25
26 import hudson.model.AbstractModelObject;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32 * Builds {@link SearchIndex}.
33 *
34 * This object is also used to represent partially build search index, much like {@link StringBuilder} is often
35 * passed around to cooperatively build search index.
36 *
37 * @author Kohsuke Kawaguchi
38 * @see AbstractModelObject#makeSearchIndex()
39 */
40 public final class SearchIndexBuilder {
41 private final List<SearchItem> items = new ArrayList<SearchItem>();
42
43 private final List<SearchIndex> indices = new ArrayList<SearchIndex>();
44
45 /**
46 * Adds all {@link QuickSilver}-annotated properties to the search index.
47 */
48 public SearchIndexBuilder addAllAnnotations(SearchableModelObject o) {
49 ParsedQuickSilver.get(o.getClass()).addTo(this,o);
50 return this;
51 }
52
53 /**
54 * Short for {@code add(urlAsWellAsName,urlAsWellAsName)}
55 */
56 public SearchIndexBuilder add(String urlAsWellAsName) {
57 return add(urlAsWellAsName,urlAsWellAsName);
58 }
59
60 /**
61 * Adds a search index under the keyword 'name' to the given URL.
62 *
63 * @param url
64 * Relative URL from the source of the search index.
65 */
66 public SearchIndexBuilder add(String url, String name) {
67 items.add(SearchItems.create(name,url));
68 return this;
69 }
70
71 public SearchIndexBuilder add(String url, String... names) {
72 for (String name : names)
73 add(url,name);
74 return this;
75 }
76
77 public SearchIndexBuilder add(SearchItem item) {
78 items.add(item);
79 return this;
80 }
81
82 public SearchIndexBuilder add(String url, SearchableModelObject searchable, String name) {
83 items.add(SearchItems.create(name,url,searchable));
84 return this;
85 }
86
87 public SearchIndexBuilder add(String url, SearchableModelObject searchable, String... names) {
88 for (String name : names)
89 add(url,searchable,name);
90 return this;
91 }
92
93 public SearchIndexBuilder add(SearchIndex index) {
94 this.indices.add(index);
95 return this;
96 }
97
98 public SearchIndexBuilder add(SearchIndexBuilder index) {
99 return add(index.make());
100 }
101
102 public SearchIndex make() {
103 SearchIndex r = new FixedSet(items);
104 for (SearchIndex index : indices)
105 r = new UnionSearchIndex(r,index);
106 return r;
107 }
108 }
109