Beispiel #1
0
        public IItem[] GetChildren()
        {
            if (_sitecoreApi == null)
            {
                throw new Exception("sitecoreApi not set please call constructor with API object");
            }

            XmlNode itemNode = _sitecoreApi.GetItemTree("{" + _ID.ToString().ToUpper() + "}", 2);

            XmlNodeList           nodeList = itemNode.SelectNodes("./item");
            List <Sitecore43Item> children = new List <Sitecore43Item>();

            foreach (XmlNode node in nodeList)
            {
                // Get full-blown item
//                XmlNode item = _sitecoreApi.GetItem(node.Attributes["id"].Value);
                XmlNode      itemXml = _sitecoreApi.GetItemXml(node.Attributes["id"].Value, "", this.Options.Language);
                XmlAttribute attr    = itemXml.OwnerDocument.CreateAttribute("haschildren");

                // there is children
                if ((node.SelectNodes("./item") != null) && (node.SelectNodes("./item").Count > 0))
                {
                    attr.Value = "1";
                }
                else
                {
                    attr.Value = "0";
                }
                itemXml.Attributes.Append(attr);

                children.Add(new Sitecore43Item(itemXml, this, _sitecoreApi));
            }
            return(children.ToArray());
        }
Beispiel #2
0
        private Sitecore43Item(XmlNode itemNode, IItem parent, Sitecore43.SitecoreClientAPI sitecoreApi)
        {
            _Parent      = parent;
            _sitecoreApi = sitecoreApi;

            _ID            = new Guid(itemNode.Attributes["id"].Value);
            _sName         = itemNode.Attributes["name"].Value;
            _sKey          = itemNode.Attributes["key"].Value;
            _sTemplateName = itemNode.Attributes["template"].Value;

            // Fetch latest field content
            XmlNode newestContentNode = _sitecoreApi.GetItem(Util.GuidToSitecoreID(_ID));

            _sPath = newestContentNode.Attributes["path"].Value;
            _sIcon = newestContentNode.Attributes["icon"].Value;

            // Only the standard template has an empty TemplateID
            // The item is an template if it's id is the same as the template id
            if ((newestContentNode.Attributes["templateid"].Value == "") ||
                (newestContentNode.Attributes["templateid"].Value == Util.GuidToSitecoreID(_ID)))
            {
                _TemplateID = Guid.Empty;
            }
            else
            {
                _TemplateID = new Guid(newestContentNode.Attributes["templateid"].Value);
            }

            // Get TemplateID from itemNode instead
//            if ((_TemplateID == Guid.Empty) && (itemNode.Attributes["tid"] != null) && (itemNode.Attributes["tid"].Value != ""))
//                _TemplateID = new Guid(itemNode.Attributes["tid"].Value);



            int         iRejected = 0;
            XmlNodeList list      = itemNode.SelectNodes("field");

            foreach (XmlNode node in list)
            {
                Sitecore43Field field = new Sitecore43Field(node, _sTemplateName, _sitecoreApi);

/*
 *              // Fetch latest field content
 *              string sContent = newestContentNode.SelectSingleNode("field[@key = '" + field.Key + "']").InnerText;
 *              if (sContent != "")
 *                  field.Content = sContent;
 */
                // Only add valid fields
                if (IsValidField(field))
                {
                    _fields.Add(field);
                }
                else
                {
                    iRejected++;
                }
            }
            _sXmlNode = itemNode.OuterXml;

            // Additional info
            _sSortOrder = itemNode.Attributes["sortorder"].Value;

            if ((itemNode.Attributes["haschildren"] != null) && (itemNode.Attributes["haschildren"].Value == "1"))
            {
                _bHasChildren = true;
            }


            // This is a template item
            if (_sPath.ToLower().IndexOf("/sitecore/templates/") > -1)
            {
                XmlNode childrenNode = _sitecoreApi.GetItemTree("{" + _ID.ToString().ToUpper() + "}", 2);
                foreach (XmlNode node in childrenNode.SelectNodes("./item"))
                {
                    // Get full-blown item
                    XmlNode templateFieldNode = _sitecoreApi.GetItemXml(node.Attributes["id"].Value, "", this.Options.Language);

                    Sitecore43Field field = new Sitecore43Field(templateFieldNode, _sTemplateName, _sitecoreApi);

                    var existingfields = from f in _fields
                                         where f.TemplateFieldID == field.TemplateFieldID
                                         select f;
                    if ((existingfields.Count() == 0) && (IsValidField(field)))
                    {
                        _fields.Add(field);
                    }
                }
            }
        }