* @param lang
* @param valTypeAndStatus @return errors
*/
public Element applyCustomSchematronRules(String schema, int metadataId, Element md,
String lang, Map<String, Integer[]> valTypeAndStatus) {
MetadataSchema metadataSchema = getSchema(schema);
final String schemaDir = this.schemaMan.getSchemaDir(schema);
Element schemaTronXmlOut = new Element("schematronerrors", Edit.NAMESPACE);
try {
final SchematronRepository schematronRepository = _applicationContext.getBean(SchematronRepository.class);
final SchematronCriteriaGroupRepository criteriaGroupRepository = _applicationContext.getBean(SchematronCriteriaGroupRepository.class);
final List<Schematron> schematronList = schematronRepository.findAllBySchemaName(metadataSchema.getName());
//Loop through all xsl files
for (Schematron schematron : schematronList) {
int id = schematron.getId();
//it contains absolute path to the xsl file
String rule = schematron.getRuleName();
String dbident = ""+id;
List<SchematronCriteriaGroup> criteriaGroups = criteriaGroupRepository.findAllById_SchematronId(schematron.getId());
//Loop through all criteria to see if apply schematron
//if any criteria does not apply, do not apply at all (AND)
SchematronRequirement requirement = SchematronRequirement.DISABLED;
for (SchematronCriteriaGroup criteriaGroup : criteriaGroups) {
List<SchematronCriteria> criterias = criteriaGroup.getCriteria();
boolean apply = false;
for(SchematronCriteria criteria : criterias) {
boolean tmpApply = criteria.accepts(_applicationContext, metadataId, md, metadataSchema.getSchemaNS());
if(!tmpApply) {
apply = false;
break;
} else {