123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- function CSelectionContext(rModel)
- {
-
- this.rModel = rModel;
- this.selections = new Array();
-
- this.metadataCells = new Array();
- this.cells = new Array();
- this.stringTable = new scStringTable();
- }
- function CSelectedCell(sDataItemName, sMetadataModelItem, sUseValue, sUseValueType, sDisplayValue, sUsage, oPropertiesObject)
- {
- this.setPropertiesObject(oPropertiesObject);
- this.dataItemName = sDataItemName;
- this.usage = sUsage;
-
- if (sUsage == 'measure' && sUseValueType == 'memberUniqueName') {
-
-
-
-
-
-
-
-
- this.metadataModelItem = sUseValue;
- } else {
- this.metadataModelItem = sMetadataModelItem;
- }
-
- this.useValue = sUseValue;
- this.useValueType = sUseValueType;
-
-
-
- if (this.useValueType == '_memberUniqueName') {
- this.useValueType = 'memberUniqueName';
- }
-
-
- this.displayValue = sDisplayValue;
- this.definingCells = new Array();
- this.dependentCells = new Array();
- this.nOutputCellId = -1;
-
-
- if (sDisplayValue != undefined) {
- this.addDependentCell('_memberCaption', '', sDisplayValue, '_memberCaption');
- }
-
-
- }
- CSelectionContext.prototype.addSelectedCell = function(sDataItemName, sMetadataModelItem, sUseValue, sUseValueType, sDisplayValue, sUsage, oPropertiesObject)
- {
- var nSelCount = this.selections.length;
-
-
- this.selections[nSelCount] = new CSelectedCell(sDataItemName, sMetadataModelItem, sUseValue, sUseValueType, sDisplayValue, sUsage, oPropertiesObject);
- return this.selections[nSelCount];
- }
- CSelectedCell.prototype.addDefiningCell = function(sDataItemName, sMetadataModelItem, sUseValue, sUseValueType, sDisplayValue, sUsage, oPropertiesObject)
- {
- var nDefiningCellCount = this.definingCells.length;
-
-
- this.definingCells[nDefiningCellCount] = new CSelectedCell(sDataItemName, sMetadataModelItem, sUseValue, sUseValueType, sDisplayValue, sUsage, oPropertiesObject);
-
-
- return this.definingCells[nDefiningCellCount];
- }
- CSelectedCell.prototype.setPropertiesObject = function(oPropertiesObject){
- if (typeof oPropertiesObject != "undefined") {
- if("queryName" in oPropertiesObject){
- this.queryName = oPropertiesObject.queryName;
- }
- }
- }
- CSelectedCell.prototype.setQueryName = function(sQueryName)
- {
- this.queryName = sQueryName;
- }
- CSelectedCell.prototype.getQueryName = function()
- {
- return this.queryName;
- }
- CSelectedCell.prototype.setDataItemName = function(sDataItemName)
- {
- this.dataItemName = sDataItemName;
- }
- CSelectedCell.prototype.getDataItemName = function()
- {
- return this.dataItemName;
- }
- CSelectedCell.prototype.setMetadataModelItem = function(sMetadataModelItem)
- {
- this.metadataModelItem = sMetadataModelItem;
- }
- CSelectedCell.prototype.getMetadataModelItem = function()
- {
- return this.metadataModelItem;
- }
- CSelectedCell.prototype.setUseValue = function(sUseValue)
- {
- this.useValue = sUseValue;
- }
- CSelectedCell.prototype.getUseValue = function()
- {
- return this.useValue;
- }
- CSelectedCell.prototype.setUseValueType = function(sUseValueType)
- {
- this.useValueType = sUseValueType;
- }
- CSelectedCell.prototype.getUseValueType = function()
- {
- return this.useValueType;
- }
- CSelectedCell.prototype.setDisplayValue = function(sDisplayValue)
- {
- this.displayValue = sDisplayValue;
- }
- CSelectedCell.prototype.getDisplayValue = function()
- {
- return this.displayValue;
- }
- CSelectedCell.prototype.setUsage = function(sUsage)
- {
- this.usage = sUsage;
-
- }
- CSelectedCell.prototype.getUsage = function()
- {
- return this.usage;
- }
- CSelectedCell.prototype.referenceDefiningCell = function(oDefiningCell)
- {
- var nDefiningCellCount = this.definingCells.length;
- this.definingCells[nDefiningCellCount] = oDefiningCell;
-
- return this.definingCells[nDefiningCellCount];
- }
- CSelectedCell.prototype.addProperty = function(sPropertyName, sPropertyValue, sMetadataModelItem, sUseValueType)
- {
- if (sPropertyName == 'LevelUniqueName') {
- this.LevelUniqueName = sPropertyValue;
- } else if (sPropertyName == 'DimensionUniqueName') {
- this.DimensionUniqueName = sPropertyValue;
- } else if (sPropertyName == 'HierarchyUniqueName') {
- this.HierarchyUniqueName = sPropertyValue;
- } else if (sPropertyName == 'ordinal') {
- this.ordinal = sPropertyValue;
- } else {
- this.addDependentCell(sPropertyName, sMetadataModelItem, sPropertyValue, sUseValueType);
- }
- }
-
- CSelectedCell.prototype.addDependentCell = function(sPropertyName, sMetadataModelItem, sUseValue, sUseValueType)
- {
- var nDependentCellCount = this.dependentCells.length;
- this.dependentCells[nDependentCellCount] = new CSelectedCell(sPropertyName, sMetadataModelItem, sUseValue, sUseValueType);
-
- return this.dependentCells[nDependentCellCount];
- }
- CSelectionContext.prototype.prepareSchemaObjects = function()
- {
- for (var i=0; i<this.selections.length; i++) {
-
- var objSelectionRoot = this.selections[i];
-
- objSelectionRoot.prepareSchemaObjects(this);
- }
- }
- CSelectedCell.prototype.prepareSchemaObjects = function(oSelectionContext)
- {
-
- var nNewCellId=oSelectionContext.cells.length;
-
-
-
- var nNewNameId=oSelectionContext.addString('N', this.dataItemName);
-
-
- var nNewMetadataIdx=oSelectionContext.metadataCells.length;
- oSelectionContext.addMetadataCell(nNewMetadataIdx, nNewNameId, this );
-
- var nNewValueIdx=oSelectionContext.addString("V", this.useValue);
-
-
- var oschemaCell = new selectioncontextSchema_Cell(nNewCellId, nNewMetadataIdx, nNewValueIdx, this.displayValue);
- oSelectionContext.cells[nNewCellId] = oschemaCell;
-
-
- if (this.definingCells!=undefined && this.definingCells.length > 0) {
- for (var i=0; i < this.definingCells.length; i++) {
- var odefiningSchemaCell = this.definingCells[i].prepareSchemaObjects(oSelectionContext);
- odefiningSchemaCell.rSelectedCell=false;
- nDefiningCellCount = oschemaCell.definingCellAxisList.length;
-
-
- oschemaCell.definingCellAxisList[nDefiningCellCount] = new selectioncontextSchema_Axis(odefiningSchemaCell.nXMLid, this.definingCells[i].ordinal);
- }
- }
-
-
- if (this.dependentCells!=undefined && this.dependentCells.length > 0) {
- for (var i=0; i < this.dependentCells.length; i++) {
- var odependentSchemaCell = this.dependentCells[i].prepareSchemaObjects(oSelectionContext);
- odependentSchemaCell.rSelectedCell=false;
- oschemaCell.addDependentCell(odependentSchemaCell);
- odependentSchemaCell.bDependentCell = true;
- }
- }
-
- this.nOutputCellId = nNewCellId;
- return oschemaCell;
- }
- function selectioncontextSchema_MetadataCell(/*xml:id="M_#"*/nXMLid, /*N_#*/nrName, /*QI_#*/nrExpression, /*T_#*/nrType, /*U_#*/nrUsage, /*QN_#*/nrQueryName)
- {
- this.nXMLid = nXMLid;
- this.nrName = nrName;
- this.nrExpression = nrExpression;
- this.nrType = nrType;
- this.nrUsage = nrUsage;
- this.nrQueryName = nrQueryName;
-
- this.nrLevelUniqueName = undefined;
- this.nrHierarchyUniqueName = undefined;
- this.nrDimensionUniqueName = undefined;
- }
- function selectioncontextSchema_Cell(/*xml:id="C_X"*/nXMLid, /*rMetadataCell="M_#"*/ nrMetadataCell, /*rValue="V_#"*/ nrValue, /*display=*/ sDisplayValue)
- {
- this.rSelectedCell = true;
- this.bDependentCell = false;
- this.nXMLid = nXMLid;
- this.nrMetadataCell = nrMetadataCell;
- this.nrValue = nrValue;
- this.displayValue = sDisplayValue;
-
- this.dependentCells = new Array();
-
- this.definingCellAxisList = new Array();
- }
- function selectioncontextSchema_Axis(/*rCell="C_X"*/nrCell, /*ordinal="X"*/nOrdinal)
- {
- this.nrCell = nrCell;
- this.nOrdinal=nOrdinal;
- }
- selectioncontextSchema_Cell.prototype.addDependentCell = function(oDependentCell)
- {
- var nDependentCellCount = this.dependentCells.length;
- this.dependentCells[nDependentCellCount] = oDependentCell;
- }
- CSelectionContext.prototype.addString = function(sTable, sValue)
- {
- if (sValue == undefined) {
- return -1;
- }
-
- var nStringTableLength=this.stringTable[sTable].length;
- for (var i=0; i<nStringTableLength; i++) {
- if (sValue == this.stringTable[sTable][i]) {
- return i;
- }
- }
-
- this.stringTable[sTable][nStringTableLength] = sValue;
- return nStringTableLength;
- }
- function scStringTable()
- {
- this.QN = new Array();
- this.N = new Array();
- this.T = new Array();
- this.V = new Array();
- this.QI = new Array();
- this.L = new Array();
- this.SV = new Array();
- this.D = new Array();
- this.H = new Array();
- this.U = new Array();
- this.MP= new Array();
- }
- CSelectionContext.prototype.serializeHeader = function()
- {
-
- var nModelIdx = this.addString('MP', this.rModel);
- var sSCHeader = '<s:selection';
- sSCHeader+=this.serializeReferenceAttr('rModel', 'MP', nModelIdx);
- sSCHeader+=' xmlns:s="http://developer.cognos.com/schemas/selection/1/"';
- sSCHeader+=' xmlns:xml="http://www.w3.org/XML/1998/namespace"';
- if (this.cells.length > 0) {
- var nPrependSpace=0;
- sSCHeader+=' rSelectedCells="';
- for (var i=0; i<this.cells.length; i++) {
- if (this.cells[i].rSelectedCell == true) {
- if (nPrependSpace==0) {
- nPrependSpace=1;
- } else {
- sSCHeader+=' ';
- }
- sSCHeader+='C_';
- sSCHeader+=i;
- }
- }
- sSCHeader+='"';
- }
- sSCHeader+='>';
- return sSCHeader;
- }
- CSelectionContext.prototype.serializeFooter = function()
- {
- return '</s:selection>';
- }
- CSelectionContext.prototype.serializeStrings = function()
- {
- var sStringTable="<s:strings>";
- var i=0;
- for (var arrayName in this.stringTable) {
- for (i=0; i<this.stringTable[arrayName].length; i++) {
- sStringTable+='<s:s xml:id="';
- sStringTable+=arrayName;
- sStringTable+='_';
- sStringTable+=i;
- sStringTable+='">';
- sStringTable+=xml_encode(this.stringTable[arrayName][i]);
- sStringTable+='</s:s>';
- }
- }
- sStringTable+="</s:strings>";
- return sStringTable;
- }
- CSelectionContext.prototype.serializeReferenceAttr = function(sRefAttrName, sAttrType, nrAttr)
- {
- var sReturn="";
- if (nrAttr != undefined && nrAttr >= 0) {
- sReturn = ' ' + sRefAttrName + '="' + sAttrType + "_" + nrAttr + '"';
- }
- return sReturn;
- }
- CSelectionContext.prototype.serializeMetadataCells = function(objMetadataTable)
- {
- var sMetadataTable="<s:metadataCells>";
-
-
- for (x=0; x<objMetadataTable.length; x++) {
- oMetadataCell = objMetadataTable[x];
- var sMetadataCellXML = '<s:metadataCell';
- sMetadataCellXML+=this.serializeReferenceAttr('xml:id', 'M', oMetadataCell.nXMLid);
- sMetadataCellXML+=this.serializeReferenceAttr('rQueryName', 'QN', oMetadataCell.nrQueryName);
- sMetadataCellXML+=this.serializeReferenceAttr('rName', 'N', oMetadataCell.nrName);
- sMetadataCellXML+=this.serializeReferenceAttr('rExpression','QI', oMetadataCell.nrExpression);
- sMetadataCellXML+=this.serializeReferenceAttr('rType', 'T', oMetadataCell.nrType);
- sMetadataCellXML+=this.serializeReferenceAttr('rUsage', 'U', oMetadataCell.nrUsage);
-
-
- sMetadataCellXML+=this.serializeReferenceAttr('rDimensionUniqueName', 'D', oMetadataCell.nrDimensionUniqueName);
- sMetadataCellXML+=this.serializeReferenceAttr('rHierarchyUniqueName', 'H', oMetadataCell.nrHierarchyUniqueName);
- sMetadataCellXML+=this.serializeReferenceAttr('rLevelUniqueName', 'L', oMetadataCell.nrLevelUniqueName);
-
- sMetadataCellXML+="/>";
- sMetadataTable+=sMetadataCellXML;
- }
- sMetadataTable+="</s:metadataCells>";
- return sMetadataTable;
- }
- selectioncontextSchema_Cell.prototype.serialize = function(oSelectionContext)
- {
- var sCellXML ='<s:cell';
- sCellXML+= oSelectionContext.serializeReferenceAttr('xml:id', 'C', this.nXMLid);
- sCellXML+= oSelectionContext.serializeReferenceAttr('rMetadataCell', 'M', this.nrMetadataCell);
- sCellXML+= oSelectionContext.serializeReferenceAttr('rValue', 'V', this.nrValue);
-
-
- if (this.displayValue != undefined) {
- sCellXML += ' display="';
- sCellXML += xml_encode(this.displayValue);
- sCellXML += '"';
- }
-
- if (this.definingCellAxisList.length > 0 || this.dependentCells.length > 0) {
- sCellXML += '>';
- }
-
- if (this.dependentCells.length > 0) {
- sCellXML += '<s:dependentCells>';
- for (var xx=0; xx < this.dependentCells.length; xx++) {
- sCellXML+=this.dependentCells[xx].serialize(oSelectionContext);
- }
- sCellXML += '</s:dependentCells>';
- }
-
-
- if (this.definingCellAxisList.length > 0) {
- sCellXML += '<s:definingCells>';
- for (var xx=0; xx<this.definingCellAxisList.length; xx++) {
- sCellXML+='<s:axis';
- sCellXML+= oSelectionContext.serializeReferenceAttr('rCell', 'C', this.definingCellAxisList[xx].nrCell);
- if (this.definingCellAxisList[xx].nOrdinal != undefined) {
- sCellXML+= (' ordinal="' + this.definingCellAxisList[xx].nOrdinal + '"');
- }
- sCellXML += '/>';
- }
- sCellXML += '</s:definingCells>';
- }
- if (this.definingCellAxisList.length == 0 && this.dependentCells.length == 0) {
- sCellXML += "/>";
- } else {
- sCellXML += "</s:cell>";
- }
-
- return sCellXML;
- }
- CSelectionContext.prototype.serializeCells = function(objCells)
- {
- var sCells="<s:cells>";
-
- for (var x=0; x<objCells.length; x++) {
-
- var oscCell = objCells[x];
- if (oscCell.bDependentCell == true) {
-
- continue;
- }
- sCells += oscCell.serialize(this);
- }
- sCells+="</s:cells>";
- return sCells;
- }
- CSelectionContext.prototype.toString = function(objSelectionTree)
- {
-
- this.prepareSchemaObjects();
- var sOutputSelectionContextXML= this.serializeHeader();
- sOutputSelectionContextXML+= this.serializeMetadataCells(this.metadataCells);
- sOutputSelectionContextXML+= this.serializeCells(this.cells);
- sOutputSelectionContextXML+= this.serializeStrings();
- sOutputSelectionContextXML+= this.serializeFooter();
- return sOutputSelectionContextXML;
- }
- CSelectionContext.prototype.addMetadataCell = function(nNewMetadataIdx, nNewNameIdx, oCell)
- {
- var nNewTypeIdx=this.addString("T", oCell.useValueType);
-
- if (oCell.metadataModelItem != '') {
-
- var nNewQueryNameIdx =this.addString("QN",oCell.queryName);
- var nNewQIIdx =this.addString("QI", oCell.metadataModelItem);
- var nNewTypeIdx =this.addString("T", oCell.useValueType);
- var nNewUsageIdx =this.addString("U", oCell.usage);
- this.metadataCells[nNewMetadataIdx]= new selectioncontextSchema_MetadataCell(nNewMetadataIdx, nNewNameIdx, nNewQIIdx, nNewTypeIdx, nNewUsageIdx, nNewQueryNameIdx);
-
-
- if (oCell.LevelUniqueName != undefined && oCell.LevelUniqueName != null) {
- var nNewLunIdx = this.addString("L", oCell.LevelUniqueName);
- this.metadataCells[nNewMetadataIdx].nrLevelUniqueName = nNewLunIdx;
- }
- if (oCell.HierarchyUniqueName != undefined && oCell.HierarchyUniqueName != null ) {
- var nNewHunIdx = this.addString("H", oCell.HierarchyUniqueName);
- this.metadataCells[nNewMetadataIdx].nrHierarchyUniqueName = nNewHunIdx;
- }
- if (oCell.DimensionUniqueName != undefined && oCell.DimensionUniqueName != null ) {
- var nNewDunIdx = this.addString("D", oCell.DimensionUniqueName);
- this.metadataCells[nNewMetadataIdx].nrDimensionUniqueName = nNewDunIdx;
- }
- } else {
- this.metadataCells[nNewMetadataIdx]= new selectioncontextSchema_MetadataCell(nNewMetadataIdx, nNewNameIdx, -1, nNewTypeIdx);
- }
- }
- function xml_encode(str) {
-
- if (str!=null && typeof str == 'string'){
- return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
- }
- return str;
- }
|