protected override void DoUofToOoxMainTransform(string inputFile, string outputFile, string resourceDir)
        {
            XmlUrlResolver    resourceResolver;
            XPathDocument     xslDoc;
            XmlReaderSettings xrs    = new XmlReaderSettings();
            XmlReader         source = null;
            XmlWriter         writer = null;

            try
            {
                xrs.ProhibitDtd = true;
                string xslLocation = TranslatorConstants.UOFToOOX_XSL;
                if (outputFile == null)
                {
                    xslLocation = TranslatorConstants.UOFToOOX_COMPUTE_SIZE_XSL;
                }

                if (resourceDir == null)
                {
                    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Powerpoint.uof2oox");
                    xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                    xrs.XmlResolver = resourceResolver;
                    source          = XmlReader.Create(inputFile);
                }
                else
                {
                    resourceResolver = new XmlUrlResolver();
                    xslDoc           = new XPathDocument(resourceDir + "/" + xslLocation);
                    source           = XmlReader.Create(resourceDir + "/" + TranslatorConstants.SOURCE_XML, xrs);
                }
                try
                {
                    XslCompiledTransform xslt     = new XslCompiledTransform();
                    XsltSettings         settings = new XsltSettings(true, false);
                    xslt.Load(xslDoc, settings, resourceResolver);
                    //Assembly ass = Assembly.Load("ppt_uof2oox");
                    //Type t = ass.GetType("uof2oox");
                    //xslt.Load(t);
                    XsltArgumentList parameters = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    if (outputFile != null)
                    {
                        parameters.AddParam("outputFile", "", outputFile);
                        parameters.AddParam("FileType", "", "Prsentation");
                        writer = new OoxZipWriter(inputFile);
                    }
                    else
                    {
                        writer = new XmlTextWriter(new StringWriter());
                    }
                    xslt.Transform(source, parameters, writer);
                }
                catch (Exception ex)
                {
                    logger.Error("Fail in the main translator of Presentation", ex);
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (source != null)
                {
                    source.Close();
                }
            }
        }
Beispiel #2
0
        protected override void DoUofToOoxMainTransform(string inputFile, string outputFile, string resourceDir)
        {
            XmlUrlResolver    resourceResolver;
            XPathDocument     xslDoc;
            XmlReaderSettings xrs          = new XmlReaderSettings();
            XmlReader         source       = null;
            XmlWriter         writer       = null;
            string            mainOutput   = Path.GetDirectoryName(inputFile) + Path.AltDirectorySeparatorChar + "mainOutput.xml";
            string            equAfterMain = Path.GetDirectoryName(inputFile) + Path.AltDirectorySeparatorChar + "equAfterMain.xml";

            try
            {
                xrs.ProhibitDtd = true;
                string xslLocation = TranslatorConstants.UOFToOOX_XSL;
                if (outputFile == null)
                {
                    xslLocation = TranslatorConstants.UOFToOOX_COMPUTE_SIZE_XSL;
                }

                if (resourceDir == null)
                {
                    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Excel.uof2oox");
                    xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                    xrs.XmlResolver = resourceResolver;
                    source          = XmlReader.Create(inputFile);
                }
                else
                {
                    resourceResolver = new XmlUrlResolver();
                    xslDoc           = new XPathDocument(resourceDir + "/" + xslLocation);
                    source           = XmlReader.Create(resourceDir + "/" + TranslatorConstants.SOURCE_XML, xrs);
                }
                try
                {
                    XslCompiledTransform xslt     = new XslCompiledTransform();
                    XsltSettings         settings = new XsltSettings(true, false);
                    //Assembly ass = Assembly.Load("excel_uof2oox");
                    //Type t = ass.GetType("uof2oox");
                    // xslt.Load(t);
                    xslt.Load(xslDoc, settings, resourceResolver);
                    XsltArgumentList parameters = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    //if (outputFile != null)
                    //{
                    //    parameters.AddParam("outputFile", "", outputFile);
                    //    writer = new OoxZipWriter(inputFile);
                    //}
                    //else
                    //{
                    //    writer = new XmlTextWriter(new StringWriter());
                    //}

                    //xslt.Transform(source, parameters, writer);
                    XmlTextWriter fs = new XmlTextWriter(mainOutput, Encoding.UTF8);
                    xslt.Transform(source, parameters, fs);
                    fs.Close();

                    SetDrawingTwoCellAnchorValue(mainOutput, equAfterMain);

                    // 增加对公式的互操作支持
                    // EquInter(mainOutput, equAfterMain);

                    xslLocation = TranslatorConstants.UOFToOOX_POSTTREAT_STEP1_XSL;

                    if (resourceDir == null)
                    {
                        resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                                this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Excel.uof2oox");
                        xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                        xrs.XmlResolver = resourceResolver;
                        source          = XmlReader.Create(equAfterMain);
                    }
                    XslCompiledTransform xslt2     = new XslCompiledTransform();
                    XsltSettings         settings2 = new XsltSettings(true, false);
                    xslt.Load(xslDoc, settings2, resourceResolver);

                    XsltArgumentList parameters2 = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    if (outputFile != null)
                    {
                        parameters2.AddParam("outputFile", "", outputFile);
                        writer = new OoxZipWriter(equAfterMain);
                    }
                    else
                    {
                        writer = new XmlTextWriter(new StringWriter());
                    }

                    xslt.Transform(source, parameters2, writer);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (source != null)
                {
                    source.Close();
                }
            }
        }