Ignore:
Timestamp:
2005-02-24T13:57:06+13:00 (19 years ago)
Author:
mdewsnip
Message:

More improvements to the GLI applet, by Matthew Whyte. Now only uploads source documents if the files or metadata has changed, and only downloads the doc.xml files rather than the whole archives directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r9095 r9166  
    602602    }
    603603
    604     static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source)
    605     {
     604    /*
     605      Method to handle zipping up of a file. Called by zipup and dirFunc.
     606
     607      @param zos the zip output stream, as a <strong>ZipOutputStream</strong>
     608      @param file_path the <strong>String</strong> containing the path to the file/directory tozip up
     609      @param prefix_strip the <strong>int</strong> used to substring the file_path
     610      @param source the <strong>GShell</strong> that is calling this method, so that we can check to see if the process has been cancelled. null if GShell is not the calling object.
     611      @param accept_expr a <strong>String</strong> containing a regular expression of files to include in the archive. All other files will be excluded.
     612      @param reject_expr a <strong>String</strong> containing a regular expression of files not to include in the archive.
     613
     614      @return boolean
     615
     616      @see dirFunc
     617      @see zipup
     618     */
     619    static protected boolean zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source, boolean encountered_file, String accept_expr, String reject_expr)
     620    {
     621   
     622    if((reject_expr != "") && (file_path.matches(reject_expr))) {
     623        // matches reject expression
     624        DebugStream.println("File \'" + file_path + "\' matches the reject expression \'" + reject_expr + "\'");
     625        return encountered_file;
     626    }
     627
     628    if ((accept_expr != "") && (!file_path.matches(accept_expr))) {
     629        // does not match accept expression
     630        DebugStream.println("File \'" + file_path + "\' doesn't match accept expression \'" + accept_expr + "\'");
     631        return encountered_file;
     632    }
     633
    606634    // Using try is required because of file io.
    607635    try {
    608636        // Exit if pressed cancel.
    609637        if (source != null && source.hasSignalledStop()) {
    610         return;
    611         }
     638        return false;
     639        }
     640
    612641        // Create a Zip Entry and put it into the archive (no data yet).
    613642
     
    616645        // Zip files use '/' for directory separator
    617646        String unix_style_path = unixStylePath(zip_path);
     647
    618648        ZipEntry fileEntry = new ZipEntry(unix_style_path);
    619649        zos.putNextEntry(fileEntry);
     
    637667        zos.write(data, 0, byteCount);
    638668        }
     669        encountered_file = true;
    639670    }
    640671    catch (IOException e) {
     
    642673    }
    643674   
    644     DebugStream.println("    Zipping up: " + file_path);
    645     }
    646 
    647     static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source)
    648     {
     675    DebugStream.println("Zipping up: " + file_path);
     676    return encountered_file;
     677    }
     678
     679    /*
     680      Method to handle ziping up of a directory.
     681
     682      @param zos
     683      @param dir_name
     684      @param prefix_strip
     685      @param source
     686      @param encountered_file ??What's this??
     687      @param accept_expr
     688      @param reject_expr
     689
     690      @see zipup
     691      @see zipFunc
     692     */
     693    static protected boolean dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source, boolean encountered_file, String accept_expr, String reject_expr)
     694    {
     695    /*
     696    if (reject_expr != "" && (dir_name.matches(reject_expr))) {
     697        // matches reject expression
     698        System.err.println("matches reject expression");
     699        return encountered_file;
     700    }
     701   
     702    if ((accept_expr != "") && (!dir_name.matches(accept_expr))) {
     703        // does not match accept expression
     704        System.err.println("doesn't match accept expression");
     705        return encountered_file;
     706    }
     707    */
     708
    649709    File dirObj = new File(dir_name);
    650710
     
    656716        // Loop through File array and display.
    657717        for (int i = 0; i < fileList.length; i++) {
    658             if(source != null) {
    659             if(source.hasSignalledStop()) {
    660                 break;
    661             }
    662             }
     718            if(source != null && source.hasSignalledStop()) { break; }
    663719            File file = fileList[i];
    664720            if (file.isDirectory()) {
     
    677733            }
    678734
    679             dirFunc(zos,dir_path,prefix_strip, source);
     735            encountered_file = dirFunc(zos, dir_path, prefix_strip, source, encountered_file, accept_expr, reject_expr);
    680736            } else if (file.isFile()) {
    681737            // Call the zipFunc function
    682738            String file_path = fileList[i].getPath();
    683             zipFunc(zos,file_path,prefix_strip, source);
     739            encountered_file = zipFunc(zos,file_path,prefix_strip, source, encountered_file, accept_expr, reject_expr);
    684740            }
    685         } 
     741        }
    686742        }
    687743        else {
     
    692748        System.err.println ("Directory "+dir_name+" does not exist.");
    693749    }
     750    return encountered_file;
    694751    }
    695752   
    696 
    697 
    698     static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source)
     753    /**
     754      Method to zip up a given file or directory
     755
     756      @param col_dir
     757      @param col_name
     758      @param dir_or_file
     759      @param source
     760      @param filter
     761
     762      @see zipFunc
     763      @see dirFunc
     764     */
     765    static public boolean zipup(String col_dir, String col_name, String dir_or_file, GShell source, String accept_expr, String reject_expr)
    699766    {
    700767    int prefix_strip = col_dir.length();
     768    boolean encountered_file = false;
    701769
    702770    String zip_fname = col_dir + col_name + ".zip";
     
    711779        if (zip_dof.isDirectory()) {
    712780            String zip_dir = zip_dir_or_file;
    713             dirFunc(zos,zip_dir,prefix_strip, source);
     781            encountered_file = dirFunc(zos, zip_dir, prefix_strip, source, encountered_file, accept_expr, reject_expr);
    714782        }
    715783        else {
     
    730798            }
    731799            }
    732             zipFunc(zos,zip_full_file,prefix_strip, source);
     800            encountered_file = zipFunc(zos, zip_full_file, prefix_strip, source, encountered_file, accept_expr, reject_expr);
    733801        }
    734802        }
     
    744812    catch (IOException exception) {
    745813        DebugStream.printStackTrace(exception);
    746     }
     814        return false;
     815    }
     816    return encountered_file;
    747817    }
    748818   
     
    760830        ZipEntry zipentry = (ZipEntry) e.nextElement();
    761831        String zentryname = col_dir + zipentry.getName();
     832        File file = new File(zentryname);
    762833        DebugStream.println("    Unzipping: " + zentryname);
    763834
     
    771842        else {
    772843            // Write out file to disk
     844
     845            //Make sure it's parent directory exists.
     846            File dir = new File(file.getParent());
     847            dir.mkdirs();
    773848
    774849            // set up input stream
Note: See TracChangeset for help on using the changeset viewer.