/*
 * ValidarCIIUOpcional.java
 *
 * Created on 27 de marzo de 2007, 03:34 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Julian
 *12,C
 */
package com.fidufosyga.rules;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.fidufosyga.context.Context;

/**
 * 
 * @author Jsolano
 */
public class ValidarCIIUOpcional extends AbstractRule {

	public static final String CIIUS = "CIIU";

	public boolean performValidation(String field, String registro[],
			String nombreArchivo) {

		if (field.length() == 0)
			return false;
		if (field.length() != 4)
			return true;

		if (Context.getContext().getAttribute(CIIUS) == null) {
			Properties defaultProps = new Properties();
			FileInputStream in;

			try {

				in = new FileInputStream(System.getProperty("user.dir")
						+ File.separator + "ciiu" + File.separator
						+ "ciius.properties");
				defaultProps.load(in);
				in.close();
				Context.getContext().addAttribute(CIIUS, defaultProps);

			} catch (FileNotFoundException e) {

				return false;
			} catch (IOException e) {

				return false;

			}

		}

		if (((Properties) Context.getContext().getAttribute(CIIUS))
				.getProperty(field) != null) {
			// System.out.println(((Properties)Context.getContext().getAttribute(CIIUS)).getProperty(field))
			// ;
			return false;
		}
		return true;
	}
}
