public void generate(Properties sepaParams, OutputStream os, boolean validate) throws Exception
{
Integer maxIndex = SepaUtil.maxIndex(sepaParams);
//Document
Document doc = new Document();
//Customer Credit Transfer Initiation
doc.setPain00800101(new Pain00800101());
doc.getPain00800101().setGrpHdr(new GroupHeader20());
final String sepaId = sepaParams.getProperty("sepaid");
final String pmtInfId = sepaParams.getProperty("pmtinfid");
//Group Header
doc.getPain00800101().getGrpHdr().setMsgId(sepaId);
doc.getPain00800101().getGrpHdr().setCreDtTm(SepaUtil.createCalendar(null));
doc.getPain00800101().getGrpHdr().setNbOfTxs(String.valueOf(maxIndex != null ? maxIndex + 1 : 1));
doc.getPain00800101().getGrpHdr().setCtrlSum(SepaUtil.sumBtgValue(sepaParams, maxIndex));
doc.getPain00800101().getGrpHdr().setGrpg(Grouping2Code.GRPD);
doc.getPain00800101().getGrpHdr().setInitgPty(new PartyIdentification20());
doc.getPain00800101().getGrpHdr().getInitgPty().setNm(sepaParams.getProperty("src.name"));
//Payment Information
PaymentInstructionInformation5 pmtInf = new PaymentInstructionInformation5();
doc.getPain00800101().setPmtInf(pmtInf);
pmtInf.setPmtInfId(pmtInfId != null && pmtInfId.length() > 0 ? pmtInfId : sepaId);
pmtInf.setPmtMtd(PaymentMethod2Code.DD);
pmtInf.setReqdColltnDt(SepaUtil.createCalendar(sepaParams.getProperty("targetdate")));