PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/cocktail/resource/php/ContainerLoader.hx

http://github.com/silexlabs/Cocktail
Haxe | 75 lines | 26 code | 8 blank | 41 comment | 0 complexity | 851c2e2c27c7d7e75cace87e211442ee MD5 | raw file
 1/*
 2This file is part of Silex - see http://projects.silexlabs.org/?/silex
 3
 4Silex is Š 2010-2011 Silex Labs and is released under the GPL License:
 5
 6This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 
 7
 8This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 9
10To read the license please visit http://www.gnu.org/copyleft/gpl.html
11*/
12package cocktail.resource.php;
13
14import haxe.Http;
15import haxe.Log;
16import php.Web;
17import cocktail.domElement.ContainerDOMElement;
18import cocktail.domElement.DOMElement;
19import cocktail.resource.abstract.AbstractResourceLoader;
20import cocktail.resource.ResourceData;
21
22/**
23 * This is the Container loader implementation for the PHP runtime. It is used to 
24 * load complex object, such as a skin formed of multiple HTML tags. It is loaded from
25 * an HTML file
26 * 
27 * @author	Raphael HARMEL
28 * @date	2011-08-03
29 */
30class ContainerLoader extends AbstractResourceLoader
31{
32	/**
33	 * class constructor
34	 */
35	public function new() 
36	{
37		super();
38	}
39	
40	//////////////////////////////////////////////////////////////////////////////////////////
41	// Overriden method to implement PHP specific behaviour
42	//////////////////////////////////////////////////////////////////////////////////////////
43
44	/**
45	 * Starts the file loading and converts the relative url to absolute url.
46	 * The default implementation is to load an url and return the result as an Xml.
47	 * @param	url the url to load
48	 */
49	override private function doLoad(relativeUrl:String):Void 
50	{
51		// get server port
52		var port:Int = untyped __var__('_SERVER', 'SERVER_PORT');
53		
54		// converts relative url to absolute url
55		var absoluteUrl:String = 'http://' + Web.getHostName() + ':' + port + Web.getURI() + relativeUrl;
56
57		// call parent method so that text file content is retreived and onLoadComplete callbac is called
58		super.doLoad(absoluteUrl);
59	}
60	
61	/**
62	 * When the HTML has been loaded, set the loaded HTML as the
63	 * native DOM of the Container DOMElement
64	 * Xml is used for easier data structuring
65	 * @param	data the loaded HTML
66	 */
67	override private function onLoadComplete(data:Dynamic):Void
68	{
69		// construction of the Xml element containing the container
70		var domElement:ContainerDOMElement = new ContainerDOMElement(Xml.parse(data));
71		
72		// calls initial callback
73		_onLoadCompleteCallback(domElement);
74	}
75}