	private void convertDocument(InputStream inputStream, OutputStream outputStream,
			DataType fromDataType, DataType toDataType, Map<String, String> properties) throws IOException,
			SaxonApiException, ConfigurationException, ConverterException {
		String toMimeType = toDataType.getMimeType();
		String profile = properties.get(ConverterConfiguration.PROFILE_KEY);
		if (ConverterConfiguration.XML_MIME.equals(toMimeType)
				&& toDataType.getFormat().equals(ConverterConfiguration.TEI)
				&& fromDataType.getFormat().equals(Format.DOCX.getId())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DOCX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformFromDocX(inputStream, outputStream, profile, properties);
		}
		else if (Format.DOCX.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DOCX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			Processor proc = SaxonProcFactory.getProcessor();
			XsltCompiler comp = proc.newXsltCompiler();
			transformToDocX(inputStream, outputStream, proc, comp, profile, properties);
		}
		else if (ConverterConfiguration.XML_MIME.equals(toMimeType)
				&& toDataType.getFormat().equals(ConverterConfiguration.TEI)
				&& fromDataType.getFormat().equals(Format.ODT.getId())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformFromOdt(inputStream, outputStream, profile, properties);
		}
		else if (Format.ODT.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			Processor proc = SaxonProcFactory.getProcessor();
			XsltCompiler comp = proc.newXsltCompiler();
			transformToOdt(inputStream, outputStream, proc, comp, profile, properties);
		}
		else if (Format.ODDHTML.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.ODDHTML.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODDHTML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "html");
			performXsltTransformation(inputStream, outputStream, Format.ODDHTML
					.getProfile(), profile, properties);
		}
		else if (Format.XHTML.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.XHTML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "html");
			performXsltTransformation(inputStream, outputStream, Format.XHTML
					.getProfile(), profile, properties);
		}
		else if (Format.RELAXNG.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rng");
			performXsltTransformation(inputStream, outputStream, Format.RELAXNG
					.getProfile(), profile, properties);
		}
		else if (Format.RNC.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.RNC.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rnc");
			try {
			    generateRngThenTrang(inputStream, outputStream, Format.RELAXNG
							       .getProfile(), profile, properties);
			}
			catch (Exception e) {
				throw new IOException("to RNG then Trang failed: " + e.toString());
			}
		}
		else if (Format.XSD.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.XSD.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "xsd");
			try {
			    generateRngThenTrang(inputStream, outputStream, Format.RELAXNG
							       .getProfile(), profile, properties);
			}
			catch (Exception e) {
				throw new IOException("to RNG then Trang failed: " + e.toString());
			}
		}
		else if (Format.DTD.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DTD
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "dtd");
			performXsltTransformation(inputStream, outputStream, Format.DTD
					.getProfile(), profile, properties);
		}
		else if (Format.LITE.getMimeType().equals(toMimeType) 
			 && fromDataType.getFormat().equals(Format.LITE.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.LITE
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "xml");
			performXsltTransformation(inputStream, outputStream, Format.LITE
					.getProfile(), profile, properties);
		}
		else if (Format.LATEX.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.LATEX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "tex");
			performXsltTransformation(inputStream, outputStream, Format.LATEX
					.getProfile(), profile, properties);
		}
		else if (Format.ODDJSON.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODDJSON
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "json");
			performXsltTransformation(inputStream, outputStream, Format.ODDJSON
					.getProfile(), profile, properties);
		}
		else if (Format.FO.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.FO
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "fo");
			performXsltTransformation(inputStream, outputStream, Format.FO
					.getProfile(), profile, properties);
		}
		else if (Format.EPUB.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.EPUB
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformToEpub(inputStream, outputStream, profile, Format.EPUB.getProfile(), properties);
		}
		else if (Format.TEXT.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.TEXT.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.TEXT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "txt");
			performXsltTransformation(inputStream, outputStream, Format.TEXT
					.getProfile(), profile, properties);
		}
		else if (Format.XML.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.XML.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.XML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "xml");
			performXsltTransformation(inputStream, outputStream, Format.XML
					.getProfile(), profile, properties);
		}
		else if (Format.RDF.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.RDF.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RDF
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rdf");
			performXsltTransformation(inputStream, outputStream, Format.RDF
					.getProfile(), profile, properties);
		}
	}

	private void convertDocument(InputStream inputStream, OutputStream outputStream,
			DataType fromDataType, DataType toDataType, Map<String, String> properties) throws IOException,
			SaxonApiException, ConfigurationException, ConverterException {
		String toMimeType = toDataType.getMimeType();
		String profile = properties.get(ConverterConfiguration.PROFILE_KEY);
		if (ConverterConfiguration.XML_MIME.equals(toMimeType)
				&& toDataType.getFormat().equals(ConverterConfiguration.TEI)
				&& fromDataType.getFormat().equals(Format.DOCX.getId())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DOCX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformFromDocX(inputStream, outputStream, profile, properties);
		}
		else if (Format.DOCX.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DOCX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			Processor proc = SaxonProcFactory.getProcessor();
			XsltCompiler comp = proc.newXsltCompiler();
			transformToDocX(inputStream, outputStream, proc, comp, profile, properties);
		}
		else if (ConverterConfiguration.XML_MIME.equals(toMimeType)
				&& toDataType.getFormat().equals(ConverterConfiguration.TEI)
				&& fromDataType.getFormat().equals(Format.ODT.getId())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformFromOdt(inputStream, outputStream, profile, properties);
		}
		else if (Format.ODT.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			Processor proc = SaxonProcFactory.getProcessor();
			XsltCompiler comp = proc.newXsltCompiler();
			transformToOdt(inputStream, outputStream, proc, comp, profile, properties);
		}
		else if (Format.ODDHTML.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.ODDHTML.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODDHTML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "html");
			performXsltTransformation(inputStream, outputStream, Format.ODDHTML
					.getProfile(), profile, properties);
		}
		else if (Format.XHTML.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.XHTML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "html");
			performXsltTransformation(inputStream, outputStream, Format.XHTML
					.getProfile(), profile, properties);
		}
		else if (Format.RELAXNG.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rng");
			performXsltTransformation(inputStream, outputStream, Format.RELAXNG
					.getProfile(), profile, properties);
		}
		else if (Format.RNC.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.RNC.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rnc");
			try {
			    generateRngThenTrang(inputStream, outputStream, Format.RELAXNG
							       .getProfile(), profile, properties);
			}
			catch (Exception e) {
				throw new IOException("to RNG then Trang failed: " + e.toString());
			}
		}
		else if (Format.XSD.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.XSD.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RELAXNG
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "zip");
			try {
			    generateRngThenTrang(inputStream, outputStream, Format.RELAXNG
							       .getProfile(), profile, properties);
			}
			catch (Exception e) {
				throw new IOException("to RNG then Trang failed: " + e.toString());
			}
		}
		else if (Format.DTD.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.DTD
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "dtd");
			performXsltTransformation(inputStream, outputStream, Format.DTD
					.getProfile(), profile, properties);
		}
		else if (Format.LITE.getMimeType().equals(toMimeType) 
			 && fromDataType.getFormat().equals(Format.LITE.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.LITE
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "xml");
			performXsltTransformation(inputStream, outputStream, Format.LITE
					.getProfile(), profile, properties);
		}
		else if (Format.LATEX.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.LATEX
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "tex");
			performXsltTransformation(inputStream, outputStream, Format.LATEX
					.getProfile(), profile, properties);
		}
		else if (Format.ODDJSON.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.ODDJSON
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "json");
			performXsltTransformation(inputStream, outputStream, Format.ODDJSON
					.getProfile(), profile, properties);
		}
		else if (Format.FO.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.FO
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "fo");
			performXsltTransformation(inputStream, outputStream, Format.FO
					.getProfile(), profile, properties);
		}
		else if (Format.EPUB.getMimeType().equals(toMimeType)) {
			if (!ConverterConfiguration.checkProfile(profile, Format.EPUB
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			transformToEpub(inputStream, outputStream, profile, Format.EPUB.getProfile(), properties);
		}
		else if (Format.TEXT.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.TEXT.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.TEXT
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "txt");
			performXsltTransformation(inputStream, outputStream, Format.TEXT
					.getProfile(), profile, properties);
		}
		else if (Format.XML.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.XML.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.XML
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "xml");
			performXsltTransformation(inputStream, outputStream, Format.XML
					.getProfile(), profile, properties);
		}
		else if (Format.RDF.getMimeType().equals(toMimeType)
			 && fromDataType.getFormat().equals(Format.RDF.getFormatName())) {
			if (!ConverterConfiguration.checkProfile(profile, Format.RDF
					.getProfile())) {
				LOGGER.debug(ConverterConfiguration.PROFILE_NOT_FOUND_MSG);
				profile = EGEConstants.DEFAULT_PROFILE;
			}
			properties.put("extension", "rdf");
			performXsltTransformation(inputStream, outputStream, Format.RDF
					.getProfile(), profile, properties);
		}
	}
