コード例 #1
0
        /// <summary>
        /// Runs the necessary stylesheet transformations.
        /// </summary>
        /// <param name="context">The IRailsEngineContext containing the necessary transformation parameters.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="templateName">Name of the template to run.</param>
        private void RunStylesheets(IRailsEngineContext context, IController controller, String templateName)
        {
            //Collect arguments
            XsltTransformationArguments arguments = CreateArguments(context, controller);
            //Start new pipeline
            XsltPipeline pipeline = new XsltPipeline(arguments);

            //First stage
            pipeline.AddStage(new XsltPipelineStage(TemplateStore.LoadTemplate(templateName, arguments)));

            //Layout stage
            if (controller.LayoutName != null)
            {
                pipeline.AddStage(new XsltPipelineStage(TemplateStore.LoadTemplate(@"layouts\" + controller.LayoutName, arguments)));
            }
            string xhtmlDocType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

            if (XHtmlRendering)
            {
                using (StreamWriter writer = new StreamWriter(context.Response.OutputStream))
                {
                    writer.WriteLine(xhtmlDocType);
                }
            }
            //Execute pipeline
            pipeline.Execute(InputDocument, new XmlTextWriter(context.Response.Output));
        }
コード例 #2
0
 private IXsltTransform CompileTransform(string templateName, XsltTransformationArguments arguments)
 {
     using (Stream templateStream = GetTemplateStream(templateName))
     {
         return(CompileTransform(new XsltTemplateStoreBasedXsltTemplateResolver(this, templateName), templateStream, arguments));
     }
 }
コード例 #3
0
		/// <summary>
		/// Registers the extensions objects in the specified
		/// transformation arguments to a new HelperTransformationBuilder.
		/// </summary>
		/// <param name="arguments">The arguments.</param>
		/// <returns></returns>
		internal static HelperTransformationBuilder BuildTransformationHelper(XsltTransformationArguments arguments)
		{
			HelperTransformationBuilder hp = new HelperTransformationBuilder();

			foreach (object exO in arguments.ExtensionObjects)
			{
				hp.AddType(exO.GetType());
			}
			return hp;
		}
コード例 #4
0
ファイル: XsltEngine.cs プロジェクト: mgagne-atman/Projects
		/// <summary>
		/// Loads the transformation from the specified stream
		/// </summary>
		/// <param name="store">The store to be used when resolving includes in the xslt stylesheet</param>
		/// <param name="stream">The stream to load the transformation from.</param>
		/// <param name="arguments">The arguments to arguments to use in the transformation.</param>
		/// <returns></returns>
		public IXsltTransform LoadTransform(IXsltTemplateResolver resolver, System.IO.Stream stream, XsltTransformationArguments arguments)
		{
			XslCompiledTransform transformer = new XslCompiledTransform();
			using (XmlReader reader = new XmlTextReader(stream))
			{
				XsltSettings settings = new XsltSettings(false,false);
				transformer.Load(reader, settings,
					new HelperTransformationResolver(resolver,
						XsltTransform.BuildTransformationHelper(arguments)));
			}
			return new XsltTransform(transformer, this);
		}
コード例 #5
0
        /// <summary>
        /// Creates an XsltTransformationArguments instance using the information
        /// from the controller and IRailsEngineContext
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="controller">The controller.</param>
        /// <returns></returns>
        private XsltTransformationArguments CreateArguments(IRailsEngineContext context, IController controller)
        {
            XsltTransformationArguments arguments = new XsltTransformationArguments();

            //Flash
            AddFlash(context, arguments);
            //P-bag
            AddPropertyBag(context, controller, arguments);
            //Helpers
            AddExtensionObjects(context, controller, arguments);

            return(arguments);
        }
コード例 #6
0
		public void Execute(XmlReader reader, XmlWriter writer, XsltTransformationArguments arguments)
		{
			if (_executed)
				throw new InvalidOperationException("XsltPipelineStage has already been executed!");

			if (BeforeExecute != null)
				BeforeExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments));

			_Transformer.Transform(reader, writer, arguments);
			_executed = true;

			if (AfterExecute != null)
				AfterExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments));
		}
