/** * This plug-in splits flat and hierarchical XML file into records for record * by record processing. It accepts two parameters: * sourceXPath ( XPath of the element to be split) * and splitSize (number of record(s) to split at a time). * To use this plug-in in the flow: * Input: It accepts XML input stream. Any Schema, Mapping or other activities * like Advanced Database Source, Database Source, XML File Source can be * used for input to this plug-in. * Output: XML data stream as per given parameters. * Note: To generate output stream, use "Multiple Stream" property * and assign any value to the "Stream Name". **/ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.Vector; import com.adeptia.indigo.services.ServiceException; import com.adeptia.indigo.system.IndigoConfig; InputStream inputStream = null; OutputStream outputStream = null; try { boolean processRecord = true; Integer startPosition = (Integer) context.get("startPosition"); if (startPosition == null) { startPosition = 1; } inputStream = service.getSourceStream(); outputStream = service.getOutputStream(); int queueSize = Integer.parseInt(service .getValueByName("splitSize")); String sourceXPath = service.getValueByName("sourceXPath"); String characterSetEncoding = service.getEncodingUsed(); Integer totalRecordCount = (Integer) context .get("totalRecordCount"); DataSplitter handler = new DataSplitter(); if (totalRecordCount == null) { totalRecordCount = handler.splitData(inputStream, outputStream, startPosition.intValue(), queueSize, sourceXPath, characterSetEncoding); if (totalRecordCount <= 0 ) processRecord = false; } else { totalRecordCount = totalRecordCount - queueSize; if (totalRecordCount <= 0 ) processRecord = false; startPosition = startPosition + queueSize; handler.splitData(inputStream, outputStream, startPosition .intValue(), queueSize, sourceXPath, characterSetEncoding); } context.put("processRecord", processRecord); context.put("totalRecordCount", totalRecordCount); context.put("startPosition", startPosition); } catch (Exception e) { throw new ServiceException(e); } finally { try { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } catch (Exception e) { e.printStackTrace(); } }