Commit 859e4043 authored by Robert Butora's avatar Robert Butora
Browse files

implements framework for VOTable response (not the VOTable yet)

parent 49b00304
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -10,6 +10,25 @@ public final class XmlSerializer

   private XmlSerializer() {} // disables instatiation

   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)
      {
         serialize(writer, subsurvey);
      }
      if(showDuration)
         writer.println("<duration unit=\"msec\">" + (System.currentTimeMillis() - startTime_msec) + "</duration>");
      writer.println("</results>");
   }


   public static void serializeToLegacyResults(PrintWriter writer, String charEncoding, SearchOutputData searchOutputData,
         boolean showDuration, long startTime_msec)
   {
+19 −3
Original line number Diff line number Diff line
@@ -111,11 +111,27 @@ public class FormatResponseFilter implements Filter
               settings.serviceUrls.mergeUrl(),
               dbSubsurveyArr);

         response.setContentType("application/xml");
         response.setCharacterEncoding(RESPONSE_ENCODING);
         final String respFormat = settings.serviceUrls.responseFormat();
         LOGGER.info("responseFormat: " + respFormat);

         if(respFormat.equals("application/vlkb+xml")) // FIXME hsould be application/x-vlkb+xml -> x- is for eXperimental a.k.a. not registered
         {
            response.setContentType("application/xml");
            boolean showDuration = true;
            XmlSerializer.serializeToLegacyResults(responseWriter, RESPONSE_ENCODING, searchOutputData,showDuration,startTime_msec);
         }
         else if(respFormat.equals("application/x-votable+xml"))
         {
            response.setContentType(respFormat);
            boolean showDuration = false;
            XmlSerializer.serializeToVoTable(responseWriter, RESPONSE_ENCODING, searchOutputData,showDuration,startTime_msec);
         }
         else
         {
            ; // FIXME throws wrong setting-file param: batter convert string to enum and throw 'unrecoginzed respFormat' then;
              // here use switch with enums and switch-default: say error: 'unsupported respFromat' type
         }

         responseWriter.close();
      }
+5 −1
Original line number Diff line number Diff line
@@ -36,19 +36,22 @@ class FormatResponseSettings
      private String cutoutUrl;
      private String mergeUrl;
      private String surveysAbsPathname;
      private String respFormat;

      public boolean cutoutUrlIsSet() { return (cutoutUrl != null) && cutoutUrl.trim().isEmpty(); }
      public boolean mergeUrlIsSet()  { return (mergeUrl != null) && mergeUrl.trim().isEmpty(); }
      public boolean surveysAbsPathnameIsSet()
       { return (surveysAbsPathname != null) && surveysAbsPathname.trim().isEmpty(); }
      public boolean responseFormatIsSet() { return (respFormat != null) && respFormat.trim().isEmpty(); }

      public String cutoutUrl() {return cutoutUrl;}
      public String mergeUrl()  {return mergeUrl;}
      public String surveysAbsPathname()  {return surveysAbsPathname;}
      public String responseFormat()  {return respFormat;}

      public String toString()
      {
         return cutoutUrl + "   "  + mergeUrl + "   " + surveysAbsPathname;
         return cutoutUrl + "   "  + mergeUrl + "   " + surveysAbsPathname + "    " + respFormat;
      }
   }

@@ -114,6 +117,7 @@ class FormatResponseSettings
      serviceUrls.cutoutUrl = properties.getProperty("cutout_url","").strip();
      serviceUrls.mergeUrl  = properties.getProperty("merge_url","").strip();
      serviceUrls.surveysAbsPathname = properties.getProperty("surveys_metadata_abs_pathname","/srv/surveys/surveys_metadata.csv").strip();
      serviceUrls.respFormat = properties.getProperty("response_format","application/x-votable+xml").strip();
      return serviceUrls;
   }