コード例 #7
0
        /// <summary>
        /// Processes the view - using the templateName to obtain the correct template,
        /// and using the context to output the result.
        /// </summary>
        public override void Process(IRailsEngineContext context, IController controller, String templateName)
        {
            try
            {
                AdjustContentType(context);

                //Todo: make configurable so this can be turned off
                //Dump all arguments in XML to the ResponseStream
                if (context.Request.Params["debugxml"] != null)
                {
                    XsltTransformationArguments arguments = CreateArguments(context, controller);

                    XmlDocument doc = new XmlDocument();
                    foreach (XsltTransformationParameter thing in arguments.Parameters)
                    {
                        XmlElement elem = doc.CreateElement(thing.Name, thing.NameSpace);

                        if (thing.Value is IXPathNavigable)
                        {
                            elem.InnerXml = (thing.Value as IXPathNavigable).CreateNavigator().OuterXml;
                        }
                        else
                        {
                            elem.Value = thing.Value.ToString();
                        }
                    }
                    context.Response.ContentType = "text/xml";
                    doc.WriteTo(new XmlTextWriter(context.Response.Output));
                }
                else
                {
                    //Run the transformations.
                    RunStylesheets(context, controller, templateName);
                }
            }
            catch (Exception ex)
            {
                if (context.Request.IsLocal)
                {
                    SendErrorDetails(ex, context.Response.Output);
                }
                else
                {
                    //TODO: possibly incorrect message
                    throw new RailsException("Could not obtain view: " + templateName, ex);
                }
            }
        }
コード例 #8
0
		/// <summary>
		/// Converts the XsltTransformationArguments to a XsltArgumentList instance
		/// </summary>
		/// <param name="arguments">The arguments.</param>
		/// <returns></returns>
		private XsltArgumentList BuildXslArgumentList(XsltTransformationArguments arguments)
		{
			XsltArgumentList list = new XsltArgumentList();

			foreach (XsltTransformationParameter param in arguments.Parameters)
			{
				list.AddParam(param.Name, param.NameSpace, param.Value);
			}

			
			foreach (object exO in arguments.ExtensionObjects)
			{
				list.AddExtensionObject("urn:" + exO.GetType().Name,
					_Engine.DynamicAdapterStore.Adapt(exO));
			}
			return list;
			
		}
コード例 #9
0
        public IXsltTransform LoadTemplate(string templateName, XsltTransformationArguments arguments)
        {
            string key = templateName.ToLower();

            lock (_lock)
            {
                if (_templateCache.ContainsKey(key))
                {
                    return(_templateCache[key]);
                }

                IXsltTransform transform = CompileTransform(key, arguments);

                _templateCache[key] = transform;

                return(transform);
            }
        }
コード例 #10
0
        public void Execute(XmlReader reader, XmlWriter writer, XsltTransformationArguments arguments)
        {
            if (_executed)
            {
                throw new InvalidOperationException("XsltPipelineStage has already been executed!");
            }

            if (BeforeExecute != null)
            {
                BeforeExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments));
            }

            _Transformer.Transform(reader, writer, arguments);
            _executed = true;

            if (AfterExecute != null)
            {
                AfterExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments));
            }
        }
コード例 #11
0
        private static void AddFlash(IRailsEngineContext context, XsltTransformationArguments arguments)
        {
            if (context.Flash.Keys.Count == 0)
            {
                return;
            }

            ObjectXPathContext ocontext = new ObjectXPathContext();

            //For each object in the flash build an ObjectXPathNavigator to
            //create an XPath-able represenation of that object
            foreach (String key in context.Flash.Keys)
            {
                object value = context.Flash[key];

                if (value != null)
                {
                    arguments.AddParam(key, string.Empty, ocontext.CreateNavigator(value));
                }
            }
        }
コード例 #12
0
ファイル: XsltPipeline.cs プロジェクト: mgagne-atman/Projects
		/// <summary>
		/// Initializes a new instance of the XsltPipeline class.
		/// </summary>
		/// <param name="arguments"></param>
		public XsltPipeline(XsltTransformationArguments arguments)
		{
			_Arguments = arguments;
		}
