Inheritance: Node, IFolder, IIndexableDocument
示例#1
2
		protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
		{
            //<MinValue>-6</MinValue>
			//<MaxValue>42</MaxValue>
			foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
			{
				switch (node.LocalName)
				{
					case MinValueName:
                        int minValue;
                        if (Int32.TryParse(node.InnerXml, out minValue))
                            _minValue = minValue;
						break;
					case MaxValueName:
						int maxValue;
						if (Int32.TryParse(node.InnerXml, out maxValue))
							_maxValue = maxValue;
						break;
                    case ShowAsPercentageName:
                        bool perc;
                        if (Boolean.TryParse(node.InnerXml, out perc))
                            _showAsPercentage = perc;
                        break;
				}
			}
		}
示例#2
0
        public FieldSettingContent(FieldSetting fieldSetting, ContentType contentType) :
            this(Repository.Root, GetNodeTypeName(fieldSetting))
        {
            this.FieldSetting = fieldSetting;
            this.ContentType = contentType;

            this.Name = this.FieldSetting.Name;
            this._isNew = false;
        }
示例#3
0
        protected internal static XmlDocument LoadContentTypeXmlDocument(SNCS.ContentType contentType)
        {
            var ctdXDoc = new XmlDocument();

            using (var ctdStream = contentType.Binary.GetStream())
                ctdXDoc.Load(ctdStream);

            return(ctdXDoc);
        }
示例#4
0
 protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
 {
     //<ExpectedXmlNamespace>htp://example.com/namespace</ExpectedXmlNamespace>
     foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
     {
         if (element.LocalName != ExpectedXmlNamespaceName)
             continue;
         _expectedXmlNamespace = element.InnerXml;
         return;
     }
 }
示例#5
0
 protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
 {
     foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
     {
         switch(element.LocalName)
         {
             case IsTextConfigString:
                 _isText = element.InnerXml == "true";
                 break;
         }
     }
 }
        protected override bool ParseValue(string value)
        {
            var x = value.Split(ContentType.XmlListSeparators, StringSplitOptions.RemoveEmptyEntries);
            var ctList = new ContentType[x.Length];
            for (int i = 0; i < x.Length; i++)
			{
                var ct = ContentType.GetByName(x[i].Trim());
                if (ct != null)
                    ctList[i] = ct;
			}
            SetData(ctList);
            return true;
        }
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (node.LocalName)
                {
                    case UrlFormatName:
                        ParseEnumValue(node.InnerXml, ref _format);
                        break;
                }
            }
        }
示例#8
0
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (node.LocalName)
                {
                    case FormatName:
                        if (!string.IsNullOrEmpty(node.InnerXml))
                            _format = node.InnerXml;
                        break;
                }
            }
        }
		protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
		{
			base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

			//<Regex>^[a-zA-Z0-9]*$</Regex>
			foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
			{
				switch (element.LocalName)
				{
					case RegexName:
						_regex = element.InnerXml;
						break;
				}
			}
		}
示例#10
0
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (node.LocalName)
                {
                    case RuleName:
                        _rule = node.InnerXml;
                        ParseRules(node);
                        break;
                }
            }
        }
示例#11
0
 protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
 {
     //<MinValue>-6</MinValue>
     //<MaxValue>42</MaxValue>
     foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
     {
         switch (node.LocalName)
         {
             case EvenOnlyName:
                 bool evenOnlyValue;
                 if (Boolean.TryParse(node.InnerXml, out evenOnlyValue))
                     _evenOnly = evenOnlyValue;
                 break;
         }
     }
     base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);
 }
示例#12
0
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (element.LocalName)
                {
                    case RangeName:
                        int range;
                        _range = Int32.TryParse(element.InnerXml, out range) ? range : DefaultRange;
                        break;
                    case SplitName:
                        int split;
                        _split = Int32.TryParse(element.InnerXml, out split) ? split : DefaultSplit;
                        break;
                }
            }
        }
示例#13
0
		protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
		{
			//<MinLength>0..sok</MinLength>
			//<MaxLength>0..sok<MaxLength>
			foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
			{
				switch (element.LocalName)
				{
					case MaxLengthName:
						int maxLength;
						if (int.TryParse(element.InnerXml, out maxLength))
							_maxLength = maxLength;
						break;
					case MinLengthName:
						int minLength;
						if (int.TryParse(element.InnerXml, out minLength))
							_minLength = minLength;
						break;
				}
			}
		}
