/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2005 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.cp.xemelios.controls.models;

import org.apache.commons.lang.StringEscapeUtils;
import org.xml.sax.SAXException;

import fr.gouv.finances.cp.utils.xml.marshal.InvalidXmlDefinition;
import fr.gouv.finances.cp.utils.xml.marshal.XmlAttributes;
import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
import fr.gouv.finances.cp.utils.xml.marshal.XmlOutputter;

/**
 * Modelise un champ de saisie
 * @author chm
 */
public class InputModel implements XmlMarshallable {
	public static final transient String TAG = "input";
	private String id, libelle, datatype, xmlFormat;
//	private boolean uppercase = false;
	
//    public boolean isUppercase() {
//        return uppercase;
//    }
	public InputModel(String tagName) { super(); }
	public void addCharacterData(String cData) throws SAXException {}
	public void addChild(XmlMarshallable child, String tagName) throws SAXException {}
	public XmlMarshallable getAttributes(XmlAttributes attributes) throws SAXException {
		id = attributes.getValue("id");
		libelle = attributes.getValue("libelle");
		datatype = attributes.getValue("datatype");
//		uppercase = attributes.getBooleanValue("uppercase");
//		value = attributes.getValue("value");
		xmlFormat = attributes.getValue("xml-format");
		return this;
	}
	public void marshall(XmlOutputter output) {
	    output.startTag(TAG);
	    output.addAttribute("id",id);
	    if(libelle!=null) output.addAttribute("libelle",StringEscapeUtils.escapeXml(libelle));
	    output.addAttribute("datatype",datatype);
//	    output.addAttribute("uppercase",uppercase);
	    if("date".equals(datatype)) output.addAttribute("xml-format",xmlFormat);
	    output.endTag(TAG);
	}
	public void validate() throws InvalidXmlDefinition {}
	public String getDatatype() {return datatype;}
	public String getId() {return id;}
	public String getLibelle() {return libelle;}
	public String getXmlDateFormat() { return xmlFormat; }
//	public String getValue() { return value; }
//	public void setValue(String value) { this.value=value; }
	@Override
	public InputModel clone() {
	    InputModel im = new InputModel(TAG);
	    im.id = this.id;
	    im.libelle = this.libelle;
	    im.datatype = this.datatype;
//	    im.uppercase = this.uppercase;
	    im.xmlFormat = this.xmlFormat;
//	    im.value=this.value;
	    return im;
	}
}
