/**
  * Gets a singleton instance 
  *
  * @return __ClientNotificator
  */
 public static function &getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new __ClientNotificator();
     }
     return self::$_instance;
 }
 /**
  * Creates an ajax message with current server end-point values
  *
  * @param __IRequest $request
  * @param __IResponse $response
  */
 public function postFilter(__IRequest &$request, __IResponse &$response)
 {
     $client_notificator = __ClientNotificator::getInstance();
     //notify to client:
     $client_notificator->notify();
     //clear dirty components to avoid notify again in next requests:
     $client_notificator->clearDirty();
 }
 public function refresh()
 {
     if ($this->_composite_writer != null) {
         $this->setAsUnsynchronized();
         $this->_composite_writer->startRender($this);
         $response = __ResponseFactory::getInstance()->createResponse();
         //clear content set by responseWriters:
         $this->_content .= $response->getContent();
         //mark the current instance as dirty:
         __ClientNotificator::getInstance()->setDirty($this);
     }
 }
 public function dispatch(__IRequest &$request, __IResponse &$response)
 {
     $front_controller = self::$_instance;
     self::$_instance = $this;
     //now call the parent dispatch method:
     parent::dispatch($request, $response);
     //finally restore the previous front controller singleton
     self::$_instance = $front_controller;
     //and clear the response writer:
     __ResponseWriterManager::getInstance()->clear();
     __ClientNotificator::getInstance()->clearDirty();
     @ob_clean();
     //clear the output buffer
 }
 /**
  * Redirect the web flow to the given uri
  *
  * @param __Uri|string the uri (or an string representing the uri) to redirect to
  * @param __IRequest &$request
  */
 public function redirect($uri, __IRequest &$request = null, $redirection_code = null)
 {
     if (is_string($uri)) {
         $uri = __UriFactory::getInstance()->createUri($uri);
     } else {
         if (!$uri instanceof __Uri) {
             throw __ExceptionFactory::getInstance()->createException('Unexpected type for uri parameter: ' . get_class($uri));
         }
     }
     $url = $uri->getUrl();
     $message = new __AsyncMessage();
     $message->getHeader()->setLocation($url);
     $this->getResponse()->addContent($message->toJson());
     $client_notificator = __ClientNotificator::getInstance();
     //notify to client:
     $client_notificator->notify();
     //clear dirty components to avoid notify again in next requests:
     $client_notificator->clearDirty();
 }
 public function endRender()
 {
     parent::endRender();
     $async_message = __ClientNotificator::getInstance()->getStartupNotification($this->_view_code);
     if ($async_message != null && ($async_message->getHeader()->getStatus() != __AsyncMessageHeader::ASYNC_MESSAGE_STATUS_OK || $async_message->hasPayload())) {
         $response_writer_manager = __ResponseWriterManager::getInstance();
         if ($response_writer_manager->hasResponseWriter('javascript')) {
             $javascript_response_writer = $response_writer_manager->getResponseWriter('javascript');
         } else {
             $javascript_response_writer = new __JavascriptOnDemandResponseWriter('javascript');
             $response_writer_manager->addResponseWriter($javascript_response_writer);
         }
         if ($response_writer_manager->hasResponseWriter('setup-client-view')) {
             $setup_client_view_rw = $response_writer_manager->getResponseWriter('setup-client-view');
         } else {
             $setup_client_view_rw = new __JavascriptOnDemandResponseWriter('setup-client-view');
             $setup_client_view_rw->setLoadAfterDomLoaded(false);
             $javascript_response_writer->addResponseWriter($setup_client_view_rw);
         }
         $javascript_response_writer->addJsCode('__MessageProcessor.process(Object.extend(new __Message(), ' . $async_message->toJson() . '));', __JavascriptOnDemandResponseWriter::JS_CODE_POSITION_BOTTOM);
     }
 }
 /**
  * Updates the sitemap
  *
  * @param __UIEvent $event
  */
 public function updateSitemap_click(__UIEvent &$event)
 {
     $this->getComponent('updateStatus')->setText(" Crawling the site, please wait...");
     $this->getComponent('updateStatus')->crawled_links = 0;
     __ClientNotificator::getInstance()->notify();
     $sitemap = __SiteMap::getInstance();
     $sitemap->update(array($this, 'updateUpdateStatus'));
     $this->getComponent('updateStatus')->setText(" Calculate page rank, please wait...");
     __ClientNotificator::getInstance()->notify();
     $page_ranker = new __PageRanker($sitemap);
     $page_ranker->calculate();
     $sitemap->saveResults();
     $this->getComponent('updateStatus')->setText("");
     $last_update = __SiteMap::getInstance()->getLastUpdate();
     if ($last_update !== null) {
         $this->getComponent('lastUpdate')->setText(date("Y/m/d H:i:s", $last_update));
     }
     $analyzerSection = $this->getComponent('analyzerSection');
     $analyzerSection->setController('siteAnalyzerResults');
     $analyzerSection->setAction('generalAnalysis');
     $analyzerSection->refresh();
 }
 /**
  * Gets a component associated with a given identifier
  *
  * @param string $component_id The component identifier
  * @return __IComponent
  */
 public function &getComponent($component_id)
 {
     $return_value = null;
     if (key_exists($component_id, $this->_components)) {
         $return_value =& $this->_components[$component_id];
         if ($return_value != null) {
             __ClientNotificator::getInstance()->setDirty($return_value);
         }
     } else {
         if (key_exists($component_id, $this->_non_poolable_components)) {
             $return_value =& $this->_non_poolable_components[$component_id];
         }
     }
     return $return_value;
 }
 public function setProgress($progress)
 {
     if (is_numeric($progress)) {
         if ($progress < 0) {
             $progress = 0;
         } else {
             if ($progress > 100) {
                 $progress = 100;
             }
         }
         $this->_progress = $progress;
         __ClientNotificator::getInstance()->notifyProgress($this);
     } else {
         throw __ExceptionFactory::getInstance()->createException('Wrong progress value: ' . $progress . '. Progress must be a numeric value between 0 and 100.');
     }
 }