示例#14
0
        protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (node.LocalName)
                {
                    case TextTypeName:
                        ParseEnumValue(node.InnerXml, ref _textType);
                        break;
                    case RowsName:
                        int rows;
                        if (int.TryParse(node.InnerXml, out rows))
                            _rows = rows;
                        break;
                    case AppendModificationsName:
                        if (!string.IsNullOrEmpty(node.InnerXml))
                            _appendModifications = node.InnerXml.ToLower().CompareTo("true") == 0;
                        break;
                }
            }
        }
示例#15
0
		protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
		{
			//...xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/SearchExpression"
			//....
			//<Configuration>
			//    <AllowMultiple>true<AllowMultiple>
			//    <AllowedTypes>
			//        <Type>Folder</Type>
			//        <Type>File</Type>
			//    </AllowedTypes>
			//    <SelectionRoot>
			//        <Path>/Root/.../1</Path>
			//        <Path>/Root/.../2</Path>
			//    <SelectionRoot>
			//    <Query>
			//        <q:And>
			//          <q:String op="StartsWith" property="Path">.</q:String>
			//          <q:String op="NotEqual" property="Name">Restricted</q:String>
			//        </q:And>
			//    </Query>
			//</Configuration>
			foreach (XPathNavigator element in configurationElement.SelectChildren(XPathNodeType.Element))
			{
				switch (element.LocalName)
				{
					case AllowMultipleName:
						_allowMultiple = element.InnerXml == "true";
						break;
					case AllowedTypesName:
						_allowedTypes = new List<string>();
						foreach (XPathNavigator typeElement in element.SelectChildren(TypeName, element.NamespaceURI))
						{
							string typeName = typeElement.InnerXml; 
							_allowedTypes.Add(typeName);
						}
						break;
					case SelectionRootName:
						_selectionRoots = new List<string>();
						foreach (XPathNavigator pathElement in element.SelectChildren(PathName, element.NamespaceURI))
						{
							string path = pathElement.InnerXml;
							if (path != ".")
							{
								try
								{
									RepositoryPath.CheckValidPath(path);
								}
								catch (InvalidPathException e) //rethrow
								{
									throw new InvalidPathException(String.Concat("Given path is invalid in SelectionRoot element. ContentType: ", contentType.Name,
										", Field name: '", this.Name, "', path: '", path, "'. Reason: ", e.Message));
								}
							}
							_selectionRoots.Add(path);
						}
						break;
					case QueryName:
						var sb = new StringBuilder();
                        sb.Append("<SearchExpression xmlns=\"").Append(NodeQuery.XmlNamespace).Append("\">");
						sb.Append(element.InnerXml);
						sb.Append("</SearchExpression>");
						_query = NodeQuery.Parse(sb.ToString());
						break;
                    case FieldNameName:
				        _fieldName = element.InnerXml;
				        break;
				}
			}
		}
示例#16
0
 public static void InstallContentTypes(TestContext testContext)
 {
     var ctdformat = @"<?xml version=""1.0"" encoding=""utf-8""?>
         <ContentType name=""{0}"" parentType=""Car"" handler=""SenseNet.ContentRepository.GenericContent""
                      xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition"">
           <AllowIncrementalNaming>{1}</AllowIncrementalNaming>
         </ContentType>";
     var ctd1 = String.Format(ctdformat, ContentType_Car1Name, "true");
     var ctd2 = String.Format(ctdformat, ContentType_Car2Name, "false");
     ContentTypeInstaller.InstallContentType(ctd1, ctd2);
     ContentType_Car1 = ContentType.GetByName(ContentType_Car1Name);
     ContentType_Car2 = ContentType.GetByName(ContentType_Car2Name);
 }
示例#17
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 (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);
                }
                fdesc.FieldTypeName = FieldManager.GetFieldHandlerName(fdesc.FieldTypeShortName);
            }

            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":
                    fdesc.Bindings.Add(subElement.GetAttribute("property", String.Empty));
                    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 = indexingSubElement.Value; 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 excplicit 'Binding' elements", contentType.Name, fdesc.FieldName);
                }
                if (dataTypes.Length == 1 && fdesc.Bindings.Count == 0)
                {
                    fdesc.Bindings.Add(fdesc.FieldName);
                }
            }

            fdesc.XmlNamespaceResolver = nsres;

            return(fdesc);
        }
