/// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config,
                                        SitecoreDataMappingContext context)
        {
            if (field == null || field.Value.Trim().IsNullOrEmpty())
            {
                return(null);
            }

            Guid fieldGuid = field.ID.Guid;

            // shortest route - we know whether or not its rich text
            var isInternalLink =
                _isInternalLinkFieldDictionary.GetOrAdd(fieldGuid, (id) => field.TypeKey == InternalLinkKey);


            Link link = new Link();

            if (isInternalLink)
            {
                InternalLinkField internalLinkField = new Sitecore.Data.Fields.InternalLinkField(field);
                MapToLinkModel(link, internalLinkField, config);
            }
            else
            {
                LinkField linkField = new LinkField(field);

                MapToLinkModel(link, linkField, config);
            }


            return(link);
        }
        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null)
            {
                return(string.Empty);
            }

            if (config.Setting == SitecoreFieldSettings.RichTextRaw)
            {
                return(field.Value);
            }

            if (config.Setting == SitecoreFieldSettings.ForceRenderField)
            {
                return(RunPipeline(field, context.Options as GetOptionsSc));
            }

            Guid fieldGuid = field.ID.Guid;

            // shortest route - we know whether or not its rich text
            if (isRichTextDictionary.ContainsKey(fieldGuid))
            {
                return(GetResult(field, isRichTextDictionary[fieldGuid], context.Options as GetOptionsSc));
            }

            // we don't know - it might still be rich text
            bool isRichText = field.TypeKey == RichTextKey;

            isRichTextDictionary.TryAdd(fieldGuid, isRichText);

            // now we know it isn't rich text - return the raw result.
            return(GetResult(field, isRichText, context.Options as GetOptionsSc));
        }
Пример #3
0
 protected LuceneField.TermVector GetVectorType(SCField field)
 {
     if (FieldTypes.ContainsKey(field.TypeKey))
     {
         var searchField = FieldTypes[field.TypeKey];
         return(searchField.VectorType);
     }
     return(LuceneField.TermVector.NO);
 }
Пример #4
0
 protected LuceneField.Store GetStorageType(SCField field)
 {
     if (FieldTypes.ContainsKey(field.TypeKey))
     {
         var searchField = FieldTypes[field.TypeKey];
         return(searchField.StorageType);
     }
     return(LuceneField.Store.NO);
 }
Пример #5
0
        public void SetFallbackSupport(Sitecore.Data.Fields.Field field, bool isSupported)
        {
            Dictionary <string, bool> cache = GetInternalCache();

            if (cache != null)
            {
                string cckey = GetFieldCacheKey(field);
                cache[cckey] = isSupported;
            }
        }
Пример #6
0
        //protected bool ShouldBeSplit(SCField field)
        //{
        //   return FieldTypeManager.GetField(field) is MultilistField;
        //}

        protected LuceneField.Index GetIndexType(SCField field)
        {
            if (FieldTypes.ContainsKey(field.TypeKey))
            {
                object searchField = FieldTypes[field.TypeKey];
                if (searchField is SearchField)
                {
                    return((searchField as SearchField).IndexType);
                }
            }
            return(LuceneField.Index.UN_TOKENIZED);
        }
Пример #7
0
        /// <summary>
        /// Converts a Sitecore Field into a Synthesis field equivalent
        /// </summary>
        public static FieldType AsStronglyTyped(this Sitecore.Data.Fields.Field field)
        {
            if (field == null)
            {
                return(null);
            }

            var mapping = ProviderResolver.Current.FieldMappingProvider.GetFieldType(field.Type);

            var lazy = new Lazy <Field>(() => field);

            return(Activator.CreateInstance(mapping, lazy, null) as FieldType);
        }
        /// <summary>
        /// Sets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="value">The value.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="System.NotSupportedException">It is not possible to save data from a rich text field when the data isn't raw.
        ///                     + Set the SitecoreFieldAttribute setting property to SitecoreFieldSettings.RichTextRaw for property {0} on type {1}.Formatted(config.PropertyInfo.Name, config.PropertyInfo.ReflectedType.FullName)</exception>
        public override void SetField(Sitecore.Data.Fields.Field field, object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null)
            {
                return;
            }

            if (field.Type.StartsWith("Rich Text") && config.Setting != SitecoreFieldSettings.RichTextRaw)
            {
                throw new NotSupportedException("It is not possible to save data from a rich text field when the data isn't raw."
                                                + "Set the SitecoreFieldAttribute setting property to SitecoreFieldSettings.RichTextRaw for property {0} on type {1}".Formatted(config.PropertyInfo.Name, config.PropertyInfo.ReflectedType.FullName));
            }

            field.Value = value != null?value.ToString() : null;
        }
