import java.awt.*; import java.lang.*; import java.applet.*; import java.util.*; import java.net.*; import java.io.*; public class GChech extends Applet { static Socket socket; static InputStream in; static OutputStream out; static DataInputStream din; static DataOutputStream dout; Button button = null; String rc = null; protected Vector entries = null; protected Vector header = null; protected File file = null; protected String name = null; protected String e_mail = null; protected String entry = null; protected String date = null; String lin2; public void loadbook(String name) { File f = new File(name); if(f.exists()&&f.canRead()) readFromFile(f); else System.out.println("This file doesn't exist."); } public void init() { setBackground(Color.lightGray); setForeground(Color.blue); Font font = new Font("TimesRoman",Font.PLAIN,20); setFont(font); setLayout(new BorderLayout()); Panel p1=new Panel(); p1.add( button=new Button("Genernate")); add("North",p1); } public boolean action(Event evt,Object what) { if (what.equals("Genernate")) // button pressed { loadbook("guestdata"); } else return false; return true; } public boolean fromHTML(String line) { int index = line.indexOf(""); if(index<0) return false; line = line.substring(index+4); index = line.indexOf(""); if(index<0) return false; name = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return false; e_mail = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return false; entry = line.substring(0,index).trim(); date = line.substring(index+4).trim(); return true; } public void readFromFile(File f) { file = f; header = new Vector(5); FileInputStream fin = null; FileOutputStream fout = null; try { fin = new FileInputStream(f);} catch(Exception fe) { System.out.println("caught exception "+fe.getMessage()); header = null; entries = null; return; } try { fout = new FileOutputStream("CheckForUpdate.html"); } catch(IOException ioe) { System.out.println("warning: couldn't save guestbook"); return; } DataOutputStream dout = new DataOutputStream(fout); try { dout.writeBytes("\nCheckForUpdate\n\n

This is a Java program that takes a URL as argument and checks to see if the document the URL points to has changed since the last\n"); dout.writeBytes("\n"); } catch(IOException ioe2) { System.out.println("error while saving guestbook :"); try {dout.close(); fout.close();} catch(Exception ce) {} return; } DataInputStream din = new DataInputStream(fin); String line = null; boolean cont = true; while(cont) { try { line = din.readLine();} catch(Exception e) { System.out.println("caught exception "+e.getMessage()); try { din.close(); fin.close();} catch(Exception ce) {} header = null; entries = null; return; } if((line!=null)&&(!line.startsWith(""))) header.addElement(line+"\n"); else cont = false; } int coun= 0; while(line!=null) { if(line.startsWith("")) break; else { GuestBookEntry entry = new GuestBookEntry(); if(entry.fromHTML(line)) { System.out.println("That is OK"); } else System.err.println("error parsing line "+line); } try { line = din.readLine(); lin2 = fromhtmlname(line); coun++; } catch(Exception e2) { System.err.println("caught execption "+e2.getMessage()); try{ din.close(); fin.close();} catch(Exception ce2){} header = null; entries = null; return; } try{ if (lin2!="" ) dout.writeBytes("\n"); } catch(Exception e33) { System.err.println("caught execption "+e33.getMessage()); try{ din.close(); fin.close();} catch(Exception ce99){} return; } } try { dout.writeBytes("\n



time the document was referenced. But If I have not start the server, it is useless to press button.



\n
Come back to my homepage
\n"); dout.flush(); } catch(Exception ce3){} try{ din.close(); fin.close();} catch(Exception ce31){} try{ dout.close(); fout.close();} catch(Exception ce32){} } public String fromhtml(String line) { int index = line.indexOf(""); if(index<0) return ""; line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; name = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; e_mail = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; entry = line.substring(0,index).trim(); date = line.substring(index+4).trim(); String rc = ""+name+""+e_mail+""+entry+""+date+"\n"; return rc; } public String fromhtmlname(String line) { int index = line.indexOf(""); if(index<0) return ""; line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; name = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; e_mail = line.substring(0,index).trim(); line = line.substring(index+4); index = line.indexOf(""); if(index<0) return ""; entry = line.substring(0,index).trim(); date = line.substring(index+4).trim(); return name; } }