src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSInseePatternPostprocessor.java
public class XFORMSInseePatternPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSInseePatternPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_INSEE_PATTERN_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, survey);
	}

	@Override
	public File process(File input, byte[] parameters, byte[] metadata, String survey) throws Exception {
		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.INSEE_PATTERN_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);
		try {
			saxonService.transformWithMetadata(inputStream, outputStream, FO_XSL, parameters, metadata);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of EditPatron post-processing " + outputForFRFile.getAbsolutePath());
		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_INSEE_PATTERN.name();
	}
}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSInseeModelPostprocessor.java
public class XFORMSInseeModelPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSInseeModelPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_INSEE_MODEL_XSL;


	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, null, null, survey);
	}

	@Override
	public File process(File input, byte[] parametersFile, byte[] metadata, byte[] specificTreatmentXsl, byte[] mapping, String survey) throws Exception {
		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.INSEE_MODEL_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		String sUB_TEMP_FOLDER = Constants.tEMP_DDI_FOLDER(Constants.sUB_TEMP_FOLDER(survey));

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);
		InputStream mappingStream=null;
		if(mapping!=null) {
			mappingStream = new ByteArrayInputStream(mapping);
		}
		else {
			File mappingFile = Constants.tEMP_MAPPING_TMP(sUB_TEMP_FOLDER);
			if(mappingFile.exists()) {
				logger.info("Loading mapping.xml file : "+mappingFile.getAbsolutePath());
				mappingStream = FileUtils.openInputStream(mappingFile);
			}
		}

		try {
			saxonService.transformInseeModelXforms(inputStream, outputStream, FO_XSL, mappingStream);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		mappingStream.close();
		logger.info("End of InseeModel post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;

	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_INSEE_MODEL.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/PoguesXmlInsertFilterLoopIntoQuestionTree.java
public class PoguesXmlInsertFilterLoopIntoQuestionTree implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(PoguesXMLPreprocessorGoToTreatment.class);

	private XslTransformation saxonService = new XslTransformation();

	@Override
	public File process(File inputFile, byte[] parametersFile, String surveyName, String in2out) throws Exception {

		logger.info("PoguesXMLPreprocessing Target : START");

		String outputPreprocessINSERTLOOPFILTERTREE = null;

		outputPreprocessINSERTLOOPFILTERTREE = FilenameUtils.removeExtension(inputFile.getAbsolutePath())
				+ Constants.TEMP_EXTENSION;

		logger.debug("INSERT LOOP FILTER TREE : -Input : " + inputFile + " -Output : " + outputPreprocessINSERTLOOPFILTERTREE + " -Stylesheet : "
				+ Constants.UTIL_POGUES_XML_LOOP_FILTER_INTO_QUESTION_TREE_XSL + " -Parameters : "
				+ (parametersFile == null ? "Default parameters" : "Provided parameters"));

		InputStream isInputFile = FileUtils.openInputStream(inputFile);
		InputStream isUTIL_POGUES_XML_LOOP_FILTER_INTO_QUESTION_TREE_XSL = Constants
				.getInputStreamFromPath(Constants.UTIL_POGUES_XML_LOOP_FILTER_INTO_QUESTION_TREE_XSL);
		OutputStream osINSERTLOOPFILTERTREE = FileUtils.openOutputStream(new File(outputPreprocessINSERTLOOPFILTERTREE));

		try {
			saxonService.transform(isInputFile, isUTIL_POGUES_XML_LOOP_FILTER_INTO_QUESTION_TREE_XSL, osINSERTLOOPFILTERTREE);
		}catch(Exception e) {
			String errorMessage = "An error was occured during the " + toString() + " transformation. "+e.getMessage();
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		isInputFile.close();
		isUTIL_POGUES_XML_LOOP_FILTER_INTO_QUESTION_TREE_XSL.close();
		osINSERTLOOPFILTERTREE.close();


		logger.debug("PoguesXMLPreprocessing : END");
		return new File(outputPreprocessINSERTLOOPFILTERTREE);

	}

	public String toString() {
		return PreProcessing.POGUES_XML_INSERT_FILTER_LOOP_INTO_QUESTION_TREE.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/DDIMarkdown2XhtmlPreprocessor.java
public class DDIMarkdown2XhtmlPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDIMarkdown2XhtmlPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_MD2XHTML_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey, String in2out) throws Exception {

		logger.info("DDIMarkdown2XhtmlPreprocessor Target : START");
		String md2xhtmlOutput = FilenameUtils.removeExtension(input.getPath()) + Constants.MD_EXTENSION;
		// ----- mw2xhtml
		logger.debug("Markdown to XHTML : -Input : " + input + " -Output : " + md2xhtmlOutput + " -Stylesheet : "
				+ Constants.UTIL_DDI_MD2XHTML_XSL + " -Parameters : " + Constants.sUB_TEMP_FOLDER(survey));

		InputStream isDDI_MW2XHTML_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		InputStream isInputFile = FileUtils.openInputStream(input);

		OutputStream osTEMP_NULL_TMP = FileUtils.openOutputStream(new File(md2xhtmlOutput));

		try {
			saxonService.transformMw2XHTML(isInputFile, isDDI_MW2XHTML_XSL, osTEMP_NULL_TMP,
					Constants.SUB_TEMP_FOLDER_FILE(survey));
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the Markdown2Xhtml transformation. %s : %s",
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		isInputFile.close();
		isDDI_MW2XHTML_XSL.close();
		osTEMP_NULL_TMP.close();

		// ----- tweak-xhtml-for-ddi
		// tweak-xhtml-for-ddi-input = mw2xhtml-output

		String outputTweakXhtmlForDdi = FilenameUtils.removeExtension(input.getPath()) + Constants.MD2_EXTENSION;

		logger.debug("Tweak-xhtml-for-ddi : -Input : " + md2xhtmlOutput + " -Output : " + outputTweakXhtmlForDdi
				+ " -Stylesheet : " + Constants.UTIL_DDI_TWEAK_XHTML_FOR_DDI_XSL + " -Parameters : "
				+ (parameters == null ? "Default parameters" : "Provided parameters"));

		InputStream isTweakXhtmlForDdi = FileUtils.openInputStream(new File(md2xhtmlOutput));
		InputStream isUTIL_DDI_TWEAK_XHTML_FOR_DDI_XSL = Constants
				.getInputStreamFromPath(Constants.UTIL_DDI_TWEAK_XHTML_FOR_DDI_XSL);
		OutputStream osTweakXhtmlForDdi = FileUtils.openOutputStream(new File(outputTweakXhtmlForDdi));
		try {
			saxonService.transformTweakXhtmlForDdi(isTweakXhtmlForDdi, isUTIL_DDI_TWEAK_XHTML_FOR_DDI_XSL,
					osTweakXhtmlForDdi, Constants.SUB_TEMP_FOLDER_FILE(survey));
		}catch(Exception e) {
			String errorMessage = "An error has occurred during the Markdown2Xhtml transformation. "+e.getMessage();
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		isTweakXhtmlForDdi.close();
		isUTIL_DDI_TWEAK_XHTML_FOR_DDI_XSL.close();
		osTweakXhtmlForDdi.close();

		logger.debug("DDIMarkdown2XhtmlPreprocessor : END");
		return new File(outputTweakXhtmlForDdi);

	}

}
src/main/java/fr/insee/eno/preprocessing/PoguesXMLPreprocessorGoToTreatment.java
public class PoguesXMLPreprocessorGoToTreatment implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(PoguesXMLPreprocessorGoToTreatment.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_POGUES_XML_GOTO_ITE_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String surveyName, String in2out) throws Exception {

		logger.info("PoguesXMLPreprocessing Target : START");

		String outputPreprocessGOT2ITE = null;

		outputPreprocessGOT2ITE = FilenameUtils.removeExtension(inputFile.getAbsolutePath())
				+ Constants.TEMP_EXTENSION;

		logger.debug("GOTO 2 ITE : -Input : " + inputFile + " -Output : " + outputPreprocessGOT2ITE + " -Stylesheet : "
				+ styleSheetPath + " -Parameters : "
				+ (parametersFile == null ? "Default parameters" : "Provided parameters"));

		InputStream isInputFile = FileUtils.openInputStream(inputFile);
		InputStream isUTIL_POGUES_XML_GOTO_ITE_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
		OutputStream osGOTO2ITE = FileUtils.openOutputStream(new File(outputPreprocessGOT2ITE));

		try {
			saxonService.transform(isInputFile, isUTIL_POGUES_XML_GOTO_ITE_XSL, osGOTO2ITE);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		isInputFile.close();
		isUTIL_POGUES_XML_GOTO_ITE_XSL.close();
		osGOTO2ITE.close();


		logger.debug("PoguesXMLPreprocessing : END");
		return new File(outputPreprocessGOT2ITE);

	}

	public String toString() {
		return PreProcessing.POGUES_XML_GOTO_2_ITE.name();
	}


}
src/main/java/fr/insee/eno/service/GenerationService.java
public class GenerationService {

	private static final Logger logger = LoggerFactory.getLogger(GenerationService.class);

	private final Preprocessor[] preprocessors;
	private final Generator generator;
	private final Postprocessor[] postprocessors;

	private byte[] parameters;
	private byte[] metadata;
	private byte[] specificTreatment;
	private byte[] mapping;
	
	private boolean cleaningFolder;

	@Inject
	public GenerationService(final Preprocessor[] preprocessors, final Generator generator,
			final Postprocessor[] postprocessors) {
		this.preprocessors = preprocessors;
		this.generator = generator;
		this.postprocessors = postprocessors;
		this.cleaningFolder = true;
	}

	@Inject
	public GenerationService(final Preprocessor preprocessor, final Generator generator,
			final Postprocessor[] postprocessors) {
		this.preprocessors = new Preprocessor[] { preprocessor };
		this.generator = generator;
		this.postprocessors = postprocessors;
		this.cleaningFolder = true;
	}

	@Inject
	public GenerationService(final Preprocessor preprocessor, final Generator generator,
			final Postprocessor postprocessor) {
		this.preprocessors = new Preprocessor[] { preprocessor };
		this.generator = generator;
		this.postprocessors = new Postprocessor[] { postprocessor };
		this.cleaningFolder = true;
	}

	/**
	 * Launch every step needed in order to generate the target questionnaire.
	 * 
	 * @param inputFile
	 *            The source file
	 * 
	 * @return The generated file
	 * @throws Exception
	 *             bim
	 */
	public File generateQuestionnaire(File inputFile, String surveyName) throws Exception {
		logger.info(this.toString());
		logger.info("Generating questionnaire for: " + surveyName);

		String tempFolder = System.getProperty("java.io.tmpdir") + "/" + surveyName;
		logger.debug("Temp folder: " + tempFolder);
		if(cleaningFolder) {
			cleanTempFolder(surveyName);
		}
		File preprocessResultFileName = null;
		
		preprocessResultFileName = this.preprocessors[0].process(inputFile, parameters, surveyName,generator.in2out());	
		
		for (int i = 1; i < preprocessors.length; i++) {
			preprocessResultFileName = this.preprocessors[i].process(preprocessResultFileName, parameters, surveyName,
					generator.in2out());
		}

		File generatedForm = this.generator.generate(preprocessResultFileName, parameters, surveyName);
		File outputForm = this.postprocessors[0].process(generatedForm, parameters, metadata, specificTreatment, mapping, surveyName);
		for (int i = 1; i < postprocessors.length; i++) {
			outputForm = this.postprocessors[i].process(outputForm, parameters, metadata, specificTreatment, mapping,surveyName);
		}
		File finalForm = new File(outputForm.getParent()+Constants.BASE_NAME_FORM_FILE+"."+FilenameUtils.getExtension(outputForm.getAbsolutePath()));
		if(!finalForm.equals(outputForm)) {
			Files.move(outputForm, finalForm);
		}
		logger.debug("Path to generated questionnaire: " + finalForm.getAbsolutePath());

		return finalForm;
	}
	
	
	public void setParameters(ByteArrayOutputStream parametersBAOS) {
		this.parameters = parametersBAOS.toByteArray();
	}	

	public void setParameters(InputStream parametersIS) throws IOException {
		if(parametersIS!=null) {
			this.parameters = IOUtils.toByteArray(parametersIS);
		}
	}
	
	public void setMetadata(InputStream metadataIS) throws IOException {
		if(metadataIS!=null) {
			this.metadata = IOUtils.toByteArray(metadataIS);
		}
	}
	
	public void setSpecificTreatment(InputStream specificTreatmentIS) throws IOException {
		if(specificTreatmentIS!=null) {
			this.specificTreatment = IOUtils.toByteArray(specificTreatmentIS);
		}
	}
	
	public void setMapping(InputStream mappingIS) throws IOException {
		if(mappingIS!=null) {
			this.mapping = IOUtils.toByteArray(mappingIS);
		}
	}

	public byte[] getParameters() {
		return parameters;
	}
	public byte[] getMetadata() {
		return metadata;
	}
	public byte[] getSpecificTreatment() {
		return specificTreatment;
	}
	public byte[] getMapping() {
		return mapping;
	}
	
	public void setCleaningFolder(boolean cleaning) {
		this.cleaningFolder = cleaning;
	}
	


	/**
	 * Clean the temp dir if it exists
	 * 
	 * @throws IOException
	 * 
	 */
	public void cleanTempFolder(String name) throws IOException {
		if (Constants.TEMP_FOLDER_PATH != null) {
			File folderTemp = new File(Constants.TEMP_FOLDER_PATH + "/" + name);
			cleanTempFolder(folderTemp);
		} else {
			logger.debug("Temp Folder is null");
		}
	}

	/**
	 * Clean the temp dir if it exists
	 * 
	 * @throws IOException
	 * 
	 */
	public void cleanTempFolder() throws IOException {
		if (Constants.TEMP_FOLDER_PATH != null) {
			File folderTemp = new File(Constants.TEMP_FOLDER_PATH);
			cleanTempFolder(folderTemp);
		} else {
			logger.debug("Temp Folder is null");
		}
	}

	/**
	 * Clean the temp dir if it exists
	 * 
	 * @throws IOException
	 * 
	 */
	private void cleanTempFolder(File folder) throws IOException {
		FolderCleaner cleanService = new FolderCleaner();
		if (folder != null) {
			cleanService.cleanOneFolder(folder);
		} else {
			logger.debug("Temp Folder is null");
		}
	}

	@Override
	public String toString() {
		return "GenerationService [preprocessors=" + Arrays.toString(preprocessors) + ", generator=" + generator.in2out()
				+ ", postprocessors=" + Arrays.toString(postprocessors) + "]";
	}
	
	

}
src/main/java/fr/insee/eno/preprocessing/DDICleaningPreprocessor.java
public class DDICleaningPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDICleaningPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_CLEANING_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDIPreprocessing Target : START");

		String cleaningOutput=null;
		String cleaningInput = inputFile.getAbsolutePath();
		cleaningOutput = FilenameUtils.removeExtension(cleaningInput) + Constants.CLEANED_EXTENSION;

		logger.debug("Cleaned output file to be created : " + cleaningOutput);
		logger.debug("Cleaning : -Input : " + cleaningInput + " -Output : " + cleaningOutput + " -Stylesheet : "
				+ styleSheetPath);

		InputStream isCleaningIn = FileUtils.openInputStream(new File(cleaningInput));
		OutputStream osCleaning = FileUtils.openOutputStream(new File(cleaningOutput));
		InputStream isUTIL_DDI_CLEANING_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		try {
			saxonService.transformCleaning(isCleaningIn, isUTIL_DDI_CLEANING_XSL, osCleaning, in2out);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isCleaningIn.close();
		isUTIL_DDI_CLEANING_XSL.close();
		osCleaning.close();

		logger.debug("DDIPreprocessing Cleaning: END");
		return new File(cleaningOutput);
	}

	public String toString() {
		return PreProcessing.DDI_CLEANING.name();
	}


}
src/main/java/fr/insee/eno/postprocessing/fo/FOTableColumnPostprocessorFake.java
public class FOTableColumnPostprocessorFake implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOTableColumnPostprocessorFake.class);

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.TABLE_COL_SIZE_PDF_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());

		FileUtils.copyFile(input, outputForFOFile);

		logger.debug("End of TableColumn post-processing (Fake)");
		return outputForFOFile;

	}

	public String toString() {
		return PostProcessing.FO_TABLE_COLUMN.name();
	}
}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSIdentificationPostprocessor.java
public class XFORMSIdentificationPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSIdentificationPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_IDENTIFICATION_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.IDENTIFICATION_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);

		try {
			saxonService.transformSimple(inputStream, outputStream, FO_XSL);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of identification post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_IDENTIFICATION.name();
	}
}
src/main/java/fr/insee/eno/preprocessing/NoopPreprocessor.java
public class NoopPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(NoopPreprocessor.class);

	@Override
	public File process(File inputFile, byte[] parameters, String survey, String in2out) throws Exception {
		logger.info("No-op preprocessor, simply returning generated file.");
		// Identity
		return inputFile;
	}

	@Override
	public String toString() {
		return "No-op preprocessor";
	}
}
src/main/java/fr/insee/eno/postprocessing/fo/FOInsertAccompanyingMailsPostprocessor.java
public class FOInsertAccompanyingMailsPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOInsertAccompanyingMailsPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_ACCOMPANYING_MAILS_FO_4PDF;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.FINAL_PDF_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());

		String surveyName = survey;
		String formName = getFormName(input);

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);

		try {
			saxonService.transformFOToStep4FO(inputStream, outputStream, FO_XSL, surveyName, formName, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of InsertAccompanyingMails post-processing " + outputForFOFile.getAbsolutePath());

		return outputForFOFile;
	}

	private String getFormName(File input) {
		return FilenameUtils.getBaseName(input.getParentFile().getParent());
	}

	public String toString() {
		return PostProcessing.FO_INSERT_ACCOMPANYING_MAILS.name();
	}

}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSInsertEndPostprocessor.java
public class XFORMSInsertEndPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSInsertEndPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_INSERT_END_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, survey);
	}

	@Override
	public File process(File input, byte[] parameters, byte[] metadata, String survey) throws Exception {

		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.INSERT_END_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);

		try {
			saxonService.transformWithMetadata(inputStream, outputStream, FO_XSL, parameters, metadata);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of insert end post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_INSERT_END.name();
	}

}
src/main/java/fr/insee/eno/postprocessing/fo/FOSpecificTreatmentPostprocessor.java
public class FOSpecificTreatmentPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOSpecificTreatmentPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, null, survey);
	}

	@Override
	public File process(File input, byte[] parametersFile, byte[] metadata, String survey) throws Exception {
		return this.process(input, parametersFile, metadata, null, survey);
	}

	@Override
	public File process(File input, byte[] parametersFile, byte[] metadata, byte[] specificTreatmentXsl, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.SPECIFIC_TREAT_PDF_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());

		InputStream specificTreatmentXslIS = null;

		if(specificTreatmentXsl!=null) {
			specificTreatmentXslIS = new ByteArrayInputStream(specificTreatmentXsl);
			InputStream inputStream = FileUtils.openInputStream(input);
			OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);

			try {
				saxonService.transformWithPDFSpecificTreatment(inputStream, outputStream, specificTreatmentXslIS, parametersFile);
			}catch(Exception e) {
				String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
						toString(),
						e.getMessage(),
						Utils.getErrorLocation("specific file passed in params",e));
				logger.error(errorMessage);
				throw new EnoGenerationException(errorMessage);
			}
			inputStream.close();
			outputStream.close();
			specificTreatmentXslIS.close();

		}
		else {
			logger.info("Not specific treatment in params : simply copying this file" + input.getAbsolutePath());
			FileUtils.copyFile(input, outputForFOFile);
		}
		logger.info("End of specific treatment post-processing " + outputForFOFile.getAbsolutePath());

		return outputForFOFile;
	}

	public String toString() {
		return PostProcessing.FO_SPECIFIC_TREATMENT.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/DDIMappingPreprocessor.java
public class DDIMappingPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDIMappingPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_MAPPING_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDIPreprocessing Target : START");
		System.out.println(saxonService);

		String sUB_TEMP_FOLDER = Constants.tEMP_DDI_FOLDER(Constants.sUB_TEMP_FOLDER(survey));

		File mappingFile =Constants.tEMP_MAPPING_TMP(sUB_TEMP_FOLDER);
		// ----- Dereferencing
		logger.debug("Mapping : -Input : " + inputFile + " -Output : " + mappingFile
				+ " -Stylesheet : " + styleSheetPath + " -Parameters : " + sUB_TEMP_FOLDER);

		InputStream isDDI_MAPPING_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		InputStream isInputFile = FileUtils.openInputStream(inputFile);
		OutputStream osTEMP_MAPPING_TMP = FileUtils.openOutputStream(mappingFile);
		
		try {
			saxonService.transformMapping(isInputFile, isDDI_MAPPING_XSL, osTEMP_MAPPING_TMP,parametersFile);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isInputFile.close();
		isDDI_MAPPING_XSL.close();
		osTEMP_MAPPING_TMP.close();

		return inputFile;

	}

	public String toString() {
		return PreProcessing.DDI_MAPPING.name();
	}


}
src/main/java/fr/insee/eno/generation/DDI2XFORMSGenerator.java
public class DDI2XFORMSGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(DDI2XFORMSGenerator.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_DDI2XFORMS_DDI2XFORMS_XSL;

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("DDI2XFORMS Target : START");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);
		String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(surveyName);
		outputBasicFormPath = Constants.tEMP_XFORMS_FOLDER(sUB_TEMP_FOLDER) + "/" + formNameFolder + "/"
				+ Constants.BASIC_FORM_TMP_FILENAME;
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);

		
		try (
			InputStream isTRANSFORMATIONS_DDI2XFORMS_DDI2XFORMS_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
			InputStream isFinalInput = FileUtils.openInputStream(finalInput);
			OutputStream osOutputBasicForm = FileUtils.openOutputStream(new File(outputBasicFormPath));){
			
			saxonService.transformDDI2XFORMS(isFinalInput, osOutputBasicForm, isTRANSFORMATIONS_DDI2XFORMS_DDI2XFORMS_XSL,
					parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					in2out(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		return new File(outputBasicFormPath);
	}

	/**
	 * @param finalInput
	 * @return
	 */
	private String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "ddi2xforms";
	}

}
src/main/java/fr/insee/eno/generation/DDI2LunaticXMLGenerator.java
public class DDI2LunaticXMLGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(DDI2LunaticXMLGenerator.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_DDI2LUNATIC_XML_DDI2LUNATIC_XML_XSL;

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("DDI2LunaticXML Target : START");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);

		outputBasicFormPath = Constants.TEMP_FOLDER_PATH + "/" + surveyName + "/" + formNameFolder + "/form";
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);

		String outputForm = outputBasicFormPath + "/form.xml";
		

		try (InputStream isTRANSFORMATIONS_DDI2LUNATIC_XML_DDI2JS_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
				InputStream isFinalInput = FileUtils.openInputStream(finalInput);
				OutputStream osOutputFile = FileUtils.openOutputStream(new File(outputForm));){
			saxonService.transformDDI2LunaticXML(isFinalInput, osOutputFile, isTRANSFORMATIONS_DDI2LUNATIC_XML_DDI2JS_XSL, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					in2out(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		return new File(outputForm);
	}

	/**
	 * @param finalInput
	 * @return
	 */
	public String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "ddi2lunatic-xml";
	}
}
src/main/java/fr/insee/eno/postprocessing/NoopPostprocessor.java
public class NoopPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(NoopPostprocessor.class);

	@Override
	public File process(File input, byte[] parameters, String survey) {
		logger.info("No-op postprocessor, simply returning generated file.");
		// Identity
		return input;
	}

	@Override
	public String toString() {
		return "No-op postprocessor";
	}

}
src/main/java/fr/insee/eno/preprocessing/Preprocessor.java
public interface Preprocessor {

