/*---------------- FILE HEADER --------------------------------------- This file is part of Geoide. Copyright (C) 2005-2006 by: IDgis B.V. http://www.idgis.nl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Herman Assink IDgis bv P.O. Box 15 7450 AA Holten The Netherlands E-Mail: herman.assink@idgis.nl * @version 1.4.0 * @author IDgis team * ------------------------------------------------------------------------*/ import nl.idgis.giclient.Ruler; import nl.idgis.giclient.io.XMLResponseListener; import nl.idgis.giclient.util.XMLTools; class nl.idgis.giclient.io.XMLResponse extends XML { private var xmlResponseListener:XMLResponseListener = null; private var request:String = ""; private var ruler:Ruler = null; private var path:String = null; private var url:String = ""; private var properties:Object = null; // Associative array. public function XMLResponse(xmlResponseListener:XMLResponseListener, request:String) { this.xmlResponseListener = xmlResponseListener; this.request = request; ignoreWhite = true; } // Every nl.idgis.giclient.io.XMLResponse shall be passed either a Ruler object or a path string. // If a path string is given instead of a Ruler object, then a new username will be asked for when the // response is a demand for authentication. A new username means that the capabilities will have // to be reset, which is the responsibility of the nl.idgis.giclient.io.XMLResponseListener object. So usually // object that create an nl.idgis.giclient.io.XMLResponse object, provide the constructor with a username. /*public function setRuler(ruler:Ruler):Void { this.ruler = ruler; path = null; }*/ public function setPath(path:String):Void { this.path = path; ruler = null; } public function setProperties(properties:Object):Void { this.properties = properties; } public function getProperties():Object { return properties; } public function load():Void { //_root["frameWork"].showProgressIndicator(); //if (ruler != null) { // url = ruler.getGIClientConfig().getServerURLPrefix() + request; //} else { url = path + request; //} _root["frameWork"].state("Doing a request:>>>" + url + xmlResponseListener + "<<<", 1); super.load(url); } public function postAndLoad(postXml:XML):Void { //_root["frameWork"].showProgressIndicator(); //if (ruler != null) { // url = ruler.getGIClientConfig().getServerPath() + request; //} else { url = path + request; //} _root["frameWork"].state("Doing a request:>>>" + url + "<<<", 2); //change the content-type to something different than "application/x-www-form-urlencoded" //to let the servlet read the post-body by a Reader postXml.addRequestHeader("Content-Type", "text/xml; charset=UTF-8"); // postXml.addRequestHeader("Transfer-Encoding", "chunked"); postXml.sendAndLoad(url, this); } public function authenticate(userName:String, passWord:String):Void { // _root["frameWork"].showProgressIndicator(); url = path.substring(0, (path.lastIndexOf("/") + 1)); //authenticate on same context as getCapabilities request url += "j_security_check?j_username=" + userName + "&j_password=" + passWord; _root["frameWork"].state("Trying to get authentication:>>>" + url + "<<<", 2); super.load(url); } function onData(src:String):Void { _root["frameWork"].state("Gotten the following raw data:>>>" + src + "<<<", 2); super.onData(src); } function onLoad(successful:Boolean):Void { //_root["frameWork"].hideProgressIndicator(); if (!successful) { _root["frameWork"].state("Could not parse the server response. Request: " + url, 0); } else if (firstChild.nodeName == "Exception") { var exceptionMessage:String = XMLTools.getStringValue("Message", firstChild); _root["frameWork"].state("The server response was an exception. \n " + exceptionMessage, 0); } else if (firstChild.nodeName == "Authentication") { var authenticationUserName:String = null; //TODO: Authentication //if (ruler != null) { // authenticationUserName = ruler.getGIS().getGICapabilities().getAuthenticationUserName(); //} // If authenticationUserName == null, shows the sign-on window with username and password to be given. // Otherwise shows the sign-on window with username fixed and password to be given. _root["frameWork"].authenticate(this, authenticationUserName); } else { xmlResponseListener.onLoadXMLResponse(this); } } }