home *** CD-ROM | disk | FTP | other *** search
- @if ( @support != @support)
- // 1 means sense support on
- // 2 means tracker support on
- @set @support = 1;
- @end
- @set @SenseSupport = ( (@support) == 1);
- @set @TrackerSupport = ( (@support) == 2);
- @set @BannerPileSupport = ( (@support) == 4);
- @set @CitatesSupport = ( (@support) == 8);
-
-
- var cxbiMajorDatabaseVersion = 1;
- var cxbiMinorDatabaseVersion = 0;
- var cxbiDatabaseVersion = cxbiMajorDatabaseVersion.toString() + "." +
- cxbiMinorDatabaseVersion.toString();
-
- var cxbiRoot = "root";
-
- var cxbiAttTimeStamp = "TimeStamp";
- var cxbiNoTimeStamp = "-1";
- var cxbiAttNextUIN = "NextUIN";
- var cxbiAttUIN = "UIN";
-
- var cxbiAttVersion = "dbversion";
-
- var cxbiDatabase = "CogTracker:ctDATABASE";
- var cxbiAttCurrentNode = "CurrentNode";
- var cxbiAttIsDatabase = "IsDatabase";
-
- var cxbiNODE = "CogTracker:ctNODE";
-
- var cxbiFRAGMENT = "CogTracker:ctFRAGMENT";
-
- //var cxbiAttComment = "Comment";
- var cxbiAttText = "Text";
- var cxbiAttComment = "Comment";
- var cxbiAttURL = "BaseURL";
- var cxbiAttDate = "CreationDate";
-
- //BannerPile database support
- var cxbiCTLIST = "CTLIST";
- var cxbiAttCurrentCategory = "CurrentCategory";
-
- var cxbiCATEGORY = "CATEGORY";
- var cxbiAttCID = "CID";
- var cxbiAttName = "Name";
- cxbiAttUnsorted = "IsUnsortedNode";
-
- var cxbiBANNERBASE = "BANNERBASE";
- var cxbiAttOpenMode = "OpenMode";
- var cxbiAttSortOrder = "SortOrder";
- var cxbiAttShowSlots = "ShowSlots";
-
- var cxbiBANNER = "BANNER";
- L_COMMON_CAT_NAME = "Common";
- L_UNNAMED_NODE_DEF = "My Citations";
- L_UNSORTED_NODE = "Default Collection";
-
- // Gets database version of XML database.
- function fnGetVersion(someBase) {
- var oDBVersion = "";
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
- if (ctRoot != null) {
- oDBVersion = ctRoot.getAttribute(cxbiAttVersion);
- };
- if (oDBVersion == null) {
- oDBVersion = "";
- };
- return oDBVersion;
- };
-
- // Checks if database version is current.
- function fnCheckVersion(someBase) {
- return (fnGetVersion(someBase) == cxbiDatabaseVersion);
- };
-
- // Sets database version of XML database to current.
- function fnSetVersion(someBase) {
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
- if (ctRoot != null) {
- ctRoot.setAttribute(cxbiAttVersion, cxbiDatabaseVersion);
- };
- };
-
- // Prompts user to confirm DB conversion.
- // Returns true if user presses OK / false on Cancel
- function fnConfirmConversion(someBase) {
- var sVersion = fnGetVersion(someBase);
-
-
- var bConfirmed = confirm ("XML Database version is not current.\n\n" +
- "Expected version: '" + cxbiDatabaseVersion + "'\n" +
- "Found version: " +
- ( (sVersion == "") ? ("No version mark found") :
- ("'" + sVersion + "'") )
- +
- "\n\nDo you want to convert it?");
- return bConfirmed;
- };
-
- //Performs DB conversions
- function fnPerformConversion(someBase) {
- var sVersion = fnGetVersion(someBase);
-
- if (sVersion == cxbiDatabaseVersion) {
- // No conversion necessary;
- return true;
- };
-
- var nMajorVersion = 0;
- var nMinorVersion = 0;
-
- if (sVersion != "") {
- var nVerDelimiterPos = sVersion.indexOf(".");
- if (nVerDelimiterPos != -1) {
- nMajorVersion = parseInt(sVersion.slice(0, nVerDelimiterPos));
- if (isNaN(nMajorVersion)) {
- nMajorVersion = 0;
- }
- nMinorVersion = parseInt(sVersion.slice(nVerDelimiterPos+1));
- if (isNaN(nMinorVersion)) {
- nMinorVersion = 0;
- }
- }
- }
-
- var bConvert = false;
- if (nMajorVersion != 0 || nMinorVersion != 0) {
- if ( (nMajorVersion > cxbiMajorDatabaseVersion) ||
- (nMajorVersion == cxbiMajorDatabaseVersion &&
- nMinorVersion > cxbiMinorDatabaseVersion)
- ) {
-
- if (confirm("Database version is higher than supported.\n\n" +
- "Are you sure that you want to continue?") == true) {
-
- bConvert = true;
-
- }
- else {
- bConvert = false;
- }
- }
- else
- bConvert = true;
-
- }
- else {
- bConvert = true;
- };
-
- if (bConvert) {
- // Here switch'es should be placed to convert from older/newer versions
- // of the DB...
- fnSetVersion(someBase);
- return true;
- }
- else {
- return false;
- };
- };
-
- // Gets time stamp of XML database.
- // When the DB has no timestamp, returns -1.
- function fnGetTimeStamp(someBase) {
- var oStamp = cxbiNoTimeStamp;
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
- if (ctRoot != null) {
- oStamp = ctRoot.getAttribute(cxbiAttTimeStamp);
- if (oStamp == "" || oStamp == null) {
- oStamp = cxbiNoTimeStamp;
- }
- if (isNaN(parseInt(oStamp, 10))) {
- oStamp = "1";
- };
- };
- return oStamp;
- };
-
- // Checks to see if memDatabase has the same TimeStamp as diskDatabase
- // Note: if diskDatabase's TimeStamp is not present, the function
- // always returns true;
- function fnCheckTimeStampsEqual(memDatabase, diskDatabase) {
- var oMemStamp = fnGetTimeStamp(memDatabase);
- var oDiskStamp = fnGetTimeStamp(diskDatabase);
-
- if (oDiskStamp != cxbiNoTimeStamp) {
- if (oMemStamp != oDiskStamp) {
- return false;
- };
- };
-
- return true;
- };
-
- function fnIncrementTimeStamp(someBase) {
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
- var oStamp = fnGetTimeStamp(someBase);
- oStamp = ( (parseInt(oStamp, 10) + 1) % 1000000 ).toString();
- ctRoot.setAttribute(cxbiAttTimeStamp, oStamp);
-
- return true;
- };
-
- function fnCreateNewCID(someBase) {
-
- @if (@BannerPileSupport)
- var UIN = 0;
- var ctCategoriesList = someBase.selectNodes(
- cxbiRoot + "/" + cxbiCTLIST + "/" + cxbiCATEGORY);
-
- for (i = 0; i < ctCategoriesList.length; i++) {
- var currCID = parseInt(ctCategoriesList[i].getAttribute(cxbiAttCID), 10);
-
- if ( ( ! isNaN(currCID)) && (currCID > UIN) ) {
- UIN = currCID;
- }
- };
- UIN ++;
- var nLength = UIN.toString().length;
- UIN = "0000000000000000" + UIN;
- UIN = UIN.slice(nLength);
-
- return UIN;
- @else
- alert("This function should not be used in current configuration !");
- window.close();
- return false;
- @end
- };
-
- // Returns new UIN for the element;
- // increments NextUIN of the root element
- function fnCreateNewUIN(someBase) {
-
- @if (@BannerPileSupport)
- var UIN = 0;
- var ctBannersList = someBase.selectNodes(
- cxbiRoot + "/" + cxbiBANNERBASE + "/" + cxbiBANNER);
-
- for (i = 0; i < ctBannersList.length; i++) {
- var currUIN = parseInt(ctBannersList[i].getAttribute(cxbiAttUIN), 10);
-
- if ( ( ! isNaN(currUIN)) && (currUIN > UIN) ) {
- UIN = currUIN;
- }
- };
- UIN ++;
- var nLength = UIN.toString().length;
- UIN = "0000000000000000" + UIN;
- UIN = UIN.slice(nLength);
-
- return UIN;
- @else
- var UIN = "";
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
- var NextUIN = ctRoot.getAttribute(cxbiAttNextUIN);
- if (NextUIN == null || NextUIN == "" || isNaN(parseInt(NextUIN)) ) {
- NextUIN = "0";
- ctRoot.setAttribute(cxbiAttNextUIN, NextUIN);
- };
- UIN = NextUIN;
- NextUIN = (parseInt(NextUIN) + 1).toString();
- ctRoot.setAttribute(cxbiAttNextUIN, NextUIN);
- return UIN;
- @end
- };
-
- // Returns element's UIN.
- // If the element has no UIN, UIN is created and assigned.
- function fnGetElementUIN(someBase, someElement) {
-
- @if (@BannerPileSupport)
- var sAttUIN = cxbiAttUIN;
- if (someElement.nodeName == cxbiCATEGORY) {
- sAttUIN = cxbiAttCID;
- }
-
- var UIN = someElement.getAttribute(sAttUIN);
- if (UIN == null || UIN == "" || isNaN(parseInt(UIN)) ) {
-
- if (sAttUIN == cxbiAttCID)
- UIN = fnCreateNewCID(someBase);
- else
- UIN = fnCreateNewUIN(someBase);
- someElement.setAttribute(sAttUIN, UIN);
- };
- return UIN;
-
- @else
- var UIN = someElement.getAttribute(cxbiAttUIN);
- if (UIN == null || UIN == "" || isNaN(parseInt(UIN)) ) {
-
- UIN = fnCreateNewUIN(someBase);
- someElement.setAttribute(cxbiAttUIN, UIN);
- };
- return UIN;
- @end
- };
-
-
- // Looks for element with specified UIN
- function fnFindElementByUIN(someBase, UIN) {
- return someBase.selectSingleNode('//*[@UIN="' + UIN + '"]');
- };
-
-
- // Loads the database and makes it valid
- function fnCheckedInitializeFile(someBase, sPath) {
-
- var bChanged = false;
- someBase.load(sPath);
-
- @if ( @SenseSupport )
-
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
-
- if (ctRoot == null) {
- ctRoot = someBase.createElement(cxbiRoot);
-
- //ctRoot.setAttribute("xmlns:CogTracker", "http://www.rword.ru/tracker/");
- ctRoot.setAttribute("xmlns:rw", "http://www.cogitum.com/sense/rw");
- ctRoot.text = "\n\t";
-
- ctRoot.setAttribute(cxbiAttTimeStamp, cxbiNoTimeStamp);
- ctRoot.setAttribute(cxbiAttNextUIN,"0");
- ctRoot.setAttribute(cxbiAttVersion, cxbiDatabaseVersion);
- someBase.appendChild(ctRoot);
-
- //var xmlInstr = someBase.createProcessingInstruction("xml", 'version="1.0" encoding="Windows-1251"');
- //someBase.insertBefore(xmlInstr, ctRoot);
-
- bChanged = true;
- }
-
- @elif ( @TrackerSupport )
-
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
-
- if (ctRoot == null) {
- ctRoot = someBase.createElement(cxbiRoot);
-
- ctRoot.setAttribute("xmlns:CogTracker", "http://www.rword.ru/tracker/");
- //ctRoot.setAttribute("xmlns:rw", "http://www.rword.ru/smysl/");
- ctRoot.text = "\n\t";
-
- ctRoot.setAttribute(cxbiAttTimeStamp, cxbiNoTimeStamp);
- ctRoot.setAttribute(cxbiAttNextUIN,"0");
- ctRoot.setAttribute(cxbiAttVersion, cxbiDatabaseVersion);
- someBase.appendChild(ctRoot);
-
- //var xmlInstr = someBase.createProcessingInstruction("xml", 'version="1.0" encoding="Windows-1251"');
- //someBase.insertBefore(xmlInstr, ctRoot);
-
- bChanged = true;
- }
-
- //CogTracker temp. turned off...
- var ctDATABASE = someBase.selectSingleNode(cxbiRoot + "/" + cxbiDatabase);
- if (ctDATABASE == null) {
- ctDATABASE = someBase.createElement(cxbiDatabase);
-
- ctDATABASE.text = "\n\t\t";
-
- ctRoot.appendChild(ctDATABASE);
-
- bChanged = true;
- }
- @elif (@BannerPileSupport)
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
-
- if (ctRoot == null) {
- ctRoot = someBase.createElement(cxbiRoot);
-
- ctRoot.text = "\n\t";
-
- ctRoot.setAttribute(cxbiAttTimeStamp, cxbiNoTimeStamp);
- ctRoot.setAttribute(cxbiAttNextUIN,"0");
- ctRoot.setAttribute(cxbiAttVersion, cxbiDatabaseVersion);
- someBase.appendChild(ctRoot);
-
- var xmlInstr = someBase.createProcessingInstruction("xml", 'version="1.0" encoding="Windows-1251"');
- someBase.insertBefore(xmlInstr, ctRoot);
-
- bChanged = true;
- }
-
-
- var CtList = someBase.selectSingleNode(cxbiRoot + "/" + cxbiCTLIST);
- if (CtList == null) {
- CtList = someBase.createElement(cxbiCTLIST);
- CtList.setAttribute(cxbiAttCurrentCategory, "0000000000000000");
-
- var CtCommon = someBase.createElement(cxbiCATEGORY);
- CtCommon.setAttribute(cxbiAttCID, "0000000000000001");
- CtCommon.setAttribute(cxbiAttName, L_COMMON_CAT_NAME);
- CtCommon.text = "\n";
-
- ctRoot.appendChild(CtList);
- CtList.appendChild(CtCommon);
-
- bChanged = true;
- }
-
- var ctDATABASE = someBase.selectSingleNode(cxbiRoot + "/" + cxbiBANNERBASE);
- if (ctDATABASE == null) {
- ctDATABASE = someBase.createElement(cxbiBANNERBASE);
-
- ctDATABASE.setAttribute(cxbiAttOpenMode, "_blank");
- ctDATABASE.setAttribute(cxbiAttSortOrder, "-@CreationDate");
- ctDATABASE.setAttribute(cxbiAttShowSlots, "63");
- ctDATABASE.text = "\n\t\t";
-
- ctRoot.appendChild(ctDATABASE);
-
- bChanged = true;
- }
- @elif (@CitatesSupport)
-
- var ctRoot = someBase.selectSingleNode(cxbiRoot);
-
- if (ctRoot == null) {
- ctRoot = someBase.createElement(cxbiRoot);
-
- ctRoot.setAttribute("xmlns:CogTracker", "http://www.rword.ru/tracker/");
- //ctRoot.setAttribute("xmlns:rw", "http://www.rword.ru/smysl/");
- ctRoot.text = "\n\t";
-
- ctRoot.setAttribute(cxbiAttTimeStamp, cxbiNoTimeStamp);
- ctRoot.setAttribute(cxbiAttNextUIN,"0");
- ctRoot.setAttribute(cxbiAttVersion, cxbiDatabaseVersion);
- someBase.appendChild(ctRoot);
-
- var xmlInstr = someBase.createProcessingInstruction("xml", 'version="1.0" encoding="UTF-8"');
- someBase.insertBefore(xmlInstr, ctRoot);
-
- bChanged = true;
- }
- else {
- if (ctRoot.getAttribute("xmlns:CogTracker") != "http://www.rword.ru/tracker/") {
- ctRoot.setAttribute("xmlns:CogTracker", "http://www.rword.ru/tracker/");
-
- bChanged = true;
- };
- };
-
- var ctDATABASE = someBase.selectSingleNode(cxbiRoot + "/" + cxbiDatabase);
- if (ctDATABASE == null) {
- ctDATABASE = someBase.createElement(cxbiDatabase);
-
- ctDATABASE.setAttribute(cxbiAttName, L_UNNAMED_NODE_DEF);
- ctDATABASE.setAttribute(cxbiAttIsDatabase, "-1");
-
- ctDATABASE.text = "\n\t\t";
-
- ctRoot.appendChild(ctDATABASE);
-
- bChanged = true;
- }
-
- var ctUNSORTED = someBase.selectSingleNode(cxbiRoot + "/" + cxbiDatabase + "/" + cxbiNODE);
- if (ctUNSORTED == null) {
- ctUNSORTED = someBase.createElement(cxbiNODE);
-
- ctUNSORTED.setAttribute(cxbiAttName, L_UNSORTED_NODE);
- ctUNSORTED.setAttribute(cxbiAttUnsorted, "1");
-
- ctUNSORTED.text = "\n\t\t";
-
- ctDATABASE.appendChild(ctUNSORTED);
-
- bChanged = true;
- }
-
-
- @else
-
- alert("none of support options turned on!");
- window.close();
- return false;
-
- @end
-
- if (bChanged) {
- // If file does not exist, this code generates an error on IE 5.5
- /*
- var oTmp = fnCreateXMLctl();
- someBase.save(oTmp);
- oTmp.save(someBase);
- */
- var sXML = new String(someBase.xml);
- someBase.loadXML("");
- someBase.loadXML(sXML);
-
-
- //someBase.save(someBase);
- };
- //someBase.load(someBase);
- return true;
- };
-