--- /dev/null
+/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
+ * text of the license. */
+\r
+OpenLayers.ProxyHost = "/proxy/?url=";\r
+//OpenLayers.ProxyHost = "examples/proxy.cgi?url=";\r
+\r
+/**\r
+* Ajax reader for OpenLayers\r
+*\r
+*@uri url to do remote XML http get\r
+*@param 'get' format params (x=y&a=b...)\r
+*@who object to handle callbacks for this request\r
+*@complete the function to be called on success \r
+*@failure the function to be called on failure\r
+*\r
+* example usage from a caller:\r
+*\r
+* caps: function(request) {\r
+* -blah- \r
+* },\r
+*\r
+* OpenLayers.loadURL(url,params,this,caps);\r
+*\r
+* Notice the above example does not provide an error handler; a default empty\r
+* handler is provided which merely logs the error if a failure handler is not \r
+* supplied\r
+*\r
+*/\r
+\r
+\r
+/** \r
+* @param {} request\r
+*/\r
+OpenLayers.nullHandler = function(request) {\r
+ alert("Unhandled request return " + request.statusText);\r
+};\r
+\r
+/** Background load a document\r
+*\r
+* @param {String} uri URI of source doc\r
+* @param {String} params Params on get (doesnt seem to work)\r
+* @param {Object} caller object which gets callbacks\r
+* @param {Function} onComplete callback for success\r
+* @param {Function} onFailure callback for failure\r
+*\r
+* Both callbacks optional (though silly)\r
+*/\r
+OpenLayers.loadURL = function(uri, params, caller,\r
+ onComplete, onFailure) {\r
+\r
+ if (OpenLayers.ProxyHost && uri.startsWith("http")) {\r
+ uri = OpenLayers.ProxyHost + escape(uri);\r
+\r
+ if (!params) {\r
+ params="";\r
+ }\r
+ params += "&cachehack=" + new Date().getTime();\r
+ }\r
+\r
+ var success = (onComplete) ? onComplete.bind(caller)\r
+ : OpenLayers.nullHandler;\r
+\r
+ var failure = (onFailure) ? onFailure.bind(caller)\r
+ : OpenLayers.nullHandler;\r
+\r
+ // from prototype.js\r
+ new Ajax.Request(uri, \r
+ { method: 'get', \r
+ parameters: params,\r
+ onComplete: success, \r
+ onFailure: failure\r
+ }\r
+ );\r
+};\r
+\r
+/** Parse XML into a doc structure\r
+* @param {String} text\r
+*\r
+* @returns Parsed Ajax Response ??\r
+* @type ?\r
+*/\r
+OpenLayers.parseXMLString = function(text) {\r
+\r
+ //MS sucks, if the server is bad it dies\r
+ var index = text.indexOf('<');\r
+ if (index > 0) {\r
+ text = text.substring(index);\r
+ }\r
+\r
+ var ajaxResponse = Try.these(\r
+ function() {\r
+ var xmldom = new ActiveXObject('Microsoft.XMLDOM');\r
+ xmldom.loadXML(text);\r
+ return xmldom;\r
+ },\r
+ function() {\r
+ return new DOMParser().parseFromString(text, 'text/xml');\r
+ },\r
+ function() {\r
+ var req = new XMLHttpRequest();\r
+ req.open("GET", "data:" + "text/xml" +\r
+ ";charset=utf-8," + encodeURIComponent(text), false);\r
+ if (req.overrideMimeType) {\r
+ req.overrideMimeType("text/xml");\r
+ }\r
+ req.send(null);\r
+ return req.responseXML;\r
+ }\r
+ );\r
+\r
+ return ajaxResponse;\r
+};