/** * This validation function has to be defined in xml2js.Parser in the "validator" option * When calling parserString this function will be executed for every tag of the xml we are * parsing. * @param {string} xmlPath Path of the tag that it's being evaluated at the current moment. * @param {Object} previousValue Existing value at this path if there is already one (e.g. this * is the second or later item in an array). * @param {Object} newValue Value of the tag that it's being evaluated at the current moment. * @throws ValidationError if the validation fails */ _validateXml(xmlPath, previousValue, newValue) { //TODO Add more cases if (xmlPath === MANIFEST_TAG_XML_PATH) { let manifestTagAttributes = newValue['$']; if (!manifestTagAttributes || !manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE]) { throw new xml2js.ValidationError( NodeTranslationService.getMessage(ERRORS.XML_PROJECTTYPE_ATTRIBUTE_MISSING) ); } else if ( manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE] !== PROJECT_SUITEAPP && manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE] !== PROJECT_ACP ) { throw new xml2js.ValidationError( NodeTranslationService.getMessage(ERRORS.XML_PROJECTTYPE_INCORRECT) ); } } return newValue; }
/** * This validation function has to be defined in xml2js.Parser in the "validator" option * When calling parserString this function will be executed for every tag of the xml we are * parsing. * @param {string} xmlPath Path of the tag that it's being evaluated at the current moment. * @param {Object} previousValue Existing value at this path if there is already one (e.g. this * is the second or later item in an array). * @param {Object} newValue Value of the tag that it's being evaluated at the current moment. * @throws ValidationError if the validation fails */ _validateXml(xmlPath, previousValue, newValue) { //TODO Add more cases if (xmlPath === MANIFEST_TAG_XML_PATH) { let manifestTagAttributes = newValue['$']; if (!manifestTagAttributes || !manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE]) { throw new xml2js.ValidationError( NodeTranslationService.getMessage(ERRORS.XML_PROJECTTYPE_ATTRIBUTE_MISSING) ); } else if ( manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE] !== PROJECT_SUITEAPP && manifestTagAttributes[PROJECT_TYPE_ATTRIBUTE] !== PROJECT_ACP ) { throw new xml2js.ValidationError( NodeTranslationService.getMessage(ERRORS.XML_PROJECTTYPE_INCORRECT) ); } } return newValue; }