コード例 #1
0
        static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (stylesheetUri == null)
            {
                throw new ArgumentNullException("stylesheetUri");
            }

            var resolver = new XmlDynamicResolver(callingAssembly);

            if (!stylesheetUri.IsAbsoluteUri)
            {
                stylesheetUri = resolver.ResolveUri(null, stylesheetUri.OriginalString);
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            ConcurrentDictionary <Uri, XsltExecutable> cache =
                uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, XsltExecutable>());

            XsltExecutable executable = cache.GetOrAdd(stylesheetUri, u => {
                using (var stylesheetSource = (Stream)resolver.GetEntity(stylesheetUri, null, typeof(Stream))) {
                    return(processor.Compile(stylesheetSource, new XsltCompileOptions {
                        BaseUri = stylesheetUri,
                        XmlResolver = resolver
                    }));
                }
            });

            return(new XsltInvoker(executable, callingAssembly));
        }
コード例 #2
0
ファイル: SchematronInvoker.cs プロジェクト: ruo2012/myxsl
        static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schemaUri == null)
            {
                throw new ArgumentNullException("schemaUri");
            }

            var resolver = new XmlDynamicResolver(callingAssembly);

            if (!schemaUri.IsAbsoluteUri)
            {
                schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString);
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            ConcurrentDictionary <Uri, SchematronValidator> cache =
                uriCache.GetOrAdd(processor, p => new ConcurrentDictionary <Uri, SchematronValidator>());

            SchematronValidator validator = cache.GetOrAdd(schemaUri, u => {
                using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) {
                    IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions {
                        BaseUri     = schemaUri,
                        XmlResolver = resolver
                    });

                    return(processor.CreateSchematronValidator(schemaDoc));
                }
            });

            return(new SchematronInvoker(validator, resolver));
        }
コード例 #3
0
        internal static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (stylesheet == null)
            {
                throw new ArgumentNullException("stylesheet");
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(stylesheet.CreateNavigator());

            ConcurrentDictionary <int, XsltExecutable> cache =
                inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, XsltExecutable>());

            XsltExecutable exec = cache.GetOrAdd(hashCode, i => {
                var resolver = new XmlDynamicResolver(callingAssembly);

                return(processor.Compile(stylesheet, new XsltCompileOptions {
                    XmlResolver = resolver
                }));
            });

            return(new XsltInvoker(exec, callingAssembly));
        }
コード例 #4
0
ファイル: XQueryInvoker.cs プロジェクト: ruo2012/myxsl
        internal static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (processor == null)
            {
                processor = Processors.XQuery.DefaultProcessor;
            }

            hashCode = query.GetHashCode();

            ConcurrentDictionary <int, XQueryExecutable> cache =
                inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, XQueryExecutable>());

            XQueryExecutable exec = cache.GetOrAdd(hashCode, i => {
                var resolver = new XmlDynamicResolver(callingAssembly);

                return(processor.Compile(new StringReader(query), new XQueryCompileOptions {
                    XmlResolver = resolver
                }));
            });

            return(new XQueryInvoker(exec, callingAssembly));
        }
コード例 #5
0
ファイル: SystemXsltExecutable.cs プロジェクト: ruo2012/myxsl
        public override void Run(XmlWriter output, XsltRuntimeOptions options)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (this.possiblyXhtmlMethod ||
                options.Serialization.Method == XPathSerializationMethods.XHtml)
            {
                output = XPathItemFactory.CreateXHtmlWriter(output);
            }

            IXPathNavigable input;

            if (options.InitialContextNode != null)
            {
                input = options.InitialContextNode;
            }
            else
            {
                // this processor doesn't support initial template,
                // a node must be provided
                input = this.Processor.ItemFactory.CreateNodeReadOnly();
            }

            XsltArgumentList args = GetArguments(options);

            XmlResolver        resolver        = options.InputXmlResolver;
            XmlDynamicResolver dynamicResolver = resolver as XmlDynamicResolver;

            if (dynamicResolver != null &&
                dynamicResolver.DefaultBaseUri == null)
            {
                dynamicResolver.DefaultBaseUri = this.StaticBaseUri;
            }

            try {
                if (CLR.IsMono)
                {
                    monoTransform(this.transform, ((input != null) ? input.CreateNavigator() : null), args, output, resolver);
                }
                else
                {
                    net20Transform(this.command, input, resolver, args, output);
                }
            } catch (XsltException ex) {
                throw new SystemXsltException(ex);
            }
        }
