private Fragment insertRecordDetector(final PipelineElementType elementType,
                                          final Fragment fragment,
                                          final boolean input,
                                          final SteppingController controller) {
        Fragment result = fragment;

        if (!input) {
            if (elementType.hasRole(PipelineElementType.ROLE_PARSER)) {
                if (controller.getRecordDetector() == null
                    || !(controller.getRecordDetector() instanceof SAXRecordDetector)) {
                    final SAXRecordDetector recordDetector = elementFactory.getElementInstance(SAXRecordDetector.class);
                    controller.setRecordDetector(recordDetector);
                    ((HasTargets) fragment.getOut()).setTarget(recordDetector);
                    result = new Fragment(fragment.getIn(), recordDetector);
                }

            } else if (elementType.hasRole(PipelineElementType.ROLE_READER)) {
                if (controller.getRecordDetector() == null) {
                    final ReaderRecordDetectorElement recordDetector = elementFactory.getElementInstance(
                            ReaderRecordDetectorElement.class);
                    controller.setRecordDetector(recordDetector);
                    ((HasTargets) fragment.getOut()).setTarget(recordDetector);
                    result = new Fragment(fragment.getIn(), recordDetector);
                }
            }
        }

        return result;
    }
Insert a pipeline element that will notify the controller when the end of
a record is detected. For XML this is whenever endDocument() is called.
For text it it when a new line character is reached.

@param elementType The type of the element that we might be inserting a record
                   detector before or after.
@param fragment    The current pipeline fragment we are modifying.
@param input       True if we are modifying the input element of the fragment,
                   false if we are modifying the output.
@param controller  The stepping controller.
@return A modified pipeline fragment if a record detector was added or
the original if it remains unchanged.
stroom-pipeline/src/main/java/stroom/pipeline/factory/PipelineFactory.java