Changeset 9166


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.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
8 edited

Legend:

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

    r9095 r9166  
    209209
    210210
    211     static public void download_url_zip(String col_name, String dir, GShell source)
     211    static public void download_url_zip(String col_name, String dir, GShell source, String accept_expr, String reject_expr)
    212212    {
    213213    try {
     
    219219        String dir_encoded = URLEncoder.encode(dir,"UTF-8");
    220220        String cgi_args = "c=" + col_name_encoded;
    221         cgi_args += "&dir=" + dir_encoded;
     221        cgi_args += "&dir=" + dir_encoded + "&a=" + accept_expr + "&r=" + reject_expr;
    222222
    223223        URL download_url = new URL(download_cgi);
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java

    r9095 r9166  
    216216        if (formats_changed && Gatherer.c_man.built()) {
    217217        // upload etc/collect.cfg to server to reflect changes
    218         Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null);
     218        Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null, "", "");
    219219        GathererApplet.upload_url_zip(collection_name, "etc", null);
    220220        }
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r9136 r9166  
    6767    /** <i>true</i> if the currently loaded collection has been saved since the last significant change, <i>false</i> otherwise. */
    6868    private boolean saved = false;
     69    /*<i>true</i> if the currently loaded collection has had files added since its last build */
     70    private boolean filesChanged = true;
     71    /*<i>true</i> if the currently loaded collection has had metadata added since its last build */
     72    private boolean metadataChanged = true;
    6973    /** The document around which this collection class is based. */
    7074    private Document document;
     
    175179    return saved;
    176180    }
    177    
     181
     182    /** Determine if this collection has had its collection files changed since the last build.
     183     * @return <i>true</i> if they have been saved, <i>false</i> otherwise.
     184     */
     185    public boolean getFilesChanged() {
     186    return filesChanged;
     187    }
     188   
     189    /** Set the flag that marks weather or not the files has been changed since the last build.
     190    @param changed if files has been added/removed, as a <strong>boolean</strong>
     191    */
     192    public void setFilesChanged(boolean changed) {
     193    filesChanged = changed;
     194    }
     195
     196    /** Determine if this collection has had metadata changed since the last build.
     197     * @return <i>true</i> if it has been changed, <i>false</i> otherwise.
     198     */
     199    public boolean getMetadataChanged() {
     200    return metadataChanged;
     201    }
     202   
     203    /** Set the flag that marks weather or not the metadata has been changed since the last build.
     204    @param changed if metadata has been added/changed/removed, as a <strong>boolean</strong>
     205    */
     206    public void setMetadataChanged(boolean changed) {
     207    metadataChanged = changed;
     208    }
     209
    178210    /** Retrieve the title of this collection.
    179211     * @return The title as a <strong>String</strong>.
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r9136 r9166  
    10641064        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE);
    10651065        Gatherer.refresh(Gatherer.COLLECTION_REBUILT);
     1066        DebugStream.println("Status is ok but !installCollection()");
    10661067        }
    10671068    }
     
    14911492        if(collection != null) {
    14921493        collection.setSaved(false);
     1494        collection.setFilesChanged(true);
    14931495        }
    14941496    }
     
    14991501        if(collection != null) {
    15001502        collection.setSaved(false);
     1503        collection.setFilesChanged(true);
    15011504        }
    15021505    }
     
    15071510        if(collection != null) {
    15081511        collection.setSaved(false);
     1512        collection.setFilesChanged(true);
     1513
    15091514        }
    15101515    }
  • trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java

    r9137 r9166  
    643643     */
    644644    public void actionPerformed(ActionEvent event) {
    645         build_button.setEnabled(true);
     645        build_button.setEnabled(false);
    646646        cancel_button.setEnabled(false);
    647647        preview_button.setEnabled(false);
    648648
    649         simple_build_button.setEnabled(true);
     649        simple_build_button.setEnabled(false);
    650650        simple_cancel_button.setEnabled(false);
    651651        simple_preview_button.setEnabled(false);
  • trunk/gli/src/org/greenstone/gatherer/gui/EnrichPane.java

    r9109 r9166  
    186186    // Add button pressed
    187187    if (esrc == add) {
     188        Gatherer.c_man.getCollection().setMetadataChanged(true);
    188189        MetadataElement metadata_element = metadata_value_table.getSelectedMetadataElement();
    189190        MetadataValueTreeNode metadata_value_tree_node = metadata_element.addMetadataValue(metadata_value_tree.getSelectedValue());
     
    195196    // Replace button pressed
    196197    else if (esrc == update) {
     198        Gatherer.c_man.getCollection().setMetadataChanged(true);
    197199        MetadataElement metadata_element = metadata_value_table.getSelectedMetadataElement();
    198200        MetadataValueTreeNode metadata_value_tree_node = metadata_element.addMetadataValue(metadata_value_tree.getSelectedValue());
     
    204206    // Remove button pressed
    205207    else if (esrc == remove) {
     208        Gatherer.c_man.getCollection().setMetadataChanged(true);
    206209        (new RemoveMetadataTask()).start();
    207210    }
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r9148 r9166  
    241241        String collect_directory_path = Gatherer.getCollectDirectoryPath();
    242242       
    243         // zip up import folder
    244         Utility.zipup(collect_directory_path, col_name, "import", this);
    245 
    246         if(hasSignalledStop()) { return; }
    247         // upload it to gsdl server
    248         GathererApplet.upload_url_zip(col_name, "import", this);
    249 
     243        //Only upload the import directory if the files or metadata has changed.
     244        System.err.println("getFilesChanged(): " + Gatherer.c_man.getCollection().getFilesChanged());
     245        System.err.println("getMetadataChanged(): " + Gatherer.c_man.getCollection().getMetadataChanged());
     246        if(Gatherer.c_man.getCollection().getFilesChanged() || Gatherer.c_man.getCollection().getMetadataChanged()) {
     247            // zip up import folder
     248            Utility.zipup(collect_directory_path, col_name, "import", this, "", "");
     249            System.err.println("collect_directory_path: " + collect_directory_path);
     250            System.err.println("col_name: " + col_name);
     251
     252            if(hasSignalledStop()) { return; }
     253            // upload it to gsdl server
     254            GathererApplet.upload_url_zip(col_name, "import", this);
     255
     256            Gatherer.c_man.getCollection().setFilesChanged(false);
     257            Gatherer.c_man.getCollection().setMetadataChanged(false);
     258        }
     259       
    250260        if(hasSignalledStop()) { return; }
    251261        // upload etc folder to server (need collect.cfg and any hfiles)
    252         Utility.zipup(collect_directory_path, col_name, "etc", this);
     262        Utility.zipup(collect_directory_path, col_name, "etc", this, "", "");
    253263
    254264        if(hasSignalledStop()) { return; }
     
    260270            // upload images/ directory to server
    261271            if(hasSignalledStop()) { return; }
    262             Utility.zipup(collect_directory_path, col_name, "images", this);
     272            Utility.zipup(collect_directory_path, col_name, "images", this, "", "");
    263273
    264274            if(hasSignalledStop()) { return; }
     
    354364            fireMessage(type, typeAsString(type) + "> " + line, status, bos);
    355365        }
    356         System.err.println("Wants to stop (1).");
     366        //System.err.println("Wants to stop (1)."); //debug --Matthew
    357367        }
    358368        stdbr.close();
     
    533543        if (type == NEW) {
    534544        if (Gatherer.isGsdlRemote) {
    535             GathererApplet.download_url_zip(col_name, ".", this);
     545            GathererApplet.download_url_zip(col_name, ".", this, "", "");
    536546            if (!hasSignalledStop()) {
    537547            Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     
    549559
    550560            Utility.delete(Gatherer.c_man.getCollectionArchivesDirectoryPath()); // remove current archives
    551             GathererApplet.download_url_zip(col_name, "archives", this);
    552                if (!hasSignalledStop()) {
    553                Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
    554                }
    555                if (progress!=null) {
    556                progress.messageOnProgressBar("");
    557                }     
     561            //new File(Gatherer.c_man.getCollectionArchivesDirectoryPath()).mkdir(); //Make a clean dir
     562            GathererApplet.download_url_zip(col_name, "archives", this, ".*doc\\.xml", "");
     563            if (hasSignalledStop()) {
     564            // Clean up, then exit
     565            fireProcessComplete(type, status);
     566            // Close bos
     567            if(bos != null) {
     568                try {
     569                bos.close();
     570                bos = null;
     571                }
     572                catch(Exception error) {
     573                DebugStream.printStackTrace(error);
     574                }
     575            }
     576            return;
     577            }
     578            Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
     579           
     580            if (progress!=null) {
     581            progress.messageOnProgressBar("");
     582            }     
    558583        }
    559584
     
    574599            File buildDir = new File(Gatherer.c_man.getCollectionBuildingDirectoryPath());
    575600            Utility.delete(buildDir); // remove current build dir
    576             buildDir.mkdir(); //Make a clean dir
    577             GathererApplet.download_url_zip(col_name, "building/build.cfg", this); //Only need build.cfg
     601            //buildDir.mkdir(); //Make a clean dir
     602            GathererApplet.download_url_zip(col_name, "building/build.cfg", this, "", ""); //Only need build.cfg
     603            //Maybe change to GathererApplet.download_url_zip(col_name, "building", this, "build.cfg")
    578604            if (!hasSignalledStop()) {
    579605            Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
  • 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.