1 /*$Id: VotableDomResults.java,v 1.2 2005/03/21 18:45:55 mch Exp $
2 * Created on 13-Nov-2003
3 *
4 * Copyright (C) AstroGrid. All rights reserved.
5 *
6 * This software is published under the terms of the AstroGrid
7 * Software License version 1.2, a copy of which has been included
8 * with this distribution in the LICENSE.txt file.
9 *
10 **/
11 package org.astrogrid.dataservice.queriers;
12
13 import java.io.IOException;
14 import javax.xml.parsers.ParserConfigurationException;
15 import org.astrogrid.dataservice.queriers.TableResults;
16 import org.astrogrid.dataservice.queriers.status.QuerierStatus;
17 import org.astrogrid.tableserver.out.TableWriter;
18 import org.astrogrid.tableserver.out.VoTableWriter;
19 import org.astrogrid.xml.DomHelper;
20 import org.w3c.dom.Document;
21 import org.xml.sax.SAXException;
22
23 /*** Trivial Implementation of {@link org.astrogrid.datacenter.queriers.QueryResults} backed by a
24 * document object model containing a VOTable document
25 *
26 */
27 public class VotableDomResults extends TableResults {
28
29 protected final Document doc;
30
31 /***
32 * Std constructor
33 */
34 public VotableDomResults(Querier querier, Document doc) {
35 super(querier);
36 this.doc = doc;
37 }
38
39 /***
40 * construct from document in given string
41 */
42 public VotableDomResults(Querier querier, String doc) throws SAXException, IOException, ParserConfigurationException {
43 super(querier);
44 if (doc == null) throw new IllegalArgumentException("Can't make a VoTable from a null string");
45 this.doc = DomHelper.newDocument(doc);
46 }
47
48 public int getCount() {
49 return doc.getDocumentElement().getElementsByTagName("TR").getLength();
50 }
51
52 /*** Writes results to the given TableWriter */
53 public void writeTable(TableWriter tableWriter, QuerierStatus statusToUpdate) throws IOException {
54 if (tableWriter instanceof VoTableWriter) {
55 DomHelper.DocumentToWriter(doc, ((VoTableWriter) tableWriter).getOut());
56 }
57 else {
58 throw new UnsupportedOperationException("Can only write to votables");
59 }
60 }
61
62 }
63
64
65 /*
66 $Log: VotableDomResults.java,v $
67 Revision 1.2 2005/03/21 18:45:55 mch
68 Naughty big lump of changes
69
70 Revision 1.1.1.1 2005/02/17 18:37:35 mch
71 Initial checkin
72
73 Revision 1.1.1.1 2005/02/16 17:11:24 mch
74 Initial checkin
75
76 Revision 1.5.10.4 2004/12/08 18:36:40 mch
77 Added Vizier, rationalised SqlWriters etc, separated out TableResults from QueryResults
78
79 Revision 1.5.10.3 2004/11/30 01:04:02 mch
80 Rationalised tablewriters, reverted AxisDataService06 to string
81
82 Revision 1.5.10.2 2004/11/22 00:57:16 mch
83 New interfaces for SIAP etc and new slinger package
84
85 Revision 1.5.10.1 2004/11/17 17:56:07 mch
86 set mime type, switched results to taking targets
87
88 Revision 1.5 2004/11/08 03:00:14 mch
89 Removed assert and replaced with proper if
90
91 Revision 1.4 2004/11/03 05:14:33 mch
92 Bringing Vizier back online
93
94 Revision 1.3 2004/11/03 00:17:56 mch
95 PAL_MCH Candidate 2 merge
96
97 Revision 1.2.6.1 2004/10/27 00:43:39 mch
98 Started adding getCount, some resource fixes, some jsps
99
100 Revision 1.2 2004/10/18 13:11:30 mch
101 Lumpy Merge
102
103 Revision 1.1.2.1 2004/10/15 19:59:05 mch
104 Lots of changes during trip to CDS to improve int test pass rate
105
106 Revision 1.1 2004/09/28 15:02:13 mch
107 Merged PAL and server packages
108
109 Revision 1.2 2004/09/07 00:54:20 mch
110 Tidied up Querier/Plugin/Results, and removed deprecated SPI-visitor-SQL-translator
111
112 Revision 1.1 2004/09/06 21:37:26 mch
113 Factored out VotableResults
114
115 Revision 1.3 2004/09/01 12:10:58 mch
116 added results.toHtml
117
118 Revision 1.2 2004/03/14 03:04:57 mch
119 Added CSV writer
120
121 Revision 1.1 2004/03/13 23:40:59 mch
122 Changes to adapt to It05 refactor
123
124 Revision 1.2 2003/12/09 16:25:08 nw
125 wrote plugin documentation
126
127 Revision 1.1 2003/11/18 11:23:49 nw
128 mavenized cds delegate
129
130 Revision 1.1 2003/11/18 11:10:05 nw
131 mavenized cds delegate
132
133 */