/**
  * Loads a page instance.
  * This method will create a page instance or load it from memory.
  * If the page name contains module ID, the module will be also loaded.
  * Errors happened during the loading will be handled using the error handler.
  * @param string the page name (either PageType or ModuleName:PageType).
  * @return TPage the loaded page instance
  * @see createComponent()
  */
 public function loadPage($type)
 {
     if (isset($this->pages[$type])) {
         return $this->pages[$type];
     }
     $type = trim($type, ':');
     $pos = strpos($type, ':');
     if ($pos === false) {
         $moduleName = '';
         $pageName = $type;
     } else {
         $moduleName = substr($type, 0, $pos);
         $pageName = substr($type, $pos + 1);
     }
     try {
         if (empty($pageName)) {
             throw new TPageNotDefinedException("[empty]");
         }
         // user authentication
         $role = $this->getRequiredRole($moduleName, $pageName);
         if (!is_null($role)) {
             if (!$this->user->isAuthenticated()) {
                 $this->user->onAuthenticationRequired($type);
                 $this->errorHandler->handleError(TErrorHandler::CASE_UNAUTHORIZED, new TPageUnauthorizedException($type));
             }
         }
         // creating the module and page objects
         $module = empty($moduleName) ? null : $this->loadModule($moduleName);
         if (!pradoImportClass($pageName)) {
             throw new TPageNotDefinedException($pageName);
         }
         $page = $this->createComponent($pageName, $pageName);
         if (!$page instanceof TPage) {
             // will use is_subclass_of since PHP 5.0.3
             throw new TPageNotDefinedException($pageName);
         }
         $page->setModule($module);
         // page authorization
         $authorized = is_null($role) ? true : $this->user->isInRole($role);
         if ($authorized) {
             $authorized = $page->onAuthorize($this->user);
         }
         if ($authorized) {
             return $page;
         } else {
             $this->user->onAuthorizationRequired($page);
             $this->errorHandler->handleError(TErrorHandler::CASE_UNAUTHORIZED, new TPageUnauthorizedException($type));
         }
     } catch (TPageNotDefinedException $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_PAGENOTFOUND, $e);
     } catch (TModuleNotDefinedException $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_PAGENOTFOUND, $e);
     } catch (Exception $e) {
         $this->errorHandler->handleError(TErrorHandler::CASE_INTERNALERROR, $e);
     }
 }