Example #1
0
  /**
   * get the directory to store the link(ShellShortCut object) throws DirectoryException if it can't
   * find the directory to store to link
   *
   * @param cmdArgs that contains user inputs and present work directory
   * @return ShellDirectory where the ShellShortCut object will be stored.
   */
  protected ShellDirectory getDirToStoreLink(String[] cmdArgs, ShellDirectory presentWorkDir)
      throws DirectoryException {
    String linkPath = getLinkPath(cmdArgs);
    String dirPathToStoreLink = new String();
    if (doesInputContainLinkName(cmdArgs, presentWorkDir)) {
      if (linkPath.indexOf("/") != -1) {
        dirPathToStoreLink = linkPath.substring(0, linkPath.lastIndexOf('/'));
      } else {
        dirPathToStoreLink = ".";
      }

    } else {
      dirPathToStoreLink = linkPath;
    }
    ShellFile DirToStore = new ShellDirectory();
    try {
      DirToStore = DirectoryNavigator.getFile(dirPathToStoreLink, presentWorkDir);
    } catch (DirectoryException e) {
      throw new DirectoryException(String.format(notFoundMessage, linkPath, "file or directory"));
    }
    // if user gave an file instead of directory, (we can't store a link in it) throw the error.
    if (DirToStore.getClass() == ShellFile.class || DirToStore.getClass() == ShellShortcut.class) {
      throw new DirectoryException(String.format(fileExistsMessage, linkPath));
    }
    return (ShellDirectory) DirToStore;
  }
Example #2
0
 /**
  * check whether the target's path is valid or not
  *
  * @param targetpath and present work directory
  * @return true if and only if the target's path is valid
  */
 protected boolean isTargetValid(String targetPath, ShellDirectory pwd) {
   return DirectoryNavigator.exists(targetPath, pwd);
 }
Example #3
0
 /**
  * check the link's path from the user input contains the name of the link will be created or just
  * stating the directory to store the link
  *
  * @param cmdArgs that contains user input and present work directory
  * @return true if and only if use input link's path contains the name of the link
  */
 protected Boolean doesInputContainLinkName(String[] cmdArgs, ShellDirectory presentWorkDir) {
   String linkPath = getLinkPath(cmdArgs);
   if (DirectoryNavigator.exists(linkPath, presentWorkDir)) {
     return false;
   } else return true;
 }