FaxBackApplet.java

This non-visual applet is used by a JavaScript deamon that runs on a server that does fax-back work. The JavaScript deamon calls public methods of the applet to obtain information it can use as part of its faxing function. The applet calls a servlet and the servlet returns values to the applet and the applet provides the information back to the fax-back deamon.
import java.applet.*;
import java.net.*;
import java.io.*;


public class FaxBackApplet extends Applet {


   public String getTaxpayerIDNumber(String idMethod, String idNumber) 
   {
      return callFaxBackServlet("GTIN", idMethod, idNumber, "");
   }


   public String getVendorName(String idNumber) 
   {
      return callFaxBackServlet("GVN", "", idNumber, "");
   }


   public String getPaymentCount(String idNumber, String daysAgo) 
   {
      return callFaxBackServlet("GPC", "", idNumber, daysAgo);
   }


   public String getPaymentAndInvoiceRptURL(String idNumber, String daysAgo) 
   {
      return callFaxBackServlet("GPIRU", "", idNumber, daysAgo);
   }

   private String getProtocol()
   {
      URL url;

      url = getCodeBase();

      return url.getProtocol();
   }

   private String getHost()
   {
      URL url;

      url = getCodeBase();

      return url.getHost();
   }


   private String getPort()
   {
      URL url;
      String port = "";

      url = getCodeBase();

      return port.valueOf(url.getPort()); 
   }


   private String getCodeBaseURL()
   {
      URL url;

      String hostMachine = "";
      String port = "";
      String fileName = "";
      String protocol = "";
      String codeBaseURL= "";

      url = getCodeBase();

      hostMachine = url.getHost();
      port = port.valueOf(url.getPort()); 
      fileName = url.getFile();
      protocol = url.getProtocol();

      if (port.equals("-1")) {
         port = "";
      }
      else
      {
         port = ":" + port;
      }

      codeBaseURL = protocol + "://" + hostMachine + port + fileName;

      return codeBaseURL;
   }


      /***********************************************************************
          Call a servlet that validates a Texas ID number and returns a
          count of payments if a a valid ID.  This mehtod was meants to be 
          called by JavaScript within a browser.

          @param methodCode code which defines what method to call
          @param idMethod ID method       
          @param idNumber ID number
          @param daysAgo  number of days from current date for report
          @return         various values depending on method called
       ***********************************************************************/
   private String callFaxBackServlet(String methodCode, String idMethod, 
                                    String idNumber, String daysAgo) 
   {
      String line = null;
      String port = "";

      port = getPort();

      if (! port.equals(""))
      {
         port = ":" + port;
      }

      String urlName = getProtocol() + "://" + getHost() + port + "/vip/servlet/" + 
                       "cpa.app.vip.FaxBackServlet" + "?methodCode=" + 
                       methodCode + "&idMethod=" + idMethod + 
                       "&idNumber=" + idNumber + "&daysAgo=" + daysAgo;

      try 
      {
         URL url = new URL(urlName);
         InputStream uin = url.openStream();
         BufferedReader in = new BufferedReader(new InputStreamReader(uin));

         line = in.readLine();
      }
      catch  (MalformedURLException e)
      {
         System.err.println("Error:FaxBackApplet:callFaxBackServlet:MalformedURLException" + e.getMessage());
      }
      catch  (IOException e)
      {
         System.err.println("Error:FaxBackApplet:callFaxBackServlet:IOException" + e.getMessage());
      }

         return  line;
   }

}