--- /dev/null
+/*
+ * Copyright
+ * 2010 axYus - http://www.axyus.com
+ * 2010 C.Marchand - christophe.marchand@axyus.com
+ *
+ * This file is part of XEMELIOS_NB.
+ *
+ * XEMELIOS_NB 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS_NB 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_NB; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+package fr.gouv.finances.dgfip.xemelios.versement.importer;
+
+import fr.gouv.finances.cp.utils.PropertiesExpansion;
+import fr.gouv.finances.dgfip.utils.xml.FactoryProvider;
+import fr.gouv.finances.dgfip.utils.xml.SAXWriter;
+import fr.gouv.finances.dgfip.xemelios.auth.XemeliosUser;
+import fr.gouv.finances.dgfip.xemelios.common.FileInfo;
+import fr.gouv.finances.dgfip.xemelios.importers.DefaultImporter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.math.BigDecimal;
+import java.util.Hashtable;
+import java.util.Stack;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.Attributes2Impl;
+import org.xml.sax.ext.DefaultHandler2;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ *
+ * @author cmarchand
+ */
+public class VersementImporter extends DefaultImporter {
+ private static final Logger logger = Logger.getLogger(VersementImporter.class);
+ File outputTmpFile;
+
+ public VersementImporter(XemeliosUser user, PropertiesExpansion applicationProperties) {
+ super(user, applicationProperties);
+ }
+
+ @Override
+ protected FileInfo importFile(File f) throws Exception {
+ getImpSvcProvider().startLongWait();
+ File newFile = wrapFile(f);
+ return super.importFile(newFile);
+ }
+ @Override
+ public void done() {
+ super.done();
+ outputTmpFile.delete();
+ }
+
+ /**
+ * Constitue l'état de totalisation
+ * @param f
+ * @return
+ */
+ protected File wrapFile(File f) {
+ SAXParserFactory fact = FactoryProvider.getSaxParserFactory();
+ outputTmpFile = new File(getTmpDir(),f.getName());
+ while(outputTmpFile.exists()) {
+ if(outputTmpFile.equals(f)) {
+ File tmpDir = outputTmpFile.getParentFile();
+ tmpDir = new File(tmpDir,"TMP-DIR");
+ tmpDir.mkdirs();
+ outputTmpFile = new File(tmpDir,f.getName());
+ } else {
+ outputTmpFile.delete();
+ }
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(outputTmpFile);
+ String encoding = getFileEncoding(f);
+ SAXWriter writer = new SummerHandler(fos, encoding, "1.0");
+ SAXParser parser = fact.newSAXParser();
+ parser.parse(f, writer);
+ } catch(Exception ex) {
+ logger.error("wrapFile(File):",ex);
+ } finally {
+ try {
+ fos.flush();
+ fos.close();
+ } catch(Throwable t) {}
+ }
+ return outputTmpFile;
+ }
+ private static void writeElement(String elementName, String value, DefaultHandler2 dh) throws SAXException {
+ if(value==null) return;
+ if(value.length()==0) return;
+ VAttr att = new VAttr(value);
+ dh.startElement(XMLConstants.NULL_NS_URI, elementName, elementName, att);
+ dh.endElement(XMLConstants.NULL_NS_URI, elementName, elementName);
+ }
+ private class InfoTiers {
+ String IdTiers, DteMalade, TypTiers, NatIdTiers, dteIdTiers, RefIdTiers;
+ String CatTiers, NatJur, Civilite, Nom, ComplNom, Prenom, Typologie;
+ @Override
+ public int hashCode() {
+ return getHashKey().hashCode();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final InfoTiers other = (InfoTiers) obj;
+ if ((this.IdTiers == null) ? (other.IdTiers != null) : !this.IdTiers.equals(other.IdTiers)) {
+ return false;
+ }
+ if ((this.RefIdTiers == null) ? (other.RefIdTiers != null) : !this.RefIdTiers.equals(other.RefIdTiers)) {
+ return false;
+ }
+ return true;
+ }
+ private String getHashKey() {
+ return new String(IdTiers==null?" ":IdTiers).concat("/").concat(RefIdTiers==null?" ":RefIdTiers);
+ }
+ public void marshall(DefaultHandler2 dh) throws SAXException {
+ AttributesImpl emptyAttr = new AttributesImpl();
+ dh.startElement(XMLConstants.NULL_NS_URI, "InfoTiers", "InfoTiers", emptyAttr);
+ writeElement("IdTiers", IdTiers, dh);
+ writeElement("DteMalade", DteMalade, dh);
+ writeElement("TypTiers", TypTiers, dh);
+ writeElement("NatIdTiers", NatIdTiers, dh);
+ writeElement("DteIdTiers", dteIdTiers, dh);
+ writeElement("RefTiers", RefIdTiers, dh);
+ writeElement("CatTiers", CatTiers, dh);
+ writeElement("NatJur", NatJur, dh);
+ writeElement("Civilite", Civilite, dh);
+ writeElement("Nom", Nom, dh);
+ writeElement("ComplNom", ComplNom, dh);
+ writeElement("Prenom", Prenom, dh);
+ writeElement("Typologie", Typologie, dh);
+ dh.endElement(XMLConstants.NULL_NS_URI, "InfoTiers", "InfoTiers");
+ }
+ }
+ private class CpteBancaire {
+ String type, ID, IdPayInt, IdBancInt, CodeEtab, CodeGuic, IdCpte;
+ String CleRib, LibBanc, TitCpte, DteBanc;
+ public void marshall(DefaultHandler2 dh) throws SAXException {
+ dh.startElement(XMLConstants.NULL_NS_URI, "CpteBancaire", "CpteBancaire", new Attributes2Impl());
+ writeElement("ID", ID, dh);
+ writeElement("IdPayInt", IdPayInt, dh);
+ writeElement("IdBancInt", IdBancInt, dh);
+ writeElement("CodeEtab", CodeEtab, dh);
+ writeElement("CodeGuic", CodeGuic, dh);
+ writeElement("IdCpte", IdCpte, dh);
+ writeElement("CleRib", CleRib, dh);
+ writeElement("LibBanc", LibBanc, dh);
+ writeElement("TitCpte", TitCpte, dh);
+ writeElement("DteBanc", DteBanc, dh);
+ dh.endElement(XMLConstants.NULL_NS_URI, "CpteBancaire", "CpteBancaire");
+ }
+ }
+ private class Adresse {
+ String TypAdr, Adr1, Adr2, Adr3, CP, Ville, CodRes, CodPays, DateAdr;
+ public void marshall(DefaultHandler2 dh) throws SAXException {
+ Attributes2Impl emptyAttr = new Attributes2Impl();
+ dh.startElement(XMLConstants.NULL_NS_URI, "Adresse", "Adresse", emptyAttr);
+ writeElement("TypAdr", TypAdr, dh);
+ writeElement("Adr1", Adr1, dh);
+ writeElement("Adr2", Adr2, dh);
+ writeElement("Adr3", Adr3, dh);
+ writeElement("CP", CP, dh);
+ writeElement("Ville", Ville, dh);
+ writeElement("CodRes", CodRes, dh);
+ writeElement("CodPays", CodPays, dh);
+ writeElement("DteAdr", DateAdr, dh);
+ dh.endElement(XMLConstants.NULL_NS_URI, "Adresse", "Adresse");
+ }
+ }
+ private class Destinataire {
+ InfoTiers infoTiers;
+ String DateNaissance;
+ Adresse adresse;
+ CpteBancaire cpteBancaire;
+ public Adresse getAdresse() {
+ return adresse;
+ }
+ public void setAdresse(Adresse adresse) {
+ this.adresse = adresse;
+ }
+ public CpteBancaire getCpteBancaire() {
+ return cpteBancaire;
+ }
+ public void setCpteBancaire(CpteBancaire cpteBancaire) {
+ this.cpteBancaire = cpteBancaire;
+ }
+ public InfoTiers getInfoTiers() {
+ return infoTiers;
+ }
+ public void setInfoTiers(InfoTiers infoTiers) {
+ this.infoTiers = infoTiers;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if(!(obj instanceof Destinataire)) return false;
+ else {
+ Destinataire other = (Destinataire)obj;
+ if(other.infoTiers==null || infoTiers==null) return false;
+ else return infoTiers.equals(other.infoTiers);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 3;
+ hash = 59 * hash + (this.infoTiers != null ? this.infoTiers.hashCode() : 0);
+ hash = 59 * hash + (this.DateNaissance != null ? this.DateNaissance.hashCode() : 0);
+ hash = 59 * hash + (this.adresse != null ? this.adresse.hashCode() : 0);
+ hash = 59 * hash + (this.cpteBancaire != null ? this.cpteBancaire.hashCode() : 0);
+ return hash;
+ }
+
+ public String getHashKey() {
+ return infoTiers!=null ? infoTiers.getHashKey() : null;
+ }
+ public void marshall(DefaultHandler2 dh) throws SAXException {
+ AttributesImpl emptyAttrs = new AttributesImpl();
+ dh.startElement(XMLConstants.NULL_NS_URI, "Destinataire", "Destinataire", emptyAttrs);
+ infoTiers.marshall(dh);
+ if(DateNaissance!=null) {
+ AttributesImpl dtNAttrs = new AttributesImpl();
+ writeElement("DateNaissance", DateNaissance, dh);
+ }
+ if(adresse!=null)
+ adresse.marshall(dh);
+ cpteBancaire.marshall(dh);
+ dh.endElement(XMLConstants.NULL_NS_URI, "Destinataire", "Destinataire");
+ }
+ }
+ private class PjRef {
+ String Support, IdUnique, NomPJ;
+ public void marshall(DefaultHandler2 dh) throws SAXException {
+ dh.startElement(XMLConstants.NULL_NS_URI, "PJRef", "PJRef", new Attributes2Impl());
+ writeElement("Support", Support, dh);
+ writeElement("IdUnique", IdUnique, dh);
+ writeElement("NomPJ", NomPJ, dh);
+ dh.endElement(XMLConstants.NULL_NS_URI, "PJRef", "PJRef");
+ }
+ }
+ private class Versement {
+ Destinataire destinataire;
+ String codePrestation;
+ BigDecimal montantTotal;
+ String mt;
+ PjRef pjRef;
+ public Versement() {
+ super();
+// destinataire = new Destinataire();
+ }
+ public Destinataire getDestinataire() {
+ return destinataire;
+ }
+ public void setDestinataire(Destinataire destinataire) {
+ this.destinataire = destinataire;
+ }
+ public String getPrestation(String defaultPrestation) {
+ if(codePrestation==null) return defaultPrestation;
+ else return codePrestation;
+ }
+ }
+ private static class VAttr extends AttributesImpl {
+ public VAttr(String value) {
+ super();
+ addAttribute(XMLConstants.NULL_NS_URI, "V", "V", "xs:string", value);
+ }
+ }
+ private class SummerHandler extends SAXWriter {
+ private static final transient String NS = "http://www.minefi.gouv.fr/cp/helios/pes/versement/1.0";
+ private static final transient String ROOT = "/{"+NS+"}EtatVersement";
+ private static final transient String PRESTATION = ROOT+"/Prestation";
+ private static final transient String CODE_PRESTATION = PRESTATION+"/Code";
+ private static final transient String LIBELLE_PRESTATION = PRESTATION+"/Libelle";
+ private static final transient String DONNEES_VERSEMENT = ROOT+"/DonneesVersement";
+ private static final transient String VERSEMENT = DONNEES_VERSEMENT+"/Versement";
+ private static final transient String PRESTATION_VERSEMENT = VERSEMENT+"/Prestation";
+ private static final transient String DESTINATAIRE = VERSEMENT+"/Destinataire";
+ private static final transient String INFOTIERS = DESTINATAIRE+"/InfoTiers";
+ private static final transient String IDTIERS = INFOTIERS+"/IdTiers";
+ private static final transient String DATEMALADE = INFOTIERS+"/DteMalade";
+ private static final transient String TYPETIERS = INFOTIERS+"/TypTiers";
+ private static final transient String NATIDTIERS = INFOTIERS+"/NatIdTiers";
+ private static final transient String DTEIDTIERS = INFOTIERS+"/DteIdTiers";
+ private static final transient String REFTIERS = INFOTIERS+"/RefTiers";
+ private static final transient String CATTIERS = INFOTIERS+"/CatTiers";
+ private static final transient String NATJUR = INFOTIERS+"/NatJur";
+ private static final transient String CIVILITE = INFOTIERS+"/Civilite";
+ private static final transient String NOM = INFOTIERS+"/Nom";
+ private static final transient String COMPLNOM = INFOTIERS+"/ComplNom";
+ private static final transient String PRENOM = INFOTIERS+"/Prenom";
+ private static final transient String TYPOLOGIE = INFOTIERS+"/Typologie";
+ private static final transient String DATE_NAISSANCE = DESTINATAIRE+"/DateNaissance";
+ private static final transient String ADRESSE = DESTINATAIRE+"/Adresse";
+ private static final transient String TYPEADR = ADRESSE+"/TypAdr";
+ private static final transient String ADR1 = ADRESSE+"/Adr1";
+ private static final transient String ADR2 = ADRESSE+"/Adr2";
+ private static final transient String ADR3 = ADRESSE+"/Adr3";
+ private static final transient String CP = ADRESSE+"/CP";
+ private static final transient String VILLE = ADRESSE+"/Ville";
+ private static final transient String CODRES = ADRESSE+"/CodRes";
+ private static final transient String CODPAYS = ADRESSE+"/CodPays";
+ private static final transient String DTEADR = ADRESSE+"/DteAdr";
+ private static final transient String CPTEBANC = DESTINATAIRE+"/CpteBancaire";
+ private static final transient String ID = CPTEBANC+"/ID";
+ private static final transient String IDPAYINT = CPTEBANC+"/IdPayInt";
+ private static final transient String IDBANCINT = CPTEBANC+"/IdBancInt";
+ private static final transient String CODEETAB = CPTEBANC+"/CodeEtab";
+ private static final transient String CODEGUIC = CPTEBANC+"/CodeGuic";
+ private static final transient String IDCPTE = CPTEBANC+"/IdCpte";
+ private static final transient String CLERIB = CPTEBANC+"/CleRib";
+ private static final transient String LIBBANC = CPTEBANC+"/LibBanc";
+ private static final transient String TITCPTE = CPTEBANC+"/TitCpte";
+ private static final transient String DTEBANC = CPTEBANC+"/DteBanc";
+ private static final transient String MT = VERSEMENT+"/Mt";
+ private static final transient String PJREF = VERSEMENT+"/Decision/PJRef";
+ private static final transient String SUPPORT = PJREF+"/Support";
+ private static final transient String IDUNIQUE = PJREF+"/IdUnique";
+ private static final transient String NOMPJ = PJREF+"/NomPJ";
+ private static final transient String ATTNAME = "V";
+ private String codePrestationPrincipale, libellePrestationPrincipale;
+ private Versement currentVersement = null;
+ private Stack<QName> xpath;
+ private Hashtable<String,Hashtable<String,Versement>> versements;
+ private PjRef currentPjRef;
+
+ public SummerHandler(OutputStream out, String encoding, String xmlVersion) {
+ super(out,encoding,xmlVersion);
+ }
+ @Override
+ public void startDocument() throws SAXException {
+ xpath = new Stack<QName>();
+ versements = new Hashtable<String, Hashtable<String, Versement>>();
+ super.startDocument();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ super.startElement(uri, localName, qName, attributes);
+ QName qn = new QName(uri, localName);
+ xpath.push(qn);
+ // TODO
+ String xp = getXPathString();
+//logger.debug(xp);
+ if(xp.equals(CODE_PRESTATION)) codePrestationPrincipale = attributes.getValue(ATTNAME);
+ else if(xp.equals(LIBELLE_PRESTATION)) libellePrestationPrincipale = attributes.getValue(ATTNAME);
+ else if(xp.equals(VERSEMENT)) currentVersement = new Versement();
+ else if(xp.equals(PRESTATION_VERSEMENT)) currentVersement.codePrestation = attributes.getValue(ATTNAME);
+ else if(xp.equals(DESTINATAIRE)) currentVersement.setDestinataire(new Destinataire());
+ else if(xp.equals(INFOTIERS)) currentVersement.getDestinataire().setInfoTiers(new InfoTiers());
+ else if(xp.equals(IDTIERS)) currentVersement.getDestinataire().getInfoTiers().IdTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(DATEMALADE)) currentVersement.getDestinataire().getInfoTiers().DteMalade = attributes.getValue(ATTNAME);
+ else if(xp.equals(TYPETIERS)) currentVersement.getDestinataire().getInfoTiers().TypTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(NATIDTIERS)) currentVersement.getDestinataire().getInfoTiers().NatIdTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(DTEIDTIERS)) currentVersement.getDestinataire().getInfoTiers().dteIdTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(REFTIERS)) currentVersement.getDestinataire().getInfoTiers().RefIdTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(CATTIERS)) currentVersement.getDestinataire().getInfoTiers().CatTiers = attributes.getValue(ATTNAME);
+ else if(xp.equals(NATJUR)) currentVersement.getDestinataire().getInfoTiers().NatJur = attributes.getValue(ATTNAME);
+ else if(xp.equals(CIVILITE)) currentVersement.getDestinataire().getInfoTiers().Civilite = attributes.getValue(ATTNAME);
+ else if(xp.equals(NOM)) currentVersement.getDestinataire().getInfoTiers().Nom = attributes.getValue(ATTNAME);
+ else if(xp.equals(COMPLNOM)) currentVersement.getDestinataire().getInfoTiers().ComplNom = attributes.getValue(ATTNAME);
+ else if(xp.equals(PRENOM)) currentVersement.getDestinataire().getInfoTiers().Prenom = attributes.getValue(ATTNAME);
+ else if(xp.equals(TYPOLOGIE)) currentVersement.getDestinataire().getInfoTiers().Typologie = attributes.getValue(ATTNAME);
+ else if(xp.equals(DATE_NAISSANCE))currentVersement.getDestinataire().DateNaissance = attributes.getValue(ATTNAME);
+ else if(xp.equals(ADRESSE)) currentVersement.getDestinataire().setAdresse(new Adresse());
+ else if(xp.equals(TYPEADR)) currentVersement.getDestinataire().getAdresse().TypAdr = attributes.getValue(ATTNAME);
+ else if(xp.equals(ADR1)) currentVersement.getDestinataire().getAdresse().Adr1 = attributes.getValue(ATTNAME);
+ else if(xp.equals(ADR2)) currentVersement.getDestinataire().getAdresse().Adr2 = attributes.getValue(ATTNAME);
+ else if(xp.equals(ADR3)) currentVersement.getDestinataire().getAdresse().Adr3 = attributes.getValue(ATTNAME);
+ else if(xp.equals(CP)) currentVersement.getDestinataire().getAdresse().CP = attributes.getValue(ATTNAME);
+ else if(xp.equals(VILLE)) currentVersement.getDestinataire().getAdresse().Ville = attributes.getValue(ATTNAME);
+ else if(xp.equals(CODRES)) currentVersement.getDestinataire().getAdresse().CodRes = attributes.getValue(ATTNAME);
+ else if(xp.equals(CODPAYS)) currentVersement.getDestinataire().getAdresse().CodPays = attributes.getValue(ATTNAME);
+ else if(xp.equals(DTEADR)) currentVersement.getDestinataire().getAdresse().DateAdr = attributes.getValue(ATTNAME);
+ else if(xp.equals(CPTEBANC)) {
+ currentVersement.getDestinataire().setCpteBancaire(new CpteBancaire());
+ currentVersement.getDestinataire().getCpteBancaire().type = attributes.getValue(ATTNAME);
+ } else if(xp.equals(ID)) currentVersement.getDestinataire().getCpteBancaire().ID = attributes.getValue(ATTNAME);
+ else if(xp.equals(IDBANCINT)) currentVersement.getDestinataire().getCpteBancaire().IdBancInt = attributes.getValue(ATTNAME);
+ else if(xp.equals(CODEETAB)) currentVersement.getDestinataire().getCpteBancaire().CodeEtab = attributes.getValue(ATTNAME);
+ else if(xp.equals(CODEGUIC)) currentVersement.getDestinataire().getCpteBancaire().CodeGuic = attributes.getValue(ATTNAME);
+ else if(xp.equals(IDCPTE)) currentVersement.getDestinataire().getCpteBancaire().IdCpte = attributes.getValue(ATTNAME);
+ else if(xp.equals(CLERIB)) currentVersement.getDestinataire().getCpteBancaire().CleRib = attributes.getValue(ATTNAME);
+ else if(xp.equals(LIBBANC)) currentVersement.getDestinataire().getCpteBancaire().LibBanc = attributes.getValue(ATTNAME);
+ else if(xp.equals(TITCPTE)) currentVersement.getDestinataire().getCpteBancaire().TitCpte = attributes.getValue(ATTNAME);
+ else if(xp.equals(DTEBANC)) currentVersement.getDestinataire().getCpteBancaire().DteBanc = attributes.getValue(ATTNAME);
+ else if(xp.equals(MT)) currentVersement.mt = attributes.getValue(ATTNAME);
+ else if(xp.equals(PJREF)) {
+ if(currentVersement.pjRef==null) {
+ currentVersement.pjRef = new PjRef();
+ currentPjRef = currentVersement.pjRef;
+ }
+ }
+ else if(xp.equals(SUPPORT)) {
+ if(currentPjRef!=null) currentPjRef.Support = attributes.getValue(ATTNAME);
+ } else if(xp.equals(IDUNIQUE)) {
+ if(currentPjRef!=null) currentPjRef.IdUnique = attributes.getValue(ATTNAME);
+ } else if(xp.equals(NOMPJ)) {
+ if(currentPjRef!=null) currentPjRef.NomPJ = attributes.getValue(ATTNAME);
+ }
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ // on vire les espaces
+ super.characters(ch, start, 0);
+ }
+
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ String xp = getXPathString();
+ if(xp.equals(VERSEMENT)) {
+ // on a finit le versement, il faut traiter
+ Hashtable<String,Versement> versementsPrestation = versements.get(currentVersement.getPrestation(codePrestationPrincipale));
+ if(versementsPrestation==null) {
+ versementsPrestation = new Hashtable<String, Versement>();
+ versements.put(currentVersement.getPrestation(codePrestationPrincipale), versementsPrestation);
+ }
+ if(currentVersement.getDestinataire()!=null) {
+ Versement v = versementsPrestation.get(currentVersement.getDestinataire().getHashKey());
+ if(v==null) {
+ try {
+ currentVersement.montantTotal = new BigDecimal(currentVersement.mt);
+ } catch(NumberFormatException bfEx) {
+ // on ignore
+ }
+ versementsPrestation.put(currentVersement.getDestinataire().getHashKey(), currentVersement);
+ } else {
+ BigDecimal nv = new BigDecimal(0);
+ try {
+ nv = new BigDecimal(currentVersement.mt);
+ } catch(NumberFormatException nfEx) {
+ // on ignore
+ }
+ v.montantTotal = v.montantTotal.add(nv);
+ }
+ }
+ // c'est fait, on le vire
+ currentVersement = null;
+ } else if(xp.equals(ROOT)) {
+ // TODO : ecrire le nouvel etat
+ Attributes emptyAttrs = new AttributesImpl();
+ startElement(XMLConstants.NULL_NS_URI, "TotalisationsDestinataires", "TotalisationsDestinataires", emptyAttrs);
+ for(String prestation:versements.keySet()) {
+ Hashtable<String,Versement> versementsPrestation = versements.get(prestation);
+ for(Versement v:versementsPrestation.values()) {
+ startElement(XMLConstants.NULL_NS_URI, "Totalisation", "Totalisation", emptyAttrs);
+ writeElement("Prestation", v.getPrestation(prestation), this);
+ v.getDestinataire().marshall(this);
+ writeElement("Montant", v.montantTotal.toPlainString(), this);
+ if(v.pjRef!=null) v.pjRef.marshall(this);
+ endElement(XMLConstants.NULL_NS_URI, "Totalisation", "Totalisation");
+ }
+ }
+ endElement(XMLConstants.NULL_NS_URI, "TotalisationsDestinataires", "TotalisationsDestinataires");
+ } else if(xp.equals(PJREF)) {
+ currentPjRef = null;
+ }
+ xpath.pop();
+ super.endElement(uri, localName, qName);
+ }
+ private String getXPathString() {
+ StringBuilder sb = new StringBuilder();
+ for(QName qn:xpath) {
+ sb.append("/").append(qn.toString());
+ }
+ return sb.toString();
+ }
+ }
+
+}