Пример #1
0
        private static object FromRtfToText(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);
                stream = new ConverterStream(stream, new RtfToText
                {
                    OutputEncoding     = ConvertUtils.UnicodeEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                }, ConverterStreamAccess.Write);
                obj = BodyWriteDelegates.GetRtfDecompressorOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
Пример #2
0
        private static object FromTextToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, new TextToHtml
                {
                    InputEncoding      = configuration.SourceEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat,
                    HtmlTagCallback    = configuration.InternalHtmlTagCallback,
                    FilterHtml         = configuration.FilterHtml
                });
                stream = htmlWriteConverterStream;
                stream = new BodyCharsetDetectionStream(stream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Text, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
Пример #3
0
        private static object FromTextToRtf(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 ConverterStream(stream, new TextToRtf
                {
                    InputEncoding      = configuration.SourceEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                }, ConverterStreamAccess.Write);
                stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.Text, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        private static object FromHtmlToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                if (!createWriter && configuration.SourceCharset == null)
                {
                    obj = bodyStream;
                }
                else
                {
                    HtmlToHtml htmlToHtml = new HtmlToHtml();
                    htmlToHtml.InputEncoding             = configuration.SourceEncoding;
                    htmlToHtml.DetectEncodingFromMetaTag = configuration.TrustHtmlMetaTag;
                    htmlToHtml.FilterHtml         = configuration.FilterHtml;
                    htmlToHtml.HtmlTagCallback    = configuration.InternalHtmlTagCallback;
                    htmlToHtml.Header             = configuration.InjectPrefix;
                    htmlToHtml.Footer             = configuration.InjectSuffix;
                    htmlToHtml.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                    bool canSkipConversionOnMatchingCharset           = !configuration.IsContentTransformationNeeded(coreItem);
                    HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, htmlToHtml, canSkipConversionOnMatchingCharset);
                    stream = htmlWriteConverterStream;
                    stream = new BodyCharsetDetectionStream(htmlWriteConverterStream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Html, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), configuration.TrustHtmlMetaTag);
                    obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
Пример #7
0
        private static object FromRtfToRtf(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                if (!createWriter && !configuration.IsContentTransformationNeeded(coreItem))
                {
                    obj = new BodyCharsetDetectionStream(bodyStream, null, coreItem, BodyStreamFormat.RtfCompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                }
                else
                {
                    stream = new ConverterStream(bodyStream, new RtfToRtfCompressed(), ConverterStreamAccess.Write);
                    stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.RtfUncompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                    if (configuration.InjectPrefix != null || configuration.InjectSuffix != null)
                    {
                        stream = new ConverterStream(stream, new RtfToRtf
                        {
                            Header             = configuration.InjectPrefix,
                            Footer             = configuration.InjectSuffix,
                            HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                        }, ConverterStreamAccess.Write);
                    }
                    obj = BodyWriteDelegates.GetRtfDecompressorOrUnicodeWriter(stream, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }