/******************************************************************************* * IBM Confidential * * OCO Source Materials * * A and PM: PD * * (c) Copyright IBM Corp. 2014 * * The source code for this program is not published or otherwise divested of * its trade secrets, irrespective of what has been deposited with the U.S. * Copyright Office. ******************************************************************************/ define([ "dojo/_base/declare", "dojo/store/Memory", "dojox/xml/parser", "dojo/_base/array", "dojo/query" ],function(declare, store, xmlParser, array, query){ var PREVIEW_DATA_SIZE = 50; var PdDataStore = declare("pd/data/PdDataStore", [store], { constructor: function(args) { if (!args.xmlInput){ throw new Error(PDMSG.ERR.IDS_ERR_MISSING_XMLDOC_PARAM); } if (typeof(args.xmlInput) == "string"){ this.xmlDoc = xmlParser.parse(dojo.trim(args.xmlInput)); } else { this.xmlDoc = args.xmlInput; } this.xmlDoc.setProperty('SelectionLanguage', 'XPath'); this.xmlDoc.setProperty('SelectionNamespaces', 'xmlns:d="http://developer.cognos.com/schemas/xmldata/1/"'); args.data = this.generateDataFromXml(); this.inherited(arguments); }, generateDataFromXml: function() { var data = []; var self = this; var numberOfRow = 1; var xmlDoc = this.xmlDoc.selectSingleNode("/pdSpec/personalPreview/d:data"); if (xmlDoc != null) { array.some( xmlDoc.childNodes, function(rowNode, index, arr){ if (numberOfRow > PREVIEW_DATA_SIZE) { return false; } numberOfRow++; var dataItem = {}; var n = 0; array.forEach( rowNode.childNodes, function (cellNode) { dataItem["col" + n] = cellNode.text; n++; } ); data.push(dataItem); } ); } return data; }, pdGetOriginalStructure: function() { var structure = []; var xmlDoc = this.xmlDoc.selectSingleNode("/pdSpec/personalData"); var n = 0; array.forEach( query("item", xmlDoc), function(node, idx, arr){ var structureItem = {}; structureItem.name = node.getAttribute("name"); structureItem.noresize = true; structureItem.simpletype = node.getAttribute("simpletype"); structureItem.regularAggregate = node.getAttribute("regularAggregate"); structureItem.field = "col" + n; structureItem.classes = "pd_idx" + n; structureItem.hidden = node.getAttribute("hidden") == "true"; structure.push(structureItem); n++; } ); return [structure]; } }); return PdDataStore; });