﻿<?xml version="1.0" encoding="utf-8" ?> 
<application-components>
		<application-component id="dwac">
		<![CDATA[
		component_init:function(){

			this.setTemplateIsEngine(1);
			this.getPointers().task_service = new org.cote.js.task.TaskServiceImpl();
			
			/// The processor invocation is in a global context when passed through the task service
			/// Use createHandler to 
		  this.createHandler("processor",0,0,1);
		  
		},
		_handle_processor : function(Service, ParentTask, TaskName, Value){
				//org.cote.js.message.MessageService.sendMessage(Value + "-" + this._handle_xhtml_token(2,Value),"200.4");
				return this._handle_xhtml_token(2,Value);
		},
		component_post_init:function(){

				 var sU = this.getStatus().DWacControlUri;
				 if(!sU) sU = this.getContainer().getAttribute("DWacControlUri");
				 var sT = this.getStatus().DWacControlTask;
				 if(!sT) sT = this.getContainer().getAttribute("DWacControlTask");
				 var sTId = this.getStatus().DWacTemplateId;
				 if(!sTId) sTId = this.getContainer().getAttribute("DWacTemplateId");

				 if(typeof sTId != "string" || sTId.length == 0) sTId = 0;
					if(typeof sU == "string" && sU.length > 0){

							if(typeof sT == "string" && sT.length > 0){
								this.getPointers().dwac_task = this.getPointers().task_service.executeTaskLoader(
									"dwac_loader",
									"xml",
									sU,
									"import-task",
									"dwac_driver",
									this._prehandle_processor
								);
							}
							else{
								this.LoadDwacTemplate(sU, sTId);
							}
					}
		},
		handle_dwac_task : function(s, v){

				var sU = this.getContainer().getAttribute("DWacControlUri");
				var sTId = this.getContainer().getAttribute("DWacTemplateId");
				if(typeof sTId != "string" || sTId.length == 0) sTId = 0;
				if(typeof sU == "string" && sU.length > 0) this.LoadDwacTemplate(sU,sTId);
		},
		LoadDwacTemplate : function(sPath, sTemplateId){
				  this.getStatus().dwac_template_path = sPath;
					this.loadTemplate(sPath, sTemplateId);			
		},
		GetDwacTemplatePath : function(){
			return this.getStatus().dwac_template_path;
		},
		local_handle_xhtml_token : function(iType, sTokenValue){
			sTokenValue = sTokenValue.replace(/\$\{dwac\.path\}/g,this.GetDwacTemplatePath());
			return sTokenValue;
		}
		]]>
		</application-component>
</application-components>


