/*
 * Récupère le code collectivité ainsi que le code bugdétaire du document contrôllé en question (c)JPT
 */
package fr.gouv.finances.cp.xemelios.controls.comm;

import java.util.Hashtable;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

import fr.gouv.finances.cp.utils.Pair;
import fr.gouv.finances.cp.xemelios.controls.AbstractUnitControl;
import fr.gouv.finances.cp.xemelios.controls.Anomalie;
import fr.gouv.finances.cp.xemelios.controls.ControlContentHandler;

public class COLLBUDG extends AbstractUnitControl {
    public static final transient String CTRL_ID = "COLLBUDG";
	private static Logger logger = Logger.getLogger(COLLBUDG.class);
//	private DocumentControlModel docModel;
	private String coll_path = null;
	private String budg_path = null;
	private String coll_lib = null;
	private String budg_lib = null;
	private ControlContentHandler cch = null;

	public void startDocument() throws SAXException {
		logger.info("In "+CTRL_ID);
	}
	
	public void startElement(String uri, String localName, String qName,Attributes atts, String xpath) {
		if (coll_path.equals("/"+xpath)) {
			Pair p = cch.getCollectivite();
			if (p==null) p = new Pair();
			p.key = atts.getValue("V");
//p.libelle = "";
			cch.setCollectivite(p);
		}
		if (coll_lib.equals("/"+xpath)) {
			Pair p = cch.getCollectivite();
			if (p == null) p = new Pair();
//if (p.key == null) p.key = "";
			p.libelle = atts.getValue("V");
			cch.setCollectivite(p);
		}
		
		if (budg_path.equals("/"+xpath)) {
			Pair p = cch.getBudget();
			if (p==null) p = new Pair();
			p.key = atts.getValue("V");
//p.libelle = "";
			cch.setBudget(p);
		}
		if (budg_lib.equals("/"+xpath)) {
			Pair p = cch.getBudget();
			if (p == null) p = new Pair();
//if(p.key == null) p.key = "";
			p.libelle = atts.getValue("V");
			cch.setBudget(p);
		}
	}
	
	public Vector<Anomalie> endElement(String uri, String localName, String qName,String xpath) {
		return null;
	}
	
//	public DocumentControlModel getDocumentModel() {
//		return docModel;
//	}

//	public void setDocumentModel(DocumentControlModel docModel) {
//		this.docModel=docModel;
//	}

	public void endDocument() throws SAXException {}
	
	public void characters(char[] ch, int start, int length, String xpath) {}
	
	public void ignorableWhitespace(char[] ch, int start, int length,String xpath) {}
	
	public void startPrefixMapping(String prefix, String uri, String xpath) {}
	
	public void endPrefixMapping(String prefix, String xpath) {}
	
	public void processingInstruction(String target, String data, String xpath) {}
	
	public void skippedEntity(String name, String xpath) {}
	
	public void setParameters(Hashtable<String,Object> params) {
	}
	
	public void setDocumentLocator(Locator locator) {}

	public String getColl_path() {
		return coll_path;
	}

	public void setColl_path(String coll_path) {
		this.coll_path = coll_path.replaceAll("@V", "");
	}
	
	public ControlContentHandler getCch() {
		return cch;
	}

	public void setCch(
			ControlContentHandler cch) {
		this.cch = cch;
	}

	public String getBudg_path() {
		return budg_path;
	}

	public void setBudg_path(String budg_path) {
		this.budg_path = budg_path.replaceAll("@V", "");
	}

	public String getBudg_lib() {
		return budg_lib;
	}

	public void setBudg_lib(
			String budg_lib) {
		this.budg_lib = budg_lib;
	}

	public String getColl_lib() {
		return coll_lib;
	}

	public void setColl_lib(
			String coll_lib) {
		this.coll_lib = coll_lib;
	}
}
