MINI MINI MANI MO
/* Copyright (c) 2012, 2013, Oracle and/or its affiliates.
All rights reserved. */
// mapping between db release versions vs. em express root path
// IMPORTANT: this mapping needs to updated every time a new version
// of em express is uploaded
// NOTE: never remove the last entry in the mapping table, i.e.,
// 99xxxx entry. It used to dynamically add new entries
// into the table based on the db release.
var versionPathMapping =
{
'99.9.9.9.9':'db_99.9.9.9.9_99999999'
}
// this is the path where the root of em express "em/" resides
// this path is different due to different db release versions
var emxRootPath = "emviewers/";
/* This function extracts the versions from the versionPathMapping
* We need the array of versions for sorting purposes
*/
function getVersions(versionPathMap)
{
var versions = [];
for(var eachVersion in versionPathMap)
{
if(versionPathMap.hasOwnProperty(eachVersion))
{
versions.push(eachVersion);
}
}
return versions;
}
/* This function compares two versions
* The format of a version looks like this: x.x.x.x.x
* (x here means a integer)
*/
function compareVersions(v1, v2)
{
// result of comparison
// when v1 < v2, compareValue = -1;
// when v1 > v2, compareValue = 1;
// when v1 == v2, compareValue = 0;
var compareValue = 0;
// first trim the version strings to get rid of the leading
// and trailing white spaces
//v1 = v1.trim();
//v2 = v2.trim();
// now split the main version into an array of numbers
// separated by "."
var v1VersionArr = v1.split(".");
var v2VersionArr = v2.split(".");
// now loop through all the numbers in the main versions to do the comparison
// stop when any of the two version number arrays no longer has any element
var index = 0;
var value1;
var value2;
while (index < v1VersionArr.length && index < v2VersionArr.length)
{
value1 = parseInt(v1VersionArr[index]);
value2 = parseInt(v2VersionArr[index]);
if (value1 < value2)
{
compareValue = -1;
break;
}
if (value1 > value2)
{
compareValue = 1;
break;
}
index++;
}
// all version numbers in the array are the same
if (compareValue == 0)
{
// now check if any version array is longer than the other
if (v1VersionArr.length < v2VersionArr.length)
compareValue = -1;
else if (v1VersionArr.length > v2VersionArr.length)
compareValue = 1;
}
return compareValue;
}
/* This function is for finding the correct em express root path "em/" given the database
* release version. If the database version maps to a directory in versionPathMapping,
* use the corresponding path for that version. If the database version is not found in
* the mapping, we use the closest one released before this version.
*/
function findRootPath()
{
// find out if this version maps to a released em express path
var path = versionPathMapping[version];
// no em express release is found for this version
// now look for the closest version released before this version
if (path == null)
{
// get the versions (without the path) into an sorted array first
var versions = getVersions(versionPathMapping).sort(compareVersions);
// by default uses the latest version if no closest matched version found
var closestVersion = versions[versions.length-1];
// loop through all the released versions in the map to find the closest one to this release
for(var i=0; i < versions.length; i++)
{
var availableVersion = versions[i];
// only compare the main version part to find the closest released version
var mainVersion = availableVersion;
// exit if mainVersion is greater than version
// at this point the closestVersion will be the last availableVersion
if (compareVersions(mainVersion, version) > 0)
{
break;
}
closestVersion = availableVersion;
}
// use the path that maps to the closest version released before this version
path = versionPathMapping[closestVersion];
}
if (path != null)
{
// path format needs to be like "path/"
//path = path.trim();
if (path.indexOf("/") == 0)
path = path.substring(1);
if (path.lastIndexOf("/") < (path.length-1))
path = path + "/";
// the root path to "em/" will be "emviewers/db[version]/"
emxRootPath = emxRootPath + path;
}
//alert("version: " + version + "; emxRootPath: " + emxRootPath);
}
/* This function is for dynamically constructing the path of the iframe tag
* based on the version of the database release
*/
function writeIframe()
{
// check for undefined for older versions, should include null/undefined
if (typeof swf_base_path === "undefined")
{
document.write('<iframe id="iframe" src="' + emxRootPath + 'em/em.html?emMode=active_report" width="100%" height="99%"></' + 'iframe>');
}
else
{
document.write('<iframe id="iframe" src="'+ swf_base_path + emxRootPath + 'em/em.html?emMode=active_report" width="100%" height="99%"></' + 'iframe>');
}
}
/* This function is called when the html is loaded to pass the
* xml to the em express active report html on ONT
*/
function sendXML()
{
// get the iframe
var frame = document.getElementById("iframe");
var frameWindow = document.getElementById("iframe").contentWindow;
// get the XML
var xmlTag = document.getElementById("fxtmodel");
// if xml is found, pass it to em express active report on ONT
if (xmlTag != null)
{
var xml = xmlTag.innerHTML + '';
frameWindow.postMessage(xml, "*");
}
}
/* This function is called when the child iframe communicates with
* parent html. Right now this is only called when the child needs
* to refresh parent when the language is changed in active report.
* So all this function does at this point is to refresh the parent.
*/
function messageReceivedFromChild(event)
{
if (event.data != null && event.data == "refreshParent")
location.reload(true);
}
/* call this function to find the right em express root path for directory "em/" */
findRootPath();
/* Register the listener when child iframe communicates with parent html */
if (typeof window.addEventListener != 'undefined')
{
window.addEventListener("message", messageReceivedFromChild, false);
}
else if (typeof window.attachEvent != 'undefined')
{
window.attachEvent("onmessage", messageReceivedFromChild);
}
OHA YOOOO