示例#18
0
		internal static void ApplyChangesInEditor(ContentType contentType, SchemaEditor editor)
		{
			//-- Find ContentHandler
			Type handlerType = TypeHandler.GetType(contentType.HandlerName);
			if (handlerType == null)
				throw new RegistrationException(String.Concat(
					SR.Exceptions.Registration.Msg_ContentHandlerNotFound, ": ", contentType.HandlerName));

			//-- parent type
			NodeType parentNodeType = null;
			if (contentType.ParentTypeName != null)
			{
				parentNodeType = editor.NodeTypes[contentType.ParentTypeName];
				if (parentNodeType == null)
					throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_UnknownParentContentType, contentType.Name);
			}

			//-- handler type
			NodeType nodeType = editor.NodeTypes[contentType.Name];
			if (nodeType == null)
				nodeType = editor.CreateNodeType(parentNodeType, contentType.Name, contentType.HandlerName);
			if (nodeType.ClassName != contentType.HandlerName)
				editor.ModifyNodeType(nodeType, contentType.HandlerName);
			if (nodeType.Parent != parentNodeType)
				editor.ModifyNodeType(nodeType, parentNodeType);

			//-- 1: ContentHandler properties
			NodeTypeRegistration ntReg = ParseAttributes(handlerType);
			if (ntReg == null)
				throw new ContentRegistrationException(
					SR.Exceptions.Registration.Msg_DefinedHandlerIsNotAContentHandler, contentType.Name);

			//-- 2: Field properties
			foreach (FieldSetting fieldSetting in contentType.FieldSettings)
			{
				Type[][] slots = fieldSetting.HandlerSlots;
				int fieldSlotCount = slots.GetLength(0);

				if (fieldSetting.Bindings.Count != fieldSlotCount)
					throw new ContentRegistrationException(String.Format(CultureInfo.InvariantCulture,
						SR.Exceptions.Registration.Msg_FieldBindingsCount_1, fieldSlotCount), contentType.Name, fieldSetting.Name);
				for (int i = 0; i < fieldSetting.Bindings.Count; i++)
				{
					string propName = fieldSetting.Bindings[i];
					var dataType = fieldSetting.DataTypes[i];
					CheckDataType(propName, dataType, contentType.Name, editor);
					PropertyInfo propInfo = handlerType.GetProperty(propName);
					if (propInfo != null)
					{
						//-- #1: there is a property under the slot:
						bool ok = false;
						for (int j = 0; j < slots[i].Length; j++)
						{
							//if (slots[i][j] == propInfo.PropertyType)
							if (slots[i][j].IsAssignableFrom(propInfo.PropertyType))
							{
								PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propName);
								if (propInfo.DeclaringType != handlerType)
								{
									if (propReg == null)
									{
										object[] attrs = propInfo.GetCustomAttributes(typeof(RepositoryPropertyAttribute), false);
										if (attrs.Length > 0)
										{
											propReg = new PropertyTypeRegistration(propInfo, (RepositoryPropertyAttribute)attrs[0]);
											ntReg.PropertyTypeRegistrations.Add(propReg);
										}
									}
								}
								if (propReg != null && propReg.DataType != fieldSetting.DataTypes[i])
									throw new ContentRegistrationException(String.Concat(
										"The data type of the field in the content type definition does not match the data type of its content handler's property. ",
										"Please modify the field type in the content type definition. ",
										"ContentTypeDefinition: '", contentType.Name,
										"', FieldName: '", fieldSetting.Name,
										"', DataType of Field's binding: '", fieldSetting.DataTypes[i],
										"', ContentHandler: '", handlerType.FullName,
										"', PropertyName: '", propReg.Name,
										"', DataType of property: '", propReg.DataType,
										"'"));

								ok = true;
								fieldSetting.HandlerSlotIndices[i] = j;
								fieldSetting.PropertyIsReadOnly = !PropertyHasPublicSetter(propInfo);
								break;
							}
						}
						if (!ok)
						{
							//if (fieldSetting.ShortName != "Reference")
							//    if (fieldSetting.DataTypes[i] != RepositoryDataType.Reference)
							//        throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable,
							//            contentType.Name, fieldSetting.Name);
							//CheckReference(propInfo, slots[i], contentType, fieldSetting);

							if (fieldSetting.ShortName == "Reference" || fieldSetting.DataTypes[i] == RepositoryDataType.Reference)
								CheckReference(propInfo, slots[i], contentType, fieldSetting);
							//else if (fieldSetting.ShortName == "Choice")
							//    CheckChoice(propInfo, slots[i], contentType, fieldSetting);
							else
								throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable,
									contentType.Name, fieldSetting.Name);
						}
					}
					else
					{
						//-- #2: there is not a property under the slot:
						PropertyTypeRegistration propReg = new PropertyTypeRegistration(propName, dataType);
						ntReg.PropertyTypeRegistrations.Add(propReg);
					}
				}
			}

			//-- Collect deletables. Check equals
			foreach (PropertyType propType in nodeType.PropertyTypes.ToArray())
			{
				PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propType.Name);
				if (propReg == null)
				{
					editor.RemovePropertyTypeFromPropertySet(propType, nodeType);
				}
			}


			//-- Register
			foreach (PropertyTypeRegistration ptReg in ntReg.PropertyTypeRegistrations)
			{
				PropertyType propType = nodeType.PropertyTypes[ptReg.Name];
				if (propType == null)
				{
					propType = editor.PropertyTypes[ptReg.Name];
					if (propType == null)
						propType = editor.CreatePropertyType(ptReg.Name, ConvertDataType(ptReg.DataType));
					editor.AddPropertyTypeToPropertySet(propType, nodeType);
				}
			}
		}
