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 tableWriter.open();
64
65
66
67 tableWriter.startTable(new ColumnInfo[] {});
68
69 if (statusToUpdate != null) {
70 statusToUpdate.newProgress("Adding file", getCount());
71 }
72
73 for (int i=0;i<urls.length;i++) {
74 if (querier.isAborted()) {
75 tableWriter.abort();
76 return;
77 }
78 if (statusToUpdate != null) {
79 statusToUpdate.setProgress(i);
80 }
81 tableWriter.writeRow(new String[] { urls[i] });
82 }
83
84 tableWriter.endTable();
85
86 if (statusToUpdate != null) { statusToUpdate.clearProgress(); }
87
88 tableWriter.close();
89 }
90
91
92 }
93
94