function httpDownloadContent()
{
if(__isDownloadEventStale(arguments) == false)
{
var i, len = arguments.length;
for(i = 1; i < len; i++)
{
var newurl = arguments[i];
newurl = addBrowserIdToURL(newurl);
var newwin = window.open(newurl);
}
__makeDownloadEventStale(arguments);
}
}
function httpMultiDownloadContent()
{
if(__isDownloadEventStale(arguments) == false)
{
var contentIds = new Array();
contentIds.push("Reload");
contentIds.push(new String(new Date().getTime()));
var i, len = arguments.length;
for(i = 1; i < len; i++)
{
contentIds.push("contentId");
contentIds.push(arguments[i]);
}
var componentUrl = generateComponentUrl(getVirtualDir(), "httpmultifiledownload", contentIds);
var newwin = window.open(componentUrl);
__makeDownloadEventStale(arguments);
}
}
function httpDownloadContentFromAcs()
{
if(__isDownloadEventStale(arguments) == false)
{
var url = arguments[1];
if (url)
{
var newWin = window.open();
var formHtml = generateFormHTML('acsForm', url);
if (Trace_CONTENTTRANSFER)
{
__trace_contentxfer("Form Parameters for ACS POST:");
__dump_contentxfer(formHtml);
}
var childDoc = newWin.document;
childDoc.write("<html><head></head><body>" + formHtml + "</body></html>");
childDoc.close();
childDoc.forms['acsForm'].submit();
}
}
function generateFormHTML(formName, strUrl)
{
var urlParser = new UrlParser(strUrl, true); // decode +'s since our URL comes from java.net.URLEncoder
var base = urlParser.getBase();
var parameters = urlParser.getParameterMap();
var strFormElems = "";
for(var name in parameters)
{
var values = parameters[name];
for(var i = 0; i < values.length; i++)
{
strFormElems += "<input type='hidden' name='" + name + "' value='" + values[i] + "' />";
}
}
return "<form name='" + formName + "' action='" + base + "' method='POST'>" + strFormElems + "</form>";
}
}
function __isDownloadEventStale(callerArgs)
{
var eventId = parseInt(callerArgs[0]);
var lastId = getCookie("lastHttpDownloadContent");
return (lastId != null && parseInt(lastId) >= eventId);
}
function __makeDownloadEventStale(callerArgs)
{
var eventId = parseInt(callerArgs[0]);
setCookie("lastHttpDownloadContent", eventId + 1, null, null);
}
function getUcfSessionId(formElement)
{
var ucfSessionId = null;
var applet = __findUcfInvokerApplet(formElement);
if(applet != null)
{
try
{
applet.getSessionRequestKey();
ucfSessionId = applet.getUcfSessionId();
}
catch(e)
{
// TODO: this only works on mozillas - it's ok for now because we come in here only
var cloned = applet.cloneNode(true);
cloned.setAttribute("code", "com.documentum.web.applet.ucfinvoker.InitConnection.class");
if (cloned.tagName == "OBJECT")
{
cloned.setAttribute("classid", "java:com.documentum.web.applet.ucfinvoker.InitConnection.class");
}
cloned.setAttribute("height", "0");
cloned.setAttribute("width", "0");
applet.parentNode.appendChild(cloned);
if (g_clientInfo.isBrowser(ClientInfo.MOZILLA))
{
// this the dom won't update until we return from the caller
req = new XMLHttpRequest();
var url = "/" + getVirtualDir() + "/wdk/blank.htm?Reload=" + (new Date().getTime());
req.open('GET', url, false);
req.send(null);
}
}
}
if(Trace_CONTENTTRANSFER) __trace_contentxfer("ucfSessionId=" + ucfSessionId);
return ucfSessionId;
}
function setUcfSessionIdElement(strFormName, strElementName)
{
if (strFormName && strElementName)
{
var ucfForm = document.forms[strFormName];
if (ucfForm)
{
var sessionIdElement = ucfForm.elements[strElementName];
if (sessionIdElement)
{
var ucfSessionId = getUcfSessionId(ucfForm);
if (ucfSessionId != null)
{
sessionIdElement.value = ucfSessionId;
if (Trace_CONTENTTRANSFER) __trace_contentxfer("Set element: " + strElementName + ", in Form:" + strFormName + " to :" + ucfSessionId);
}
}
}
}
}
function __findUcfInvokerAppletByTagName(formElement, tagName)
{
var applet = null;
for(var applts = formElement.getElementsByTagName(tagName), i = 0; i < applts.length; i++)
{
// we have to get to parameter invoker_applet_tag_name which carries applet's name
if(g_clientInfo.isBrowser(ClientInfo.SAFARI))
{
for(var params = document.getElementsByName("appletName515f7ddee55e428b964a3839a78fbaa6"), j = 0; j < params.length; j++)
{
if(params[j].tagName == "PARAM" && params[j].parentNode == applts[i])
{
var appletName = params[j].value;
var appletTmp = eval("document." + appletName);
applet = appletTmp;
break;
}
}
}
else
{
var id = applts[i].getAttribute("id");
if(id != null && id.indexOf("515f7ddee55e428b964a3839a78fbaa6") != - 1)
{
applet = applts[i];
}
}
}
return applet;
}
function __findUcfInvokerApplet(formElement)
{
var applet = __findUcfInvokerAppletByTagName(formElement, "APPLET");
if (applet == null)
{
applet = __findUcfInvokerAppletByTagName(formElement, "OBJECT");
}
return applet;
}
function UrlParser(strUrl, bDecodePlusChar)
{
this.strUrl = strUrl;
this.base = null;
this.queryString = null;
this.parameterMap = new Object();
this.bDecodePlusChar = (bDecodePlusChar) ? true : false;
this._unescape = function(str)
{
var unEscStr = (str) ? str : "";
if (this.bDecodePlusChar)
{
// Javascript unescape doesn't replace '+' with ' ', but does decode %2B into '+' so if the strURL
// came from an encoder which replaces ' ' with '+' need to decode them before sending to unescape
unEscStr = unEscStr.replace(/\+/g," ");
}
unEscStr = unescape(unEscStr);
return unEscStr;
}
if (this.strUrl != null)
{
var i = this.strUrl.indexOf("?");
if (i == -1)
{
this.base = this.strUrl;
this.queryString = null;
}
else
{
this.base = this.strUrl.substring(0, i);
this.queryString = this.strUrl.substring(i + 1);
}
if (this.queryString)
{
var parameters = this.queryString.split("&");
if (parameters && parameters.length > 0)
{
for (var i = 0; i < parameters.length; i++)
{
var namevalue = parameters[i].split("=");
var name = this._unescape(namevalue[0]);
var value = this._unescape(namevalue[1]);
if(!this.parameterMap[name])
{
this.parameterMap[name] = new Array();
}
this.parameterMap[name].push(value);
}
}
}
}
}
UrlParser.prototype.getBase = function()
{
return this.base;
}
UrlParser.prototype.getQueryString = function()
{
return this.queryString;
}
UrlParser.prototype.getParameterMap = function()
{
return this.parameterMap;
}
UrlParser.prototype.toString = function()
{
var s = "BASE='" + this.base  + "', PARAMETERS=";
for (var name in this.parameterMap)
{
s += ("[" + name + "=" + this.parameterMap[name] + "]");
}
s += "', QUERY='" + this.queryString;
return s;
}
function __trace_contentxfer(msg)
{
Trace_println("contenttransfer.js: " + msg);
}
function __dump_contentxfer(obj)
{
Trace_println("contenttransfer.js:");
Trace_dump(obj);
}
if (typeof(g_include_contenttransfer) == "undefined")
{
g_include_contenttransfer = true;
registerClientEventHandler(null, "httpDownloadContent", httpDownloadContent);
registerClientEventHandler(null, "httpDownloadContentFromAcs", httpDownloadContentFromAcs);
registerClientEventHandler(null, "httpMultiDownloadContent", httpMultiDownloadContent);
}
