/** * @see org.opencms.xml.I_CmsXmlDocument#validate(org.opencms.file.CmsObject) */ public CmsXmlContentErrorHandler validate(CmsObject cms) { // XML pages currently do not support validation return new CmsXmlContentErrorHandler(); }
/** * Returns <code>true</code> if there is at last one error in the selected locale.<p> * * @param locale the locale to check * * @return <code>true</code> if there is at last one error in the selected locale */ public boolean hasErrors(Locale locale) { return null != getErrors(locale); }
/** * Returns <code>true</code> if there is at last one warning in the selected locale.<p> * * @param locale the locale to check * * @return <code>true</code> if there is at last one warning in the selected locale */ public boolean hasWarnings(Locale locale) { return null != getWarnings(locale); }
Map<String, Map<String[], String>> errorsByEntity = new HashMap<String, Map<String[], String>>(); if (errorHandler.hasErrors()) { boolean reallyHasErrors = false; for (Entry<Locale, Map<String, String>> localeEntry : errorHandler.getErrors().entrySet()) { Map<String[], String> errors = new HashMap<String[], String>(); for (Entry<String, String> error : localeEntry.getValue().entrySet()) { if (errorHandler.hasWarnings()) { boolean reallyHasErrors = false; for (Entry<Locale, Map<String, String>> localeEntry : errorHandler.getWarnings().entrySet()) { Map<String[], String> warnings = new HashMap<String[], String>(); for (Entry<String, String> warning : localeEntry.getValue().entrySet()) {
errorHandler.addError(value, e.getMessage()); return errorHandler; } catch (Exception e) { errorHandler.addError(value, e.getMessage()); return errorHandler; errorHandler.addWarning(value, message); } else { errorHandler.addError(value, message);
/** * @see org.opencms.xml.content.I_CmsXmlContentHandler#resolveValidation(org.opencms.file.CmsObject, org.opencms.xml.types.I_CmsXmlContentValue, org.opencms.xml.content.CmsXmlContentErrorHandler) */ @Override public CmsXmlContentErrorHandler resolveValidation( CmsObject cms, I_CmsXmlContentValue value, CmsXmlContentErrorHandler errorHandler) { if (errorHandler == null) { // init a new error handler if required errorHandler = new CmsXmlContentErrorHandler(); } // we only have to validate containers if ((value != null) && CmsXmlUtils.removeXpath(value.getPath()).equals(CmsXmlContainerPage.XmlNode.Containers.name())) { CmsXmlContent content = (CmsXmlContent)value.getDocument(); try { validateNames(cms, value, content); } catch (CmsXmlException e) { errorHandler.addError(value, e.getLocalizedMessage()); } } return errorHandler; }
/** * @see org.opencms.ugc.shared.rpc.I_CmsUgcEditService#saveContent(org.opencms.util.CmsUUID, java.util.Map) */ public Map<String, String> saveContent(CmsUUID sessionId, Map<String, String> contentValues) throws CmsUgcException { Map<String, String> result = null; try { CmsUgcSession session = getFormSession(sessionId); if ((session != null) && sessionId.equals(session.getId())) { CmsXmlContentErrorHandler errorHandler = session.saveContent(contentValues); if (errorHandler.hasErrors()) { result = errorHandler.getErrors(session.getMessageLocale()); } else { session.finish(); result = Collections.emptyMap(); } } else { // invalid session } } catch (Exception e) { error(e); } return result; }
/** * Returns true if the edited content contains validation errors, otherwise false.<p> * * @return true if the edited content contains validation errors, otherwise false */ public boolean hasValidationErrors() { return getValidationHandler().hasErrors(); }
/** * Checks the default XML schema validation rules.<p> * * These rules should only be tested if this is not a test for warnings.<p> * * @param cms the current users OpenCms context * @param value the value to validate * @param valueStr the string value of the given value * @param errorHandler the error handler to use in case errors or warnings are detected * @param isWarning if true, this validation should be stored as a warning, otherwise as an error * * @return the updated error handler */ protected CmsXmlContentErrorHandler validateValue( CmsObject cms, I_CmsXmlContentValue value, String valueStr, CmsXmlContentErrorHandler errorHandler, boolean isWarning) { if (isWarning) { // default schema validation only applies to errors return errorHandler; } if (!value.validateValue(valueStr)) { // value is not valid, add an error to the handler String message = getValidationMessage(cms, value, value.getTypeName(), valueStr, true, false); errorHandler.addError(value, message); } return errorHandler; }
/** * Adds an warning message to the internal list of errors, * also raised the "has warning" flag.<p> * * @param value the value that contians the warning * @param message the warning message to add */ public void addWarning(I_CmsXmlContentValue value, String message) { m_hasWarnings = true; Locale locale = value.getLocale(); Map<String, String> localeWarnings = getLocalIssueMap(m_warnings, locale); localeWarnings.put(value.getPath(), message); if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key(Messages.LOG_XMLCONTENT_VALIDATION_WARN_2, value.getPath(), message)); } }
if (getValidationHandler().hasWarnings(getElementLocale())) {
if (!nested && showErrors && (getValidationHandler().hasErrors())) { "<span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\"></span>"); boolean differentLocaleErrors = false; if ((getValidationHandler().getErrors(getElementLocale()) == null) || (getValidationHandler().getErrors().size() > getValidationHandler().getErrors( getElementLocale()).size())) { Map<Locale, Map<String, String>> locErrors = getValidationHandler().getErrors(); Iterator<Map.Entry<Locale, Map<String, String>>> locErrorsIter = locErrors.entrySet().iterator(); while (locErrorsIter.hasNext()) { && getValidationHandler().hasErrors(getElementLocale()) && getValidationHandler().getErrors(getElementLocale()).containsKey(key)) { result.append(getEditorResourceUri()); result.append("error.png\" border=\"0\" alt=\"\" align=\"left\" hspace=\"5\">"); result.append(resolveMacros(getValidationHandler().getErrors(getElementLocale()).get(key))); result.append("</td><td></td></tr>\n"); } else { result.append("error.png"); result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError\">"); result.append(resolveMacros(getValidationHandler().getErrors(getElementLocale()).get(key))); result.append("</td><td></td></tr>\n"); && getValidationHandler().hasWarnings(getElementLocale()) && getValidationHandler().getWarnings(getElementLocale()).containsKey(key)) {
errorHandler.addError(value, e.getMessage()); return errorHandler; } catch (Exception e) { errorHandler.addError(value, e.getMessage()); return errorHandler; errorHandler.addWarning(value, message); } else { errorHandler.addError(value, message);
/** * Returns true if the edited content contains validation errors, otherwise false.<p> * * @return true if the edited content contains validation errors, otherwise false */ public boolean hasValidationErrors() { return getValidationHandler().hasErrors(); }
/** * Checks the default XML schema validation rules.<p> * * These rules should only be tested if this is not a test for warnings.<p> * * @param cms the current users OpenCms context * @param value the value to validate * @param valueStr the string value of the given value * @param errorHandler the error handler to use in case errors or warnings are detected * @param isWarning if true, this validation should be stored as a warning, otherwise as an error * * @return the updated error handler */ protected CmsXmlContentErrorHandler validateValue( CmsObject cms, I_CmsXmlContentValue value, String valueStr, CmsXmlContentErrorHandler errorHandler, boolean isWarning) { if (isWarning) { // default schema validation only applies to errors return errorHandler; } if (!value.validateValue(valueStr)) { // value is not valid, add an error to the handler String message = getValidationMessage(cms, value, value.getTypeName(), valueStr, true, false); errorHandler.addError(value, message); } return errorHandler; }
/** * Adds an error message to the internal list of errors, * also raised the "has errors" flag.<p> * * @param value the value that contains the error * @param message the error message to add */ public void addError(I_CmsXmlContentValue value, String message) { m_hasErrors = true; Locale locale = value.getLocale(); Map<String, String> localeErrors = getLocalIssueMap(m_errors, locale); localeErrors.put(value.getPath(), message); if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key(Messages.LOG_XMLCONTENT_VALIDATION_ERR_2, value.getPath(), message)); } }
if (getValidationHandler().hasWarnings(getElementLocale())) {
if (!nested && showErrors && (getValidationHandler().hasErrors())) { result.append("<span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\"></span>"); boolean differentLocaleErrors = false; if ((getValidationHandler().getErrors(getElementLocale()) == null) || (getValidationHandler().getErrors().size() > getValidationHandler().getErrors(getElementLocale()).size())) { Map locErrors = getValidationHandler().getErrors(); Iterator locErrorsIter = locErrors.entrySet().iterator(); while (locErrorsIter.hasNext()) { && getValidationHandler().hasErrors(getElementLocale()) && getValidationHandler().getErrors(getElementLocale()).containsKey(key)) { result.append(getEditorResourceUri()); result.append("error.png\" border=\"0\" alt=\"\" align=\"left\" hspace=\"5\">"); result.append(resolveMacros(getValidationHandler().getErrors(getElementLocale()).get(key))); result.append("</td><td></td></tr>\n"); } else { result.append("error.png"); result.append("\" border=\"0\" alt=\"\"></td><td class=\"xmlTdError\">"); result.append(resolveMacros(getValidationHandler().getErrors(getElementLocale()).get(key))); result.append("</td><td></td></tr>\n"); && getValidationHandler().hasWarnings(getElementLocale()) && getValidationHandler().getWarnings(getElementLocale()).containsKey(key)) { result.append(getEditorResourceUri());
if (errorHandler != null) { errorHandler.addWarning(value, Messages.get().getBundle(value.getLocale()).key( Messages.GUI_XMLCONTENT_CHECK_WARNING_NOT_RELEASED_0)); if (errorHandler != null) { errorHandler.addWarning(value, Messages.get().getBundle(value.getLocale()).key( Messages.GUI_XMLCONTENT_CHECK_WARNING_EXPIRED_0)); if (errorHandler != null) { errorHandler.addError(value, Messages.get().getBundle(value.getLocale()).key( Messages.GUI_XMLCONTENT_CHECK_ERROR_0));
/** * Creates a new validation node visitor.<p> * * @param cms the initialized OpenCms user context (required for VFS access) */ public CmsXmlContentValidationVisitor(CmsObject cms) { // start with a new instance of the error handler m_errorHandler = new CmsXmlContentErrorHandler(); // store reference to the provided CmsObject m_cms = cms; }