Example #1
0
		/// <summary>
		/// <see cref="DnaTransformer"/>
		/// </summary>
		public override bool TransformXML(IDnaComponent component)
		{
#if DEBUG
            // purexml shouldn't redirect
			XPathDocument xdoc = new XPathDocument(new XmlNodeReader(component.RootElement.FirstChild));
			XPathNavigator xnav = xdoc.CreateNavigator();
			XPathNavigator redirect = xnav.SelectSingleNode("/H2G2/REDIRECT/@URL");
			if (null != redirect)
			{
				OutputContext.Redirect(redirect.InnerXml);
				return true;
			}
#endif
            OutputContext.SetContentType("text/xml");
			// Make the PageComponent Render itself into the page
			//_page.RenderPage(writer);
            OutputContext.Writer.Write("<?xml version=\"1.0\"?>\r\n" + Entities.GetEntities() + "\r\n");
			OutputContext.Writer.Write(component.RootElement.InnerXml);

			OutputContext.Diagnostics.WriteTimedEventToLog("PureXmlTransform", "Applied PureXml transform");
			return true;
		}
Example #2
0
        /// <summary>
        /// The main transformation function. This takes a component and then transforms the XML Doc with the required xslt file.
        /// This function will also check to see if a redirect has been inserted into the tree, and if so execute the redirect without the
        /// transformation.
        /// </summary>
        /// <remarks>Note that only the first redirect will be executed, so first come first served!!!</remarks>
        /// <param name="component">The IDNACompnent you are transforming</param>
        /// <returns>true if ok, false if not</returns>
        public override bool TransformXML(IDnaComponent component)
        {
            // Create the XML navigator for the given component XMLDoc. Check to see if we've been given a redirect
            XPathDocument xdoc = new XPathDocument(new XmlNodeReader(component.RootElement.FirstChild));
            XPathNavigator xnav = xdoc.CreateNavigator();
            XPathNavigator redirect = xnav.SelectSingleNode("/H2G2/REDIRECT/@URL");
            if (null != redirect)
            {
                OutputContext.Redirect(redirect.InnerXml);

                return true;
            }

            // Try to get a cached transform for this xslt file
            string xslFile = OutputContext.GetSkinPath(XsltFileName);
#if DEBUG
            // Check to see if we've been given a debug skin override
            if (OutputContext.DebugSkinFile.Length > 0)
            {
                // Override the skin with the one specified in the debug url param
                xslFile = OutputContext.DebugSkinFile;
            }
#endif
            XslCompiledTransform Transformer = OutputContext.GetCachedXslTransform(xslFile);

            // Now transform the document into the output context

            OutputContext.Diagnostics.WriteTimedEventToLog("HTMLTransform", "Applying " + xslFile);

            int htmlCachingTime = OutputContext.GetHtmlCachingTime();
            if (htmlCachingTime > 0 && OutputContext.IsHtmlCachingEnabled())
            {
                // We need to cache the output before sending it to OutputContext.Writer so write to a StringWriter 
                StringWriter sw = new StringWriter();
                Transformer.Transform(xnav, null, sw);

                //  Write to OutputContext.Writer
                string output = sw.ToString();
                /*  Uncomment if you ever need this for debugging purposes
                #if DEBUG
                output = "<!--Caching HTML output on " + DateTime.Now.ToString() + " for " + htmlCachingTime.ToString() + " seconds-->" + output;
                #endif
                 */
                OutputContext.Writer.Write(output);

                // Now cache the output
                string key = CreateTransformerRequestCacheKey();
                OutputContext.CacheObject(key, output, htmlCachingTime);


                OutputContext.Diagnostics.WriteTimedEventToLog("HTMLTransformCached", "Applied and cached output");
            }
            else
            {
                try
                {
                    // No output caching, so write directly to OutputContext.Writer
                    Transformer.Transform(xnav, null, OutputContext.Writer);
                }
                catch (Exception ex)
                {
                    OutputContext.Diagnostics.WriteTimedEventToLog("Transform", ex.Message);
                    throw;
                }

                OutputContext.Diagnostics.WriteTimedEventToLog("HTMLTransform", "Applied");
            }

            // Make a note on how long it took
            return true;
        }
