Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/fu/FuFileHttp.java


1   /**
2    * @modification $Date: 2002/12/16 09:09:11 $
3    * @statut       unstable
4    * @file         FuFileHttp.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.fu;
13  
14  import com.memoire.fu.*;
15  import com.memoire.xml.*;
16  
17  import java.io.*;
18  import java.net.*;
19  import java.util.*;
20  
21  /**
22   * Remote http file.
23   */
24  public class FuFileHttp
25    extends    FuFileUrl
26  {
27    public FuFileHttp(URL _a, String _n) throws MalformedURLException
28    {
29      this(new URL(_a,_n));
30    }
31  
32    public FuFileHttp(URL _url)
33    {
34      super(_url);
35      if(!"http".equals(_url.getProtocol()))
36        throw new IllegalArgumentException("Not a HTTP url");
37    }
38  
39    protected Vector readList(BufferedReader _nr)
40      throws IOException
41    {
42      Vector v=new Vector();
43  
44      v.addElement("[content].html");
45  
46      XmlParser p=new XmlParser(_nr,url_.toString(),XmlParser.HTML);
47      XmlReader r=new XmlReader(XmlParser.HTML);
48      p.setXmlListener(r);
49      p.parse();
50      //System.out.println(r.getTree());
51      XmlNode[] nodes=r.getTree().findNodes("A");
52      String    base =""+url_;
53        
54      for(int i=0;i<nodes.length;i++)
55      {
56        String href=nodes[i].getAttribute("HREF");
57        if(href!=null)
58        {
59    try
60    {
61      String l=""+new URL(url_,href);
62      if(l.startsWith(base))
63      {
64        l=l.substring(base.length());
65        int k;
66        k=l.indexOf("?");
67        if(k>=0) l=l.substring(0,k);
68        k=l.indexOf("#");
69        if(k>=0) l=l.substring(0,k);
70        k=l.indexOf("/");
71        if((k==-1)||(k==l.length()-1))
72      if(!"".equals(l)&&!v.contains(l))
73        v.addElement(l);
74      }
75    }
76    catch(Exception ex) { }
77        }
78      }
79  
80      return v;
81    }
82  
83    public URL getContentURL()
84    {
85      if(getPath().endsWith("[content].html"))
86      {
87        try { return new URL(getParent()); }
88        catch(MalformedURLException ex) { }
89      }
90      
91      return url_;
92    }
93  
94    // GET POST HEAD OPTIONS PUT DELETE TRACE
95  
96    public final boolean mkdir()
97    {
98      return true;
99  
100     /*
101     boolean r=false;
102     try
103     {
104       String p=url_.toString();
105       if(!p.endsWith("/")) p+="/";
106       URL u=new URL(p);
107 
108       HttpURLConnection cnx=new HttpURLConnection(u);
109       cnx.setRequestMethode("PUT");
110       cnx.connect();
111       int    c=cnx.getResponseCode();
112       String m=cnx.getResponseMessage();
113       System.err.println("HTTP: "+c+" "+m);
114       cnx.disconect();
115     }
116     catch(Exception ex) { }
117     return r;
118     */
119   }
120 }