|
1 |
| package photospace.web.tags; |
|
2 |
| |
|
3 |
| import java.io.*; |
|
4 |
| import java.util.*; |
|
5 |
| import javax.servlet.jsp.*; |
|
6 |
| import javax.servlet.jsp.jstl.core.*; |
|
7 |
| import photospace.*; |
|
8 |
| import photospace.search.*; |
|
9 |
| |
|
10 |
| public class TermsTag |
|
11 |
| extends LoopTagSupport |
|
12 |
| { |
|
13 |
| private String field; |
|
14 |
| private String path; |
|
15 |
| private Iterator matches; |
|
16 |
| |
|
17 |
2
| public void prepare() throws JspTagException
|
|
18 |
| { |
|
19 |
0
| if (field == null && path == null) throw new JspTagException("One of 'path' or 'field' (or both) is required");
|
|
20 |
| |
|
21 |
2
| Searcher searcher = (Searcher) Application.searcher();
|
|
22 |
2
| try
|
|
23 |
| { |
|
24 |
1
| if (path != null && field != null) matches = searcher.getDocumentMatches(path, field).iterator();
|
|
25 |
0
| else if (path != null) matches = searcher.getDocumentMatches(path).iterator();
|
|
26 |
1
| else if (field != null) matches = searcher.getFieldMatches(field).iterator();
|
|
27 |
0
| else matches = null;
|
|
28 |
| } |
|
29 |
| catch (IOException e) |
|
30 |
| { |
|
31 |
0
| throw new JspTagException(e);
|
|
32 |
| } |
|
33 |
| } |
|
34 |
| |
|
35 |
7
| public boolean hasNext()
|
|
36 |
| { |
|
37 |
0
| if (matches == null) return false;
|
|
38 |
7
| return matches.hasNext();
|
|
39 |
| } |
|
40 |
| |
|
41 |
3
| public Object next()
|
|
42 |
| { |
|
43 |
3
| return matches.next();
|
|
44 |
| } |
|
45 |
| |
|
46 |
1
| public void setField(String field)
|
|
47 |
| { |
|
48 |
1
| this.field = field;
|
|
49 |
| } |
|
50 |
| |
|
51 |
1
| public void setPath(String path)
|
|
52 |
| { |
|
53 |
1
| this.path = path;
|
|
54 |
| } |
|
55 |
| } |