private static IPublishedContent FindContentByAlias(ContextualPublishedContentCache cache, int rootNodeId, string alias) { if (alias == null) throw new ArgumentNullException("alias"); // the alias may be "foo/bar" or "/foo/bar" // there may be spaces as in "/foo/bar, /foo/nil" // these should probably be taken care of earlier on alias = alias.TrimStart('/'); var xpathBuilder = new StringBuilder(); xpathBuilder.Append(XPathStringsDefinition.Root); if (rootNodeId > 0) xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentById, rootNodeId); XPathVariable var = null; if (alias.Contains('\'') || alias.Contains('"')) { // use a var, as escaping gets ugly pretty quickly var = new XPathVariable("alias", alias); alias = "$alias"; } xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentByAlias, alias); var xpath = xpathBuilder.ToString(); // note: it's OK if var is null, will be ignored return cache.GetSingleByXPath(xpath, var); }
public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars) { throw new NotImplementedException("PublishedMediaCache does not support XPath."); }
public virtual IEnumerable<IPublishedContent> GetByXPath(UmbracoContext umbracoContext, bool preview, XPathExpression xpath, XPathVariable[] vars) { throw new NotImplementedException("PublishedMediaCache does not support XPath."); }
public IPublishedContent GetDocumentByUrlAlias(UmbracoContext umbracoContext, int rootNodeId, string alias) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); if (alias == null) throw new ArgumentNullException("alias"); // the alias may be "foo/bar" or "/foo/bar" // there may be spaces as in "/foo/bar, /foo/nil" // these should probably be taken care of earlier on alias = alias.TrimStart('/'); var xpathBuilder = new StringBuilder(); xpathBuilder.Append(XPathStrings.Root); if (rootNodeId > 0) xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentById, rootNodeId); XPathVariable var = null; if (alias.Contains('\'') || alias.Contains('"')) { // use a var, escaping gets ugly pretty quickly var = new XPathVariable("alias", alias); alias = "$alias"; } xpathBuilder.AppendFormat(XPathStrings.DescendantDocumentByAlias, alias); var xpath = xpathBuilder.ToString(); return ConvertToDocument(GetXml(umbracoContext).SelectSingleNode(xpath, var)); }
private dynamic DocumentsByXPath(XPathExpression xpath, XPathVariable[] vars, ContextualPublishedCache cache) { return new DynamicPublishedContentList( cache.GetByXPath(xpath, vars) .Select(publishedContent => new DynamicPublishedContent(publishedContent)) ); }
private dynamic DocumentByXPath(XPathExpression xpath, XPathVariable[] vars, ContextualPublishedCache cache, object ifNotFound) { var doc = cache.GetSingleByXPath(xpath, vars); return doc == null ? ifNotFound : new DynamicPublishedContent(doc).AsDynamic(); }
private IEnumerable<IPublishedContent> TypedDocumentsByXPath(XPathExpression xpath, XPathVariable[] vars, ContextualPublishedContentCache cache) { var doc = cache.GetByXPath(xpath, vars); return doc; }
private IPublishedContent TypedDocumentByXPath(string xpath, XPathVariable[] vars, ContextualPublishedContentCache cache) { var doc = cache.GetSingleByXPath(xpath, vars); return doc; }