<commit_before><?php
/**
 * @version     $Id$
 * @package     Nooku_Components
 * @subpackage  Files
 * @copyright   Copyright (C) 2011 - 2012 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Node Controller Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/ercanozkaya>
 * @package     Nooku_Components
 * @subpackage  Files
 */

class ComFilesControllerDefault extends ComDefaultControllerDefault
{
	protected function _initialize(KConfig $config)
	{
		$config->append(array(
			'persistable' => false,
			'request' => array(
				'container' => 'files-files'
			),
			'limit' => array('max' => 1000)
		));

		parent::_initialize($config);
	}

	public function getRequest()
	{
		$request = parent::getRequest();
		// "e_name" is needed to be compatible with com_content of Joomla
		if ($request->e_name) {
			$request->editor = $request->e_name;
		}

		// "config" state is only used in HMVC requests and passed to the JS application
		if ($this->isDispatched()) {
			unset($request->config);
		}

		
		return $request;
	}

	protected function _actionCopy(KCommandContext $context)
	{
		$data = $this->getModel()->getItem();

		if(!$data->isNew())
		{
			$data->setData(KConfig::unbox($context->data));

			//Only throw an error if the action explicitly failed.
			if($data->copy() === false)
			{
				$error = $data->getStatusMessage();
                $context->response->setStatus(
                    KHttpResponse::INTERNAL_SERVER_ERROR, $error ? $error : 'Copy Action Failed'
                );
			}
			else
            {
                $context->reponse->setStatus(
                    $data->getStatus() === KDatabase::STATUS_CREATED ? KHttpResponse::CREATED : KHttpResponse::NO_CONTENT
                );
            }
		}
		else $context->response->setStatus(KHttpResponse::NOT_FOUND, 'Resource Not Found');

		return $data;
	}

	protected function _actionMove(KCommandContext $context)
	{
		$data = $this->getModel()->getItem();

		if(!$data->isNew())
		{
			$data->setData(KConfig::unbox($context->data));

			//Only throw an error if the action explicitly failed.
			if($data->move() === false)
			{
				$error = $data->getStatusMessage();
				$context->response->setStatus(
                    KHttpResponse::INTERNAL_SERVER_ERROR, $error ? $error : 'Move Action Failed'
				);

			}
			else
            {
                $context->response->setStatus(
                    $data->getStatus() === KDatabase::STATUS_CREATED ? KHttpResponse::CREATED : KHttpResponse::NO_CONTENT
                );
            }
		}
		else $context->response->setStatus(KHttpResponse::NOT_FOUND, 'Resource Not Found');

		return $data;
	}

	/**
	 * Overridden method to be able to use it with both resource and service controllers
	 */
	protected function _actionGet(KCommandContext $context)
	{
		if ($this->getIdentifier()->name == 'image' || ($this->getIdentifier()->name == 'file' && $this->getRequest()->format == 'html'))
		{
            JFactory::getLanguage()->load($this->getIdentifier()->package);

			$result = $this->getView()->display();
			return $result;
		}

		return parent::_actionGet($context);

	}
	
	/**
	 * Copied to allow 0 as a limit
	 * 
	 * @param KCommandContext $context
	 */
	protected function _actionBrowse(KCommandContext $context)
	{
	    if($this->isDispatched())
	    {
	        $limit = $this->getModel()->get('limit');

	        //If limit is empty use default
	        if(empty($limit) && $limit !== 0) {
	            $limit = $this->_limit->default;
	        }
	
	        //Force the maximum limit
	        if($limit > $this->_limit->max) {
	            $limit = $this->_limit->max;
	        }
	
	        $this->limit = $limit;
	    }
	
	    $data = $this->getModel()->getList();
		return $data;
	}
}
<commit_msg>Synced with changes in framework.<commit_after><?php
/**
 * @version     $Id$
 * @package     Nooku_Components
 * @subpackage  Files
 * @copyright   Copyright (C) 2011 - 2012 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Node Controller Class
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/ercanozkaya>
 * @package     Nooku_Components
 * @subpackage  Files
 */

class ComFilesControllerDefault extends ComDefaultControllerDefault
{
	protected function _initialize(KConfig $config)
	{
		$config->append(array(
			'persistable' => false,
			'request' => array(
				'container' => 'files-files'
			),
			'limit' => array('max' => 1000)
		));

		parent::_initialize($config);
	}

	public function getRequest()
	{
		$request = parent::getRequest();

		// "config" state is only used in HMVC requests and passed to the JS application
		if ($this->isDispatched()) {
			unset($request->query->config);
		}

		return $request;
	}

	protected function _actionCopy(KCommandContext $context)
	{
		$entity = $this->getModel()->getRow();

		if(!$entity->isNew())
		{
			$entity->setData(KConfig::unbox($context->request->data->toArray()));

			//Only throw an error if the action explicitly failed.
			if($entity->copy() === false)
			{
				$error = $entity->getStatusMessage();
                throw new KControllerExceptionActionFailed($error ? $error : 'Copy Action Failed');
			}
			else
            {
                $context->response->setStatus(
                    $entity->getStatus() === KDatabase::STATUS_CREATED ? self::STATUS_CREATED : self::STATUS_UNCHANGED
                );
            }
		}
		else throw new KControllerExceptionNotFound('Resource Not Found');

		return $entity;
	}

	protected function _actionMove(KCommandContext $context)
	{
		$entity = $this->getModel()->getRow();

		if(!$entity->isNew())
		{
			$entity->setData(KConfig::unbox($context->request->data->toArray()));

			//Only throw an error if the action explicitly failed.
			if($entity->move() === false)
			{
				$error = $entity->getStatusMessage();
                throw new KControllerExceptionActionFailed($error ? $error : 'Move Action Failed');
			}
			else
            {
                $context->response->setStatus(
                    $entity->getStatus() === KDatabase::STATUS_CREATED ? self::STATUS_CREATED : self::STATUS_UNCHANGED
                );
            }
		}
		else throw new KControllerExceptionNotFound('Resource Not Found');

		return $entity;
	}

	/**
	 * Overridden method to be able to use it with both resource and service controllers
	 */
	protected function _actionRender(KCommandContext $context)
	{
		if ($this->getIdentifier()->name == 'image' || ($this->getIdentifier()->name == 'file' && $context->request->getFormat() == 'html'))
		{
            JFactory::getLanguage()->load($this->getIdentifier()->package);

			$result = $this->getView()->display();
			return $result;
		}

		return parent::_actionRender($context);
	}
	
	/**
	 * Copied to allow 0 as a limit
	 * 
	 * @param KCommandContext $context
	 */
	protected function _actionBrowse(KCommandContext $context)
	{
	    if($this->isDispatched())
	    {
	        $limit = $this->getModel()->get('limit');

	        //If limit is empty use default
	        if(empty($limit) && $limit !== 0) {
	            $limit = $this->_limit->default;
	        }
	
	        //Force the maximum limit
	        if($limit > $this->_limit->max) {
	            $limit = $this->_limit->max;
	        }
	
	        $this->limit = $limit;
	    }
	
	    $entity = $this->getModel()->getRowset();
		return $entity;
	}
}

{'fraction_non_alphanumeric': 0.15603584607274645, 'fraction_numerical': 0.003953610964681075, 'mean_word_length': 2.738423645320197, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4263326', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2266, 'n_words': 484}