package obfuscated.cms.editor.validator.plugins; import org.apache.wicket.model.IModel; import org.hippoecm.editor.type.JcrTypeLocator; import org.hippoecm.frontend.editor.validator.JcrTypeValidator; import org.hippoecm.frontend.editor.validator.ValidatorService; import org.hippoecm.frontend.editor.validator.plugins.AbstractCmsValidator; import org.hippoecm.frontend.model.JcrNodeModel; import org.hippoecm.frontend.model.ocm.StoreException; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.types.ITypeDescriptor; import org.hippoecm.frontend.validation.IFieldValidator; import org.hippoecm.frontend.validation.ValidationException; import org.hippoecm.frontend.validation.Violation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.Node; import javax.jcr.RepositoryException; import java.util.HashSet; import java.util.Set; /** * Validator for the Content blocks. The validator delegates to the correct validators based on the * content block documenttype. */ public class ContentBlocksValidator extends AbstractCmsValidator { private static Logger log = LoggerFactory.getLogger(ContentBlocksDelegatingValidator.class); public ContentBlocksDelegatingValidator(IPluginContext context, IPluginConfig config) { super(context, config); } @Override public void preValidation(IFieldValidator type) throws ValidationException { //Do nothing as we configure the validator ourselves. } @Override public Set validate(IFieldValidator iFieldValidator, JcrNodeModel jcrNodeModel, IModel iModel) throws ValidationException { Node node = (Node) iModel.getObject(); JcrTypeLocator jcrTypeLocator = new JcrTypeLocator(); try { ITypeDescriptor descriptor = jcrTypeLocator.locate(node.getPrimaryNodeType().getName()); ValidatorService validatorService = getPluginContext().getService("field.validator.service", ValidatorService.class); JcrTypeValidator validator = new JcrTypeValidator(descriptor, validatorService); return validator.validate(new JcrNodeModel(node)); } catch (StoreException e) { log.warn("StoreException occurred during locating the correct jcr type", e); } catch (RepositoryException e) { log.warn("RepositoryException occurred during retrieval of primaryNodeType", e); } return new HashSet(); } }