Changeset 15164


Ignore:
Timestamp:
2008-04-02T18:08:50+13:00 (14 years ago)
Author:
ak19
Message:

modified Download Collection file's ERROR string handling, added method exists(collection, file) to check if a file exists on the server end and to this end added class RemoteGreenstoneServerExistsAction

File:
1 edited

Legend:

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

    r14974 r15164  
    149149    }
    150150
     151    static public boolean exists(String collection_name, File collection_file)
     152    {
     153    String result = performAction(new RemoteGreenstoneServerExistsAction(collection_name, collection_file));
     154    if(result.contains("exists")) {
     155        return true;
     156    }
     157    else if(result.contains("does not exist")) {
     158        return false;
     159    }
     160    return false;
     161    }
    151162
    152163    // ----------------------------------------------------------------------------------------------------
     
    518529    /**
    519530     * --------------------------------------------------------------------------------------------
     531     *    CHECKING IF A FILE/FOLDER EXISTS ON SERVER SIDE
     532     * --------------------------------------------------------------------------------------------
     533     */
     534    static private class RemoteGreenstoneServerExistsAction
     535    extends RemoteGreenstoneServerAction
     536    {
     537    private String collection_name;
     538    private File collection_file;
     539   
     540    public RemoteGreenstoneServerExistsAction(String collection_name, File collection_file)
     541    {
     542        this.collection_name = collection_name;
     543        this.collection_file = collection_file;
     544    }
     545   
     546    public void perform()
     547        throws Exception
     548    {
     549        String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection_name);
     550        String collection_file_relative_path = getPathRelativeToDirectory(collection_file, collection_directory_path);
     551        collection_file_relative_path = collection_file_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
     552        File file = new File(collection_directory_path, collection_file_relative_path);
     553
     554        String file_exists_command = "cmd=file-exists";
     555        file_exists_command += "&c=" + URLEncoder.encode(collection_name, "UTF-8");
     556        file_exists_command += "&file=" + URLEncoder.encode(collection_file_relative_path, "UTF-8");
     557        // returns either "File <filename> exists" or "File <filename> does not exist"
     558        // for the file/folder collection_file
     559        action_output = sendCommandToServer(file_exists_command, null);
     560    }   
     561    }
     562   
     563
     564    /**
     565     * --------------------------------------------------------------------------------------------
    520566     *    DOWNLOAD COLLECTION FILE
    521567     * --------------------------------------------------------------------------------------------
     
    10141060        }
    10151061        // Handle other types of errors by throwing an exception
    1016         else if (command_output.startsWith("ERROR: ")) {
     1062        else if (command_output.startsWith("ERROR: ")) { 
    10171063        throw new Exception(command_output.substring("ERROR: ".length()));
     1064        } else if (command_output.contains("ERROR: ")) { // check if ERROR occurs anywhere else in the output
     1065        throw new Exception(command_output);
    10181066        }
    10191067
     
    11671215    }
    11681216
    1169 
     1217           
    11701218    /** Returns the command output if the action completed, throws some kind of exception otherwise. */
    11711219    static private String uploadFileInternal(String upload_cgi, String cgi_args, String file_path)
Note: See TracChangeset for help on using the changeset viewer.