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

Java tutorial

Introduction

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

Source

/*$Id: FolkeBibValidator.java 12977 2009-02-11 14:03:06Z 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 public library 
 * (folkebibliotek) schema.
 *
 * @author: Henning Kulander hennikul@linpro.no
 * @author $Author: jens $
 * @version $Rev: 12977 $
 * @date $Date: 2009-02-11 15:03:06 +0100 (Wed, 11 Feb 2009) $
 * @since 2005-02-02 (Rev. 903)
 * copyright ABM-Utvikling
 * 
 */
public class FolkeBibValidator extends SchemaReportValidator {
    private static final Log logger = (Log) LogFactory.getLog(FolkeBibValidator.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("folkeBibSchema");

        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 = 385; i <= 387; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 410; i <= 430; 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 <= 101; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 257));
            for (i = 389; i <= 390; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 431; i <= 484; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }

            break;
        case 4:
            fieldKeys.add(fieldNameFormater.format((long) 137));
            fieldKeys.add(fieldNameFormater.format((long) 143));
            for (i = 146; i <= 147; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 150));
            fieldKeys.add(fieldNameFormater.format((long) 186));
            for (i = 188; i <= 191; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 193; i <= 201; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 391; i <= 398; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            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 = 223; i <= 225; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 230; i <= 242; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            fieldKeys.add(fieldNameFormater.format((long) 244));
            for (i = 399; i <= 402; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }

            break;
        case 6:
            for (i = 259; i <= 266; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            for (i = 381; i <= 382; i++) {
                fieldKeys.add(fieldNameFormater.format((long) i));
            }
            break;
        default:
            break;
        }
        logger.debug("Keys to validate: " + fieldKeys);
        setValidateFieldKeys(fieldKeys);
        super.validate(obj, errors);
    }

    /**
     * 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;
    }

}