CredentialManager = Class.create(); CredentialManager.prototype = { /** @classDescription Deals with credentials for the report. * * Initializes a new #CredentialManager. * @param coreController The CoreController instance that owns this object. */ initialize: function(coreController){ this._coreController = coreController; this._isCredentialsRequired = false; this._credentialList = new Array(); }, /** * Returns true if credentials are required by the current report. Otherwise false is returned. * Technically this is only valid after calling readMetadataCredentials. */ isCredentialsRequired: function() { return this._isCredentialsRequired; }, /** * Reads the credential information from the report metadata node. * @param {HTMLElement} metadataNode the main report metadata node. */ readMetadataCredentials: function(metadataNode) { // clear any exist credentials this._credentialList = new Array(0); try { elem = metadataNode.getElementsByTagName('credentials'); if (elem != null && elem.length > 0) { this._credentialList = new Array(elem.length); var credentialsElement = elem[0];//should only be one of these var credentialElements = credentialsElement.getElementsByTagName('credential'); if (credentialElements != null && credentialElements.length > 0) { this._isCredentialsRequired = true; for (var credentialIndex=0; credentialIndex < credentialElements.length; credentialIndex++) { var credElement = credentialElements[credentialIndex]; this._credentialList[credentialIndex] = new Credential(credElement); } } else { this._isCredentialsRequired = false; } } else { this._isCredentialsRequired = false; } } catch (exception) { DiagContext.traceError("error checking for credentials ", exception); } }, /** * Returns data based on the current report instance so it can be processed by the server. */ getCredentalsXmlData: function() { var text = ""; text += ""; for (var credentialIndex = 0; credentialIndex < this._credentialList.length; credentialIndex++) { var cred = this._credentialList[credentialIndex]; text += "'; text += "" + cred.promptText + ""; text += "" + cred.userName + ""; text += "" + cred.password + ""; text += ""; } text += ""; // turn it into a document object (this is useful for sending it via XMLHttpREquest as it will automatically be serialized into the body.) //return this._createDocumentFromText(text); return text; }, /** * Creates an HTMLDocument from the specified text in a browser indipendent manner. */ _createDocumentFromText: function(text) { // code for IE var doc; if (window.ActiveXObject) { doc=new ActiveXObject("Microsoft.XMLDOM"); doc.async="false"; doc.loadXML(text); } // code for Mozilla, Firefox, Opera, etc. else { var parser=new DOMParser(); doc=parser.parseFromString(text,"text/xml"); } return doc; }, getCredentialList: function(){ return this._credentialList; }, /* * REQUIRED by Prototype AJAX for callback * Gets called when send request is called on a credentials request */ ajaxUpdate: function(request){ DiagContext.traceVerbose('CredentialManager: ajaxUpdate'); // actually we have nothing to do in this case. Just submitted parameters, we should only refresh the report this._coreController.reportInstance.refreshReport(); } };//close CredentialManager Credential = Class.create(); Credential.prototype = { /** * @classDescription Represents a single credential needed by the report. * Initializes a new instance of Credential. * @param {HTMLElement} credentialElement The main HTMLElement for the credential in the metadata. */ initialize: function(credentialElement) { // initialize this instance from credentialElement this.dataSourceName = credentialElement.getAttribute("dataSourceName"); this.promptText = XElement.getChildElementValueOrNull(credentialElement, "promptText"); this.userName = XElement.getChildElementValueOrNull(credentialElement, "userName"); this.password = XElement.getChildElementValueOrNull(credentialElement, "password"); } };//close Credential XElement = Class.create(); XElement.prototype = { /** * @classDescription Extension methods for a DOM Element (e.g. @see #HTMLElement). */ initialize: function(){ } };//close XElement.prototype /** * Returns the value of the specified childElement where childElement is a descendent of the provided parentElement. * If an error occurs or something isn't found null is returned. * @param {HTMLElement} parentElement A reference to the parent element. * @param {String} childElementTagName Name of the sought child element. */ XElement.getChildElementValueOrNull = function(parentElement, childElementTagName) { return XElement.getChildElementValue(parentElement, childElementTagName, null); }; /** * Returns the value of the specified childElement where childElement is a descendent of the provided parentElement. * If an error occurs or something isn't found the specified default value is returned. * @param {HTMLElement} parentElement A reference to the parent element. * @param {String} childElementTagName Name of the sought child element. * @param {Object} defaultValueIfNotFoundOrErrorOccurs value to be returned in the event of an error or if the specified child element does not exist. */ XElement.getChildElementValue = function(parentElement, childElementTagName, defaultValueIfNotFoundOrErrorOccurs) { try { if (parentElement != null) { var childElementList = parentElement.getElementsByTagName(childElementTagName); if (childElementList != null && childElementList.length > 0) { var childNode = childElementList[0]; /* NOTE: We're using firstchild as the content of the element is it's own node! */ if (childNode.firstChild != null) return childNode.firstChild.nodeValue; } } return defaultValueIfNotFoundOrErrorOccurs; } catch (exception) { return defaultValueIfNotFoundOrErrorOccurs; } }; /** * Create a new Document object. If no arguments are specified, * the document will be empty. If a root tag is specified, the document * will contain that single root tag. If the root tag has a namespace * prefix, the second argument must specify the URL that identifies the * namespace. */ XML = Class.create(); XML.newDocument = Class.create(); XML.newDocument = function(rootTagName, namespaceURL) { if (!rootTagName) rootTagName = ""; if (!namespaceURL) namespaceURL = ""; if (document.implementation && document.implementation.createDocument) { // This is the W3C standard way to do it return document.implementation.createDocument(namespaceURL, rootTagName, null); } else { // This is the IE way to do it // Create an empty document as an ActiveX object // If there is no root element, this is all we have to do var doc = new ActiveXObject("MSXML2.DOMDocument"); // If there is a root tag, initialize the document if (rootTagName) { // Look for a namespace prefix var prefix = ""; var tagname = rootTagName; var p = rootTagName.indexOf(':'); if (p != -1) { prefix = rootTagName.substring(0, p); tagname = rootTagName.substring(p+1); } // If we have a namespace, we must have a namespace prefix // If we don't have a namespace, we discard any prefix if (namespaceURL) { if (!prefix) prefix = "a0"; // What Firefox uses } else prefix = ""; // Create the root element (with optional namespace) as a // string of text var text = "<" + (prefix?(prefix+":"):"") + tagname + (namespaceURL ?(" xmlns:" + prefix + '="' + namespaceURL +'"') :"") + "/>"; // And parse that text into the empty document doc.loadXML(text); } return doc; } };