1
2
3
4
5
6
7 package org.astrogrid.dataservice.queriers;
8
9 import java.io.IOException;
10 import java.security.Principal;
11 import org.astrogrid.dataservice.queriers.Querier;
12 import org.astrogrid.dataservice.queriers.TableResults;
13 import org.astrogrid.dataservice.queriers.status.QuerierStatus;
14 import org.astrogrid.query.returns.ReturnTable;
15 import org.astrogrid.slinger.targets.TargetIdentifier;
16 import org.astrogrid.tableserver.metadata.ColumnInfo;
17 import org.astrogrid.tableserver.out.HtmlTableWriter;
18 import org.astrogrid.tableserver.out.TableWriter;
19 import org.astrogrid.tableserver.out.VoTableFitsWriter;
20 import org.astrogrid.tableserver.out.VoTableWriter;
21 import org.astrogrid.tableserver.out.XsvTableWriter;
22
23 /***
24 * Results which are a list of URLs
25 *
26 * @author M Hill
27 */
28
29 public class UrlListResults extends TableResults {
30
31
32
33 /*** List of URLs to (probably) FITS files */
34 protected String[] urls;
35
36 /***
37 * Construct this wrapper around the given list of results
38 */
39 public UrlListResults(Querier parentQuerier, String[] results) {
40 super(parentQuerier);
41 this.urls = results;
42 }
43
44 /*** Returns number of found files */
45 public int getCount() throws IOException {
46 return urls.length;
47 }
48
49 /*** Overriden to return VoTableFitsWriter instead of VotableWriter */
50 public TableWriter makeTableWriter(TargetIdentifier target, String requestedFormat, Principal user) throws IOException {
51
52 if (requestedFormat.equals(ReturnTable.VOTABLE)) {
53 return new VoTableFitsWriter(target, "Query Results", user);
54 }
55
56 return super.makeTableWriter(target, requestedFormat, user);
57 }
58
59
60 /*** Subclasses implement suitable ways of writing their results to the given TableWriter */
61 public void writeTable(TableWriter tableWriter, QuerierStatus statusToUpdate) throws IOException {
62
63
64
65 tableWriter.startTable(new ColumnInfo[] {});
66
67 if (statusToUpdate != null) {
68 statusToUpdate.newProgress("Adding file", getCount());
69 }
70
71 for (int i=0;i<urls.length;i++) {
72 if (querier.isAborted()) {
73 tableWriter.abort();
74 return;
75 }
76 if (statusToUpdate != null) {
77 statusToUpdate.setProgress(i);
78 }
79 tableWriter.writeRow(new String[] { urls[i] });
80 }
81
82 tableWriter.endTable();
83
84 if (statusToUpdate != null) { statusToUpdate.clearProgress(); }
85
86 tableWriter.close();
87 }
88
89
90 }
91
92