Пример #1
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // we only want query type data sources, e.g. queries, fast queries, or relative sources
            if (!(args.DataSource.StartsWith("query:") || args.DataSource.StartsWith("fast:") || args.DataSource.StartsWith(".")))
            {
                return;
            }

            string query        = args.DataSource;
            bool   useFastQuery = false;

            // strip the starting query: if one exists, we wont send that on to Sitecore
            if (query.StartsWith("query:"))
            {
                query = query.Substring(6);
            }

            // strip fast: if present, but keep a note if it was a fast query for later
            if (query.StartsWith("fast:"))
            {
                query        = query.Substring(5);
                useFastQuery = true;
            }

            Item rootItem = args.ContextItem;

            // move up any parent items until we get to the meat of the query
            while (query.StartsWith("../"))
            {
                rootItem = rootItem.Parent;
                query    = query.Substring(3);
            }

            // strip any explicit relative paths; we'll "relative-ize" the query with the root item's full path anyway
            if (query.StartsWith("./"))
            {
                query = query.Substring(2);
            }

            // if the path is not an absolute one, we'll prepend the full path of the root item to turn it into an effectively relative query
            if (!query.StartsWith("/"))
            {
                query = rootItem.Paths.FullPath + "/" + query;
            }

            // if the original query contained the fast moniker we'll re-add it here to the parsed query
            if (useFastQuery)
            {
                query = "fast:" + query;
            }

            args.DataSourceItems.AddRange(rootItem.Database.SelectItems(query));

            args.HasItems = true;
        }
Пример #2
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // had a valid data source, so skip processing an empty context data source
            if (!string.IsNullOrEmpty(args.DataSource)) return;

            args.DataSourceItems.Add(Sitecore.Context.Item);

            args.HasItems = true;
        }
Пример #3
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            // had a valid data source, so skip processing an empty context data source
            if (!string.IsNullOrEmpty(args.DataSource))
            {
                return;
            }

            args.DataSourceItems.Add(Sitecore.Context.Item);

            args.HasItems = true;
        }
Пример #4
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // ignore data sources that are not absolute paths or IDs
            if (!(args.DataSource.StartsWith("/") || args.DataSource.StartsWith("{")))
            {
                return;
            }

            // the split on | supports multilist style ID lists (but also path lists technically...)
            foreach (string identifier in args.DataSource.Split('|'))
            {
                string[] parts = identifier.Split(':');

                // verify bounds (for an item multilist identifier e.g. "/sitecore/content/foo:fieldName")
                // note: relative paths are not supported with multilist identifiers' source item
                Assert.IsTrue(parts.Length > 0, "parts > 0");
                Assert.IsTrue(parts.Length < 3, "parts < 3");

                Item item = args.ContextItem.Database.GetItem(parts[0]);

                // couldn't resolve data source item, skip entry
                if (item == null)
                {
                    Log.Warn(string.Format("HandleStaticItems: A rendering on {0} contains an invalid item reference: {1}", args.ContextItem.Paths.FullPath, parts[0]), this);
                    continue;
                }

                // parse a item multilist field reference
                if (parts.Length > 1)
                {
                    MultilistField field = item.Fields[parts[1]];

                    // invalid field reference
                    if (field == null || string.IsNullOrEmpty(field.Value))
                    {
                        Log.Warn(string.Format("HandleStaticItems: The multilist field {0} on {1} referred to in a rendering data source on {2} did not exist.", item.Paths.FullPath, parts[1], args.ContextItem.Paths.FullPath), this);
                        continue;
                    }

                    args.DataSourceItems.AddRange(field.GetItems());

                    return;
                }

                // add a single identifier from the data source string
                args.DataSourceItems.Add(item);
            }

            args.HasItems = true;
        }
