1 /* 2 * This file is part of *** M y C o R e *** 3 * See http://www.mycore.de/ for details. 4 * 5 * MyCoRe is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * MyCoRe is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package org.mycore.frontend.xeditor.validation; 20 21 /** 22 * Validates date values specified by one or more SimpleDateFormat patterns separated by ";". 23 * Example: <xed:validate type="date" format="yyyy-MM-dd;dd.MM.yyyy" ... /> 24 * * 25 * @author Frank L\u00FCtzenkirchen 26 */ 27 public class MCRDateValidator extends MCRValidator { 28 29 private static final String TYPE_DATE = "date"; 30 31 private static final String ATTR_TYPE = "type"; 32 33 private static final String ATTR_FORMAT = "format"; 34 35 /** The converter used to convert strings to dates */ 36 protected MCRDateConverter converter; 37 38 @Override 39 public boolean hasRequiredAttributes() { 40 return TYPE_DATE.equals(getAttributeValue(ATTR_TYPE)) && hasAttributeValue(ATTR_FORMAT); 41 } 42 43 @Override 44 public void configure() { 45 String format = getAttributeValue(ATTR_FORMAT); 46 converter = new MCRDateConverter(format); 47 } 48 49 @Override 50 protected boolean isValid(String value) { 51 return (converter.string2date(value) != null); 52 } 53 }