	/**
	 * This method handles the preprocessing of an input file. TODO Exception is
	 * also weak, change to a more robust Exception
	 * 
	 * @param inputFile
	 *            The file to preprocess
	 * @param parameters
	 *            An optional parameters file
	 * @param survey
	 *            An optional parameters file
	 * @return the preprocessed file
	 * @throws Exception
	 *             when it goes wrong
	 */
	public File process(File inputFile, byte[] parameters, String survey, String in2out) throws Exception;

	public String toString();
}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSInsertGenericQuestionsPostprocessor.java
public class XFORMSInsertGenericQuestionsPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSInsertGenericQuestionsPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_INSERT_GENERIC_QUESTIONS_XSL;

	@Override
	public File process(File input, byte[] parameters, String surveyName) throws Exception {

		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.INSERT_GENERIC_QUESTIONS_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);

		InputStream FR_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		try {
			saxonService.transformXformsToXformsSimplePost(inputStream,outputStream, FR_XSL,parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		inputStream.close();
		outputStream.close();
		FR_XSL.close();
		logger.info("End of Insert-generic-questions post-processing." + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_INSERT_GENERIC_QUESTIONS.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/DDIDereferencingPreprocessor.java
public class DDIDereferencingPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDIDereferencingPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_DEREFERENCING_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDIPreprocessing Target : START");

		String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(survey);
		// ----- Dereferencing
		logger.debug("Dereferencing : -Input : " + inputFile + " -Output : " + Constants.tEMP_NULL_TMP(sUB_TEMP_FOLDER)
		+ " -Stylesheet : " + styleSheetPath + " -Parameters : " + sUB_TEMP_FOLDER);

		InputStream isDDI_DEREFERENCING_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		InputStream isInputFile = FileUtils.openInputStream(inputFile);
		OutputStream osTEMP_NULL_TMP = FileUtils.openOutputStream(Constants.tEMP_NULL_TMP(sUB_TEMP_FOLDER));

		try {
			saxonService.transformDereferencing(isInputFile, isDDI_DEREFERENCING_XSL, osTEMP_NULL_TMP,
					Constants.SUB_TEMP_FOLDER_FILE(survey));
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isInputFile.close();
		isDDI_DEREFERENCING_XSL.close();
		osTEMP_NULL_TMP.close();
		// ----- Cleaning
		logger.debug("Cleaning target");
		File f = Constants.SUB_TEMP_FOLDER_FILE(survey);
		File[] matchCleaningInput = f.listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String name) {
				return !(name.startsWith("null")||name.contains("-modal")) && name.endsWith(".tmp");
			}
		});

		String cleaningInput = null;

		logger.debug("Searching matching files in : " + sUB_TEMP_FOLDER);
		for (File file : matchCleaningInput) {
			if(!file.isDirectory()) {
				cleaningInput = file.getAbsolutePath();
				logger.debug("Found : " + cleaningInput);
			}
		}
		if(cleaningInput==null) {
			throw new EnoGenerationException("DDIDereferencing produced no file.");
		}

		logger.debug("DDIPreprocessing Dereferencing : END");
		return new File(cleaningInput);
	}

	public String toString() {
		return PreProcessing.DDI_DEREFERENCING.name();
	}


}
src/main/java/fr/insee/eno/preprocessing/DDI32ToDDI33Preprocessor.java
public class DDI32ToDDI33Preprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDI32ToDDI33Preprocessor.class);

	// FIXME Inject !
	private static XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI32_TO_DDI33_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDI32ToDDI33Preprocessing Target : START");

		String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(survey);
		String output = FilenameUtils.removeExtension(inputFile.getAbsolutePath()) + Constants.DDI32_DDI33_EXTENSION;;
		
		logger.debug("DDI32ToDDI33 : -Input : " + inputFile + " -Output : " +output
				+ " -Stylesheet : " + styleSheetPath + " -Parameters : " + sUB_TEMP_FOLDER);

		InputStream isDDI32_TO_DDI33_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		InputStream isInputFile = FileUtils.openInputStream(inputFile);
		OutputStream osDDI32DDI33 = FileUtils.openOutputStream(new File(output));
		
		try {
			saxonService.transform(isInputFile, isDDI32_TO_DDI33_XSL, osDDI32DDI33);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		isInputFile.close();
		isDDI32_TO_DDI33_XSL.close();
		osDDI32DDI33.close();
		
		logger.debug("DDI32ToDDI33Preprocessing : END");
		return new File(output);
	}
	
	public String toString() {
		return PreProcessing.DDI_32_TO_DDI_33.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/DDITitlingPreprocessor.java
public class DDITitlingPreprocessor implements Preprocessor {

	private static final Logger logger = LoggerFactory.getLogger(DDITitlingPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_TITLING_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDIPreprocessing Target : START");

		String outputTitling = null;
		String titlingInput = inputFile.getAbsolutePath();

		outputTitling = titlingInput.replace(Constants.CLEANED_EXTENSION, Constants.FINAL_EXTENSION);

		logger.debug("Titling : -Input : " + titlingInput + " -Output : " + outputTitling + " -Stylesheet : "
				+ styleSheetPath + " -Parameters : "
				+ (parametersFile == null ? "Default parameters" : "Provided parameters"));

		InputStream isCleaningTitling = FileUtils.openInputStream(new File(titlingInput));
		InputStream isUTIL_DDI_TITLING_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		OutputStream osTitling = FileUtils.openOutputStream(new File(outputTitling));

		try {
			saxonService.transformTitling(isCleaningTitling, isUTIL_DDI_TITLING_XSL, osTitling, parametersFile);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isCleaningTitling.close();
		isUTIL_DDI_TITLING_XSL.close();
		osTitling.close();
		logger.debug("DDIPreprocessing titling: END");
		return new File(outputTitling);
	}

	public String toString() {
		return PreProcessing.DDI_TITLING.name();
	}

}
src/main/java/fr/insee/eno/generation/PoguesXML2DDIGenerator.java
public class PoguesXML2DDIGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(PoguesXML2DDIGenerator.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_POGUES_XML2DDI_POGUES_XML2DDI_XSL;

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("PoguesXML2DDI Target : START");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);
		String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(surveyName);
		outputBasicFormPath = Constants.tEMP_DDI_FOLDER(sUB_TEMP_FOLDER) + "/" + formNameFolder + "/"
				+ Constants.BASIC_FORM_TMP_FILENAME;
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);

		InputStream isTRANSFORMATIONS_POGUES_XML2DDI_POGUES_XML2DDI_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
		InputStream isFinalInput = FileUtils.openInputStream(finalInput);
		OutputStream osOutputBasicForm = FileUtils.openOutputStream(new File(outputBasicFormPath));

		try {
			saxonService.transformPoguesXML2DDI(isFinalInput, osOutputBasicForm,
					isTRANSFORMATIONS_POGUES_XML2DDI_POGUES_XML2DDI_XSL, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					in2out(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isTRANSFORMATIONS_POGUES_XML2DDI_POGUES_XML2DDI_XSL.close();
		isFinalInput.close();
		osOutputBasicForm.close();

		return new File(outputBasicFormPath);
	}

	/**
	 * @param finalInput
	 * @return
	 */
	private String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "xml-pogues2ddi";
	}
}
src/main/java/fr/insee/eno/generation/DDI2FODTGenerator.java
public class DDI2FODTGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(DDI2FODTGenerator.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_DDI2FODT_DDI2FODT_XSL;

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("DDI2ODT Target : START");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);

		outputBasicFormPath = Constants.TEMP_FOLDER_PATH + "/" + surveyName + "/" + formNameFolder + "/form";
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);

		String outputForm = outputBasicFormPath + "/form.fodt";
		

		try (InputStream isTRANSFORMATIONS_DDI2FODT_DDI2ODT_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
			InputStream isFinalInput = FileUtils.openInputStream(finalInput);
			OutputStream osOutputFile = FileUtils.openOutputStream(new File(outputForm));){
			
			saxonService.transformDDI2FODT(isFinalInput, osOutputFile, isTRANSFORMATIONS_DDI2FODT_DDI2ODT_XSL, parameters);
		
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					in2out(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		return new File(outputForm);
	}

	/**
	 * @param finalInput
	 * @return
	 */
	public String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "ddi2fodt";
	}
}
src/main/java/fr/insee/eno/postprocessing/fo/FOMailingPostprocessor.java
public class FOMailingPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOMailingPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_CUSTOMIZATION_FO_4PDF_2;

	@Override
	public File process(File input, byte[] parameters, String surveyName) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.MAILING_FO_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());	
		

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);
		
		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);
		try {
			saxonService.transformFOToStep1FO(inputStream, outputStream, FO_XSL);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}
		
		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of Mailing post-processing : ");

		return outputForFOFile;
	}

	public String toString() {
		return PostProcessing.FO_MAILING.name();
	}

}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSSpecificTreatmentPostprocessor.java
public class XFORMSSpecificTreatmentPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSSpecificTreatmentPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, null, survey);
	}

	@Override
	public File process(File input, byte[] parametersFile, byte[] metadata, String survey) throws Exception {
		return this.process(input, parametersFile, metadata, null, survey);
	}

	@Override
	public File process(File input, byte[] parametersFile, byte[] metadata, byte[] specificTreatmentXsl, String survey) throws Exception {
		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.SPECIFIC_TREATMENT_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream specificTreatmentXslIS = null;

		if(specificTreatmentXsl!=null) {
			specificTreatmentXslIS = new ByteArrayInputStream(specificTreatmentXsl);
			InputStream inputStream = FileUtils.openInputStream(input);
			OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);
			try {
				saxonService.transformWithFRSpecificTreatment(inputStream, outputStream, specificTreatmentXslIS, parametersFile);
			}catch(Exception e) {
				String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
						toString(),
						e.getMessage(),
						Utils.getErrorLocation("specific file passed in params",e));
				logger.error(errorMessage);
				throw new EnoGenerationException(errorMessage);
			}

			inputStream.close();
			outputStream.close();
			specificTreatmentXslIS.close();

		}
		else {
			logger.info("Not specific treatment in params : simply copying this file" + input.getAbsolutePath());
			FileUtils.copyFile(input, outputForFRFile);
		}
		logger.info("End of specific treatment post-processing " + outputForFRFile.getAbsolutePath());		

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_SPECIFIC_TREATMENT.name();
	}

}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSBrowsingPostprocessor.java
public class XFORMSBrowsingPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSBrowsingPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();;

	private static final String styleSheetPath = Constants.UTIL_XFORMS_BROWSING_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.BROWSING_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);
		try {
			saxonService.transformBrowsingXforms(inputStream, outputStream, FO_XSL);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of Browsing post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_BROWSING.name();
	}


}
src/main/java/fr/insee/eno/generation/IdentityGenerator.java
public class IdentityGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(IdentityGenerator.class);

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("Identity generation : START");
		logger.info("Identity generation : simply copying input file in another file");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);
		outputBasicFormPath = Constants.TEMP_FOLDER_PATH + "/" + surveyName + "/" + formNameFolder + "/form";
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);
		String outputForm = outputBasicFormPath + "/form.xml";
		FileUtils.copyFile(finalInput, new File(outputForm));
		logger.info("Identity generation : END");
		return new File(outputForm);
	}
	
	private String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "identity";
	}	
}
src/main/java/fr/insee/eno/postprocessing/fo/FOInsertEndQuestionPostprocessor.java
public class FOInsertEndQuestionPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOInsertEndQuestionPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_END_QUESTION_FO_4PDF;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.END_QUESTION_FO_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());

		String surveyName = survey;
		String formName = getFormName(input);

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);

		try {
			saxonService.transformFOToStep4FO(inputStream, outputStream, FO_XSL, surveyName, formName, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of InsertEndQuestion post-processing " + outputForFOFile.getAbsolutePath());

		return outputForFOFile;
	}

	private String getFormName(File input) {
		return FilenameUtils.getBaseName(input.getParentFile().getParent());
	}

	public String toString() {
		return PostProcessing.FO_INSERT_END_QUESTION.name();
	}

}
src/main/java/fr/insee/eno/preprocessing/DDIMultimodalSelectionPreprocessor.java
public class DDIMultimodalSelectionPreprocessor implements Preprocessor {
	
