PdColumnAnalyser.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/_base/declare",
  16. "dojox/xml/parser",
  17. "dojo/_base/array",
  18. "dojo/query",
  19. "pd/model/deltaSpec"
  20. ],function(declare, xmlParser, array, query, deltaSpec){
  21. var PdColumnAnalyser = declare("pd/data/PdColumnAnalyser", [], {
  22. constructor: function(args) {
  23. if (!args.xmlInput){
  24. throw new Error(PDMSG.ERR.IDS_ERR_MISSING_XMLDOC_PARAM);
  25. }
  26. this.xmlInput = args.xmlInput;
  27. if (typeof(args.xmlInput) == "string"){
  28. this.xmlDoc = xmlParser.parse(dojo.trim(args.xmlInput));
  29. } else {
  30. this.xmlDoc = args.xmlInput;
  31. }
  32. this.inherited(arguments);
  33. },
  34. getDeltaFromXml: function() {
  35. var delta = {};
  36. for (var i=0; i<deltaSpec.length; i++){
  37. var section = [];
  38. var xmlDoc = this.xmlDoc.selectSingleNode("/pdSpec/delta/" + deltaSpec[i].name);
  39. if (xmlDoc != null) {
  40. array.some(
  41. xmlDoc.childNodes, function(rowNode, index, arr){
  42. section[index] = {
  43. name: rowNode.getAttribute("name"),
  44. simpletype: rowNode.getAttribute("simpletype"),
  45. previoustype: rowNode.getAttribute("previoustype")
  46. };
  47. }
  48. );
  49. }
  50. delta[deltaSpec[i].name] = section;
  51. }
  52. return delta;
  53. },
  54. getSpecFromXml: function() {
  55. //prune off preview and delta blob
  56. prunedNodes = ["personalPreview", "delta"];
  57. var xmlDoc = xmlParser.parse(dojo.trim(this.xmlInput));
  58. for (var i=0; i<prunedNodes.length; i++){
  59. var prunedNode = xmlDoc.selectSingleNode("/pdSpec/" + prunedNodes[i]);
  60. if (prunedNode){
  61. prunedNode.parentNode.removeChild(prunedNode);
  62. }
  63. }
  64. return xmlParser.innerXML(xmlDoc);
  65. }
  66. });
  67. return PdColumnAnalyser;
  68. });