<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  Fork unstable media GmbH
//  Copyright 2006-2008 Fork unstable media GmbH
//  All Rights Reserved.
//
//  NOTICE: Fork unstable media permits you to use, modify, and distribute this
//  file in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package reprise.core
{
	import reprise.core.Application;
	import reprise.core.CoreResourceLoader;
	import reprise.i18n.II18NService;
	import reprise.services.tracking.ITrackingService;
	
	import flash.display.LoaderInfo;
	import flash.utils.ByteArray;	

	public class ApplicationContext
	{
		/***************************************************************************
		*                             Public properties                            *
		***************************************************************************/
		public var coreResourceLoader:CoreResourceLoader;
		public var applicationURL:String;
		public var applicationParameters:Object;
		
		
		/***************************************************************************
		*                           Protected properties                           *
		***************************************************************************/
		protected static var g_mainContext:ApplicationContext;
		protected var m_application:Application;
		
		protected var m_i18nService : II18NService;
		protected var m_trackingService : ITrackingService;
		
		
		/***************************************************************************
		*                              Public methods                              *
		***************************************************************************/
		public function ApplicationContext(application:Application, loaderInfo:LoaderInfo)
		{
//			if (!g_mainContext)
//			{
//				g_mainContext = this;
//				coreResourceLoader = new CoreResourceLoader(this);
//			}
//			else
//			{
//				coreResourceLoader = g_mainContext.coreResourceLoader;
//			}
			/*
			 * TODO: find a way to use a global loader for all applications while correctly 
			 * resolving relative URLs
			 */
			coreResourceLoader = new CoreResourceLoader(this);
			
			var objCopy:ByteArray = new ByteArray();
			objCopy.writeObject(loaderInfo.parameters);
			objCopy.position = 0;
			applicationURL = application.applicationURL();
			applicationParameters = objCopy.readObject();
		}
		
		public function setI18NService(i18nService : II18NService) : void
		{
			m_i18nService = i18nService;
		}
		
		public function setTrackingService(
			trackingService : ITrackingService) : void
		{
			m_trackingService = trackingService;
		}
		
		public function i18n(key : String, defaultReturnValue : * = null) : *
		{
			if (!m_i18nService)
			{
				log('w No i18n service set, can\'t resolve key "' + key + '"');
				return defaultReturnValue == null ? key : defaultReturnValue;
			}
			var result : *;
			if (m_i18nService.keyExists(key))
			{
				result = m_i18nService.contentByKey(key);
				if (typeof result == "string")
				{
					result = (result as String).split('\r\n').join('\n').split('\r').join('\n');
				}
			}
			if (result == null)
			{
				log('w No i18n result found for key "' + key + '"');
				return defaultReturnValue == null ? key : defaultReturnValue;
			}
			return result;
		}
		
		public function track(trackingId : String) : void
		{
			m_trackingService.track(trackingId);
		}
	}
}<commit_msg>- bugfix: ApplicationContext always used its own loaderInfo to gather applicationParameters. In almost all cases, this is wrong as soon as the application is loaded into another SWF. This fix uses the Stage's loaderInfo and afterwards merges any parameters defined for the application's own SWF.<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  Fork unstable media GmbH
//  Copyright 2006-2008 Fork unstable media GmbH
//  All Rights Reserved.
//
//  NOTICE: Fork unstable media permits you to use, modify, and distribute this
//  file in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package reprise.core
{
	import reprise.core.Application;
	import reprise.core.CoreResourceLoader;
	import reprise.i18n.II18NService;
	import reprise.services.tracking.ITrackingService;
	
	import flash.display.LoaderInfo;
	import flash.utils.ByteArray;	

	public class ApplicationContext
	{
		/***************************************************************************
		*                             Public properties                            *
		***************************************************************************/
		public var coreResourceLoader:CoreResourceLoader;
		public var applicationURL:String;
		public var applicationParameters:Object;
		
		
		/***************************************************************************
		*                           Protected properties                           *
		***************************************************************************/
		protected static var g_mainContext:ApplicationContext;
		protected var m_application:Application;
		
		protected var m_i18nService : II18NService;
		protected var m_trackingService : ITrackingService;
		
		
		/***************************************************************************
		*                              Public methods                              *
		***************************************************************************/
		public function ApplicationContext(application:Application, loaderInfo:LoaderInfo)
		{
//			if (!g_mainContext)
//			{
//				g_mainContext = this;
//				coreResourceLoader = new CoreResourceLoader(this);
//			}
//			else
//			{
//				coreResourceLoader = g_mainContext.coreResourceLoader;
//			}
			/*
			 * TODO: find a way to use a global loader for all applications while correctly 
			 * resolving relative URLs
			 */
			coreResourceLoader = new CoreResourceLoader(this);
			
			//copy parameters of stage loader
			var objCopy:ByteArray = new ByteArray();
			objCopy.writeObject(application.stage.loaderInfo.parameters);
			objCopy.position = 0;
			applicationURL = application.applicationURL();
			applicationParameters = objCopy.readObject();
			//merge parameters of application loader if it's not the same as the stage loader
			if (loaderInfo.url != application.stage.loaderInfo.url)
			{
				for (var i : String in loaderInfo.parameters)
				{
					applicationParameters[i] = loaderInfo.parameters[i];
				}
			}
		}
		
		public function setI18NService(i18nService : II18NService) : void
		{
			m_i18nService = i18nService;
		}
		
		public function setTrackingService(
			trackingService : ITrackingService) : void
		{
			m_trackingService = trackingService;
		}
		
		public function i18n(key : String, defaultReturnValue : * = null) : *
		{
			if (!m_i18nService)
			{
				log('w No i18n service set, can\'t resolve key "' + key + '"');
				return defaultReturnValue == null ? key : defaultReturnValue;
			}
			var result : *;
			if (m_i18nService.keyExists(key))
			{
				result = m_i18nService.contentByKey(key);
				if (typeof result == "string")
				{
					result = (result as String).split('\r\n').join('\n').split('\r').join('\n');
				}
			}
			if (result == null)
			{
				log('w No i18n result found for key "' + key + '"');
				return defaultReturnValue == null ? key : defaultReturnValue;
			}
			return result;
		}
		
		public function track(trackingId : String) : void
		{
			m_trackingService.track(trackingId);
		}
	}
}
{'fraction_non_alphanumeric': 0.2386230277741557, 'fraction_numerical': 0.010170817577259095, 'mean_word_length': 2.7414634146341466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1772780', 'n_tokens_mistral': 2322, 'n_tokens_neox': 1865, 'n_words': 484}