	private static final Logger logger = LoggerFactory.getLogger(DDIMultimodalSelectionPreprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_DDI_MULTIMODAL_SELECTION_XSL;

	@Override
	public File process(File inputFile, byte[] parametersFile, String survey, String in2out) throws Exception {
		logger.info("DDIPreprocessing Target : START");

		String sUB_TEMP_FOLDER = Constants.sUB_TEMP_FOLDER(survey);
		String modalSelectionOutput=null;
		String multimodalInput = inputFile.getAbsolutePath();
		modalSelectionOutput = sUB_TEMP_FOLDER + "\\" + FilenameUtils.getBaseName(multimodalInput) + Constants.MULTIMODAL_EXTENSION;

		logger.debug("Modal DDI output file to be created : " + modalSelectionOutput);
		logger.debug("Multimodal Selection : -Input : " + multimodalInput + " -Output : " + modalSelectionOutput + " -Stylesheet : "
				+ styleSheetPath + " -Parameters : " + (parametersFile == null ? "Default parameters" : "Provided parameters"));

		InputStream isMultimodalIn = FileUtils.openInputStream(new File(multimodalInput));
		OutputStream osModalSelection = FileUtils.openOutputStream(new File(modalSelectionOutput));
		InputStream isUTIL_DDI_MULTIMODAL_SELECTION_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		try {
			saxonService.transformModalSelection(isMultimodalIn, isUTIL_DDI_MULTIMODAL_SELECTION_XSL, osModalSelection, parametersFile);
		}catch(Exception e) {
			String errorMessage = String.format("An error has occurred during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		isMultimodalIn.close();
		isUTIL_DDI_MULTIMODAL_SELECTION_XSL.close();
		osModalSelection.close();

		logger.debug("DDIPreprocessing Multimodal Selection: END");
		return new File(modalSelectionOutput);
	}

	public String toString() {
		return PreProcessing.DDI_MULTIMODAL_SELECTION.name();
	}

	
}
src/main/java/fr/insee/eno/postprocessing/fo/FOEditStructurePagesPostprocessor.java
public class FOEditStructurePagesPostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOEditStructurePagesPostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_EDIT_STRUCTURE_PAGES_FO_4PDF;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.EDIT_STRUCTURE_FO_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());

		String surveyName = survey;
		String formName = getFormName(input);
		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);