示例#19
0
 protected string LoadContentTypeString(SNCS.ContentType contentType)
 {
     using (var reader = new StreamReader(contentType.Binary.GetStream()))
         return(reader.ReadToEnd());
 }
示例#20
0
        // ---------------------------------------------------------------------- Information methods

        internal ContentType[] GetContentTypes()
        {
            ContentType[] array = new ContentType[_contentTypes.Count];
            _contentTypes.Values.CopyTo(array, 0);
            return(array);
        }
示例#21
0
		internal void AddContentType(ContentType contentType)
		{
			lock (_syncRoot)
			{
				var parentContentTypeName = contentType.ParentName;
				
				ContentType parentContentType;
				//if(!_contentTypes.TryGetValue(parentContentTypeName, out parentContentType))
				//    parentContentType = null;
				_contentTypes.TryGetValue(parentContentTypeName, out parentContentType);

				string name = contentType.Name;
				if (!_contentTypes.ContainsKey(name))
					_contentTypes.Add(name, contentType);
				if (!_contentPaths.ContainsKey(name))
					_contentPaths.Add(name, contentType.Path);
				contentType.SetParentContentType(parentContentType);
			}
		}
示例#22
0
 internal static ContentType Create(ISupportsDynamicFields handler, ContentType baseContentType)
 {
     var ctd = DynamicContentTools.GenerateCtd(handler, baseContentType);
     return Create(handler, baseContentType, ctd);
 }
示例#23
0
        //======================================================================================================= Runtime ContentType

        internal static ContentType Create(Type type, string ctd)
        {
            var contentType = new ContentType(ContentType.GetByName("GenericContent"));//HACK: come from ctd

            var reader = new StringReader(ctd);
            var xml = new XPathDocument(reader);
            var nametable = new NameTable();
            var nav = xml.CreateNavigator();
            var nsres = new XmlNamespaceManager(nav.NameTable);
            nsres.AddNamespace("x", ContentDefinitionXmlNamespace);
            var contentTypeElement = nav.Select("/x:ContentType", nsres);
            contentTypeElement.MoveNext();
            var contentTypeName = contentTypeElement.Current.GetAttribute("name", "");
            contentType.Name = contentTypeName;
            var fieldElements = nav.Select("/x:ContentType/x:Fields/x:Field", nsres);
            foreach (XPathNavigator fieldElement in fieldElements)
            {
                var fieldDescriptor = FieldDescriptor.Parse(fieldElement, nsres, contentType);
                var fieldSetting = FieldSetting.Create(fieldDescriptor);
                contentType.FieldSettings.Add(fieldSetting);
            }
            contentType.SetFieldSlots(type);
            return contentType;
        }
示例#24
0
		//---------------------------------------------------------------------- Information methods

		internal ContentType[] GetContentTypes()
		{
			//Initialize();
			ContentType[] array = new ContentType[_contentTypes.Count];
			_contentTypes.Values.CopyTo(array, 0);
			return array;
		}
 public static void RemoveContentType(ContentType contentType)
 {
     contentType.Delete();
     // The ContentTypeManager distributes its reset, no custom DistributedAction call needed
     ContentTypeManager.Reset();
 }
示例#26
0
        private static ContentType Create(ISupportsDynamicFields handler, ContentType baseContentType, string ctd)
        {
            var contentType = new ContentType(baseContentType);
            contentType.DisplayName = baseContentType.DisplayName;
            contentType.Description = baseContentType.Description;

            //contentType.ParentType = baseContentType.ParentType;
            contentType.ParentType = baseContentType;

            contentType.FieldSettings.AddRange(baseContentType.FieldSettings);

            var reader = new StringReader(ctd);
            var xml = new XPathDocument(reader);
            var nametable = new NameTable();
            var nav = xml.CreateNavigator();
            var nsres = new XmlNamespaceManager(nav.NameTable);
            nsres.AddNamespace("x", ContentDefinitionXmlNamespace);
            var contentTypeElement = nav.Select("/x:ContentType", nsres);
            contentTypeElement.MoveNext();
            var contentTypeName = contentTypeElement.Current.GetAttribute("name", "");
            contentType.Name = contentTypeName;
            var fieldElements = nav.Select("/x:ContentType/x:Fields/x:Field", nsres);
            foreach (XPathNavigator fieldElement in fieldElements)
            {
                var fieldDescriptor = FieldDescriptor.Parse(fieldElement, nsres, contentType);
                var fieldSetting = FieldSetting.Create(fieldDescriptor);
                contentType.SetFieldSlots(fieldSetting, handler);
                contentType.FieldSettings.Add(fieldSetting);
            }
            return contentType;
        }
示例#27
0
		private void RemoveContentType(ContentType contentType, SchemaEditor editor)
		{
			//-- Remove recursive
			foreach (FieldSetting fieldSetting in contentType.FieldSettings)
				if (fieldSetting.Owner == contentType)
					fieldSetting.ParentFieldSetting = null;
			foreach (ContentType childType in contentType.ChildTypes)
				RemoveContentType(childType, editor);
			NodeType nodeType = editor.NodeTypes[contentType.Name];
			if (nodeType != null)
				editor.DeleteNodeType(nodeType);
			_contentTypes.Remove(contentType.Name);
			_contentPaths.Remove(contentType.Name);
		}
示例#28
0
        protected override void ParseConfiguration(System.Xml.XPath.XPathNavigator configurationElement, System.Xml.IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
        {
            base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);

            //<Enabled>true|false</Enabled>
            //<AdminEmail>[email protected]</AdminEmail>
            //<RequireUniqueEmail>true|false</RequireUniqueEmail>
            //<MailDefinition>...</MailDefinition>
            //<IsBodyHtml>true|false</IsBodyHtml>
            //<MailSubject>...</MailSubject>
            //<MailPriority>Low|Normal|High</MailPriority>
            //<MailFrom>[email protected]</MailFrom>
            foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
            {
                switch (node.LocalName)
                {
                    case EnabledName:
                        bool enabled;
                        if (Boolean.TryParse(node.InnerXml, out enabled))
                            _enabled = enabled;
                        break;
                    case AdminEmailName:
                        _adminEmail = node.InnerXml;
                        break;
                    case RequireUniqueEmailName:
                        bool requireUniqueEmail;
                        if (Boolean.TryParse(node.InnerXml, out requireUniqueEmail))
                            _requireUniqueEmail = requireUniqueEmail;
                        break;
                    case MailDefinitionName:
                        _mailDefinition = node.InnerXml;
                        break;
                    case IsBodyHtmlName:
                        bool isBodyHtml;
                        if (Boolean.TryParse(node.InnerXml, out isBodyHtml))
                            _isBodyHtml = isBodyHtml;
                        break;
                    case MailSubjectName:
                        _mailSubject = node.InnerXml;
                        break;
                    case MailPriorityName:
                        if (node.InnerXml == Enum.GetName(typeof(MailPriority), MailPriority.Low))
                            _mailPriority = MailPriority.Low;
                        else if (node.InnerXml == Enum.GetName(typeof(MailPriority), MailPriority.Normal))
                            _mailPriority = MailPriority.Normal;
                        else if (node.InnerXml == Enum.GetName(typeof(MailPriority), MailPriority.High))
                            _mailPriority = MailPriority.High;
                        else
                            _mailPriority = MailPriority.Normal;
                        break;
                    case MailFromName:
                        _mailFrom = node.InnerXml;
                        break;
                }
            }
        }
