예제 #1
0
        public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
        {
            try
            {
                Stream stream = null;

                if (entries.Contains(absoluteUri.AbsoluteUri))
                {
                    stream = archive.GetEntry((string)entries[absoluteUri.AbsoluteUri]);
                }
                if (stream == null)
                {
                    stream = new MemoryStream();
                }
                // Cannot have a 0 byte xml document !
                else if (stream.Length == 0)
                {
                    throw new IOException(entries[absoluteUri.AbsoluteUri] + " is 0 length");
                }
                return(stream);
            }
            catch (Exception)
            {
                // failsafe on a dummy xml document
                return(EmbeddedResourceResolver.GetSharedResource("source.xml"));
            }
        }
예제 #2
0
        protected virtual XslCompiledTransform Load(bool computeSize)
        {
            string         xslLocation = this.DirectTransform ? ODFToOOX_XSL : OOXToODF_XSL;
            XPathDocument  xslDoc      = null;
            XmlUrlResolver resolver    = this.ResourceResolver;

            if (this.ExternalResources == null)
            {
                if (computeSize)
                {
                    xslLocation = this.DirectTransform ? ODFToOOX_COMPUTE_SIZE_XSL : OOXToODF_COMPUTE_SIZE_XSL;
                }
                EmbeddedResourceResolver emr = (EmbeddedResourceResolver)resolver;
                emr.IsDirectTransform = this.DirectTransform;
                xslDoc = new XPathDocument(emr.GetInnerStream(xslLocation));
            }
            else
            {
                string xsltFile = this.ExternalResources;

                if (!File.Exists(xsltFile))
                {
                    // try several subfolders within the project directory tree
                    xsltFile = Path.Combine(this.ExternalResources, xslLocation);

                    if (!File.Exists(xsltFile))
                    {
                        xslLocation = Path.Combine(this.DirectTransform ? "odf2oox" : "oox2odf", xslLocation);
                        xsltFile    = Path.Combine(this.ExternalResources, xslLocation);

                        if (!File.Exists(xsltFile))
                        {
                            xslLocation = Path.Combine("resources", xslLocation);
                            xsltFile    = Path.Combine(this.ExternalResources, xslLocation);

                            if (!File.Exists(xsltFile))
                            {
                                throw new FileNotFoundException("No external XSLT file could be found at the specified location.", this.ExternalResources);
                            }
                        }
                    }
                }
                xslDoc = new XPathDocument(xsltFile);
            }

            if (!this.compiledProcessors.ContainsKey(xslLocation))
            {
                // create an XSL transformer

                // Activation of XSL Debugging only in "DEBUG" compilation mode
#if DEBUG
                XslCompiledTransform xslt = new XslCompiledTransform(true);
#else
                XslCompiledTransform xslt = new XslCompiledTransform();
#endif

                //JP - 03/07/2007
                // compile the stylesheet.
                // Input stylesheet, xslt settings and uri resolver are retrieve from the implementation class.
                try
                {
#if (!DEBUG)
                    Type       t  = typeof(XslCompiledTransform);
                    MethodInfo mi = t.GetMethod("Load", new Type[] { typeof(Type) });
                    Type       compiledStylesheet = this.LoadPrecompiledXslt();

                    // check if optimization of precompiled XSLT works on current
                    // .NET Framework installation and with current conversion direction
                    // (this feature requires .NET Framework 2.0 SP1)
                    if (mi != null && compiledStylesheet != null)
                    {
                        // dynamically invoke xslt.Load(compiledStylesheet);
                        mi.Invoke(xslt, new object[] { compiledStylesheet });
                    }
                    else
                    {
#endif
                    xslt.Load(xslDoc, this.XsltProcSettings, this.ResourceResolver);
#if (!DEBUG)
                }
#endif
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                this.compiledProcessors.Add(xslLocation, xslt);
            }
            return((XslCompiledTransform)this.compiledProcessors[xslLocation]);
        }