Пример #9
0
        public bool?GetFallbackSupport(Sitecore.Data.Fields.Field field)
        {
            bool?isSupported = null;
            Dictionary <string, bool> cache = GetInternalCache();

            if (cache != null)
            {
                string cckey = GetFieldCacheKey(field);
                if (cache.ContainsKey(cckey))
                {
                    isSupported = cache[cckey];
                }
            }

            return(isSupported);
        }
 private bool ShouldIndexField(Sitecore.Data.Fields.Field field)
 {
     return(!field.Name.StartsWith("__") && this.IsTextField(field) && !string.IsNullOrEmpty(field.Value));
 }
 public DateFieldCrawler(Field field)
     : base(field)
 {
 }
        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null || field.Value.Trim().IsNullOrEmpty())
            {
                return(null);
            }



            Link      link      = new Link();
            LinkField linkField = new LinkField(field);

            switch (linkField.LinkType)
            {
            case "anchor":
                link.Url  = linkField.Anchor;
                link.Type = LinkType.Anchor;
                break;

            case "external":
                link.Url  = linkField.Url;
                link.Type = LinkType.External;
                break;

            case "mailto":
                link.Url  = linkField.Url;
                link.Type = LinkType.MailTo;
                break;

            case "javascript":
                link.Url  = linkField.Url;
                link.Type = LinkType.JavaScript;
                break;

            case "media":
                if (linkField.TargetItem == null)
                {
                    link.Url = string.Empty;
                }
                else
                {
                    global::Sitecore.Data.Items.MediaItem media =
                        new global::Sitecore.Data.Items.MediaItem(linkField.TargetItem);
                    link.Url = global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media);
                }
                link.Type     = LinkType.Media;
                link.TargetId = linkField.TargetID.Guid;
                break;

            case "internal":
                if (linkField.TargetItem == null)
                {
                    link.Url = string.Empty;
                }
                else
                {
                    link.Url = LinkManager.GetItemUrl(linkField.TargetItem);
                }
                link.Type     = LinkType.Internal;
                link.TargetId = linkField.TargetID.Guid;

                break;

            default:
                return(null);

                break;
            }


            link.Anchor = linkField.Anchor;
            link.Class  = linkField.Class;
            link.Text   = linkField.Text;
            link.Title  = linkField.Title;
            link.Target = linkField.Target;
            link.Query  = linkField.QueryString;

            return(link);
        }
Пример #13
0
 protected LuceneField.TermVector GetVectorType(SCField field)
 {
     if (FieldTypes.ContainsKey(field.TypeKey))
      {
     var searchField = FieldTypes[field.TypeKey];
     return searchField.VectorType;
      }
      return LuceneField.TermVector.NO;
 }
Пример #14
0
 protected virtual void AddDefaultFieldByType(Document document, Field field, string fieldType)
 {
     FieldConfiguration fieldConfiguration;
     // default handling
     switch (fieldType)
     {
         case "multilist":
             fieldConfiguration = GetFieldConfiguration(field);
             AddMultilistField(document, field, fieldConfiguration);
             break;
         case "link":
             fieldConfiguration = GetFieldConfiguration(field, false);
             AddLinkField(document, field, fieldConfiguration);
             break;
         case "datetime":
             fieldConfiguration = GetFieldConfiguration(field, false);
             AddDateTimeField(document, field, fieldConfiguration);
             break;
         default:
             fieldConfiguration = GetFieldConfiguration(field);
             AddValueField(document, field, fieldConfiguration);
             break;
     }
 }