Example #3
0
/// <summary>
		/// Transforms the page into an XML format. Uses XSLT but will output using a correct mimetype
		/// </summary>
		/// <param name="component">Component (probably a WholePage) to transform</param>
		/// <returns>true if succeeded, false otherwise</returns>
		public override bool TransformXML(IDnaComponent component)
		{
			// Create the XML navigator for the given component XMLDoc. Check to see if we've been given a redirect
			XPathDocument xdoc = new XPathDocument(new XmlNodeReader(component.RootElement.FirstChild));
			XPathNavigator xnav = xdoc.CreateNavigator();
			XPathNavigator redirect = xnav.SelectSingleNode("/H2G2/REDIRECT/@URL");
			if (null != redirect)
			{
				// We've been given a redirect, so execute it and return
				OutputContext.Redirect(redirect.InnerXml);
				return true;
			}

			// Try to get a cached transform for this xslt file
			string xslFile = OutputContext.GetSkinPath(XsltFileName);
#if DEBUG
			// Check to see if we've been given a debug skin override
			if (OutputContext.DebugSkinFile.Length > 0)
			{
				// Override the skin with the one specified in the debug url param
				xslFile = OutputContext.DebugSkinFile;
			}
#endif
			XslCompiledTransform Transformer = OutputContext.GetCachedXslTransform(xslFile);

			// Now transform the document into the output context

			OutputContext.Diagnostics.WriteTimedEventToLog("XMLTransform", "Applying " + xslFile);

            int xmlCachingTime = 60*5;	// Cache for five minutes 
            if (xmlCachingTime > 0)		// Leave this test in case we add a condition to disable XML caching
            {
                // We need to cache the output before sending it to OutputContext.Writer so write to a StringWriter 
                StringWriter sw = new StringWriter();
                Transformer.Transform(xnav, null, sw);

                //  Write to OutputContext.Writer
                string output = sw.ToString();
//#if DEBUG
//                output = "Caching HTML output on " + DateTime.Now.ToString() + " for " + htmlCachingTime.ToString() + " seconds" + output;
//#endif
				OutputContext.SetContentType("text/xml");
				OutputContext.Writer.Write(output);

                // Now cache the output
                string key = CreateTransformerRequestCacheKey();
                OutputContext.CacheObject(key, output, xmlCachingTime);


                OutputContext.Diagnostics.WriteTimedEventToLog("XMLTransformCached", "Applied and cached output");
            }
            else
            {
				// No output caching, so write directly to OutputContext.Writer
			OutputContext.SetContentType("text/xml");	
			Transformer.Transform(xnav, null, OutputContext.Writer);

				OutputContext.Diagnostics.WriteTimedEventToLog("XMLTransform", "Applied");
			}

			// Make a note on how long it took
			return true;
		}
Example #4
0
        /// <summary>
        /// Add a component to the Page.
        /// </summary>
        /// <param name="component">The component to add to the page.</param>
		public void AddComponent(IDnaComponent component)
		{
            _page.AddComponent(component);
		}
Example #5
0
 /// <summary>
 /// Adds a component to base page
 /// </summary>
 /// <param name="component">The component that you want to add to the base page</param>
 protected void AddComponent(IDnaComponent component)
 {
     _basePage.AddComponent(component);
 }
Example #6
0
        /// <summary>
        /// Add a component to the whole page.
        /// </summary>
        /// <param name="component"></param>
		public void AddComponent(IDnaComponent component)
		{
			_componentList.Add(component);
		}
Example #7
0
        /// <summary>
        /// Inserts a given DnaComponents XML into the current page
        /// </summary>
        /// <param name="component">The component you want to insert</param>
        /// <param name="nodeName">The name of the node you want to insert the component into. Leave empty to insert on the root node</param>
        /// <returns>True if ok, false if not</returns>
        public bool AddInside(IDnaComponent component, string nodeName)
        {
            XmlElement insertNode = RootElement;
            // Make sure that the component actually has a XML doc
            XmlElement componentRoot = component.RootElement;
            if (componentRoot == null)
            {
                return false;
            }

            // Now get the root node for this component

            // If given a name of a node to insert into, find it
            if (nodeName.Length > 0)
            {
                // Get the requested node
                insertNode = insertNode.SelectSingleNode("//" + nodeName.ToUpper()) as XmlElement;
            }

            // If we have a node to add to, append the component
            if (insertNode != null)
            {
                foreach (XmlNode child in componentRoot.ChildNodes)
                {
                    insertNode.AppendChild(_XMLDoc.ImportNode(child, true));
                }
                return true;
            }
            return false;
        }
Example #8
0
 /// <summary>
 /// Inserts a given DnaComponents XML into the current page at the Root
 /// </summary>
 /// <param name="component">The component you want to insert</param>
 /// <returns>True if ok, false if not</returns>
 public bool AddInside(IDnaComponent component)
 {
     return AddInside(component, "");
 }
Example #9
0
 /// <summary>
 /// Adds the XmlNode from the given component to the specified parent
 /// </summary>
 /// <param name="parent">Parent node to which to add the imported node</param>
 /// <param name="component">DnaComponent whose node should be appended</param>
 /// <param name="xpathNode">The xpath of the node that you want to append to the parent node</param>
 /// <returns>The imported node</returns>
 public XmlNode AddInside(XmlNode parent, IDnaComponent component, string xpathNode)
 {
     return parent.AppendChild(_XMLDoc.ImportNode(component.RootElement.SelectSingleNode(xpathNode), true));
 }
Example #10
0
		/// <summary>
		/// Adds the XML contents of a DnaComponent to the current component at the specified node
		/// </summary>
		/// <param name="parent">Parent node to which to add the imported nodes</param>
		/// <param name="component">DnaComponent whose XML should be appended</param>
		/// <returns>The imported node</returns>
		public XmlNode AddInside(XmlNode parent, IDnaComponent component)
		{
			XmlNode lastInserted = null;
			foreach (XmlNode child in component.RootElement.ChildNodes)
			{
				lastInserted = parent.AppendChild(_XMLDoc.ImportNode(child, true));
			}

			return lastInserted;
		}
Example #11
0
        /// <summary>
        /// The abstract Transform method
        /// </summary>
        /// <param name="component">The IDNACompnent you are transforming</param>
        /// <returns>true if ok, false if not</returns>
		public abstract bool TransformXML(IDnaComponent component);