1 31 32 package org.opencms.xml.content; 33 34 import org.opencms.main.CmsLog; 35 import org.opencms.xml.types.I_CmsXmlContentValue; 36 37 import java.util.HashMap ; 38 import java.util.Locale ; 39 import java.util.Map ; 40 41 import org.apache.commons.logging.Log; 42 43 52 public class CmsXmlContentErrorHandler { 53 54 55 private static final Log LOG = CmsLog.getLog(CmsXmlContentErrorHandler.class); 56 57 58 private Map m_errors; 59 60 61 private boolean m_hasErrors; 62 63 64 private boolean m_hasWarnings; 65 66 67 private Map m_warnings; 68 69 72 public CmsXmlContentErrorHandler() { 73 74 m_warnings = new HashMap (); 76 m_errors = new HashMap (); 77 } 78 79 86 public void addError(I_CmsXmlContentValue value, String message) { 87 88 m_hasErrors = true; 89 Locale locale = value.getLocale(); 90 Map localeErrors = getLocalIssueMap(m_errors, locale); 91 localeErrors.put(value.getPath(), message); 92 93 if (LOG.isDebugEnabled()) { 94 LOG.debug(Messages.get().getBundle().key(Messages.LOG_XMLCONTENT_VALIDATION_ERR_2, value.getPath(), message)); 95 } 96 } 97 98 105 public void addWarning(I_CmsXmlContentValue value, String message) { 106 107 m_hasWarnings = true; 108 Locale locale = value.getLocale(); 109 Map localeWarnings = getLocalIssueMap(m_warnings, locale); 110 localeWarnings.put(value.getPath(), message); 111 112 if (LOG.isDebugEnabled()) { 113 LOG.debug(Messages.get().getBundle().key( 114 Messages.LOG_XMLCONTENT_VALIDATION_WARN_2, 115 value.getPath(), 116 message)); 117 } 118 } 119 120 130 public Map getErrors() { 131 132 return m_errors; 133 } 134 135 142 public Map getErrors(Locale locale) { 143 144 return (Map )m_errors.get(locale); 145 } 146 147 157 public Map getWarnings() { 158 159 return m_warnings; 160 } 161 162 169 public Map getWarnings(Locale locale) { 170 171 return (Map )m_warnings.get(locale); 172 } 173 174 179 public boolean hasErrors() { 180 181 return m_hasErrors; 182 } 183 184 191 public boolean hasErrors(Locale locale) { 192 193 return null != getErrors(locale); 194 } 195 196 201 public boolean hasWarnings() { 202 203 return m_hasWarnings; 204 } 205 206 213 public boolean hasWarnings(Locale locale) { 214 215 return null != getWarnings(locale); 216 } 217 218 229 private Map getLocalIssueMap(Map base, Locale locale) { 230 231 Map result = (Map )base.get(locale); 232 if (result == null) { 233 result = new HashMap (); 234 base.put(locale, result); 235 } 236 return result; 237 } 238 } | Popular Tags |