Пример #15
0
 public DateFieldCrawler(Field field) : base(field)
 {
 }
Пример #16
0
 protected virtual FieldConfiguration GetFieldConfiguration(Field field, bool analyze = true, bool store = false)
 {
     // todo: Allow this to read from the item
     FieldConfiguration fieldConfiguration = new FieldConfiguration { FieldId = field.ID, Analyze = analyze, Store = store };
     if (FieldConfigurations.ContainsKey(field.ID))
     {
         fieldConfiguration = FieldConfigurations[field.ID];
     }
     return fieldConfiguration;
 }
Пример #17
0
        protected virtual void AddValueField(Document document, Field field, FieldConfiguration fieldConfiguration, bool stripHtml = false)
        {
            if (field == null || fieldConfiguration == null)
            {
                return;
            }

            ID valueId;
            string fieldValue = field.Value;

            if (stripHtml && !String.IsNullOrEmpty(fieldValue))
            {
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(fieldValue);
                fieldValue = htmlDoc.DocumentNode.InnerText;
            }

            if (ID.TryParse(field.Value, out valueId))
            {
                fieldConfiguration.Analyze = false;
                fieldValue = valueId.ToLuceneId();
            }

            string fieldName = SitecoreQueryBuilderExtensions.GetEncodedFieldName(field.Name);
            if (fieldConfiguration.Analyze)
            {
                document.AddAnalysedField(fieldName, fieldValue, fieldConfiguration.Store);
                return;
            }
            document.AddNonAnalysedField(fieldName, fieldValue, fieldConfiguration.Store);
        }
Пример #18
0
 protected virtual bool AddSpecificFieldByTypeKey(Document document, Field field, string fieldTypeKey)
 {
     FieldConfiguration fieldConfiguration;
     bool handled = false;
     // specific field type handling
     switch (fieldTypeKey)
     {
         case "rich text":
             fieldConfiguration = GetFieldConfiguration(field);
             AddValueField(document, field, fieldConfiguration, true);
             break;
         case "accountsmultilist":
             fieldConfiguration = GetFieldConfiguration(field);
             AddMultilistField(document, field, fieldConfiguration);
             handled = true;
             break;
         case "date":
             fieldConfiguration = GetFieldConfiguration(field, false);
             AddDateTimeField(document, field, fieldConfiguration);
             handled = true;
             break;
     }
     return handled;
 }
Пример #19
0
        protected virtual void AddField(Document document, Field field)
        {
            string fieldType = "value";
            string fieldTypeKey = field.TypeKey.ToLower();
            if (FieldTypes.ContainsKey(fieldTypeKey))
            {
                fieldType = FieldTypes[fieldTypeKey].ToLower();
            }

            var handled = AddSpecificFieldByTypeKey(document, field, fieldTypeKey);

            if (handled)
            {
                return;
            }
            AddDefaultFieldByType(document, field, fieldType);
        }
Пример #20
0
 public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
 {
     return(Create(field));
 }
Пример #21
0
 //protected bool ShouldBeSplit(SCField field)
 //{
 //   return FieldTypeManager.GetField(field) is MultilistField;
 //}
 protected LuceneField.Index GetIndexType(SCField field)
 {
     if (FieldTypes.ContainsKey(field.TypeKey))
      {
     object searchField = FieldTypes[field.TypeKey];
     if (searchField is SearchField)
     {
        return (searchField as SearchField).IndexType;
     }
      }
      return LuceneField.Index.UN_TOKENIZED;
 }
Пример #22
0
 protected LuceneField.Store GetStorageType(SCField field)
 {
     if (FieldTypes.ContainsKey(field.TypeKey))
      {
     var searchField = FieldTypes[field.TypeKey];
     return searchField.StorageType;
      }
      return LuceneField.Store.NO;
 }
Пример #23
0
 /// <summary>
 /// Converts a Sitecore Field into a specific Synthesis field equivalent
 /// </summary>
 public static TField As <TField>(this Sitecore.Data.Fields.Field field)
     where TField : FieldType
 {
     return(AsStronglyTyped(field) as TField);
 }