/**
  * Action to rename a file or directory
  *
  * Every argument to this method is a part of the rename path. eg.
  * $fb->renameAction('application', 'data', 'test.txt') would rename to application/data/test.txt
  * @return null
  */
 public function renameAction()
 {
     $pieces = func_get_args();
     $file = $this->getFileFromPieces($pieces, false);
     if (!$file) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
     } else {
         $absoluteFile = new File($this->fileBrowser->getRoot(), $file);
         if (!$absoluteFile->exists()) {
             $this->addError(self::TRANSLATION_ERROR_EXIST_NOT, array('path' => $file));
             $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         }
     }
     if ($this->response->getStatusCode() == Response::STATUS_CODE_NOT_FOUND) {
         $this->response->setView(new BaseView());
         return;
     }
     $basePath = $this->request->getBasePath();
     $parent = $absoluteFile->getParent();
     $redirectUrl = $basePath . '/' . self::ACTION_PATH . '/' . $this->fileBrowser->getPath($parent, false);
     $form = new RenameForm($basePath . '/' . self::ACTION_RENAME . '/' . $file, $file);
     if ($form->isSubmitted()) {
         if ($form->isCancelled()) {
             $this->response->setRedirect($redirectUrl);
             return;
         }
         try {
             $form->validate();
             $name = $form->getFileName();
             $name = String::safeString($name);
             $destination = new File($parent, $name);
             if ($destination->getAbsolutePath() != $absoluteFile->getPath() && $destination->exists()) {
                 $error = new ValidationError(self::TRANSLATION_ERROR_EXIST, '%path% exists already', array('path' => $this->fileBrowser->getPath($destination, false)));
                 $exception = new ValidationException();
                 $exception->addErrors(RenameForm::FIELD_NAME, array($error));
                 throw $exception;
             }
             $absoluteFile->move($destination);
             $this->addInformation(self::TRANSLATION_INFORMATION_RENAMED, array('old' => $file->getName(), 'new' => $name));
             $this->response->setRedirect($redirectUrl);
             return;
         } catch (ValidationException $exception) {
             $form->setValidationException($exception);
         } catch (Exception $exception) {
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
             $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage()));
             $this->response->setStatusCode(Response::STATUS_CODE_SERVER_ERROR);
         }
     }
     if (!$absoluteFile->isWritable() || !$absoluteFile->getParent()->isWritable()) {
         $this->addWarning(self::TRANSLATION_ERROR_WRITABLE, array('path' => $file));
         $form->setIsDisabled(true, RenameForm::BUTTON_SUBMIT);
     }
     $view = new RenameView($form, $file);
     $view->setPageTitle(Module::TRANSLATION_FILE_BROWSER, true);
     $this->response->setView($view);
 }