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

Java tutorial

Introduction

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

Source

/*$Id: FylkesBibValidator.java 13015 2009-02-13 13:11:39Z 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 county library 
 * (fylkesbibliotek) schema.
 *
 * @author: Henning Kulander hennikul@linpro.no
 * @author $Author: jens $
 * @version $Rev: 13015 $
 * @date $Date: 2009-02-13 14:11:39 +0100 (Fri, 13 Feb 2009) $
 * @since 2005-02-02 (Rev. 903)
 * copyright ABM-Utvikling
 * 
 */
public class FylkesBibValidator extends SchemaReportValidator {
    private static final Log logger = (Log) LogFactory.getLog(FylkesBibValidator.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) {
        NumberFormat fieldNameFormater = NumberFormat.getNumberInstance();
        fieldNameFormater.setMinimumIntegerDigits(3);
        Set fieldKeys = new HashSet();
        int i;

        setSchemaName("fylkesBibSchema");

        switch (pageNumber) {
        case 1:
            break;
        case 2:
            for (i = 13; i <= 14; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 16; i <= 17; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 19; i <= 20; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 22; i <= 23; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 31; i <= 32; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 34; i <= 35; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 37; i <= 38; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 40; i <= 41; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 46; i <= 47; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 49; i <= 50; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 58; i <= 59; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 61; i <= 62; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 64; i <= 65; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 365; i <= 366; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 385; i <= 386; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        case 3:
            for (i = 276; i <= 343; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 344; i <= 355; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 362; i <= 364; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 481; i <= 483; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 485));
            break;
        case 4:
            fieldKeys.add(fieldNameFormater.format((long) 122));
            fieldKeys.add(fieldNameFormater.format((long) 125));
            fieldKeys.add(fieldNameFormater.format((long) 143));
            for (i = 146; i <= 147; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 268; i <= 275; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 367; i <= 370; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 392; i <= 394; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 404));
            fieldKeys.add(fieldNameFormater.format((long) 484));
            break;
        case 5:
            for (i = 205; i <= 210; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 215; i <= 216; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 219; i <= 224; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 381; i <= 382; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 401; i <= 402; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        default:
            break;
        }
        logger.debug("Keys to validate: " + fieldKeys);
        setValidateFieldKeys(fieldKeys);
        super.validate(obj, errors);
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

}