
function WFSEngine_clearCommunication() {
	wfscommunication.document.write('<html><head></head><body><form id="ogcform" name="ogcform" action="'+this.url+'" method="POST"><input type="hidden" name="meth" value="SOAP"/><input type="hidden" name="data" value=""/><input type="hidden" name="node" value=""/><input type="hidden" name="application" value=""/></form></body></html>');
	//wfscommunication.document.write('<html><head></head><body><form id="ogcform" name="ogcform" action="'+this.url+'" method="POST"><input type="hidden" name="meth" value="SOAP"/><input type="hidden" name="data" value=""/></form></body></html>');
	
}

/*
 * Invia una richiesta al motore java. Il metodo è asincrono. Ciò significa che
 * non viene attesa la risposta. Tale risposta verrà inviata alla funzione <responseHandler>,
 * oppure al metodo <responseHandler> di <responseHandlerObject>.
 * Il tipo di richiesta viene indicata dal parametro <msgAction>. Ogni tipo di richiesta 
 * può prevedere una serie di parametri aggiuntivi.
 */
function WFSEngine_handleMsg(msgAction,otherArgs) {
	var wfsquery=otherArgs[1];
	var node=otherArgs[2];
	var url=this.url;		
	var msg='meth=SOAP';
	var wfsRequest='<?xml version="1.0"?>';
	wfsRequest+='<GetFeature xmlns:gml="http://www.intergraph.com/geomedia/gml" service="WFS" version="1.0.0" maxFeatures="1000">';
	wfsRequest+=wfsquery;
	wfsRequest+='</GetFeature>';
	var encodedRequest=wfsRequest;
	var ogcform=window.wfscommunication.document.getElementById('ogcform');
	ogcform.data.value=encodedRequest;
	
	ogcform.node.value=node;
	ogcform.application.value=mapInfo.getProperty('applicationName');
	ogcform.submit();
	return wfscommunication;
}

/**
 * Costruttore. Viene passato come parametro la <DIV> usata per la comunicazione con il motore.
 */
function WFSEngine(url) {
	this.url=url;
	this.clearCommunication();
}


WFSEngine.prototype.handleMsg=WFSEngine_handleMsg;
WFSEngine.prototype.clearCommunication=WFSEngine_clearCommunication;

function WMSEngine_clearCommunication() {
	wmscommunication.document.write('<html><head></head><body><form id="ogcform" name="ogcform" action="'+this.url+'" method="POST"><input type="hidden" name="meth" value="SOAP"/><input type="hidden" name="data" value=""/><input type="hidden" name="layer" value=""/><input type="hidden" name="node" value=""/><input type="hidden" name="application" value=""/></form></body></html>');
	
}

/*
 * Invia una richiesta al motore java. Il metodo è asincrono. Ciò significa che
 * non viene attesa la risposta. Tale risposta verrà inviata alla funzione <responseHandler>,
 * oppure al metodo <responseHandler> di <responseHandlerObject>.
 * Il tipo di richiesta viene indicata dal parametro <msgAction>. Ogni tipo di richiesta 
 * può prevedere una serie di parametri aggiuntivi.
 */
function WMSEngine_handleMsg(msgAction,otherArgs) {
	var queryName=otherArgs[0];
	var filterCond=otherArgs[1];
	
	var layerName=otherArgs[2];
	var node=otherArgs[3];
	var resolution=10;
	if(otherArgs.length>4)
		resolution=parseFloat(otherArgs[4]);
	var range=map.maxRealRange;
	if(otherArgs.length>5)
		range=otherArgs[5];
	
	//var queryDesc=mapInfo.getProperty('queries')[queryName];
	
	/*
	 * VERSIONE INSTALLAZIONE RFI
	var wmsquery='<GetMap xmlns:gml="http://www.intergraph.com/geomedia/gml" service="WMS" version="1.3.0" format="image/svg"  width="'+mapWidth+'"  height="'+mapHeight+'" transparent="true" bgcolor="0xFFFFFF"  crs="UTM32" xslfilename="RFI.xsl">';
	 */
	var wmsquery='<GetMap xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.intergraph.com/geomedia/gml" service="WMS" version="1.3.0" format="image/svg"  width="'+mapWidth+'"  height="'+mapHeight+'" transparent="false" bgcolor="0xFFFFFF"  crs="gauss">';
	
	wmsquery   +='<StyledLayerDescriptor version ="1.0.0">'+filterCond;
	wmsquery   +='</StyledLayerDescriptor>';
    wmsquery   +='<BoundingBox dimensions="2"><LowerCorner>'+range.minX+' '+range.minY+'</LowerCorner><UpperCorner>'+range.maxX+' '+range.maxY+'</UpperCorner></BoundingBox>';
	wmsquery   +='<Output><Format>image/svg</Format><Transparent>false</Transparent><Size><Width>'+parseInt(mapWidth*resolution)+'</Width><Height>'+parseInt(mapHeight*resolution)+'</Height></Size></Output>';
	wmsquery   +='<Exceptions>XML</Exceptions></GetMap>';

	var url=this.url;		
		
	var encodedRequest=wmsquery;
	var ogcform=window.wmscommunication.document.getElementById('ogcform');
	ogcform.layer.value=layerName;
	ogcform.data.value=encodedRequest;
	
	ogcform.node.value=node;
	ogcform.application.value=mapInfo.getProperty('applicationName');
	ogcform.submit();
	return wmscommunication;
}

/**
 * Costruttore. Viene passato come parametro la <DIV> usata per la comunicazione con il motore.
 */
function WMSEngine(url) {
	this.url=url;
	this.clearCommunication();
}


WMSEngine.prototype.handleMsg=WMSEngine_handleMsg;
WMSEngine.prototype.clearCommunication=WMSEngine_clearCommunication;

function Node(name,wfsurl,wmsurl) {
	this.name=name;
	this.wfsurl=wfsurl;
	this.wmsurl=wmsurl;
}


function SLDReader_read(stream,renderer) {
	var rexp=new RegExp('<Rule[^>]*>(.*?)</Rule>',"gi");
	var result;
	var decodedStream=stream;
	decodedStream=decodedStream.replace(/\n/gi,'');
	var ruleCount=0;
	while((result=rexp.exec(decodedStream))!=null) {
		ruleCount++;
	}
	
	if(ruleCount>1)
		renderer.dynamic=true;

	rexp=new RegExp('<CssParameter\\s*name="([^"]*)"[^>]*>(.*?)</CssParameter>',"gi");
	
	
	while((result=rexp.exec(decodedStream))!=null) {
		var styleName=result[1];
		var styleValue=result[2];
		
		if(styleName=='stroke')
			renderer.setProperty('color',styleValue);
		if(styleName=='stroke-width')
			renderer.setProperty('stroke',styleValue);
		if(styleName=='fill')
			renderer.setProperty('fill',styleValue);
	}
	rexp=new RegExp('<GraphicFill>.*?<WellKnownName>(.*?)</WellKnownName>.*?</GraphicFill>',"gi");
	while((result=rexp.exec(decodedStream))!=null) {
		var pattern=result[1];
		renderer.setProperty('fillpattern',pattern);
		
	}
	rexp=new RegExp('<Size>(\\d+)</Size>',"gi");
	while((result=rexp.exec(decodedStream))!=null) {
		var size=result[1];
		renderer.setProperty('size',size);
	}
}

function SLDReader() {
}

SLDReader.prototype.read=SLDReader_read;

