Skip to content
Snippets Groups Projects
Commit ed302e3a authored by Robert Butora's avatar Robert Butora
Browse files

response: implements preliminary VOTable response.xml

parent d95b1dcb
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,14 @@
//import java.util.logging.Logger;
import java.io.PrintWriter;
// VOTable
import uk.ac.starlink.table.*;// StarTable needed
import uk.ac.starlink.votable.*;// Writer needed
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
public final class XmlSerializer
......@@ -13,21 +21,84 @@ public final class XmlSerializer
public static void serializeToVoTable(PrintWriter writer, String charEncoding, SearchOutputData searchOutputData,
boolean showDuration, long startTime_msec)
{
writer.println("<?xml version=\"1.0\" encoding=\"" + charEncoding + "\" standalone=\"yes\"?>");
writer.println("<results>");
writer.println("<description> TBD: VOTable " + searchOutputData.description + " </description>");
serialize(writer, searchOutputData.inputs);
writer.println("<msg> " + searchOutputData.versionString + " </msg>");
writer.println("<DatacubeCount> " + searchOutputData.datacubeCount + " </DatacubeCount>");
for(Subsurvey subsurvey : searchOutputData.subsurveyArr)
// writer.println("<msg> " + searchOutputData.versionString + " </msg>");
// writer.println("<DatacubeCount> " + searchOutputData.datacubeCount + " </DatacubeCount>");
StarTable dstable = makeSearchResultsTable( searchOutputData.subsurveyArr );
StarTable[] tables = {dstable};
try
{
serialize(writer, subsurvey);
writeTables(writer, tables);
}
if(showDuration)
writer.println("<duration unit=\"msec\">" + (System.currentTimeMillis() - startTime_msec) + "</duration>");
writer.println("</results>");
catch(IOException ex)
{
;// FIXME System.out.println( ex.getMessage() );
}
}
private static void writeTables(PrintWriter writer, StarTable[] tables ) throws IOException
{
BufferedWriter out = new BufferedWriter( writer /*new OutputStreamWriter( System.out )*/ );
out.write( "<VOTABLE version='1.1'>\n" );
out.write( "<RESOURCE>\n" );
out.write( "<DESCRIPTION>Some tables</DESCRIPTION>\n" );
for ( int i = 0; i < tables.length; i++ ) {
VOSerializer.makeSerializer( DataFormat.TABLEDATA, tables[ i ] )
.writeInlineTableElement( out );
}
out.write( "</RESOURCE>\n" );
out.write( "</VOTABLE>\n" );
out.flush();
}
private static StarTable makeSearchResultsTable(Subsurvey[] ssurv)
{
ColumnInfo[] colInfos = new ColumnInfo[ 5 + 2*4 ];
colInfos[ 0 ] = new ColumnInfo( "overlap", Integer.class, "Overlap Code" );
colInfos[ 1 ] = new ColumnInfo( "overlapSky", Integer.class, "Overlap Code for Sky axes" );
colInfos[ 2 ] = new ColumnInfo( "overlapSpec", Integer.class, "Overlap Code for Spectral axis" );
colInfos[ 3 ] = new ColumnInfo( "dataType", String.class, "Data Type (image|cube)" );
colInfos[ 4 ] = new ColumnInfo( "pubdid", String.class, "PublisherDid" );
colInfos[ 5 ] = new ColumnInfo( "P1lon", Double.class, "longitude" );
colInfos[ 6 ] = new ColumnInfo( "P1lat", Double.class, "latitude" );
colInfos[ 7 ] = new ColumnInfo( "P2lon", Double.class, "longitude" );
colInfos[ 8 ] = new ColumnInfo( "P2lat", Double.class, "latitude" );
colInfos[ 9 ] = new ColumnInfo( "P3lon", Double.class, "longitude" );
colInfos[ 10 ] = new ColumnInfo( "P3lat", Double.class, "latitude" );
colInfos[ 11 ] = new ColumnInfo( "P4lon", Double.class, "longitude" );
colInfos[ 12 ] = new ColumnInfo( "P4lat", Double.class, "latitude" );
RowListStarTable astro = new RowListStarTable( colInfos );
for(Subsurvey subsurvey : ssurv)
{
for(Dataset dataset : subsurvey.datasetArr)
{
astro.addRow( new Object[]
{
new Integer( dataset.overlapCode ),
new Integer( dataset.overlapCodeSky ),
new Integer( dataset.overlapCodeVel ),
dataset.dataType,
dataset.publisherDid,
new Double(dataset.vertices_deg.lon[0]), new Double(dataset.vertices_deg.lat[0]),
new Double(dataset.vertices_deg.lon[1]), new Double(dataset.vertices_deg.lat[1]),
new Double(dataset.vertices_deg.lon[2]), new Double(dataset.vertices_deg.lat[2]),
new Double(dataset.vertices_deg.lon[3]), new Double(dataset.vertices_deg.lat[3]),
});
}
}
return astro;
}
// legacy
public static void serializeToLegacyResults(PrintWriter writer, String charEncoding, SearchOutputData searchOutputData,
boolean showDuration, long startTime_msec)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment