public Sitecore43Field(XmlNode fieldNode, string sTemplateName, Sitecore43.SitecoreClientAPI sitecoreApi) { _sitecoreApi = sitecoreApi; _sName = fieldNode.Attributes["name"].Value; _sKey = fieldNode.Attributes["key"].Value; _sSortOrder = fieldNode.Attributes["sortorder"].Value; // This is a template field // if ((fieldNode.Attributes["master"] != null) && // (fieldNode.Attributes["master"].Value == "__Template field")) if (fieldNode.Attributes["title"] == null) { if ((fieldNode.Attributes["master"] != null) && (fieldNode.Attributes["master"].Value == "__Template")) throw new Exception("Template fields cannot be handled here"); _sLanguageTitle = Util.GetNodeFieldValue(fieldNode, "//field[@key='title']/content"); _sSection = Util.GetNodeFieldValue(fieldNode, "//field[@key='section']/content"); _sSource = Util.GetNodeFieldValue(fieldNode, "//field[@key='source']/content"); _sType = Util.GetNodeFieldValue(fieldNode, "//field[@key='type']/content"); _TemplateFieldID = new Guid(fieldNode.Attributes["id"].Value); // _sNoLanguage = Util.GetNodeFieldValue(fieldNode, "//field[@key='nolang']/content"); // Actual values reside in masters _sContent = ""; } else if ((fieldNode.Attributes["master"] != null) && (fieldNode.Attributes["master"].Value == "__Template")) { throw new Exception("Template fields cannot be handled here"); } // Normal field else { _sLanguageTitle = fieldNode.Attributes["title"].Value; _sSection = fieldNode.Attributes["section"].Value; _sSource = fieldNode.Attributes["source"].Value; _sType = fieldNode.Attributes["type"].Value; if (fieldNode.Attributes["tfid"].Value != "") _TemplateFieldID = new Guid(fieldNode.Attributes["tfid"].Value); if (fieldNode.InnerText != "") _sContent = fieldNode.InnerText; else if ((fieldNode.SelectSingleNode("content") != null) && (fieldNode.SelectSingleNode("content").InnerXml != "")) _sContent = fieldNode.SelectSingleNode("content").InnerXml; } _sTemplateName = sTemplateName; // Remap id's if neeeded RemapTemplateIDs(); }
public void SetAPIConnection(Sitecore43.SitecoreClientAPI sitecoreApi) { _sitecoreApi = sitecoreApi; }
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); } } } }