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

Java tutorial

Introduction

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

Source

/*$Id: MobilBibValidator.java 12985 2009-02-11 21:46:46Z 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 mobil library 
 * (mobile bibliotek enheter) schema.
 *
 * @author: Henning Kulander hennikul@linpro.no
 * @author $Author: jens $
 * @version $Rev: 12985 $
 * @date $Date: 2009-02-11 22:46:46 +0100 (Wed, 11 Feb 2009) $
 * @since 2005-01-31 (Rev. 858)
 * copyright ABM-Utvikling
 * 
 */
public class MobilBibValidator extends SchemaReportValidator {
    private static final Log logger = (Log) LogFactory.getLog(MobilBibValidator.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("mobilBibSchema");

        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));
            }

            fieldKeys.add(fieldNameFormater.format((long) 383));

            for (i = 385; i <= 387; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }

            break;
        case 3:
            fieldKeys.add(fieldNameFormater.format((long) 82));
            for (i = 84; i <= 86; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 90));

            for (i = 97; i <= 99; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 389; i <= 390; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 431; i <= 452; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        case 4:
            fieldKeys.add(fieldNameFormater.format((long) 137));
            fieldKeys.add(fieldNameFormater.format((long) 140));
            fieldKeys.add(fieldNameFormater.format((long) 143));
            fieldKeys.add(fieldNameFormater.format((long) 146));
            for (i = 169; i <= 179; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 371));
            for (i = 392; i <= 394; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 403));
            break;
        case 5:
            for (i = 205; i <= 210; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 215; i <= 218; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 223; 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;
    }

}