<commit_before><?php

class website_PageRessourceService extends BaseService
{
	const GLOBAL_SCREEN_NAME = 'screen';
	const GLOBAL_PRINT_NAME = 'print';
	const CHANGE_PAGE_EDITOR_NS = "http://www.rbs.fr/change/1.0/schema";

	/**
	 * @var f_web_CSSVariables
	 */
	private $skin;

	/**
	 * @var website_persistentdocument_page
	 */
	private $page;
	
	/**
	 * @var string
	 */
	private $templateType;

	
	/**
	 * @var website_PageRessourceService
	 */
	private static $instance;
	


	/**
	 * @return website_PageRessourceService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}


	/**
	 * @param f_web_CSSVariables $skin
	 */
	public function setSkin($skin)
	{
		$this->skin = $skin;
	}

	/**
	 * @return f_web_CSSVariables
	 */
	private function getSkin()
	{
		return $this->skin;
	}

	/**
	 * @return website_persistentdocument_page
	 */
	public function getPage()
	{
		return $this->page;
	}

	/**
	 * @param website_persistentdocument_page $page
	 */
	public function setPage($page)
	{
		$this->page = $page;
	}
	
	public function getTemplateType()
	{
		return $this->templateType;
	}

	/**
	 * @param website_persistentdocument_page $page
	 * @param boolean $throwException
	 * @return theme_persistentdocument_pagetemplate
	 */	
	public function getPageTemplate($page, $throwException = true)
	{		
		$template = theme_PagetemplateService::getInstance()->getByCodeName($page->getTemplate());
		if ($throwException && !$template)
		{
			throw new TemplateNotFoundException($page->getTemplate());
		}
		return $template;
	}
	
	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getPageDocType($page)
	{
		$template = $this->getPageTemplate($page, false);
		return  ($template) ? $template->getDocTypeDeclaration() : null;
	}	
	
	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getPagetemplateAsDOMDocument($page)
	{
		$this->setPage($page);
		$DOMDocument = $this->getPageTemplate($page)->getReplacedDOMContent();
		if ($DOMDocument->documentElement->hasAttribute('templateType'))
		{
			$this->templateType = $DOMDocument->documentElement->getAttribute('templateType');
		}
		else
		{
			$this->templateType = "freeLayout";
			$xslPath = FileResolver::getInstance() ->setPackageName('modules_website')
				->setDirectory('lib')->getPath('pageRenderContentTransform.xsl');
		}		
		$resultXPath = new DOMXPath($DOMDocument);
		$resultXPath->registerNameSpace('change', self::CHANGE_PAGE_EDITOR_NS);
		$htmlTemplate = $this->getChangeTemplateByContentType('html', $resultXPath);
		return $this->getPageContent($htmlTemplate, $resultXPath, $xslPath);
	}

	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getBackpagetemplateAsDOMDocument($page)
	{
		$this->setPage($page);
		$DOMDocument = $this->getPageTemplate($page)->getReplacedDOMContent();
		if ($DOMDocument->documentElement->hasAttribute('templateType'))
		{
			$this->templateType = $DOMDocument->documentElement->getAttribute('templateType');
		}
		else
		{
			$this->templateType = "freeLayout";
			$xslPath = FileResolver::getInstance() ->setPackageName('modules_website')
				->setDirectory('lib')->getPath('pageEditContentTransform.xsl');
		}
				
		$resultXPath = new DOMXPath($DOMDocument);
		$resultXPath->registerNameSpace('change', self::CHANGE_PAGE_EDITOR_NS);
		$xulTemplate = $this->getChangeTemplateByContentType('xul', $resultXPath);
		return $this->getPageContent($xulTemplate, $resultXPath, $xslPath);
	}
	
	/**
	 * @param String $type<commit_msg>[UPDATE] Prise en compte de nouveau type d'editeur de page<commit_after><?php

class website_PageRessourceService extends BaseService
{
	const GLOBAL_SCREEN_NAME = 'screen';
	const GLOBAL_PRINT_NAME = 'print';
	const CHANGE_PAGE_EDITOR_NS = "http://www.rbs.fr/change/1.0/schema";

	/**
	 * @var f_web_CSSVariables
	 */
	private $skin;

