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