Java tutorial
/*$Id: GrunnskoleBibValidator.java 8683 2008-02-22 09:38:00Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2005 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.abmstatistikk.annualstatistic.service; import java.text.NumberFormat; import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.validation.Errors; /** * Validator for primary school library * (grunnskolebibliotek) schema. * * @author: Henning Kulander hennikul@linpro.no * @author $Author: jens $ * @version $Rev: 8683 $ * @date $Date: 2008-02-22 10:38:00 +0100 (Fri, 22 Feb 2008) $ * @since 2005-02-08 * copyright ABM-Utvikling * */ public class GrunnskoleBibValidator extends SchemaReportValidator { private static final Log logger = (Log) LogFactory.getLog(GrunnskoleBibValidator.class); private int pageNumber; public boolean supports(Class clazz) { logger.info("Checking if validator supports " + clazz.getName()); return (clazz.equals(FolkeBibScreen.class) || super.supports(clazz)); } public void validate(Object obj, Errors errors) { setSchemaName("grunnskoleBibSchema"); computeValidateFieldKeys(); super.validate(obj, errors); } public void computeValidateFieldKeys() { NumberFormat fieldNameFormater = NumberFormat.getNumberInstance(); fieldNameFormater.setMinimumIntegerDigits(3); Set fieldKeys = new HashSet(); int i; switch (pageNumber) { case 1: break; case 2: fieldKeys.add(fieldNameFormater.format((long) 226)); for (i = 405; i <= 409; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 3: for (i = 13; i <= 18; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 25; i <= 30; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 202; i <= 203; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 148; i <= 150; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 67; i <= 68; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; case 4: for (i = 102; i <= 104; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 108; i <= 119; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 165; i <= 166; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } for (i = 183; i <= 184; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } fieldKeys.add(fieldNameFormater.format((long) 225)); break; case 5: fieldKeys.add(fieldNameFormater.format((long) 244)); fieldKeys.add(fieldNameFormater.format((long) 247)); fieldKeys.add(fieldNameFormater.format((long) 250)); fieldKeys.add(fieldNameFormater.format((long) 253)); for (i = 381; i <= 382; i++) { fieldKeys.add(fieldNameFormater.format((long) i)); } break; default: break; } logger.debug("Keys to validate: " + fieldKeys); setValidateFieldKeys(fieldKeys); } /** * Getting pageNumber of page to be validated. * * @return pageNumber - int the pageNumber of page to be validated. */ public int getPageNumber() { return pageNumber; } /** * Setting pageNumber of page to be validated. * * @param pageNumber The pageNumber to set. */ public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; } }