コード例 #13
0
		/// <summary>
		/// Creates an XsltTransformationArguments instance using the information
		/// from the controller and IRailsEngineContext
		/// </summary>
		/// <param name="context">The context.</param>
		/// <param name="controller">The controller.</param>
		/// <returns></returns>
		private XsltTransformationArguments CreateArguments(IRailsEngineContext context, IController controller)
		{
			XsltTransformationArguments arguments = new XsltTransformationArguments();
			
			//Flash
			AddFlash(context, arguments);
			//P-bag
			AddPropertyBag(context, controller, arguments);
			//Helpers
			AddExtensionObjects(context, controller, arguments);

			return arguments;
		}
コード例 #14
0
        /// <summary>
        /// Adds XPathNavigable representations of the items in the propertybag
        /// of the controller.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="arguments">The arguments.</param>
        private static void AddPropertyBag(IRailsEngineContext railscontext, IController controller, XsltTransformationArguments arguments)
        {
            ObjectXPathContext context = new ObjectXPathContext();

            //For each object in the property bag build an ObjectXPathNavigator to
            //create an XPath-able represenation of that object
            foreach (String key in controller.PropertyBag.Keys)
            {
                object value = controller.PropertyBag[key];

                if (value != null)
                {
                    arguments.AddParam(key, string.Empty, context.CreateNavigator(value));
                }
            }

            arguments.AddParam("context", string.Empty, context.CreateNavigator(railscontext));
            //arguments.AddExtensionObject("urn:request", context.Request);
            //arguments.AddExtensionObject("urn:response", context.Response);
            //arguments.AddExtensionObject("urn:server", context.Server);
            //arguments.AddExtensionObject("urn:session", context.Session);
        }
コード例 #15
0
        /// <summary>
        /// Adds the necessary helper objects to the specified
        /// XsltTransformationArguments instance.
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="controller">The controller to get the Helpers from</param>
        /// <param name="arguments">The XsltTransformationArguments instance to add the Helpers to.</param>
        private static void AddExtensionObjects(IRailsEngineContext context, IController controller, XsltTransformationArguments arguments)
        {
            List <string> extensions = new List <string>();

            foreach (object helper in controller.Helpers.Values)
            {
                //TODO: get_Name is an expensive reflection operation
                string name = helper.GetType().Name;

                //Make sure every helper is only added once
                if (extensions.Contains(name))
                {
                    continue;
                }

                arguments.AddExtensionObject(helper);
                extensions.Add(name);
            }

            arguments.AddExtensionObject(new XsltReflectionHelper());
        }
コード例 #16
0
		/// <summary>
		/// Adds the necessary helper objects to the specified
		/// XsltTransformationArguments instance.
		/// </summary>
		/// <param name="context">The context</param>
		/// <param name="controller">The controller to get the Helpers from</param>
		/// <param name="arguments">The XsltTransformationArguments instance to add the Helpers to.</param>
		private static void AddExtensionObjects(IRailsEngineContext context, IController controller, XsltTransformationArguments arguments)
		{
			List<string> extensions = new List<string>();
			foreach (object helper in controller.Helpers.Values)
			{
				//TODO: get_Name is an expensive reflection operation
				string name = helper.GetType().Name;

				//Make sure every helper is only added once
				if (extensions.Contains(name)) continue;

				arguments.AddExtensionObject(helper);
				extensions.Add(name);
			}

			arguments.AddExtensionObject(new XsltReflectionHelper());
			
		}
