Package net.eldiosantos.command.commands.response

Examples of net.eldiosantos.command.commands.response.Response


  // }

  @Override
  public Response execCommand(String[] params) {
    // TODO Add change to a specific path
    Response response = null;
    System.out.println("Params[1]" + params[1]);
    try {
      // Changing to a parent folder
      if (params[1].equals("..")) {
        path = path.getParentFile();
      } else {
        // Changing to a child path
        File newPath = new File(path.getAbsolutePath() + File.separator
            + params[1]);

        path = newPath;
      }
      List<String> resp = new Vector<String>();
      resp.add(path.getAbsolutePath());

      response = new Response(resp, null);

    } catch (Exception e) {
      response = new Response(null, e);
    }

    return response;
  }
View Full Code Here


  // super();
  // }

  @Override
  public Response execCommand(String[] params) {
    Response response = null;
    try {
      List<String> lines = new Vector<String>();

      System.out.println(path.getAbsolutePath() + File.separator
          + params[1]);

      File file = new File(path.getAbsolutePath() + File.separator
          + params[1]);
      Scanner sc = new Scanner(file);
      while (sc.hasNext()) {
        lines.add(sc.nextLine() + "\n");
      }

      response = new Response(lines, null);
    } catch (Exception e) {
      response = new Response(null, e);
    }
    return response;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public Response execCommand(String[] params) {
    // TODO Test if the loaded classes may be used by another classloader.
    Response response = null;

    CommandVault vault = new CommandVault();

    try {

      CustomClassLoader loader = new CustomClassLoader();
      File file = null;

      for (int i = 1; i < params.length - 1; i++) {
        file = new File(params[i]);
        List<Class<?>> list = loader
            .loadAndScanJar(Command.class, file);

        for (Class<?> clazz : list) {
          vault.addClass((Class<? extends Command>) clazz);
        }

        file = null;
      }

      // Verify this.

      List<String> lines = new Vector<String>();
      lines.add("All jars loaded.");
      response = new Response(lines, null);

    } catch (Exception e) {
      // TODO: handle exception
      response = new Response(null, e);
    }
    return response;
  }
View Full Code Here

  @Override
  public Response execCommand(String[] params) {
    // TODO Implement search for a specific file and add support to search
    // params

    Response response = null;
    try {
      List<String> lines = new Vector<String>();

      lines.add(path.getAbsolutePath());

      List<File> tmp = Arrays.asList(super.getPath().listFiles());

      Collections.sort(tmp, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {

          return o1.getName().compareToIgnoreCase(o2.getName());
        }
      });

      Collections.sort(tmp, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {

          return o1.isDirectory() && !o2.isDirectory() ? -1 : 1;
        }
      });

      for (File f : tmp) {

        StringBuffer sb = new StringBuffer();
        if (f.isDirectory()) {
          sb.append("Directory");
        } else {
          sb.append("         ");
        }

        sb.append("\t" + f.getName() + "\t");

        lines.add(sb.toString());
      }

      response = new Response(lines, null);
    } catch (Exception e) {
      response = new Response(null, e);
    }

    return response;
  }
View Full Code Here

    String tokens[] = command.split(" ");
    try {

      Command cmd = vault.getCommandObject(tokens[0], path);
      Response response = cmd.execCommand(tokens);

      this.path = cmd.getPath();

      if (response.isOk()) {
        for (String string : response.getLines()) {
          System.out.println(string);
        }
      } else {
        System.out.println("Exception raised...");
        System.out.println(response.getException().getMessage());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of net.eldiosantos.command.commands.response.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.