001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.shared; 029 030import com.google.gwt.user.client.rpc.IsSerializable; 031 032/** 033 * The result of a single field validation.<p> 034 * 035 * @since 8.0.0 036 */ 037public class CmsValidationResult implements IsSerializable { 038 039 /** Convenience constant which contains a validation result for successful validations. */ 040 public static final CmsValidationResult VALIDATION_OK = new CmsValidationResult(null); 041 042 /** The error message to display, or null. */ 043 private String m_errorMessage; 044 045 /** The flag indicating whether the field value should be replaced. */ 046 private boolean m_hasNewValue; 047 048 /** The replacement for the field value. */ 049 private String m_newValue; 050 051 /** 052 * Creates a new validation result which doesn't replace the current field value.<p> 053 * 054 * @param errorMessage the error message to display, or null if there 055 */ 056 public CmsValidationResult(String errorMessage) { 057 058 m_errorMessage = errorMessage; 059 m_hasNewValue = false; 060 } 061 062 /** 063 * Creates a new validation result which also replaces the current field value.<p> 064 * 065 * @param errorMessage the error message to display, or null if there was no error 066 * @param newValue the replacement for the field value 067 */ 068 public CmsValidationResult(String errorMessage, String newValue) { 069 070 m_errorMessage = errorMessage; 071 m_newValue = newValue; 072 m_hasNewValue = true; 073 } 074 075 /** 076 * Hidden default constructor.<p> 077 */ 078 protected CmsValidationResult() { 079 080 // do nothing 081 } 082 083 /** 084 * Returns the error message, or null if the validation has succeeded.<p> 085 * 086 * @return an error message or null the 087 */ 088 public String getErrorMessage() { 089 090 return m_errorMessage; 091 } 092 093 /** 094 * Returns the replacement for the field value.<p> 095 * 096 * @return the replacement for the field value 097 */ 098 public String getNewValue() { 099 100 return m_newValue; 101 } 102 103 /** 104 * Returns true if the field value should be replaced.<p> 105 * 106 * @return true if the field value should be replaced 107 */ 108 public boolean hasNewValue() { 109 110 return m_hasNewValue; 111 } 112 113 /** 114 * Returns true if the validation has succeeded.<p> 115 * 116 * @return true if the validation has succeeded 117 */ 118 public boolean isOk() { 119 120 return m_errorMessage == null; 121 } 122 123}