GetShortName() static private method

static private GetShortName ( string fieldClassName ) : string
fieldClassName string
return string
Ejemplo n.º 1
0
        public FieldSettingContent(Node parent, string nodeTypeName) : base(parent, nodeTypeName)
        {
            this.ContentList = parent as ContentList;

            var fsType = (from fst in TypeHandler.GetTypesByBaseType(typeof(FieldSetting))
                          where fst.Name.CompareTo(nodeTypeName) == 0
                          select fst).FirstOrDefault();

            if (fsType == null)
            {
                return;
            }

            var typeName = fsType.FullName;

            if (typeName.EndsWith("Setting"))
            {
                typeName = typeName.Remove(typeName.LastIndexOf("Setting"));
            }

            this.FieldSetting = Activator.CreateInstance(fsType) as FieldSetting;

            if (this.FieldSetting == null)
            {
                return;
            }

            this.FieldSetting.ShortName = FieldManager.GetShortName(typeName);
            this.AddToDefaultView       = true;

            base.Initialize();
        }
Ejemplo n.º 2
0
        internal static FieldDescriptor Parse(XPathNavigator fieldElement, IXmlNamespaceResolver nsres, ContentType contentType)
        {
            FieldDescriptor fdesc = new FieldDescriptor();

            fdesc.Owner = contentType;
            var fieldName = fieldElement.GetAttribute("name", String.Empty);

            fdesc.FieldName          = fieldName;
            fdesc.FieldTypeShortName = fieldElement.GetAttribute("type", String.Empty);
            fdesc.FieldTypeName      = fieldElement.GetAttribute("handler", String.Empty);
            fdesc.IsContentListField = fdesc.FieldName[0] == '#';
            if (String.IsNullOrEmpty(fdesc.FieldTypeShortName))
            {
                fdesc.FieldTypeShortName = FieldManager.GetShortName(fdesc.FieldTypeName);

                if (string.IsNullOrEmpty(fdesc.FieldTypeShortName))
                {
                    throw new ContentRegistrationException($"Unknown field handler: {fdesc.FieldTypeName}", null,
                                                           contentType.Name, fieldName);
                }
            }

            if (fdesc.FieldTypeName.Length == 0)
            {
                if (fdesc.FieldTypeShortName.Length == 0)
                {
                    throw new ContentRegistrationException("Field element's 'handler' attribute is required if 'type' attribute is not given.", contentType.Name, fdesc.FieldName);
                }

                try
                {
                    fdesc.FieldTypeName = FieldManager.GetFieldHandlerName(fdesc.FieldTypeShortName);
                }
                catch (NotSupportedException ex)
                {
                    throw new ContentRegistrationException($"Unknown field type: {fdesc.FieldTypeShortName}", ex,
                                                           contentType.Name, fieldName);
                }
            }

            fdesc.Bindings = new List <string>();

            foreach (XPathNavigator subElement in fieldElement.SelectChildren(XPathNodeType.Element))
            {
                switch (subElement.LocalName)
                {
                case "DisplayName":
                    fdesc.DisplayName = subElement.Value;
                    break;

                case "Description":
                    fdesc.Description = subElement.Value;
                    break;

                case "Icon":
                    fdesc.Icon = subElement.Value;
                    break;

                case "Bind":
                    var propertyName = subElement.GetAttribute("property", String.Empty);
                    fdesc.Bindings.Add(propertyName);
                    fdesc.IsRerouted |= propertyName != fdesc.FieldName;
                    break;

                case "Indexing":
                    foreach (XPathNavigator indexingSubElement in subElement.SelectChildren(XPathNodeType.Element))
                    {
                        switch (indexingSubElement.LocalName)
                        {
                        case "Mode": fdesc.IndexingMode = indexingSubElement.Value; break;

                        case "Store": fdesc.IndexStoringMode = indexingSubElement.Value; break;

                        case "TermVector": fdesc.IndexingTermVector = indexingSubElement.Value; break;

                        case "Analyzer": fdesc.Analyzer = ParseAnalyzer(indexingSubElement.Value, contentType.Name, fieldName); break;

                        case "IndexHandler": fdesc.IndexHandlerTypeName = indexingSubElement.Value; break;
                        }
                    }
                    break;

                case "Configuration":
                    fdesc.ConfigurationElement = subElement;
                    fdesc.FieldSettingTypeName = subElement.GetAttribute("handler", String.Empty);
                    break;

                case "AppInfo":
                    fdesc.AppInfo = subElement;
                    break;

                default:
                    throw new NotSupportedException(String.Concat("Unknown element in Field: ", subElement.LocalName));
                }
            }

            // Default binding;
            RepositoryDataType[] dataTypes = FieldManager.GetDataTypes(fdesc.FieldTypeShortName);
            fdesc.DataTypes = dataTypes;
            if (fdesc.IsContentListField)
            {
                foreach (var d in dataTypes)
                {
                    fdesc.Bindings.Add(null);
                }
            }
            else
            {
                if (dataTypes.Length > 1 && fdesc.Bindings.Count != dataTypes.Length)
                {
                    throw new ContentRegistrationException("Missing explicit 'Binding' elements", contentType.Name, fdesc.FieldName);
                }
                if (dataTypes.Length == 1 && fdesc.Bindings.Count == 0)
                {
                    fdesc.Bindings.Add(fdesc.FieldName);
                }
            }

            fdesc.XmlNamespaceResolver = nsres;

            return(fdesc);
        }