コード例 #6
0
        public static void Start()
        {
            if (!startWasCalled)
            {
                startWasCalled = true;

                TypeLoader.Instance = new WebTypeLoader();

                XmlDynamicResolver.RegisterResolver(Uri.UriSchemeFile, typeof(XmlVirtualPathAwareUrlResolver));
                XmlDynamicResolver.RegisterResolver(Uri.UriSchemeHttp, typeof(XmlVirtualPathAwareUrlResolver));

                BuildProvider.RegisterBuildProvider(".xsl", typeof(XsltPageBuildProvider));
                BuildProvider.RegisterBuildProvider(".xqy", typeof(XQueryPageBuildProvider));
            }
        }
コード例 #7
0
ファイル: SchematronInvoker.cs プロジェクト: ruo2012/myxsl
        static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            if (processor == null)
            {
                processor = Processors.Xslt.DefaultProcessor;
            }

            int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator());

            ConcurrentDictionary <int, SchematronValidator> cache =
                inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary <int, SchematronValidator>());

            SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema));
            var resolver = new XmlDynamicResolver(callingAssembly);

            return(new SchematronInvoker(validator, resolver));
        }
コード例 #8
0
        XQueryEvaluator GetEvaluator(XQueryRuntimeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            XQueryEvaluator eval = this.executable.Load();

            if (options.InputXmlResolver != null)
            {
                eval.InputXmlResolver = options.InputXmlResolver;

                XmlDynamicResolver dynamicResolver = options.InputXmlResolver as XmlDynamicResolver;

                if (dynamicResolver != null &&
                    dynamicResolver.DefaultBaseUri == null)
                {
                    dynamicResolver.DefaultBaseUri = this.StaticBaseUri;
                }
            }

            if (options.ContextItem != null)
            {
                eval.ContextItem = options.ContextItem.ToXdmItem(this.Processor.ItemFactory);
            }

            foreach (var pair in options.ExternalVariables)
            {
                var      qname    = new QName(pair.Key);
                XdmValue xdmValue = pair.Value.ToXdmValue(this.Processor.ItemFactory);

                eval.SetExternalVariable(qname, xdmValue);
            }

            return(eval);
        }
コード例 #9
0
ファイル: XsltInvoker.cs プロジェクト: skurdiukov/myxsl
        static XsltInvoker With(Uri stylesheetUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (stylesheetUri == null) throw new ArgumentNullException("stylesheetUri");

             var resolver = new XmlDynamicResolver(callingAssembly);

             if (!stylesheetUri.IsAbsoluteUri) {
            stylesheetUri = resolver.ResolveUri(null, stylesheetUri.OriginalString);
             }

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             ConcurrentDictionary<Uri, XsltExecutable> cache =
            uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, XsltExecutable>());

             XsltExecutable executable = cache.GetOrAdd(stylesheetUri, u => {

            using (var stylesheetSource = (Stream)resolver.GetEntity(stylesheetUri, null, typeof(Stream))) {
               return processor.Compile(stylesheetSource, new XsltCompileOptions {
                  BaseUri = stylesheetUri,
                  XmlResolver = resolver
               });
            }
             });

             return new XsltInvoker(executable, callingAssembly);
        }
コード例 #10
0
ファイル: XsltInvoker.cs プロジェクト: skurdiukov/myxsl
        internal static XsltInvoker With(IXPathNavigable stylesheet, IXsltProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (stylesheet == null) throw new ArgumentNullException("stylesheet");

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(stylesheet.CreateNavigator());

             ConcurrentDictionary<int, XsltExecutable> cache =
            inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, XsltExecutable>());

             XsltExecutable exec = cache.GetOrAdd(hashCode, i => {

            var resolver = new XmlDynamicResolver(callingAssembly);

            return processor.Compile(stylesheet, new XsltCompileOptions {
               XmlResolver = resolver
            });
             });

             return new XsltInvoker(exec, callingAssembly);
        }