	/**
	 * @var website_persistentdocument_page
	 */
	private $page;
	
	/**
	 * @var string
	 */
	private $templateType;

	
	/**
	 * @var website_PageRessourceService
	 */
	private static $instance;
	


	/**
	 * @return website_PageRessourceService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}


	/**
	 * @param f_web_CSSVariables $skin
	 */
	public function setSkin($skin)
	{
		$this->skin = $skin;
	}

	/**
	 * @return f_web_CSSVariables
	 */
	private function getSkin()
	{
		return $this->skin;
	}

	/**
	 * @return website_persistentdocument_page
	 */
	public function getPage()
	{
		return $this->page;
	}

	/**
	 * @param website_persistentdocument_page $page
	 */
	public function setPage($page)
	{
		$this->page = $page;
	}
	
	public function getTemplateType()
	{
		return $this->templateType;
	}

	/**
	 * @param website_persistentdocument_page $page
	 * @param boolean $throwException
	 * @return theme_persistentdocument_pagetemplate
	 */	
	public function getPageTemplate($page, $throwException = true)
	{		
		$template = theme_PagetemplateService::getInstance()->getByCodeName($page->getTemplate());
		if ($throwException && !$template)
		{
			throw new TemplateNotFoundException($page->getTemplate());
		}
		return $template;
	}
	
	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getPageDocType($page)
	{
		$template = $this->getPageTemplate($page, false);
		return  ($template) ? $template->getDocTypeDeclaration() : null;
	}	
	
	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getPagetemplateAsDOMDocument($page)
	{
		$this->setPage($page);
		$DOMDocument = $this->getPageTemplate($page)->getReplacedDOMContent();
		if ($DOMDocument->documentElement->hasAttribute('templateType'))
		{
			$this->templateType = $DOMDocument->documentElement->getAttribute('templateType');
			$xslPath = FileResolver::getInstance() ->setPackageName('modules_website')
				->setDirectory('lib')->getPath($this->templateType . 'RenderContent.xsl');
		}
		else
		{
			$this->templateType = "freeLayout";
			$xslPath = FileResolver::getInstance() ->setPackageName('modules_website')
				->setDirectory('lib')->getPath('pageRenderContentTransform.xsl');
		}		
		$resultXPath = new DOMXPath($DOMDocument);
		$resultXPath->registerNameSpace('change', self::CHANGE_PAGE_EDITOR_NS);
		$htmlTemplate = $this->getChangeTemplateByContentType('html', $resultXPath);
		return $this->getPageContent($htmlTemplate, $resultXPath, $xslPath);
	}

	/**
	 * @param website_persistentdocument_page $page
	 * @return DOMDocument
	 */
	public function getBackpagetemplateAsDOMDocument($page)
	{
		$this->setPage($page);
		$DOMDocument = $this->getPageTemplate($page)->getReplacedDOMContent();
		if ($DOMDocument->documentElement->hasAttribute('templateType'))
		{
			$this->templateType = $DOMDocument->documentElement->getAttribute('templateType');
			$xslPath = FileResolver::getInstance()->setPackageName('modules_website')
				->setDirectory('lib')->getPath($this->templateType . 'EditContent.xsl');	
		}
		else
		{
			$this->templateType = "freeLayout";
			$xslPath = FileResolver::getInstance() ->setPackageName('modules_website')
				->setDirectory('lib')->getPath('pageEditContentTransform.xsl');
		}
				
		$resultXPath = new DOMXPath($DOMDocument);
		$resultXPath->registerNameSpace('change', self::CHANGE_PAGE_EDITOR_NS);
		$xulTemplate = $this->getChangeTemplateByContentType('xul', $resultXPath);
		return $this->getPageContent($xulTemplate, $resultXPath, $xslPath);
	}
	
	/**
	 * @param String $type
{'fraction_non_alphanumeric': 0.14915560139229084, 'fraction_numerical': 0.00051566327188346, 'mean_word_length': 4.886191198786039, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5926088', 'n_tokens_mistral': 2699, 'n_tokens_neox': 2446, 'n_words': 393}