001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.datamodel; 019 020import java.util.ArrayList; 021import java.util.Collections; 022import java.util.List; 023 024import org.opends.guitools.controlpanel.util.Utilities; 025import org.forgerock.i18n.LocalizableMessage; 026import org.opends.server.types.OpenDsException; 027 028/** 029 * The exception that occurs when the user is editing an entry and some of the 030 * provided data is not valid. 031 * 032 */ 033public class CheckEntrySyntaxException extends OpenDsException 034{ 035 private static final long serialVersionUID = 8145911071581212822L; 036 private List<LocalizableMessage> errors; 037 /** 038 * Constructor of the exception. 039 * @param errors the list of error description that were found. 040 */ 041 public CheckEntrySyntaxException(List<LocalizableMessage> errors) 042 { 043 super(getMessage(errors)); 044 this.errors = Collections.unmodifiableList(errors); 045 } 046 047 /** 048 * Returns the list of errors that were encountered. 049 * @return the list of errors that were encountered. 050 */ 051 public List<LocalizableMessage> getErrors() 052 { 053 return errors; 054 } 055 056 /** 057 * Returns a single message using the provided messages. This method assumes 058 * that the messages have HTML format. 059 * @param errors the list of errors. 060 * @return a single message using the provided messages. 061 */ 062 private static LocalizableMessage getMessage(List<LocalizableMessage> errors) 063 { 064 ArrayList<String> s = new ArrayList<>(); 065 for (LocalizableMessage error : errors) 066 { 067 s.add(error.toString()); 068 } 069 return LocalizableMessage.raw(Utilities.getStringFromCollection(s, "<br>")); 070 } 071}