示例#29
0
		internal static ContentType LoadOrCreateNew(IXPathNavigable contentTypeDefinitionXml)
		{
			//==== saves and puts the holder

			//-- #1 Determine name and parent's name
			XPathNavigator nav = contentTypeDefinitionXml.CreateNavigator().SelectSingleNode("/*[1]");
			string name = nav.GetAttribute("name", "");
			string parentTypeName = nav.GetAttribute("parentType", "");

			//-- #2 Load ContentType
			ContentType contentType = ContentTypeManager.Current.GetContentTypeByName(name);

			//-- #3 Parent Node: if it is loaded yet use it (ReferenceEqals)
			Node parentNode;
			if (String.IsNullOrEmpty(parentTypeName))
			{
				parentNode = (Folder)Node.LoadNode(Repository.ContentTypesFolderPath);
			}
			else
			{
				parentNode = ContentTypeManager.Current.GetContentTypeByName(parentTypeName);
				if (parentNode == null)
					throw new ApplicationException(String.Concat(SR.Exceptions.Content.Msg_UnknownContentType, ": ", parentTypeName));
			}

			//-- #4 Create ContentType if it does not exist
			if (contentType == null)
			{
				contentType = new ContentType(parentNode);
				contentType.Name = name;
			}

			//-- #5 Update hierarchy if parent is changed
			if (contentType.ParentId != parentNode.Id)
			{
				throw new NotImplementedException("Change ContentType hierarchy is not implemented");
			}

			//-- #6 Set Binary data
			BinaryData binaryData = new BinaryData();
			binaryData.FileName = new BinaryFileName(name, ContentType.ContentTypeFileNameExtension);
			binaryData.SetStream(Tools.GetStreamFromString(contentTypeDefinitionXml.CreateNavigator().OuterXml));
			contentType.Binary = binaryData;

			//contentType.Save(false);
			//ContentTypeManager.Current.AddContentType(contentType, parentNode as ContentType);
			return contentType;
		}