コード例 #17
0
		/// <summary>
		/// Adds XPathNavigable representations of the items in the propertybag
		/// of the controller.
		/// </summary>
		/// <param name="controller">The controller.</param>
		/// <param name="arguments">The arguments.</param>
		private static void AddPropertyBag(IRailsEngineContext railscontext, IController controller, XsltTransformationArguments arguments)
		{
			ObjectXPathContext context = new ObjectXPathContext();
			//For each object in the property bag build an ObjectXPathNavigator to
			//create an XPath-able represenation of that object
			foreach (String key in controller.PropertyBag.Keys)
			{
				object value = controller.PropertyBag[key];

				if (value != null)
				{
					arguments.AddParam(key, string.Empty, context.CreateNavigator(value));
				}
			}

			arguments.AddParam("context", string.Empty, context.CreateNavigator(railscontext));
			//arguments.AddExtensionObject("urn:request", context.Request);
			//arguments.AddExtensionObject("urn:response", context.Response);
			//arguments.AddExtensionObject("urn:server", context.Server);
			//arguments.AddExtensionObject("urn:session", context.Session);
		}
コード例 #18
0
 private IXsltTransform CompileTransform(IXsltTemplateResolver resolver, Stream transformStream, XsltTransformationArguments arguments)
 {
     return(_xsltEngine.LoadTransform(resolver, transformStream, arguments));
 }
コード例 #19
0
		private static void AddFlash(IRailsEngineContext context, XsltTransformationArguments arguments)
		{
			if (context.Flash.Keys.Count == 0) return;

				ObjectXPathContext ocontext = new ObjectXPathContext();
				//For each object in the flash build an ObjectXPathNavigator to
				//create an XPath-able represenation of that object
				foreach (String key in context.Flash.Keys)
				{
					object value = context.Flash[key];

					if (value != null)
					{
						arguments.AddParam(key, string.Empty, ocontext.CreateNavigator(value));
					}
				}
		}
コード例 #20
0
		/// <summary>
		/// Initializes a new instance of the XsltPipelineStageEventArgs class.
		/// </summary>
		/// <param name="reader"></param>
		/// <param name="writer"></param>
		/// <param name="arguments"></param>
		public XsltPipelineStageEventArgs(XmlReader reader, XmlWriter writer, XsltTransformationArguments arguments)
		{
			_Reader = reader;
			_Writer = writer;
			_Arguments = arguments;
		}
コード例 #21
0
		private IXsltTransform CompileTransform(IXsltTemplateResolver resolver, Stream transformStream, XsltTransformationArguments arguments)
		{
			return _xsltEngine.LoadTransform(resolver, transformStream, arguments);
		}
コード例 #22
0
		private IXsltTransform CompileTransform(string templateName, XsltTransformationArguments arguments)
		{
			using (Stream templateStream = GetTemplateStream(templateName))
			{
				return CompileTransform(new XsltTemplateStoreBasedXsltTemplateResolver(this, templateName), templateStream, arguments);
			}
		}
コード例 #23
0
		public IXsltTransform LoadTemplate(string templateName, XsltTransformationArguments arguments)
		{
			string key = templateName.ToLower();

			lock (_lock)
			{
				if (_templateCache.ContainsKey(key))
					return _templateCache[key];

				IXsltTransform transform = CompileTransform(key, arguments);

				_templateCache[key] = transform;

				return transform;
			}
		}
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the XsltPipelineStageEventArgs class.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="writer"></param>
 /// <param name="arguments"></param>
 public XsltPipelineStageEventArgs(XmlReader reader, XmlWriter writer, XsltTransformationArguments arguments)
 {
     _Reader    = reader;
     _Writer    = writer;
     _Arguments = arguments;
 }
コード例 #25
0
		/// <summary>
		/// Transforms the specified input to the specified output using the specified arguments.
		/// </summary>
		/// <param name="input">The input document.</param>
		/// <param name="output">The output document to write to.</param>
		/// <param name="arguments">The arguments of the transformation.</param>
		public void Transform(System.Xml.XmlReader input, System.Xml.XmlWriter output, XsltTransformationArguments arguments)
		{
			XsltArgumentList xslArguments = BuildXslArgumentList(arguments);

			_transformer.Transform(input, xslArguments, output);
		}
コード例 #26
0
 /// <summary>
 /// Initializes a new instance of the XsltPipeline class.
 /// </summary>
 /// <param name="arguments"></param>
 public XsltPipeline(XsltTransformationArguments arguments)
 {
     _Arguments = arguments;
 }