package seedu.tasklist.logic.commands;

import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;

import seedu.tasklist.logic.commands.exceptions.CommandException;
//@@author A0141993X
/**
 * Load user data file for task list.
 */
public class LoadCommand extends Command {

    public static final String COMMAND_WORD = "load";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": loads data from specified location.\n"
            + "Parameters: FILE_PATH/FILE_NAME.xml\n"
            + "Example: " + COMMAND_WORD + " data/mytasklist.xml";

    public static final String MESSAGE_SUCCESS = "Data successfully loaded from: %1$s";
    public static final String MESSAGE_INVALID_PATH = "The file path specified is invalid: %1$s";
    public static final String MESSAGE_FAILURE = "The file cannot be loaded: %1$s";

    private String filePath;
    private static final String XML = ".xml";

    public LoadCommand(String filePath) {
        this.filePath = filePath.trim();
    }

    @Override
    public CommandResult execute() throws CommandException {
       assert filePath != null;
       assert model != null;

        if (!isValidPath(filePath)) {
            return new CommandResult(String.format(MESSAGE_INVALID_PATH, filePath));
        }

        try {
            model.loadTaskList(filePath);
            return new CommandResult(String.format(MESSAGE_SUCCESS, filePath));
        } catch (IOException e) {
            return new CommandResult(String.format(MESSAGE_FAILURE, filePath));
        }
    }

    /**
     * Returns true if the given file path is a valid path
     */
    private boolean isValidPath(String path) {
        try {
            Paths.get(path);
            return isXML(path);
        } catch (InvalidPathException e) {
            return false;
        }
    }

    /**
     * Returns true if the given file path ends with the .xml extension.
     */
    private static boolean isXML(String path) {
        return path.endsWith(XML);
    }
}

@@ -430,17 +430,17 @@
 RD + %22: 
-l
+L
 oads dat
@@ -646,16 +646,19 @@
 = %22Data 
+is 
 successf
@@ -855,16 +855,38 @@
 e loaded
+, check if file exists
 : %251$s%22;
@@ -1602,36 +1602,30 @@
  /**%0A     * 
-Returns true
+Checks
  if the give
@@ -1652,16 +1652,89 @@
 id path%0A
+     * Returns true if it is a valid path else false%0A     * @param path %0A
      */%0A
@@ -1847,16 +1847,25 @@
 rn isXML
+Extension
 (path);%0A
@@ -1961,36 +1961,30 @@
  /**%0A     * 
-Returns true
+Checks
  if the give
@@ -2025,16 +2025,87 @@
 ension.%0A
+     * Returns true if extension is .xml else false%0A     * @param path%0A
      */%0A
@@ -2136,16 +2136,25 @@
 an isXML
+Extension
 (String 

Update LoadCommand.java