no.abmu.abmstatistikk.annualstatistic.service.VideregaaendeSkoleBibValidator.java Source code

Java tutorial

Introduction

Here is the source code for no.abmu.abmstatistikk.annualstatistic.service.VideregaaendeSkoleBibValidator.java

Source

/*$Id: VideregaaendeSkoleBibValidator.java 14218 2009-11-07 14:38:57Z 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 high school library 
 * (bibliotek i den videregende skole) schema.
 *
 * @author: Henning Kulander hennikul@linpro.no
 * @author $Author: jens $
 * @version $Rev: 14218 $
 * @date $Date: 2009-11-07 15:38:57 +0100 (Sat, 07 Nov 2009) $
 * @since 2005-02-06 (Rev. 965)
 * copyright ABM-Utvikling
 * 
 */
public class VideregaaendeSkoleBibValidator extends SchemaReportValidator {
    private static final Log logger = (Log) LogFactory.getLog(VideregaaendeSkoleBibValidator.class);

    private int pageNumber;

    public boolean supports(Class clazz) {
        logger.debug("Checking if validator supports " + clazz.getName());
        return (clazz.equals(FolkeBibScreen.class) || super.supports(clazz));
    }

    public void validate(Object obj, Errors errors) {
        setSchemaName("videregaaendeSkoleBibSchema");
        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 = 19; i <= 30; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 34; i <= 36; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 40; i <= 42; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 49; i <= 51; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 55; i <= 60; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 64; i <= 66; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 202; i <= 204; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        case 4:
            for (i = 69; i <= 70; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 80));
            fieldKeys.add(fieldNameFormater.format((long) 82));
            for (i = 84; i <= 86; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 91; i <= 96; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 486));
            break;
        case 5:
            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 = 148; i <= 150; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 167; i <= 168; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 183));
            fieldKeys.add(fieldNameFormater.format((long) 185));
            break;
        case 6:
            for (i = 211; i <= 214; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 225; i <= 229; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        case 7:
            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);

    }

    /**
     * getPageNumber.
     * 
     * @return Returns the pageNumber.
     */
    public int getPageNumber() {
        return pageNumber;
    }

    /**
     * setPageNumber.
     * 
     * @param pageNumber The pageNumber to set.
     */
    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

}