1 | /**
|
---|
2 | * SearchFramesetNoResults.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.agents;
|
---|
20 |
|
---|
21 | import java.util.Collection;
|
---|
22 | import java.util.HashMap;
|
---|
23 | import java.util.Map;
|
---|
24 |
|
---|
25 | import org.expeditee.gui.Frame;
|
---|
26 | import org.expeditee.gui.FrameIO;
|
---|
27 |
|
---|
28 | public class SearchFramesetNoResults extends SearchAgent {
|
---|
29 | private long _firstFrame = 1;
|
---|
30 | private long _maxFrame = Integer.MAX_VALUE;
|
---|
31 | private Map<String, Collection<String>> _results = new HashMap<String, Collection<String>>();
|
---|
32 |
|
---|
33 | public SearchFramesetNoResults(long firstFrame, long maxFrame, String searchText) {
|
---|
34 | this(searchText);
|
---|
35 | _firstFrame = firstFrame;
|
---|
36 | _maxFrame = maxFrame;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public SearchFramesetNoResults(String searchText) {
|
---|
40 | super(searchText);
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected Frame process(Frame frame) {
|
---|
45 | String path = frame.getPath();
|
---|
46 | int count = FrameIO.getLastNumber(frame.getFramesetName());
|
---|
47 | for (long i = _firstFrame;i <= _maxFrame && i <= count; i++) {
|
---|
48 | if (_stop) {
|
---|
49 | break;
|
---|
50 | }
|
---|
51 | String frameName = _startName + i;
|
---|
52 | Collection<String> found = FrameIO.searchFrame(frameName, _pattern, path);
|
---|
53 | int size = found == null? 0 :found.size();
|
---|
54 | if(found!= null)
|
---|
55 | _frameCount++;
|
---|
56 | if(size > 0){
|
---|
57 | _results.put(frameName, found);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | return null;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public Map<String, Collection<String>> getResult(){
|
---|
64 | return _results;
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | public boolean hasResultFrame() {
|
---|
69 | return false;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public boolean hasResultString() {
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public String toString(){
|
---|
79 | StringBuffer resultString = new StringBuffer();
|
---|
80 | for(String frame: _results.keySet()){
|
---|
81 | resultString.append(frame);
|
---|
82 | for(String found: _results.get(frame)){
|
---|
83 | resultString.append('[').append(found).append(']');
|
---|
84 | }
|
---|
85 | resultString.append('\n');
|
---|
86 | }
|
---|
87 | resultString.deleteCharAt(resultString.length()-1);
|
---|
88 | return resultString.toString();
|
---|
89 | }
|
---|
90 | }
|
---|