home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / samples.z / IURL_Poller.wxc < prev    next >
Text File  |  1997-01-28  |  7KB  |  241 lines

  1. Save Format v2.0(1)
  2. @begin ClassFile "IURL_Poller"
  3.  Exported 0;
  4.  Abstract 0;
  5.  Interface 0;
  6.  PackageName "";
  7.  Language "Java";
  8.  
  9.  @begin UserFunction "IURL_Poller()"
  10.   Compiler 1;
  11.   GencodeSrcLine 13;
  12.   FunctionName "IURL_Poller::IURL_Poller()";
  13.  @end;
  14.  
  15.  @begin UserFunction "main(String args[])"
  16.   Compiler 1;
  17.   GencodeFunction 1;
  18.   GencodeSrcLine 17;
  19.   FunctionName "IURL_Poller::main(String args[])";
  20.  @end;
  21.  
  22.  @begin UserFunction "CreateMainForm()"
  23.   Compiler 1;
  24.   GencodeFunction 1;
  25.   GencodeSrcLine 24;
  26.   FunctionName "IURL_Poller::CreateMainForm()";
  27.  @end;
  28.  
  29.  @begin UserFunction "StartApp(String args[])"
  30.   Compiler 1;
  31.   GencodeSrcLine 27;
  32.   FunctionName "IURL_Poller::StartApp(String args[])";
  33.  @end;
  34.  
  35.  @begin UserFunction "RunApp(String args[])"
  36.   Compiler 1;
  37.   GencodeSrcLine 35;
  38.   FunctionName "IURL_Poller::RunApp(String args[])";
  39.  @end;
  40.  
  41.  @begin UserFunction "EndApp(String args[])"
  42.   Compiler 1;
  43.   GencodeSrcLine 141;
  44.   FunctionName "IURL_Poller::EndApp(String args[])";
  45.  @end;
  46.  
  47.  @begin HPPPrefixBlock
  48. @begin-code HPPPrefix
  49.  
  50. // add your custom import statements here
  51. import java.io.*;
  52. import java.net.*;
  53. import java.util.*;
  54.  
  55. @end-code;
  56.   GencodeSrcLine 6;
  57.  @end;
  58.  
  59.  @begin ClassContentsBlock
  60. @begin-code ClassContents
  61.  
  62.     // add your data members here
  63.     WebConnection server;
  64.  
  65. @end-code;
  66.   GencodeSrcLine 144;
  67.  @end;
  68.  
  69. @begin-code BaseClassList
  70.  
  71. extends Object
  72.  
  73. @end-code;
  74.  
  75. @begin-code GeneratedClassContents
  76.  
  77.  
  78. @end-code;
  79.  
  80. @begin-code Code "IURL_Poller::IURL_Poller()"
  81.  
  82.     public @CLASSNAME@()
  83.     {
  84.         super();
  85.     }
  86.  
  87. @end-code;
  88.  
  89. @begin-code Code "IURL_Poller::main(String args[])"
  90.  
  91.     public static void main(String args[])
  92.     {
  93.         @@CLASSNAME@ app = new @CLASSNAME@();
  94.         app.StartApp(args);
  95.         app.RunApp(args);
  96.         app.EndApp(args);
  97.     }
  98.  
  99. @end-code;
  100.  
  101. @begin-code Code "IURL_Poller::CreateMainForm()"
  102.  
  103.     public void CreateMainForm()
  104.     {
  105.     }
  106.  
  107. @end-code;
  108.  
  109. @begin-code Code "IURL_Poller::StartApp(String args[])"
  110.  
  111.     public void StartApp(String args[])
  112.     {
  113.         server = new WebConnection(args);
  114.         if (! server.getConnected() ) {
  115.             System.err.println("Connection to Server failed");
  116.             System.exit(2);
  117.         }       
  118.     }
  119.  
  120. @end-code;
  121.  
  122. @begin-code Code "IURL_Poller::RunApp(String args[])"
  123.  
  124.     public void RunApp(String args[])
  125.     {
  126.         //CreateMainForm();
  127.         try {
  128.             // Print out the headers and titles
  129.             server.setResponseHeader( "Content-Type", "text/html" );  
  130.             server.writeln( "<CENTER><H1>Java ISAPI / NSAPI URL Poller Sample</H1></CENTER>" ); 
  131.             server.writeln( "<P>\n<BR>\n<HR>\n<BR>" );
  132.  
  133.             URLList urlList = new URLList();      
  134.  
  135.             // Get the URL to be added, as well as the time interval for polling            
  136.             String URLString = null;
  137.             String pollInterval = null;
  138.             if( server.getIsPostMethod() ) {
  139.                 URLString = server.getFormVariable( "url" );
  140.                 pollInterval = server.getFormVariable( "pollInterval" );
  141.             } else {
  142.                 URLString = server.getQueryVariable( "url" );
  143.                 pollInterval = server.getQueryVariable( "pollInterval" );
  144.             }
  145.  
  146.             // Get the polling interval; if none is specified, used the default            
  147.             long pollTime = 0;
  148.             if( pollInterval != null ) {
  149.                 pollTime = ( new Long( pollInterval ) ).longValue();
  150.                 pollTime = pollTime * 60 * 1000;
  151.             } else {
  152.                 pollTime = urlList.getPollInterval();
  153.             }
  154.             pollTime = ( pollTime / 1000 ) / 60;
  155.  
  156.             server.write( "<P>This server will poll the list of URLs every " );
  157.             server.write( Long.toString( pollTime ) );
  158.             server.writeln( " minute(s)." );
  159.             server.write( "<P>Here is a current list of the URLs stored by the server" );           
  160.             server.writeln( " and their status since the last poll." );
  161.             server.writeln( "<P>\n<BR>" );
  162.  
  163.             // If a URL was specified to be added, add it to the list
  164.             if( URLString != null ) {
  165.                 urlList.addURL( URLString );
  166.             }
  167.             urlList.startPolling();
  168.  
  169.             // Print out a list of URLs currently stored by the server, as well
  170.             // as their status since the last poll
  171.             server.writeln( "<CENTER><TABLE BORDER=4 BGCOLOR=WHITE>" );        
  172.             server.writeln( "<TR>" );
  173.             server.writeln( "<TH>URL</TH>" );
  174.             server.writeln( "<TH>Status</TH>" );
  175.             server.writeln( "</TR>" );
  176.  
  177.             for( Enumeration e = urlList.getURLs(); e.hasMoreElements(); ) { 
  178.                 URLStatus oneItem = ( URLStatus ) e.nextElement();
  179.  
  180.                 URL url = oneItem.getURL();
  181.                 int status = oneItem.getStatus();
  182.  
  183.                 server.writeln( "<TR>" );
  184.  
  185.                 // Print out the URL and make a link to it if it's new
  186.                 server.write( "<TD>" );
  187.                 if( status == URLStatus.NEW ) {                
  188.                     server.write( "<A HREF=\"" );
  189.                     server.write( url.toString() );
  190.                     server.write( "\">" );
  191.                     server.write( url.toString() );
  192.                     server.write( "</A>" );
  193.                 } else {
  194.                     server.write( url.toString() );
  195.                 }
  196.                 server.writeln( "</TD>" );
  197.  
  198.                 // Print out the status of this URL
  199.                 server.write( "<TD>" );
  200.                 switch( status ) {
  201.                     case URLStatus.NEW: {
  202.                         server.write( "<FONT COLOR=\"red\">" );
  203.                         server.write( "NEW" ); 
  204.                         server.write( "</FONT>" );
  205.                         break;
  206.                     } case URLStatus.UNCHANGED: {
  207.                         server.write( "Unchanged" ); 
  208.                         break;
  209.                     } case URLStatus.UNKNOWN: {
  210.                         server.write( "Unknown" ); 
  211.                         break;
  212.                     } default: {
  213.                         server.write( "Error" ); 
  214.                         break;
  215.                     }
  216.                 }
  217.                 server.writeln( "</TD>" );
  218.                 server.writeln( "</TR>" );
  219.             }             
  220.             server.writeln( "</TABLE></CENTER>" );  
  221.             server.writeln( "<P>\n<BR>\n<HR>\n<BR>" );    
  222.  
  223.         } catch( WebServiceException e ) {
  224.             server.writeln( "<H2>WebService Exception: " + e.getMessage() );        
  225.         } catch( Exception e ) {
  226.             server.writeln( "<H2>Exception: " + e.getMessage() ); 
  227.         }
  228.  
  229.     }
  230.  
  231. @end-code;
  232.  
  233. @begin-code Code "IURL_Poller::EndApp(String args[])"
  234.  
  235.     public void EndApp(String args[])
  236.     {
  237.     }
  238.  
  239. @end-code;
  240. @end;
  241.