示例#30
0
        internal static void ApplyChangesInEditor(ContentType contentType, SchemaEditor editor)
        {
            // Find ContentHandler
            var handlerType = TypeResolver.GetType(contentType.HandlerName, false);

            if (handlerType == null)
            {
                throw new RegistrationException(string.Concat(
                                                    SR.Exceptions.Registration.Msg_ContentHandlerNotFound, ": ", contentType.HandlerName));
            }

            // parent type
            NodeType parentNodeType = null;

            if (contentType.ParentTypeName != null)
            {
                parentNodeType = editor.NodeTypes[contentType.ParentTypeName];
                if (parentNodeType == null)
                {
                    throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_UnknownParentContentType, contentType.Name);
                }

                // make sure that all content handlers defined on the parent chain exist
                var pnt = parentNodeType;
                while (pnt != null)
                {
                    var ht = TypeResolver.GetType(pnt.ClassName, false);
                    if (ht == null)
                    {
                        throw new RegistrationException($"Unknown content handler: {pnt.ClassName}");
                    }

                    pnt = pnt.Parent;
                }
            }

            // handler type
            NodeType nodeType = editor.NodeTypes[contentType.Name];

            if (nodeType == null)
            {
                nodeType = editor.CreateNodeType(parentNodeType, contentType.Name, contentType.HandlerName);
            }
            if (nodeType.ClassName != contentType.HandlerName)
            {
                editor.ModifyNodeType(nodeType, contentType.HandlerName);
            }
            if (nodeType.Parent != parentNodeType)
            {
                editor.ModifyNodeType(nodeType, parentNodeType);
            }

            // 1: ContentHandler properties
            NodeTypeRegistration ntReg = ParseAttributes(handlerType);

            if (ntReg == null)
            {
                throw new ContentRegistrationException(
                          SR.Exceptions.Registration.Msg_DefinedHandlerIsNotAContentHandler, contentType.Name);
            }

            // 2: Field properties
            foreach (FieldSetting fieldSetting in contentType.FieldSettings)
            {
                Type[][] slots          = fieldSetting.HandlerSlots;
                int      fieldSlotCount = slots.GetLength(0);

                if (fieldSetting.Bindings.Count != fieldSlotCount)
                {
                    throw new ContentRegistrationException(String.Format(CultureInfo.InvariantCulture,
                                                                         SR.Exceptions.Registration.Msg_FieldBindingsCount_1, fieldSlotCount), contentType.Name, fieldSetting.Name);
                }
                for (int i = 0; i < fieldSetting.Bindings.Count; i++)
                {
                    string propName = fieldSetting.Bindings[i];
                    var    dataType = fieldSetting.DataTypes[i];
                    CheckDataType(propName, dataType, contentType.Name, editor);
                    PropertyInfo propInfo = handlerType.GetProperty(propName);
                    if (propInfo != null)
                    {
                        // #1: there is a property under the slot:
                        bool ok = false;
                        for (int j = 0; j < slots[i].Length; j++)
                        {
                            if (slots[i][j].IsAssignableFrom(propInfo.PropertyType))
                            {
                                PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propName);
                                if (propInfo.DeclaringType != handlerType)
                                {
                                    if (propReg == null)
                                    {
                                        object[] attrs = propInfo.GetCustomAttributes(typeof(RepositoryPropertyAttribute), false);
                                        if (attrs.Length > 0)
                                        {
                                            propReg = new PropertyTypeRegistration(propInfo, (RepositoryPropertyAttribute)attrs[0]);
                                            ntReg.PropertyTypeRegistrations.Add(propReg);
                                        }
                                    }
                                }
                                if (propReg != null && propReg.DataType != fieldSetting.DataTypes[i])
                                {
                                    throw new ContentRegistrationException(String.Concat(
                                                                               "The data type of the field in the content type definition does not match the data type of its content handler's property. ",
                                                                               "Please modify the field type in the content type definition. ",
                                                                               "ContentTypeDefinition: '", contentType.Name,
                                                                               "', FieldName: '", fieldSetting.Name,
                                                                               "', DataType of Field's binding: '", fieldSetting.DataTypes[i],
                                                                               "', ContentHandler: '", handlerType.FullName,
                                                                               "', PropertyName: '", propReg.Name,
                                                                               "', DataType of property: '", propReg.DataType,
                                                                               "'"));
                                }

                                ok = true;
                                fieldSetting.HandlerSlotIndices[i] = j;
                                fieldSetting.PropertyIsReadOnly    = !PropertyHasPublicSetter(propInfo);
                                break;
                            }
                        }
                        if (!ok)
                        {
                            if (fieldSetting.ShortName == "Reference" || fieldSetting.DataTypes[i] == RepositoryDataType.Reference)
                            {
                                CheckReference(propInfo, slots[i], contentType, fieldSetting);
                            }
                            else
                            {
                                throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable,
                                                                       contentType.Name, fieldSetting.Name);
                            }
                        }
                    }
                    else
                    {
                        // #2: there is not a property under the slot:
                        PropertyTypeRegistration propReg = new PropertyTypeRegistration(propName, dataType);
                        ntReg.PropertyTypeRegistrations.Add(propReg);
                    }
                }
            }

            // Collect deletables. Check equals
            foreach (PropertyType propType in nodeType.PropertyTypes.ToArray())
            {
                PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propType.Name);
                if (propReg == null)
                {
                    editor.RemovePropertyTypeFromPropertySet(propType, nodeType);
                }
            }


            // Register
            foreach (PropertyTypeRegistration ptReg in ntReg.PropertyTypeRegistrations)
            {
                PropertyType propType = nodeType.PropertyTypes[ptReg.Name];
                if (propType == null)
                {
                    propType = editor.PropertyTypes[ptReg.Name];
                    if (propType == null)
                    {
                        propType = editor.CreatePropertyType(ptReg.Name, ConvertDataType(ptReg.DataType));
                    }
                    editor.AddPropertyTypeToPropertySet(propType, nodeType);
                }
            }
        }
示例#31
0
		internal static void ApplyChanges(ContentType settings)
		{
			SchemaEditor editor = new SchemaEditor();
			editor.Load();
			ApplyChangesInEditor(settings, editor);
			editor.Register();

			// The ContentTypeManager distributes its reset, no custom DistributedAction call needed
			ContentTypeManager.Reset();
		}
示例#32
0
 protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
 {
     if (configurationElement == null) throw new ArgumentNullException("configurationElement");
     base.ParseConfiguration(configurationElement, xmlNamespaceResolver, contentType);
     foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
     {
         switch (node.LocalName)
         {
             case ReenterTitleName:
                 _reenterTitle = node.InnerXml;
                 break;
             case ReenterDescriptionName:
                 _reenterDescription = node.InnerXml;
                 break;
             case PasswordHistoryLengthName:
                 _passwordHistoryLength = Int32.Parse(node.InnerXml);
                 break;
         }
     }
 }
