use of org.apache.sling.validation.impl.model.MergedValidationModel in project sling by apache.
the class ValidationModelRetrieverImpl method getValidationModel.
/*
* (non-Javadoc)
*
* @see org.apache.sling.validation.impl.ValidationModelRetriever#getModels(java.lang.String, java.lang.String)
*/
@CheckForNull
public ValidationModel getValidationModel(@Nonnull String resourceType, String resourcePath, boolean considerResourceSuperTypeModels) {
// first get model for exactly the requested resource type
ValidationModel baseModel = getModel(resourceType, resourcePath);
String currentResourceType = resourceType;
if (considerResourceSuperTypeModels) {
Collection<ValidationModel> modelsToMerge = new ArrayList<ValidationModel>();
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getServiceResourceResolver(null);
while ((currentResourceType = resourceResolver.getParentResourceType(currentResourceType)) != null) {
LOG.debug("Retrieving validation models for resource super type {}...", currentResourceType);
ValidationModel modelToMerge = getModel(currentResourceType, resourcePath);
if (modelToMerge != null) {
if (baseModel == null) {
baseModel = modelToMerge;
} else {
modelsToMerge.add(modelToMerge);
}
}
}
if (!modelsToMerge.isEmpty()) {
return new MergedValidationModel(baseModel, modelsToMerge.toArray(new ValidationModel[modelsToMerge.size()]));
}
} catch (LoginException e) {
throw new IllegalStateException("Could not get service resource resolver", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
return baseModel;
}
Aggregations