using System; using System.Web; using umbraco.presentation.LiveEditing; using umbraco.BasePages; using umbraco.cms.businesslogic.web; using System.Xml.Linq; using umbraco.IO; using umbraco.presentation.preview; using umbraco.BusinessLogic; using System.Xml; namespace umbraco.presentation { public class UmbracoServerUtility : HttpServerUtilityWrapper { private HttpServerUtility m_Server; public UmbracoServerUtility(HttpServerUtility server) : base(server) { m_Server = server; } /// /// Returns the physical file path that corresponds to the specified virtual path on the Web server. /// /// The virtual path of the Web server. /// /// The physical file path that corresponds to . /// /// /// The current is null. /// public override string MapPath(string path) { return IOHelper.MapPath(path); } public string UmbracoPath { get { return IOHelper.ResolveUrl( SystemDirectories.Umbraco ); } } public string ContentXmlPath { get { return IOHelper.ResolveUrl( SystemFiles.ContentCacheXml ); } } private readonly string XDocumentCacheKey = "XDocumentCache"; /// /// Gets the Umbraco XML cache /// /// The content XML. public XDocument ContentXml { get { if (UmbracoContext.Current.InPreviewMode) { PreviewContent pc = new PreviewContent(new Guid(StateHelper.Cookies.Preview.GetValue())); pc.LoadPreviewset(); return XmlDocumentToXDocument(pc.XmlContent); } else { if (HttpContext.Current == null) return XDocument.Load(ContentXmlPath); XDocument xml = HttpContext.Current.Items[XDocumentCacheKey] as XDocument; if (xml == null) { xml = XmlDocumentToXDocument(content.Instance.XmlContent); HttpContext.Current.Items[XDocumentCacheKey] = xml; } return xml; } } } private XDocument XmlDocumentToXDocument(XmlDocument xml) { using (var nodeReader = new XmlNodeReader(xml)) { nodeReader.MoveToContent(); return XDocument.Load(nodeReader); } } public string DataFolder { get { return IOHelper.ResolveUrl( SystemDirectories.Data ); } } } }