1 31 32 package org.opencms.main; 33 34 import org.opencms.i18n.CmsMessageContainer; 35 36 import java.util.ArrayList ; 37 import java.util.Collections ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 import java.util.Locale ; 41 42 54 public class CmsMultiException extends CmsException { 55 56 57 private static final long serialVersionUID = 1197300254684159700L; 58 59 60 protected List m_exceptions; 61 62 63 protected boolean m_individualMessage; 64 65 68 public CmsMultiException() { 69 70 this(Messages.get().container(Messages.ERR_MULTI_EXCEPTION_1, new Integer (0))); 71 } 72 73 78 public CmsMultiException(CmsMessageContainer message) { 79 80 super(message); 81 m_exceptions = new ArrayList (); 82 setMessage(message); 83 } 84 85 90 public CmsMultiException(List exceptions) { 91 92 this(); 93 setExceptions(exceptions); 94 } 95 96 101 public void addException(CmsException exception) { 102 103 m_exceptions.add(exception); 104 updateMessage(); 105 } 106 107 112 public void addExceptions(List exceptions) { 113 114 m_exceptions.addAll(exceptions); 115 updateMessage(); 116 } 117 118 121 public CmsException createException(CmsMessageContainer container, Throwable cause) { 122 123 if (cause instanceof CmsMultiException) { 124 CmsMultiException multiException = (CmsMultiException)cause; 125 return new CmsMultiException(multiException.getExceptions()); 126 } 127 return super.createException(container, cause); 129 } 130 131 136 public List getExceptions() { 137 138 return Collections.unmodifiableList(m_exceptions); 139 } 140 141 146 public String getLocalizedMessage() { 147 148 if (m_exceptions.isEmpty()) { 149 return null; 150 } 151 StringBuffer result = new StringBuffer (128); 152 Iterator it = m_exceptions.iterator(); 153 while (it.hasNext()) { 154 CmsException ex = (CmsException)it.next(); 155 result.append(ex.getLocalizedMessage()); 156 if (it.hasNext()) { 157 result.append('\n'); 158 } 159 } 160 return result.toString(); 161 } 162 163 168 public String getLocalizedMessage(Locale locale) { 169 170 if (m_exceptions.isEmpty()) { 171 return null; 172 } 173 StringBuffer result = new StringBuffer (128); 174 Iterator it = m_exceptions.iterator(); 175 while (it.hasNext()) { 176 CmsException ex = (CmsException)it.next(); 177 result.append(ex.getLocalizedMessage(locale)); 178 if (it.hasNext()) { 179 result.append('\n'); 180 } 181 } 182 return result.toString(); 183 } 184 185 191 public String getMessage(Locale locale) { 192 193 if (hasIndividualMessage()) { 194 return m_message.key(locale); 195 } 196 return ""; 197 } 198 199 204 public boolean hasExceptions() { 205 206 return !m_exceptions.isEmpty(); 207 } 208 209 216 public boolean hasIndividualMessage() { 217 218 return m_individualMessage; 219 } 220 221 232 public void setMessage(CmsMessageContainer message) { 233 234 if ((message != null) && (message.getKey() != Messages.ERR_MULTI_EXCEPTION_1)) { 235 m_individualMessage = true; 236 m_message = message; 237 } else { 238 m_individualMessage = false; 240 updateMessage(); 241 } 242 } 243 244 249 protected void setExceptions(List exceptions) { 250 251 m_exceptions = new ArrayList (exceptions); 252 updateMessage(); 253 } 254 255 258 protected void updateMessage() { 259 260 if (!hasIndividualMessage()) { 261 m_message = Messages.get().container(Messages.ERR_MULTI_EXCEPTION_1, new Integer (m_exceptions.size())); 262 } 263 } 264 } | Popular Tags |