Exemplo n.º 1
0
        private static object FromRtfToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, new RtfToHtml
                {
                    FilterHtml         = configuration.FilterHtml,
                    HtmlTagCallback    = configuration.InternalHtmlTagCallback,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                });
                stream = htmlWriteConverterStream;
                stream = new BodyCharsetDetectionStream(stream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.RtfUncompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetRtfDecompressorOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }