home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / jload18.zip / localurl.java < prev    next >
Text File  |  2000-04-13  |  2KB  |  125 lines

  1. import java.io.*;
  2.  
  3. public class localurl
  4. {
  5.  protected String name; /* jmeno bez adresare */
  6.  protected String localname; /* jmeno souboru, kde to je */
  7.  protected String location; /* redirect info */
  8.  protected String dir; /* kde jsem ulozen ? */
  9.  
  10.  protected long date; /* update time */
  11.  protected String ctype; /* content-type */
  12.  
  13.  
  14.  /* interni flagy */
  15.  protected boolean modified;
  16.  protected boolean exists;
  17.  
  18.  
  19.  public localurl(String ldir,String uname)
  20.  {
  21.   dir=ldir;
  22.   name=localname=uname;
  23.   if(uname.length()==0) localname="index.html";
  24.   modified=false;
  25.   checkFile();
  26.  }
  27.  
  28.  protected void checkFile()
  29.  {
  30.   File f=new File(dir,localname);
  31.   if(f.isFile()) exists=true; else { exists=false;return;}
  32.   if(date==0) date=f.lastModified();
  33.   if(ctype==null)
  34.    {
  35.     String ln=localname.toLowerCase();
  36.     if(ln.endsWith(".gif") ||
  37.        ln.endsWith(".jpeg") ||
  38.        ln.endsWith(".jpg") ||
  39.        ln.endsWith(".png") ||
  40.        ln.endsWith(".xbm"))
  41.          ctype="image/unknown"; else ctype="text/html";
  42.    }
  43.  }
  44.   
  45.  
  46.  public localurl(String ldir,String uname,String localname,String ctype,String location,long date)
  47.  {
  48.   dir=ldir;
  49.   name=uname;
  50.   this.ctype=ctype;
  51.   this.location=location;
  52.   this.date=date;
  53.   this.localname=localname;
  54.   modified=false;
  55.   exists=true;
  56.  }
  57.   
  58.  public static void init(String z[])
  59.  {
  60.  }
  61.  
  62.  public long getDate()
  63.  {
  64.   return date;
  65.  }
  66.  
  67.  public void setDate(long d)
  68.  {
  69.   date=d;
  70.   modified=true;
  71.  }
  72.  
  73.  public boolean isModified()
  74.  {
  75.   return modified;
  76.  }
  77.  
  78.  public boolean exists()
  79.  {
  80.   return exists;
  81.  }
  82.  
  83.  public InputStream getInputStream() throws IOException
  84.  {
  85.   if(!exists) throw new FileNotFoundException();
  86.   return new FileInputStream(dir+localname);
  87.  }
  88.  
  89.  public OutputStream getOutputStream() throws IOException
  90.  {
  91.   OutputStream res;
  92.   res=new FileOutputStream(dir+localname);
  93.   touch();
  94.   return res;
  95.  }
  96.  
  97.  public void touch()
  98.  {
  99.   modified=true;
  100.   date=System.currentTimeMillis();
  101.  }
  102.  
  103.  public String getLocation()
  104.  {
  105.   return location;
  106.  }
  107.  
  108.  public int hashCode()
  109.  {
  110.   return name.hashCode();
  111.  }
  112.  
  113.  public void setLocation(String s)
  114.  {
  115.   location=s;
  116.   modified=true;
  117.  }
  118.  
  119.  public boolean isParseable()
  120.  {
  121.   if(exists==true && ctype.startsWith("text/html")) return true;
  122.    else return false;
  123.  }
  124. }
  125.