private ModelMap browse(String dir) {
   ModelMap model = new ModelMap();
   String decodedDir = pathEncodingUtils.decodeDir(dir);
   JsTreeFile resource = this.serverAccess.get(decodedDir, userParameters, false, false);
   pathEncodingUtils.encodeDir(resource);
   model = new ModelMap("resource", resource);
   List<JsTreeFile> files = this.serverAccess.getChildren(decodedDir, userParameters);
   Collections.sort(files);
   pathEncodingUtils.encodeDir(files);
   model.put("files", files);
   model.put("currentDir", dir);
   ListOrderedMap parentsEncPathes = pathEncodingUtils.getParentsEncPathes(resource);
   model.put("parentsEncPathes", parentsEncPathes);
   return model;
 }
  @RequestMapping(
      value = {"VIEW"},
      params = {"action=browseWai"})
  public ModelAndView browseWai(
      RenderRequest request,
      RenderResponse response,
      @RequestParam(required = false) String dir,
      @RequestParam(required = false) String msg) {
    this.init(request);

    String decodedDir = pathEncodingUtils.decodeDir(dir);

    if (!serverAccess.isInitialized(userParameters)) {
      serverAccess.initializeServices(userParameters);
    }

    ModelMap model;
    if (!(dir == null || dir.length() == 0 || decodedDir.equals(JsTreeFile.ROOT_DRIVE))) {
      if (this.serverAccess.formAuthenticationRequired(decodedDir, userParameters)) {
        ListOrderedMap parentPathes = pathEncodingUtils.getParentsEncPathes(decodedDir, null, null);
        // we want to get the (last-1) key of sortedmap "parentPathes"
        String parentDir = (String) parentPathes.get(parentPathes.size() - 2);
        model = new ModelMap("currentDir", dir);
        model.put("parentDir", parentDir);
        model.put(
            "username",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getUsername());
        model.put(
            "password",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getPassword());
        if (msg != null) model.put("msg", msg);
        return new ModelAndView("authenticationForm-portlet-wai", model);
      }
    }

    model = browse(dir);
    FormCommand command = new FormCommand();
    model.put("command", command);
    if (msg != null) model.put("msg", msg);
    return new ModelAndView("view-portlet-wai", model);
  }
  @RequestMapping(
      value = {"VIEW"},
      params = {"action=browseMobile"})
  public ModelAndView browseMobile(
      RenderRequest request, RenderResponse response, @RequestParam String dir) {
    this.init(request);

    final PortletPreferences prefs = request.getPreferences();
    boolean forceMaximized4Mobile =
        "true".equals(prefs.getValue(PREF_FORCE_MAXIMIZED_4_MOBILE, "true"));
    String forceWindowState4Mobile =
        forceMaximized4Mobile
            ? WindowState.MAXIMIZED.toString()
            : request.getWindowState().toString();

    String decodedDir = pathEncodingUtils.decodeDir(dir);

    ModelMap model;
    if (!(dir == null || dir.length() == 0 || decodedDir.equals(JsTreeFile.ROOT_DRIVE))) {
      if (this.serverAccess.formAuthenticationRequired(decodedDir, userParameters)) {
        ListOrderedMap parentPathes = pathEncodingUtils.getParentsEncPathes(decodedDir, null, null);
        // we want to get the (last-1) key of sortedmap "parentPathes"
        String parentDir = (String) parentPathes.get(parentPathes.size() - 2);
        model = new ModelMap("currentDir", dir);
        model.put("parentDir", parentDir);
        model.put(
            "username",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getUsername());
        model.put(
            "password",
            this.serverAccess.getUserPassword(decodedDir, userParameters).getPassword());
        model.put("forceWindowState4Mobile", forceWindowState4Mobile);
        return new ModelAndView("authenticationForm-portlet-mobile", model);
      }
    }
    model = browse(dir);
    model.put("forceWindowState4Mobile", forceWindowState4Mobile);
    return new ModelAndView("view-portlet-mobile", model);
  }
  @RequestMapping("VIEW")
  protected ModelAndView renderView(RenderRequest request, RenderResponse response)
      throws Exception {
    this.init(request);
    final PortletPreferences prefs = request.getPreferences();
    String defaultPortletView = prefs.getValue(PREF_PORTLET_VIEW, STANDARD_VIEW);
    String[] prefsDefaultPathes = prefs.getValues(PREF_DEFAULT_PATH, null);
    if (log.isDebugEnabled()) {
      log.debug(PREF_DEFAULT_PATH + " preference : ");
      for (String prefDefaultPath : prefsDefaultPathes) log.debug("- " + prefDefaultPath);
    }

    boolean showHiddenFiles = "true".equals(prefs.getValue(PREF_SHOW_HIDDEN_FILES, "false"));
    userParameters.setShowHiddenFiles(showHiddenFiles);

    UploadActionType uploadOption =
        UploadActionType.valueOf(
            prefs.getValue(PREF_UPLOAD_ACTION_EXIST_FILE, UploadActionType.OVERRIDE.toString()));
    userParameters.setUploadOption(uploadOption);

    serverAccess.initializeServices(userParameters);

    String defaultPath = serverAccess.getFirstAvailablePath(userParameters, prefsDefaultPathes);
    log.info("defaultPath will be : " + defaultPath);
    defaultPath = pathEncodingUtils.encodeDir(defaultPath);

    if (userAgentInspector.isMobile(request)) {
      return this.browseMobile(request, response, defaultPath);
    } else {
      if (MOBILE_VIEW.equals(defaultPortletView))
        return this.browseMobile(request, response, defaultPath);
      else if (WAI_VIEW.equals(defaultPortletView))
        return this.browseWai(request, response, defaultPath, null);
      else return this.browseStandard(request, response, defaultPath);
    }
  }