package seedu.tasklist.logic.commands;

import java.io.IOException;

public class SaveCommand extends Command {
    
    public static final String COMMAND_WORD = "save";
    
    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Change the directory and file name of the data that is being saved.\n"
            + "Parameters: FILE_PATH/FILE_NAME.xml\n"
            + "Example: " + COMMAND_WORD + " data/mytasklist.xml";
    
    public static final String MESSAGE_SUCCESS = "File is successfully saved to: %1$s";
    public static final String MESSAGE_INVALID_PATH = "Invalid file path: %1$s";
    
 private final String filePath;
    
    public SaveCommand(String filePath){
        this.filePath = filePath;
    }
    
    @Override
    public CommandResult execute() {
        try{
            model.saveTaskList(filePath);
            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));
        }catch (IOException e){
            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));
        }
        
    }

}

@@ -60,16 +60,87 @@
 ception;
+%0Aimport java.nio.file.InvalidPathException;%0Aimport java.nio.file.Paths;
 %0A%0Apublic
@@ -679,459 +679,1264 @@
     
-%0A private final String filePath;%0A    %0A    public SaveCommand(String filePath)%7B%0A        this.filePath = filePath;%0A    %7D%0A    %0A    @Override%0A    public CommandResult execute() %7B%0A        try%7B%0A            model.saveTaskList(filePath);%0A            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));%0A        %7Dcatch (IOException e)%7B%0A            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));%0A        %7D%0A        %0A    %7D
+public static final String MESSAGE_FAILURE = %22Unable to save file at specified path: %251$s%22;%0A    %0A    private final String filePath;%0A    private static final String XML = %22.xml%22;%0A    %0A    public SaveCommand(String filePath)%7B%0A        this.filePath = filePath;%0A    %7D%0A    %0A    @Override%0A    public CommandResult execute() %7B%0A        assert filePath != null; %0A        assert model != null;%0A        %0A        if (!isValidPath(filePath)) %7B%0A            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));%0A        %7D%0A%0A        try%7B%0A            model.saveTaskList(filePath);%0A            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));%0A        %7Dcatch (IOException e)%7B%0A            return new CommandResult(String.format(MESSAGE_FAILURE, filePath));%0A        %7D%0A        %0A    %7D%0A    %0A%0A    /**%0A     * Returns true if the given path is a valid path%0A     */%0A    private boolean isValidPath(String path) %7B%0A        try %7B%0A            Paths.get(path);%0A            return isXML(path);%0A        %7D catch (InvalidPathException e) %7B%0A            return false;%0A        %7D%0A    %7D%0A%0A    /**%0A     * Returns true if the given path ends with the .xml extension.%0A     */%0A    private static boolean isXML(String path) %7B%0A        return path.endsWith(XML);%0A    %7D%0A
 %0A%0A%7D%0A

Update SaveCommand.java