示例#33
0
		private static void CheckReference(PropertyInfo propInfo, Type[] type, ContentType cts, FieldSetting fs)
		{
			if (propInfo.PropertyType == (typeof(Node)))
				return;
			if (propInfo.PropertyType.IsSubclassOf(typeof(Node)))
				return;
			if (typeof(System.Collections.IEnumerable).IsAssignableFrom(propInfo.PropertyType))
				return;
			//if (propInfo.PropertyType == typeof(System.Collections.IEnumerable))
			//    return;
			//if (propInfo.PropertyType.Name == "IEnumerable`1")
			//    return;
			//if (propInfo.PropertyType.Name == "NodeList`1")
			//    return;
			throw new NotSupportedException(String.Format(CultureInfo.InvariantCulture,
				SR.Exceptions.Registration.Msg_InvalidReferenceField_2, cts.Name, fs.Name));
		}
示例#34
0
		protected override void ParseConfiguration(XPathNavigator configurationElement, IXmlNamespaceResolver xmlNamespaceResolver, ContentType contentType)
		{
			//<MinValue>-6</MinValue>
			//<MaxValue>42</MaxValue>
			foreach (XPathNavigator node in configurationElement.SelectChildren(XPathNodeType.Element))
			{
				switch (node.LocalName)
				{
					case MinValueName:
						decimal minValue;
						if (Decimal.TryParse(node.InnerXml, NumberStyles.Number, CultureInfo.InvariantCulture, out minValue))
							_minValue = minValue;
						break;
					case MaxValueName:
						decimal maxValue;
						if (Decimal.TryParse(node.InnerXml, NumberStyles.Number, CultureInfo.InvariantCulture, out maxValue))
							_maxValue = maxValue;
						break;
					case DigitsName:
						int digits;
						if (Int32.TryParse(node.InnerXml, NumberStyles.Number, CultureInfo.InvariantCulture, out digits))
							_digits = digits;
						break;
                    case ShowAsPercentageName:
                        bool perc;
                        if (Boolean.TryParse(node.InnerXml, out perc))
                            _showAsPercentage = perc;
                        break;
				}
			}
		}
示例#35
0
		private void TraceContentSchema(StringBuilder sb, ContentType root)
		{
			sb.Append(root.Name);
			if (root.ChildTypes.Count > 0)
				sb.Append("{");
			bool first = true;
			foreach (ContentType child in root.ChildTypes)
			{
				if (!first)
				{
					sb.Append(", ");
					first = false;
				}
				TraceContentSchema(sb, child);
			}
			if (root.ChildTypes.Count > 0)
				sb.Append("}");
		}
示例#36
0
        public static string GenerateCtd(ISupportsDynamicFields handler, ContentType baseContentType)
        {
            var ctdFormat = @"<ContentType name=""{0}"" parentType=""{1}"" handler=""{2}"" xmlns=""{4}"">
    <Fields>
{3}
    </Fields>
</ContentType>";
            var fieldFormat = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
        </Field>
";
            var enumFieldFormat = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
            <Configuration>
                <AllowMultiple>false</AllowMultiple>
                <AllowExtraValue>false</AllowExtraValue>
                <Options>
                    <Enum type='{5}' />
                </Options>
            </Configuration>
        </Field>
";

            var handlerType = handler.GetType();
            var nameAttr = baseContentType.Name; //handlerType.Name;
            var parentAttr = baseContentType.Name;
            var handlerAttr = handlerType.FullName;

            var fields = new StringBuilder();
            var dynamicFieldMetadata = handler.GetDynamicFieldMetadata();
            foreach (var propertyName in dynamicFieldMetadata.Keys)
            {
                var dynamicField = dynamicFieldMetadata[propertyName];

                if (dynamicField.FieldSetting == null)
                {
                    var proptype = dynamicField.PropertyType;
                    var fieldType = dynamicField.FieldType; //GetSuggestedFieldType(proptype);
                    if (typeof (Enum).IsAssignableFrom(proptype))
                    {
                        fields.AppendFormat(enumFieldFormat, dynamicField.FieldName, fieldType, dynamicField.DisplayName,
                            dynamicField.Description, propertyName, proptype.FullName);
                    }
                    else
                    {
                        fields.AppendFormat(fieldFormat, dynamicField.FieldName, fieldType,
                                            dynamicField.DisplayName, dynamicField.Description, propertyName);
                    }
                }
                else
                {
                    fields.Append(dynamicField.FieldSetting.ToXml());
                }
            }

            return String.Format(ctdFormat, nameAttr, parentAttr, handlerAttr, 
                fields, ContentType.ContentDefinitionXmlNamespace);
        }