		try {
			saxonService.transformFOToStep4FO(inputStream, outputStream, FO_XSL, surveyName, formName, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of EditStructurePages post-processing " + outputForFOFile.getAbsolutePath());

		return outputForFOFile;
	}

	private String getFormName(File input) {
		return FilenameUtils.getBaseName(input.getParentFile().getParent());
	}

	public String toString() {
		return PostProcessing.FO_EDIT_STRUCTURE_PAGES.name();
	}

}
src/main/java/fr/insee/eno/generation/DDI2FOGenerator.java
public class DDI2FOGenerator implements Generator {

	private static final Logger logger = LoggerFactory.getLogger(DDI2FOGenerator.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_DDI2FO_DDI2FO_XSL;

	@Override
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception {
		logger.info("DDI2FO Target : START");
		logger.debug("Arguments : finalInput : " + finalInput + " surveyName " + surveyName);
		String formNameFolder = null;
		String outputBasicFormPath = null;

		formNameFolder = getFormNameFolder(finalInput);

		logger.debug("formNameFolder : " + formNameFolder);

		outputBasicFormPath = Constants.TEMP_FOLDER_PATH + "/" + surveyName + "/" + formNameFolder + "/form";
		logger.debug("Output folder for basic-form : " + outputBasicFormPath);

		String outputForm = outputBasicFormPath + "/form.fo";


		try (InputStream isTRANSFORMATIONS_DDI2FO_DDI2PDF_XSL = Constants
				.getInputStreamFromPath(styleSheetPath);
			 InputStream isFinalInput = FileUtils.openInputStream(finalInput);
				OutputStream osOutputForm = FileUtils.openOutputStream(new File(outputForm));) {
			
			saxonService.transformDDI2FO(isFinalInput, osOutputForm, isTRANSFORMATIONS_DDI2FO_DDI2PDF_XSL, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					in2out(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		return new File(outputForm);
	}

	/**
	 * @param finalInput
	 * @return
	 */
	private String getFormNameFolder(File finalInput) {
		String formNameFolder;
		formNameFolder = FilenameUtils.getBaseName(finalInput.getAbsolutePath());
		formNameFolder = FilenameUtils.removeExtension(formNameFolder);
		formNameFolder = formNameFolder.replace(XslParameters.TITLED_EXTENSION, "");
		return formNameFolder;
	}

	public String in2out() {
		return "ddi2fo";
	}

}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSInsertWelcomePostprocessor.java
public class XFORMSInsertWelcomePostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSInsertWelcomePostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_INSERT_WELCOME_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {
		return this.process(input, parameters, null, survey);
	}

	@Override
	public File process(File input, byte[] parameters, byte[] metadata, String survey) throws Exception {

		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.INSERT_WELCOME_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);

		try {
			saxonService.transformWithMetadata(inputStream, outputStream, FO_XSL, parameters, metadata);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of insert welcome post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_INSERT_WELCOME.name();
	}

}
src/main/java/fr/insee/eno/postprocessing/fo/FOInsertCoverPagePostprocessor.java
public class FOInsertCoverPagePostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(FOInsertCoverPagePostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.TRANSFORMATIONS_COVER_PAGE_FO_4PDF;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {

		File outputForFOFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.COVER_PAGE_FO_EXTENSION);
		logger.debug("Output folder for basic-form : " + outputForFOFile.getAbsolutePath());
		String surveyName = survey;
		String formName = getFormName(input);

		InputStream FO_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFOFile);

		try {
			saxonService.transformFOToStep4FO(inputStream, outputStream, FO_XSL, surveyName, formName, parameters);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FO_XSL.close();
		logger.info("End of InsertCoverPage post-processing " + outputForFOFile.getAbsolutePath());

		return outputForFOFile;
	}

	private String getFormName(File input) {
		return FilenameUtils.getBaseName(input.getParentFile().getParent());
	}

	public String toString() {
		return PostProcessing.FO_INSERT_COVER_PAGE.name();
	}

}
src/main/java/fr/insee/eno/generation/Generator.java
public interface Generator {

	/**
	 * This method handles the preprocessing of an input file. TODO Exception is
	 * also weak, change to a more robust Exception
	 * 
	 * @param finalInput
	 *            The input file, previously transformed in the preprocessing step
	 * @param parameters
	 *            The parameters of the survey for which we generate a questionnaire
	 * @param surveyName
	 *            The name of the survey for which we generate a questionnaire
	 * @return the generated file
	 * @throws Exception
	 *             Generic exception
	 */
	public File generate(File finalInput, byte[] parameters, String surveyName) throws Exception;

	/**
	 * This method return in2out implementation
	 * 
	 * @return the in2out implementation
	 */
	public String in2out() ;

}
src/main/java/fr/insee/eno/postprocessing/Postprocessor.java
public interface Postprocessor {

	File process(File input, byte[] parametersFile, String survey) throws Exception;

	default File process(File input, byte[] parametersFile, byte[] metadata, String survey) throws Exception{
		return this.process(input,parametersFile,survey);
	}
	
	default File process(File input, byte[] parametersFile, byte[] metadata, byte[] specificTreatmentXsl, String survey) throws Exception{
		return this.process(input,parametersFile,metadata,survey);
	}
	
	default File process(File input, byte[] parametersFile, byte[] metadata, byte[] specificTreatmentXsl, byte[] mapping, String survey) throws Exception{
		return this.process(input,parametersFile,metadata,specificTreatmentXsl,survey);
	}
	
	public String toString();
}
src/main/java/fr/insee/eno/postprocessing/xforms/XFORMSFixAdherencePostprocessor.java
public class XFORMSFixAdherencePostprocessor implements Postprocessor {

	private static final Logger logger = LoggerFactory.getLogger(XFORMSFixAdherencePostprocessor.class);

	private XslTransformation saxonService = new XslTransformation();

	private static final String styleSheetPath = Constants.UTIL_XFORMS_FIX_ADHERENCE_XSL;

	@Override
	public File process(File input, byte[] parameters, String survey) throws Exception {


		File outputForFRFile = new File(input.getParent(),
				Constants.BASE_NAME_FORM_FILE +
				Constants.FIX_ADHERENCE_XFORMS_EXTENSION);

		logger.debug("Output folder for basic-form : " + outputForFRFile.getAbsolutePath());

		InputStream FR_XSL = Constants.getInputStreamFromPath(styleSheetPath);

		InputStream inputStream = FileUtils.openInputStream(input);
		OutputStream outputStream = FileUtils.openOutputStream(outputForFRFile);

		try {
			saxonService.transformSimple(inputStream, outputStream, FR_XSL);
		}catch(Exception e) {
			String errorMessage = String.format("An error was occured during the %s transformation. %s : %s",
					toString(),
					e.getMessage(),
					Utils.getErrorLocation(styleSheetPath,e));
			logger.error(errorMessage);
			throw new EnoGenerationException(errorMessage);
		}

		inputStream.close();
		outputStream.close();
		FR_XSL.close();
		logger.info("End of fix adherence treatment post-processing " + outputForFRFile.getAbsolutePath());

		return outputForFRFile;
	}

	@Override
	public String toString() {
		return PostProcessing.XFORMS_FIX_ADHERENCE.name();
	}
}


Question: package fr.insee.eno.params.pipeline;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import fr.insee.eno.postprocessing.lunaticxml.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.insee.eno.generation.DDI2FODTGenerator;
import fr.insee.eno.generation.DDI2FOGenerator;
import fr.insee.eno.generation.DDI2LunaticXMLGenerator;
import fr.insee.eno.generation.DDI2XFORMSGenerator;
import fr.insee.eno.generation.Generator;
import fr.insee.eno.generation.IdentityGenerator;
import fr.insee.eno.generation.PoguesXML2DDIGenerator;
import fr.insee.eno.parameters.InFormat;
import fr.insee.eno.parameters.OutFormat;
import fr.insee.eno.parameters.Pipeline;
import fr.insee.eno.parameters.PostProcessing;
import fr.insee.eno.parameters.PreProcessing;
import fr.insee.eno.postprocessing.NoopPostprocessor;
import fr.insee.eno.postprocessing.Postprocessor;
import fr.insee.eno.postprocessing.fo.FOEditStructurePagesPostprocessor;
import fr.insee.eno.postprocessing.fo.FOInsertAccompanyingMailsPostprocessor;
import fr.insee.eno.postprocessing.fo.FOInsertCoverPagePostprocessor;
import fr.insee.eno.postprocessing.fo.FOInsertEndQuestionPostprocessor;
import fr.insee.eno.postprocessing.fo.FOMailingPostprocessor;
import fr.insee.eno.postprocessing.fo.FOSpecificTreatmentPostprocessor;
import fr.insee.eno.postprocessing.fo.FOTableColumnPostprocessorFake;
import fr.insee.eno.postprocessing.xforms.XFORMSBrowsingPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSFixAdherencePostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSIdentificationPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSInseeModelPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSInseePatternPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSInsertEndPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSInsertGenericQuestionsPostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSInsertWelcomePostprocessor;
import fr.insee.eno.postprocessing.xforms.XFORMSSpecificTreatmentPostprocessor;
import fr.insee.eno.preprocessing.DDI32ToDDI33Preprocessor;
import fr.insee.eno.preprocessing.DDICleaningPreprocessor;
import fr.insee.eno.preprocessing.DDIDereferencingPreprocessor;
import fr.insee.eno.preprocessing.DDIMappingPreprocessor;
import fr.insee.eno.preprocessing.DDIMarkdown2XhtmlPreprocessor;
import fr.insee.eno.preprocessing.DDIMultimodalSelectionPreprocessor;
import fr.insee.eno.preprocessing.DDITitlingPreprocessor;
import fr.insee.eno.preprocessing.NoopPreprocessor;
import fr.insee.eno.preprocessing.PoguesXmlInsertFilterLoopIntoQuestionTree;
import fr.insee.eno.preprocessing.PoguesXMLPreprocessorGoToTreatment;
import fr.insee.eno.preprocessing.Preprocessor;
import fr.insee.eno.service.GenerationService;




public class PipeLineGeneratorImpl implements PipelineGenerator {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(PipeLineGeneratorImpl.class);
	
	// In2Out Generator
	private IdentityGenerator identityGenerator = new IdentityGenerator();
	
	private DDI2XFORMSGenerator ddi2xformsGenerator = new DDI2XFORMSGenerator();

	private DDI2LunaticXMLGenerator ddi2lunaticXmlGenerator = new DDI2LunaticXMLGenerator();

	private DDI2FODTGenerator ddi2fodtGenerator = new DDI2FODTGenerator();

	private DDI2FOGenerator ddi2foGenerator = new DDI2FOGenerator();

	private PoguesXML2DDIGenerator poguesXml2ddiGenerator = new PoguesXML2DDIGenerator();
	
	// PreProcessing
	
	private NoopPreprocessor noopPreprocessor = new NoopPreprocessor();
	
	private DDIDereferencingPreprocessor ddiDereferencing = new DDIDereferencingPreprocessor();

	private DDICleaningPreprocessor ddiCleaning = new DDICleaningPreprocessor();

	private DDITitlingPreprocessor ddiTitling = new DDITitlingPreprocessor();

	private DDIMappingPreprocessor ddiMapping = new DDIMappingPreprocessor();
	
	private DDIMultimodalSelectionPreprocessor ddiMultimodal = new DDIMultimodalSelectionPreprocessor();
	
	private DDIMarkdown2XhtmlPreprocessor ddiMW2XHTML = new DDIMarkdown2XhtmlPreprocessor();

	private PoguesXMLPreprocessorGoToTreatment poguesXmlGoTo = new PoguesXMLPreprocessorGoToTreatment();
	
Answer: 	private PoguesXmlInsertFilterLoopIntoQuestionTree poguesXmlFilterLoopIntoQuestionTree = new PoguesXmlInsertFilterLoopIntoQuestionTree();