Changeset 11645


Ignore:
Timestamp:
2006-04-12T09:22:10+12:00 (18 years ago)
Author:
shaoqun
Message:

add a method to check wether an image and its screenview (if any) has been visited before downloading it

File:
1 edited

Legend:

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

    r11563 r11645  
    6565    int verbosity_ = 0;
    6666
    67     protected boolean busy_ = false;
    68    
     67     /** Records all images which have already been examined */
     68    Hashtable visited_images_  = null;
     69       
    6970    MediaTracker tracker;
    7071
     
    99100    System.err.println("starting_url_ "  + starting_url +"\n"+
    100101                       "href_musthave_ " +  href_musthave +"\n"+
    101                "image_mustnothave_" + image_mustnothave+"\n"+
     102               "image_mustnothave_ " + image_mustnothave+"\n"+
    102103               "image_ignore_ "+  image_ignore+"\n"+
    103104               "image_type_ "+ image_type+"\n"+
     
    110111    }
    111112
    112       public boolean getStatus(){
    113     return busy_;
    114 
    115     }
    116 
     113 
    117114    /** Determines whether or not a url has already been examined
    118115     *
     
    128125     }
    129126
    130     // if the url has been visited before, return true
     127        // if the url has been visited before, return true
    131128    if (visited_url_.containsKey(url_string))
    132129    {
     
    142139    return false;
    143140    }
     141
     142  /** Determines whether or not an images or its screenview has been visited)
     143     *  has already been examined
     144     *
     145     *  @param url_string the url to check
     146     *  @param img_name the image to check
     147     *  @return true if the url has been visited, false if not */
     148    public boolean image_visited(String url_string, String img_name)
     149    {
     150    String hash_dir = url_string.substring(0,url_string.lastIndexOf("/")); 
     151   
     152    if ( visited_images_.containsKey(hash_dir)){
     153        Hashtable hashed_images = (Hashtable)visited_images_.get(hash_dir);   
     154       
     155            if (img_name.startsWith("screenview")){
     156        return true;
     157        }
     158
     159        if (hashed_images.containsKey(img_name)){
     160        return true;
     161        }
     162         
     163            Enumeration enu = hashed_images.keys();
     164            for(;enu.hasMoreElements();){
     165        String name = (String)enu.nextElement();
     166        if(name.startsWith("screenview")){
     167            return true;
     168        }
     169        }
     170   
     171            hashed_images.put(img_name,"visited");           
     172    }
     173    else{
     174        Hashtable hashed_images = new Hashtable();
     175        hashed_images.put(img_name,"visited");
     176        visited_images_.put(hash_dir,hashed_images);       
     177    }
     178         
     179    return false;
     180    }
     181
     182   
     183
     184
    144185
    145186    /** Restricts the type of images that can be included in the collage
     
    328369        }
    329370
     371            //System.out.println("add image**"+url.toString());
     372        //System.out.println("***** URL Path**"+from_url);
     373        //System.out.println("*** imagename**"+img_name);
     374
     375           if (image_visited(url.toString(),img_name)) return;
     376
    330377       int size = download_images_.downloadImage(tracker,url, from_url, img_name);
    331378         
     
    386433        URL url = (URL)src_links.get(i);
    387434        String url_string  = url.toString();
    388                
     435           
    389436        //System.err.println(" source links " + i + " ["  + url_string +"]");
    390437
     
    442489            URL url = (URL)href_links.get(i);
    443490            String url_string  = url.toString();
    444 
    445             //System.err.println(" href links " + i + "["  + url_string +"]");
    446                    
     491            //System.err.println(" href links " + i + "["  + url_string +"]");     
    447492
    448493            if (image_file_extension(url_string))
    449494            {
    450                                      
     495                                 
    451496                if (filter_image(url_string))
    452497
    453498                {
     499                                       
    454500                    img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
    455501
     
    543589    System.err.println("Starting download thread.");
    544590    visited_url_ = new Hashtable();
    545    
     591    visited_images_ = new Hashtable();
     592
    546593        rec_add_images(starting_url_,1);
    547594    download_images_.stopDownload();
Note: See TracChangeset for help on using the changeset viewer.