public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context) { if (this.CanProcessItem(itemDefinition.ID, context)) { context.Abort(); if (context.DataManager.DataSource.ItemExists(itemDefinition.ID)) { ReflectionUtil.CallMethod( typeof(ItemCache), CacheManager.GetItemCache(context.DataManager.Database), "RemoveItem", true, true, new object[] { itemDefinition.ID }); } var sitecoreId = itemDefinition.ID; var key = this.GetIdTableExternalKey(sitecoreId, this.IdTablePrefix); var itemName = this.DataProviderDamHelper.GetItemName(key); if (itemName == "Undefined") { return(base.GetItemFields(itemDefinition, versionUri, context)); } var result = new CoreItem.Builder(itemDefinition.ID, ItemUtil.ProposeValidItemName(Path.GetFileNameWithoutExtension(itemName)), itemDefinition.TemplateID, context.DataManager); result.AddField("__Created", DateTime.Now.ToString(SitecoreDateFormat)); result.AddField("__Updated", DateTime.Now.ToString(SitecoreDateFormat)); result.AddField("__Owner", this.SettingsHelper.GetSetting("Kumquat.IconFormat", "sitecore\\admin")); var fields = this.DataProviderDamHelper.GetItemFields(key); this.DataProviderHelper.MapFields(result, fields, this.DataProviderDamHelper.ProcessingParentFieldNames); var values = result.ItemData.Fields[new ID("{E992FBF9-2F76-4BBA-A613-D17087AA609C}")]; values += result.ItemData.Fields[new ID("{3D70C570-614F-455A-8DEF-E4424033BCC5}")]; var revision = GetHashString(values); result.AddField("__Revision", revision); if (key.StartsWith(this.DataProviderDamHelper.FolderIdPrefix)) { result.AddField("__Sortorder", "1"); return(result.ItemData.Fields); } if (this.DataProviderDamHelper.EnabledMethods.Contains(DataProviderMethods.BlobStreamExists)) { result.AddField("Blob", itemDefinition.ID.ToString()); var iconFormat = this.SettingsHelper.GetSetting("Kumquat.IconFormat", "-/media/{0}.ashx?h=16&thn=1&w=16"); var iconUrl = String.Format(iconFormat, itemDefinition.ID.ToShortID()); result.AddField("__Icon", iconUrl); var extension = ""; if (!String.IsNullOrEmpty(itemName)) { extension = itemName.Split('.').Last(); } var resolver = new MimeResolver(); var mimeType = resolver.GetMimeType(extension); result.AddField("Extension", extension); result.AddField("Mime Type", mimeType); } //result.AddField("Size", fields["size"]); result.AddField("Linked Asset", "1"); result.AddField("__Sortorder", "2"); return(result.ItemData.Fields); } return(base.GetItemFields(itemDefinition, versionUri, context)); }
public void MapFields(CoreItem.Builder result, IDictionary <string, string> fields, IEnumerable <string> idFields) { var database = Factory.GetDatabase("master"); var settings = database.GetItem(new ID("{D6D93348-9CFD-42A3-9E78-9F602CDCBEB6}")); var container = Bootstrapper.Container; var publicFieldValue = settings.Fields["Public Fields"]; var publicFieldNames = publicFieldValue.Value.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); var urlParamsToParse = settings["Mapped Fields"]; var fieldMappings = Sitecore.Web.WebUtil.ParseUrlParameters(urlParamsToParse); var fieldConvertorsParamsToParse = settings["Field Converters"]; var fieldConvertors = Sitecore.Web.WebUtil.ParseUrlParameters(fieldConvertorsParamsToParse); var privateBuilder = new StringBuilder(); var publicBuilder = new StringBuilder(); var privateFields = new NameValueCollection(); var publicFields = new NameValueCollection(); var converterFactory = container.GetInstance <IConverterFactory>(); //TODO: Replace idFields with content configured field mapping. foreach (var field in fields) { var value = field.Value; Regex rgx = new Regex("[^a-zA-Z0-9-]"); var key = rgx.Replace(field.Key, ""); var converterValue = fieldConvertors[key]; if (converterValue != null) { var converter = converterFactory.CreateNew(converterValue); if (converter != null) { value = converter.Convert(value); } } if (idFields.Contains(field.Key)) { result.AddField(field.Key, value); } var mappedValue = fieldMappings[key]; if (mappedValue != null) { result.AddField(mappedValue, value); } if (publicFieldNames.Contains(key)) { publicFields.Add(key, value); } else { privateFields.Add(key, value); } } foreach (var key in publicFields.AllKeys) { var value = publicFields[key]; if (!String.IsNullOrEmpty(value)) { publicBuilder.Append( String.Concat(Uri.EscapeDataString(key).Replace("'", "%27"), "=", Uri.EscapeDataString(value).Replace("'", "%27"), "&")); } else { publicBuilder.Append( String.Concat(Uri.EscapeDataString(key).Replace("'", "%27"), "&")); } } foreach (var key in privateFields.AllKeys) { var value = privateFields[key]; if (!String.IsNullOrEmpty(value)) { privateBuilder.Append( String.Concat(Uri.EscapeDataString(key).Replace("'", "%27"), "=", Uri.EscapeDataString(value).Replace("'", "%27"), "&")); } else { privateBuilder.Append( String.Concat(Uri.EscapeDataString(key).Replace("'", "%27"), "&")); } } var privateUpper = ""; var publicUpper = ""; if (privateBuilder.Length > 0) { privateUpper = privateBuilder.ToString(0, privateBuilder.Length - 1); } if (publicBuilder.Length > 0) { publicUpper = publicBuilder.ToString(0, publicBuilder.Length - 1); } Regex reg = new Regex(@"%[a-f0-9]{2}"); privateUpper = reg.Replace(privateUpper, m => m.Value.ToUpperInvariant()).TrimEnd('='); publicUpper = reg.Replace(publicUpper, m => m.Value.ToUpperInvariant()).TrimEnd('='); if (privateUpper.Length > 0) { result.AddField("Private Metadata", privateUpper); } if (publicUpper.Length > 0) { result.AddField("Public Metadata", publicUpper); } }