Check if the specified CDF document is empty.
Contributed by Kartik Sarangi
left
/* * Method to check if the CDF is empty or not. *@param server (Object) server instance i.e. this.getServer() *@param strCDF {String} unique CDF name i.e CDF_EMPLOYEE_LIST *@return boolean */ utils.isCDFEmpty = function(server, strCDF) { LOG.info("Inside isCDFEmpty "); var localCache = server.getCache(); var objXML = localCache.getDocument(strCDF); if (objXML === null || (objXML.getFirstChild() === null)) { return true; } else { return false; } };
Modified Version
/* * Method to check if a Document or Document associated with a CDF control is empty or not. *@param object (Object) jsx3.app.Server or class that implements jsx3.xml.CDF *@param strCDF {String} Cache ID of document stored in application Cache *@return boolean */ isDocEmpty = function(object, strCDF) { var objXML = null; if (object.instanceOf(jsx3.app.Server) ) objXML = object.getCache().getDocument(strCDF); if (object.instanceOf(jsx3.xml.CDF) ) objXML = object.getXML(); return (objXML === null || (objXML.getFirstChild() === null)); };
Short version for in-line code.
//var objXML = matrix1.getXML(); var isDocEmpty = (objXML && objXML.getFirstChild() == null);
Or with additional check for asynch loaded document
// async loaded document with error is considered empty var isDocEmpty = (objXML && !objXML.hasError() && objXML.getFirstChild() == null);
