1 /** 2 * @fileOverview 3 * Copyright (c) 2013 Regione Autonoma della Sardegna 4 * Published under the GPL license.<br> 5 * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a> 6 * for the full text of the license. 7 * @version 0.1 8 */ 9 10 /* 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /** 26 * @namespace framework.data 27 */ 28 Ext.namespace("framework.data"); 29 30 /** 31 * XSL reader for Inviluppi Immagini service of Regione Sardegna 32 * @name_ EnvelopesObliquePhotos_XLSReader 33 * @class XSL reader for toponimi search service of Regione Sardegna 34 * @extends Ext.data.XmlReader - See <a href="http://dev.sencha.com/deploy/ext-3.3.1/docs?class=Ext.data.XmlReader">Ext.data.XmlReader</a> 35 * @constructor 36 * @param {object} meta object configuration 37 * @param {Ext.data.Record} recordType object definition 38 */ 39 framework.data.EnvelopesObliquePhotos_XLSReader = function(meta, recordType) { 40 meta = meta || {}; 41 42 this.propertyName = meta.propertyName; 43 44 Ext.applyIf(meta, { 45 idProperty: meta.idProperty || meta.idPath || meta.id, 46 successProperty: meta.successProperty || meta.success 47 }); 48 49 framework.data.EnvelopesObliquePhotos_XLSReader.superclass.constructor.call(this, meta, recordType || meta.fields); 50 }; 51 52 Ext.extend(framework.data.EnvelopesObliquePhotos_XLSReader, Ext.data.XmlReader, 53 /** 54 * @lends framework.data.EnvelopesObliquePhotos_XLSReader.prototype 55 */ 56 { 57 propertyName: "id", 58 59 /** This method is only used by a DataProxy which has retrieved data from a remote server. 60 * Create responseXML if the responseText is a XML format 61 * @public 62 * @param {Object} response The XHR object which contains the parsed XML document. 63 * The response is expected to contain a method called 'responseXML' that returns an XML document object. 64 * @returns {Object} records A data block which is used by an {@link Ext.data.Store} as 65 * a cache of Ext.data.Records. 66 */ 67 read : function(response){ 68 if(!response.responseXML){ 69 var text = response.responseText; 70 try { // code for IE 71 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 72 xmlDoc.async = "false"; 73 xmlDoc.loadXML(text); 74 response.responseXML = xmlDoc; 75 }catch(error) { // code for Mozilla, Firefox, Opera, etc. 76 try { 77 var parser = new DOMParser(); 78 var xmlDoc = parser.parseFromString(text,"text/xml"); 79 response.responseXML = xmlDoc; 80 }catch(error) { 81 alert(error.message); 82 return; 83 } 84 } 85 } 86 var doc = response.responseXML; 87 if(!doc) { 88 throw {message: "XmlReader.read: XML Document not available"}; 89 } 90 return this.readRecords(doc); 91 }, 92 93 94 /** fill up a object with query result 95 * @public 96 * @param {string} doc xml document 97 * @returns {object} array of record plus search informations 98 */ 99 readRecords: function(doc) { 100 101 this.xmlData = doc; 102 103 var root = doc.documentElement || doc; 104 105 var records = this.extractData(root); 106 107 return { 108 success: true, 109 records: records, 110 totalRecords: records[0].data.numresult 111 }; 112 }, 113 114 /** create array of record extracting data from a xml 115 * @public create records from xml content 116 * @param {string} root xml document 117 * @returns {array} record 118 */ 119 extractData: function(root) { 120 var opts = { 121 /** 122 * Property: namespaces 123 * {Object} Mapping of namespace aliases to namespace URIs. 124 */ 125 namespaces: { 126 gml: "http://www.opengis.net/gml", 127 wfs:"http://www.opengis.net/wfs" 128 129 } 130 }; 131 var records = []; 132 133 // Create record for each address 134 var recordType = Ext.data.Record.create([this.propertyName]); 135 136 var format = new OpenLayers.Format.XML(opts); 137 var zone = format.getElementsByTagNameNS(root, "http://www.regione.sardegna.it/", this.propertyName); 138 139 if (zone.length > 0){ 140 141 Ext.each(zone, function(point, index) { 142 143 //inserire record zona 144 var idzona = format.getChildValue(point); 145 146 var values = { 147 id: idzona 148 }; 149 var record = new recordType(values, index); 150 151 records.push(record); 152 }) 153 return records; 154 } 155 else 156 { 157 /** 158 * 1: result not found 159 */ 160 var values = { 161 msg_error: 1 162 }; 163 var record = new recordType(values, 0); 164 records.push(record); 165 return records; 166 } 167 } 168 }); 169 170