001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nicolas Chapurlat <nchapurlat@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.core.api.validation; 019 020import java.util.Collections; 021import java.util.List; 022import java.util.Locale; 023 024/** 025 * A managed set of {@link ConstraintViolation}. 026 * 027 * @since 7.1 028 */ 029public class DocumentValidationReport { 030 031 protected List<ConstraintViolation> violations; 032 033 public DocumentValidationReport(List<ConstraintViolation> violations) { 034 super(); 035 this.violations = violations; 036 } 037 038 public boolean hasError() { 039 return !violations.isEmpty(); 040 } 041 042 public int numberOfErrors() { 043 return violations.size(); 044 } 045 046 public List<ConstraintViolation> asList() { 047 return Collections.unmodifiableList(violations); 048 } 049 050 @Override 051 public String toString() { 052 if (violations != null) { 053 StringBuilder res = new StringBuilder(); 054 for (ConstraintViolation violation : violations) { 055 res.append(violation.getMessage(Locale.ENGLISH)).append('\n'); 056 } 057 return res.toString(); 058 } else { 059 return "no error"; 060 } 061 } 062 063}