Changeset 11419 for trunk/gsdl


Ignore:
Timestamp:
2006-03-21T09:32:05+12:00 (18 years ago)
Author:
shaoqun
Message:

fix code that test the image file extension and external links

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java

    r7334 r11419  
    3030    String starting_url_  = null;
    3131
     32    /** the root directory of Greenstone*/ 
     33    String document_root_ = null;
     34
     35
    3236    /** CHRIS - Holds the contents of the collection's assoc directory */
    3337    //    File[] assocDir_ = null;
     
    5963    boolean thread_running_ = true;
    6064
    61     int verbosity_;
     65    int verbosity_ = 0;
    6266
    6367    /** Constructor to initialise a download thread from which images are found,
     
    7478            DownloadImages download_images, String starting_url,
    7579            String href_musthave, String image_mustnothave,
    76             String image_ignore, String image_type, int verbosity)
     80            String image_ignore, String image_type, String document_root,int verbosity)
    7781    {
    7882    super("DownloadUrls");
     
    8589    image_ignore_  = image_ignore;
    8690    image_type_    = image_type;
    87    
     91    document_root_ = document_root;
    8892    verbosity_ = verbosity;
     93     
     94
     95    System.err.println("starting_url_ "  + starting_url +"\n"+
     96                       "href_musthave_ " +  href_musthave +"\n"+
     97               "image_mustnothave_" + image_mustnothave+"\n"+
     98               "image_ignore_ "+  image_ignore+"\n"+
     99               "image_type_ "+ image_type+"\n"+
     100               "document root "+ document_root_
     101                   );
     102
     103
     104
     105
    89106    }
    90107
     
    137154       
    138155        tmp = image_type_.substring(0, image_type_.indexOf("%"));
     156             
    139157        if (image_type_.length() > image_type_.indexOf("%") + 1)
    140         image_type_ = image_type_.substring(image_type_.indexOf("%") + 1, image_type_.length());
     158        image_type_ = image_type_.substring(image_type_.indexOf("%") + 1, image_type_.length());                 
    141159        else
    142160        image_type_ = null;
    143 
    144         if (url_lstring.endsWith(tmp)) {
     161           
     162        if (!tmp.trim().equals("") && url_lstring.endsWith(tmp)) {
    145163        image_type_ = original_image_type_;
    146164        return true;
     
    164182    public boolean filter_image(String url_string)
    165183    {
     184       
    166185    if (image_ignore_==null || !url_string.startsWith(image_ignore_))
    167186    {
     
    181200            else
    182201                image_mustnothave_ = null;
    183            
    184             if (url_string.indexOf(tmp) >= 0) {
     202                                   
     203                     
     204                         
     205            if (!tmp.trim().equals("") && url_string.indexOf(tmp) >= 0) {
     206               
    185207                image_mustnothave_ = original_image_mustnothave_;
    186208                return false;
    187209            }
    188             }
    189 
     210                }
     211
     212            image_mustnothave_ = original_image_mustnothave_;
     213                   
    190214            if (image_mustnothave_ != null && url_string.indexOf(image_mustnothave_) >= 0) {
    191215            image_mustnothave_ = original_image_mustnothave_;
     
    198222           
    199223            image_mustnothave_ = original_image_mustnothave_;
    200             return true;
     224           
    201225        }
    202         }
    203     }
    204 
    205     return false;
     226   
     227        }
     228           
     229    }
     230   
     231    return true;
    206232    }
    207233
     
    351377    public void rec_add_images(String new_url, int depth)
    352378    {
    353     System.err.println("Parsing url = " + new_url);
     379
     380       
     381    System.err.println("Parsing url =  " + new_url);
    354382   
    355383    if (already_visited(new_url)) return;
     
    384412        URL url = (URL)src_links.elementAt(i);
    385413        String url_string  = url.toString();
     414               
     415        //System.err.println(" source links " + i + " ["  + url_string +"]");
    386416
    387417        if (verbosity_ >= 3) {
     
    394424                {
    395425                img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
    396 
     426                               
    397427                if (verbosity_ >= 2) {
    398428                    System.err.println("    Filtered: src_link[" + i + "] = " + url_string);
     
    401431                if ((external_links_ != null) && (!external_links_.isEmpty())) {
    402432                    String ext = (String) external_links_.get(img_name);
    403                    
    404                     if (ext != null)
     433                         
     434                           
     435                    if (ext != null){
    405436                    add_image(url, ext, img_name);
    406                     else
     437                                       
     438                    }
     439                    else{
     440               
    407441                    add_image(url, new_url, img_name);
     442                    }
    408443                }
    409444                else {
     445                   
    410446                    add_image(url, new_url, img_name);
    411447                }
     448                           
     449               
    412450                }
     451       
    413452            }
    414453       
     
    418457        Vector href_links = curl.getHrefLinks();
    419458       
     459     
     460        if (verbosity_ >= 2) {
     461        System.err.println("  Got href links... there are " + href_links.size() + " of them.");
     462        }
     463       
     464
    420465        // process each of the href links according to the parameters given.
    421466        for (int i = 0; i < href_links.size(); i++)
     
    423468            URL url = (URL)href_links.elementAt(i);
    424469            String url_string  = url.toString();
    425            
     470
     471            //System.err.println(" href links " + i + "["  + url_string +"]");
     472                   
     473
    426474            if (image_file_extension(url_string))
    427475            {
     476                                     
    428477                if (filter_image(url_string))
     478
    429479                {
    430480                    img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
     
    447497                if (filter_href(url_string,new_url,depth))
    448498                {
     499           
     500                                    System.out.println("*************************************");
    449501                    rec_add_images(url_string,depth+1);
    450502                   
     
    471523    try {
    472524
    473         if (starting_url_.indexOf("gsdl") >= 0) {
     525        if (starting_url_.indexOf(document_root_) >= 0 ){
    474526        external_links_ = null;
    475527        return;
     
    519571    System.err.println("Starting download thread.");
    520572    visited_url_ = new Hashtable();
    521     rec_add_images(starting_url_,1);
     573   
     574        rec_add_images(starting_url_,1);
    522575
    523576    System.err.println("Download thread finished.");
Note: See TracChangeset for help on using the changeset viewer.