Пример #5
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // ignore data sources that are not absolute paths or IDs
            if (!(args.DataSource.StartsWith("/") || args.DataSource.StartsWith("{"))) return;

            // the split on | supports multilist style ID lists (but also path lists technically...)
            foreach (string identifier in args.DataSource.Split('|'))
            {
                string[] parts = identifier.Split(':');

                // verify bounds (for an item multilist identifier e.g. "/sitecore/content/foo:fieldName")
                // note: relative paths are not supported with multilist identifiers' source item
                Assert.IsTrue(parts.Length > 0, "parts > 0");
                Assert.IsTrue(parts.Length < 3, "parts < 3");

                Item item = args.ContextItem.Database.GetItem(parts[0]);

                // couldn't resolve data source item, skip entry
                if (item == null)
                {
                    Log.Warn(string.Format("HandleStaticItems: A rendering on {0} contains an invalid item reference: {1}", args.ContextItem.Paths.FullPath, parts[0]), this);
                    continue;
                }

                // parse a item multilist field reference
                if (parts.Length > 1)
                {
                    MultilistField field = item.Fields[parts[1]];

                    // invalid field reference
                    if (field == null || string.IsNullOrEmpty(field.Value))
                    {
                        Log.Warn(string.Format("HandleStaticItems: The multilist field {0} on {1} referred to in a rendering data source on {2} did not exist.", item.Paths.FullPath, parts[1], args.ContextItem.Paths.FullPath), this);
                        continue;
                    }

                    args.DataSourceItems.AddRange(field.GetItems());

                    return;
                }

                // add a single identifier from the data source string
                args.DataSourceItems.Add(item);
            }

            args.HasItems = true;
        }
Пример #6
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // we only want query type data sources, e.g. queries, fast queries, or relative sources
            if (!(args.DataSource.StartsWith("query:") || args.DataSource.StartsWith("fast:") || args.DataSource.StartsWith(".")))
            {
                return;
            }

            string query = args.DataSource;
            bool useFastQuery = false;

            // strip the starting query: if one exists, we wont send that on to Sitecore
            if (query.StartsWith("query:"))
                query = query.Substring(6);

            // strip fast: if present, but keep a note if it was a fast query for later
            if (query.StartsWith("fast:"))
            {
                query = query.Substring(5);
                useFastQuery = true;
            }

            Item rootItem = args.ContextItem;

            // move up any parent items until we get to the meat of the query
            while (query.StartsWith("../"))
            {
                rootItem = rootItem.Parent;
                query = query.Substring(3);
            }

            // strip any explicit relative paths; we'll "relative-ize" the query with the root item's full path anyway
            if (query.StartsWith("./"))
                query = query.Substring(2);

            // if the path is not an absolute one, we'll prepend the full path of the root item to turn it into an effectively relative query
            if (!query.StartsWith("/"))
                query = rootItem.Paths.FullPath + "/" + query;

            // if the original query contained the fast moniker we'll re-add it here to the parsed query
            if (useFastQuery) query = "fast:" + query;

            args.DataSourceItems.AddRange(rootItem.Database.SelectItems(query));

            args.HasItems = true;
        }
Пример #7
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // if a search context came in, we don't dispose it when done - otherwise we dispose our temp context
            bool disposeSearchContext = args.SearchContext == null;

            IProviderSearchContext searchContext = null;
            try
            {
                searchContext = args.SearchContext ?? ContentSearchManager.CreateSearchContext(new SitecoreIndexableItem(args.ContextItem));

                var query = CreateQuery(searchContext, args.DataSource);

                args.DataSourceItems.AddRange(ProcessQueryResults(query));
            }
            finally
            {
                if(disposeSearchContext && searchContext != null) searchContext.Dispose();
            }
        }
Пример #8
0
        public override void DoProcess(ResolveRenderingDataSourceArgs args)
        {
            // if a search context came in, we don't dispose it when done - otherwise we dispose our temp context
            bool disposeSearchContext = args.SearchContext == null;

            IProviderSearchContext searchContext = null;

            try
            {
                searchContext = args.SearchContext ?? ContentSearchManager.CreateSearchContext(new SitecoreIndexableItem(args.ContextItem));

                var query = CreateQuery(searchContext, args.DataSource);

                args.DataSourceItems.AddRange(ProcessQueryResults(query));
            }
            finally
            {
                if (disposeSearchContext && searchContext != null)
                {
                    searchContext.Dispose();
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Invoke the ResolveRenderingDataSource pipeline to resolve the data source item
        /// </summary>
        private static Item[] RunPipeline(string dataSource, Item contextItem, IProviderSearchContext searchContext)
        {
            var args = new ResolveRenderingDataSourceArgs(dataSource, contextItem, searchContext);

            CorePipeline.Run("resolveRenderingDataSource", args);

            return args.DataSourceItems.ToArray();
        }