コード例 #11
0
        void Run(XmlDestination destination, XsltRuntimeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            XsltTransformer transformer = executable.Load();

            transformer.RecoveryPolicy = RecoveryPolicy.DoNotRecover;

            if (options.InputXmlResolver != null)
            {
                XmlDynamicResolver dynamicResolver = options.InputXmlResolver as XmlDynamicResolver;

                if (dynamicResolver != null &&
                    dynamicResolver.DefaultBaseUri == null)
                {
                    dynamicResolver.DefaultBaseUri = this.StaticBaseUri;
                }

                transformer.InputXmlResolver = options.InputXmlResolver;
            }

            // XsltTransformer.BaseOutputUri doesn't accept null
            if (options.BaseOutputUri != null)
            {
                transformer.BaseOutputUri = options.BaseOutputUri;
            }

            // TODO: Bug in Saxon 9.3
            //else if (this.StaticBaseUri != null && this.StaticBaseUri.IsFile)
            //   transformer.BaseOutputUri = new Uri(Path.GetDirectoryName(this.StaticBaseUri.LocalPath), UriKind.Absolute);

            try {
                if (options.InitialTemplate != null)
                {
                    transformer.InitialTemplate = new QName(options.InitialTemplate);
                }
            } catch (DynamicError err) {
                throw new SaxonException(err);
            }

            if (options.InitialMode != null)
            {
                transformer.InitialMode = new QName(options.InitialMode);
            }

            if (options.InitialContextNode != null)
            {
                XdmNode node = options.InitialContextNode.ToXdmNode(this.Processor.ItemFactory);

                BugHandler.ThrowIfBug1675(node);

                transformer.InitialContextNode = node;
            }

            foreach (var pair in options.Parameters)
            {
                var      qname    = new QName(pair.Key);
                XdmValue xdmValue = pair.Value.ToXdmValue(this.Processor.ItemFactory);

                transformer.SetParameter(qname, xdmValue);
            }

            transformer.MessageListener = new TraceMessageListener();

            try {
                transformer.Run(destination);
            } catch (DynamicError ex) {
                throw new SaxonException(ex);
            } catch (Exception ex) {
                throw new SaxonException(ex.Message, ex);
            }
        }
コード例 #12
0
ファイル: SchematronInvoker.cs プロジェクト: skurdiukov/myxsl
        static SchematronInvoker With(IXPathNavigable schema, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schema == null) throw new ArgumentNullException("schema");

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             int hashCode = XPathNavigatorEqualityComparer.Instance.GetHashCode(schema.CreateNavigator());

             ConcurrentDictionary<int, SchematronValidator> cache =
            inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, SchematronValidator>());

             SchematronValidator validator = cache.GetOrAdd(hashCode, i => processor.CreateSchematronValidator(schema));
             var resolver = new XmlDynamicResolver(callingAssembly);

             return new SchematronInvoker(validator, resolver);
        }
コード例 #13
0
ファイル: SchematronInvoker.cs プロジェクト: skurdiukov/myxsl
        static SchematronInvoker With(Uri schemaUri, IXsltProcessor processor, Assembly callingAssembly)
        {
            if (schemaUri == null) throw new ArgumentNullException("schemaUri");

             var resolver = new XmlDynamicResolver(callingAssembly);

             if (!schemaUri.IsAbsoluteUri) {
            schemaUri = resolver.ResolveUri(null, schemaUri.OriginalString);
             }

             if (processor == null) {
            processor = Processors.Xslt.DefaultProcessor;
             }

             ConcurrentDictionary<Uri, SchematronValidator> cache =
            uriCache.GetOrAdd(processor, p => new ConcurrentDictionary<Uri, SchematronValidator>());

             SchematronValidator validator = cache.GetOrAdd(schemaUri, u => {

            using (var schemaSource = (Stream)resolver.GetEntity(schemaUri, null, typeof(Stream))) {

               IXPathNavigable schemaDoc = processor.ItemFactory.CreateNodeReadOnly(schemaSource, new XmlParsingOptions {
                  BaseUri = schemaUri,
                  XmlResolver = resolver
               });

               return processor.CreateSchematronValidator(schemaDoc);
            }
             });

             return new SchematronInvoker(validator, resolver);
        }
コード例 #14
0
ファイル: XQueryInvoker.cs プロジェクト: skurdiukov/myxsl
        internal static XQueryInvoker WithQuery(string query, IXQueryProcessor processor, Assembly callingAssembly, out int hashCode)
        {
            if (query == null) throw new ArgumentNullException("query");

             if (processor == null) {
            processor = Processors.XQuery.DefaultProcessor;
             }

             hashCode = query.GetHashCode();

             ConcurrentDictionary<int, XQueryExecutable> cache =
            inlineCache.GetOrAdd(processor, p => new ConcurrentDictionary<int, XQueryExecutable>());

             XQueryExecutable exec = cache.GetOrAdd(hashCode, i => {

            var resolver = new XmlDynamicResolver(callingAssembly);

            return processor.Compile(new StringReader(query), new XQueryCompileOptions {
               XmlResolver = resolver
            });
             });

             return new XQueryInvoker(exec, callingAssembly);
        }