예제 #1
0
        private static object FromTextToText(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                stream = new BodyCharsetDetectionStream(bodyStream, null, coreItem, BodyStreamFormat.Text, ConvertUtils.UnicodeCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                if (!createWriter && !configuration.IsContentTransformationNeeded(coreItem))
                {
                    obj = stream;
                }
                else
                {
                    TextToText textToText;
                    if (string.IsNullOrEmpty(configuration.InjectPrefix) && string.IsNullOrEmpty(configuration.InjectSuffix))
                    {
                        textToText = new TextToText(TextToTextConversionMode.ConvertCodePageOnly);
                    }
                    else
                    {
                        textToText = new TextToText();
                    }
                    textToText.InputEncoding  = configuration.SourceEncoding;
                    textToText.OutputEncoding = ConvertUtils.UnicodeEncoding;
                    if (!string.IsNullOrEmpty(configuration.InjectPrefix) || !string.IsNullOrEmpty(configuration.InjectSuffix))
                    {
                        textToText.Header             = configuration.InjectPrefix;
                        textToText.Footer             = configuration.InjectSuffix;
                        textToText.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                    }
                    obj = BodyWriteDelegates.GetConverterStreamOrWriter(stream, textToText, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #2
0
        private static object FromHtmlToRtf(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                stream = new ConverterStream(bodyStream, new RtfToRtfCompressed(), ConverterStreamAccess.Write);
                stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.RtfUncompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                HtmlToRtf htmlToRtf = new HtmlToRtf();
                htmlToRtf.InputEncoding             = configuration.SourceEncoding;
                htmlToRtf.DetectEncodingFromMetaTag = false;
                htmlToRtf.Header             = configuration.InjectPrefix;
                htmlToRtf.Footer             = configuration.InjectSuffix;
                htmlToRtf.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                if (configuration.ImageRenderingCallback != null)
                {
                    TextConvertersInternalHelpers.SetImageRenderingCallback(htmlToRtf, configuration.ImageRenderingCallback);
                }
                TextConverter converter = htmlToRtf;
                if (configuration.FilterHtml || configuration.InternalHtmlTagCallback != null)
                {
                    stream    = new ConverterStream(stream, htmlToRtf, ConverterStreamAccess.Write);
                    converter = new HtmlToHtml
                    {
                        InputEncoding             = configuration.SourceEncoding,
                        OutputEncoding            = configuration.SourceEncoding,
                        DetectEncodingFromMetaTag = false,
                        FilterHtml      = configuration.FilterHtml,
                        HtmlTagCallback = configuration.InternalHtmlTagCallback
                    };
                }
                obj = BodyWriteDelegates.GetConverterStreamOrWriter(stream, converter, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }