Example #1
0
        public string RenderTemplate(HtmlHelper htmlHelper, ContentItem item, IContentItemContainer container, string action)
        {
            RouteValueDictionary routeValues = new RouteValueDictionary();
            routeValues.Add(ContentRoute.ContentItemKey, item);
            routeValues.Add(ContentRoute.AreaKey, _controllerMapper.GetAreaName(item.GetType()));

            return htmlHelper.Action(action,
                _controllerMapper.GetControllerName(item.GetType()),
                routeValues).ToString();
        }
Example #2
0
        private ContentItem LocateStartPage(ContentItem startPageConfigured)
        {
            ContentItem startPage = startPageConfigured;

            lock (_syncLock)
            {
                if (host.CurrentSite.StartPageID != host.CurrentSite.RootItemID) // only when start <> root
                {
                    if (startPage != null)
                    {
                        if (!(startPage is IStartPage))
                        {
                            logger.WarnFormat("Configured start page is no IStartPage #{0} -> {1}",
                                              host.CurrentSite.StartPageID,
                                              startPage.GetType().FullName);
                            startPage = null;
                        }

                        if (startPage != null && !startPage.IsPublished())
                        {
                            logger.ErrorFormat("Configured start page is not published #{0} -> {1}", startPage.ID,
                                               startPage.GetType().FullName);
                            startPage = null;
                        }
                    }

                    if (startPage == null)
                    {
                        // try to locate start page below root
                        var root = persister.Repository.Get(host.CurrentSite.RootItemID);
                        if (root == null)
                        {
                            // no content?
                            return(null);
                        }

                        ItemList children = root.GetChildren(new TypeFilter(typeof(IStartPage)), new PublishedFilter());
                        if (children.Count == 1)
                        {
                            startPage = children[0];
                            logger.InfoFormat("Auto updated start page to #{0} -> {1}", startPage.ID,
                                              startPage.GetType().FullName);
                            var newSite = new Site(root.ID, startPage.ID);
                            host.ReplaceSites(newSite, new List <Site>());
                        }
                    }

                    if (startPage == null)
                    {
                        return(startPageConfigured); // keep configured
                    }
                }
            }
            return(startPage);
        }
Example #3
0
		public virtual void WriteDetail(ContentItem item, ContentDetail detail, XmlTextWriter writer)
		{
			using (ElementWriter detailElement = new ElementWriter("detail", writer))
			{
				detailElement.WriteAttribute("name", detail.Name);
				detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType));
				detailElement.WriteAttribute("meta", detail.Meta);

				
				var prop = item.GetType().GetProperty(detail.Name);

				if (prop != null)
				{
					if (Attribute.IsDefined(prop, typeof(N2.Details.XMLTranslateAttribute)))
					{
						string translate = "Value";

						//if (options.HasFlag(ExportOptions.TranslateDetailName))
						//		translate += ",Name";

						//if (options.HasFlag(ExportOptions.TranslateDetailTitle))
						//		translate += ",Title";

						detailElement.WriteAttribute("xmlTranslate", translate);
					}
				}

				WriteInnerContents(item, detail, detail.ValueTypeKey, detailElement);

			}
		}
        // Used in code snippet 1.
        static void ProcessStructElement(SElement element, int indent)
        {
            if (!element.IsValid())
            {
                return;
            }

            // Print out the type and title info, if any.
            PrintIndent(indent++);
            Console.Write("Type: " + element.GetType());
            if (element.HasTitle())
            {
                Console.Write(". Title: " + element.GetTitle());
            }

            int num = element.GetNumKids();

            for (int i = 0; i < num; ++i)
            {
                // Check is the kid is a leaf node (i.e. it is a ContentItem).
                if (element.IsContentItem(i))
                {
                    ContentItem      cont = element.GetAsContentItem(i);
                    ContentItem.Type type = cont.GetType();

                    Page page = cont.GetPage();

                    PrintIndent(indent);
                    Console.Write("Content Item. Part of page #" + page.GetIndex());

                    PrintIndent(indent);
                    switch (type)
                    {
                    case ContentItem.Type.e_MCID:
                    case ContentItem.Type.e_MCR:
                        Console.Write("MCID: " + cont.GetMCID());
                        break;

                    case ContentItem.Type.e_OBJR:
                    {
                        Console.Write("OBJR ");
                        Obj ref_obj = cont.GetRefObj();
                        if (ref_obj != null)
                        {
                            Console.Write("- Referenced Object#: " + ref_obj.GetObjNum());
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                else                    // the kid is another StructElement node.
                {
                    ProcessStructElement(element.GetAsStructElem(i), indent);
                }
            }
        }
Example #5
0
		private static string ComputeReplacement(ContentItem item, Match match)
		{
			var pn = match.Groups[1].Value.Split(new[] {':'}, 2);
			try
			{
				var d1 = item.GetDetail(pn[0]);
				if (d1 == null)
				{
					// hard-coded a few properties here to avoid reflection
					if (pn[0] == "Title")
						d1 = item.Title;
					else if (pn[0] == "Url")
						d1 = item.Url;
					else if (pn[0] == "Id")
						d1 = item.ID;
					else if (pn[0] == "Published")
						d1 = item.Published;
					else if (pn[0] == "TranslationKey")
						d1 = item.TranslationKey;
					else if (pn[0] == "SavedBy")
						d1 = item.SavedBy;
					else if (pn[0] == "Updated")
						d1 = item.Updated;
					else if (pn[0] == "Published")
						d1 = item.Published;
					else if (pn[0] == "Path")
						d1 = item.Path;
					else
					{
						// Use Reflection to resolve property. 
						var type = item.GetType();
						var props =
							type.GetProperties().Where(f => f.Name == pn[0]).
								ToArray();
						if (props.Length > 0)
							d1 = props[0].GetValue(item, null);
							// it's a property
						else
						{
							var fields =
								type.GetFields().Where(f => f.Name == pn[0]).
									ToArray();
							if (fields.Length > 0)
								d1 = fields[0].GetValue(item); // it's a field
						}
					}
				}
				if (d1 == null)
					return String.Concat('{', pn[0], ":null}");
				return (pn.Length == 2
					        ? String.Format(
						        String.Concat("{0:", pn[1], '}'), d1)
					        : d1.ToString());
			}
			catch (Exception err)
			{
				return err.ToString();
			}
		}
Example #6
0
 public IContentItemRestorer CreateRestorer(string blobRelativePath, ContentItem item)
 {
     if (item.GetType() == typeof(BlogArticle))
     {
         return(new BlogArticleRestorer());
     }
     return(new StaticPageRestorer());
 }
Example #7
0
        public override bool IsEnabled(ContentItem contentItem)
        {
            ContentType definition = Context.ContentTypes.GetContentType(contentItem.GetType());
            if (!definition.AvailableZones.Any())
                return false;

            return base.IsEnabled(contentItem);
        }
Example #8
0
 public override void UpdateEditor(ContentItem item, Control editor)
 {
     ItemSelector selector = (ItemSelector)editor;
     selector.SelectedItem = item[Name] as ContentItem;
     var pi = item.GetType().GetProperty(Name);
     if(pi != null)
         selector.RequiredType = pi.PropertyType;
 }
Example #9
0
 protected static PropertyInfo GetPropertyInfo(ContentItem parentItem, string name)
 {
     if (parentItem == null || name == null)
     {
         return(null);
     }
     return(parentItem.GetType().GetProperty(name));
 }
Example #10
0
        /// <summary>Retrieves allowed item definitions.</summary>
        /// <param name="parentItem">The parent item.</param>
        /// <param name="zoneName">The zone where children would be placed.</param>
        /// <param name="user">The user to restrict access for.</param>
        /// <returns>Item definitions allowed by zone, parent restrictions and security.</returns>
        public virtual IEnumerable<ContentType> GetAllowedDefinitions(ContentItem parentItem, string zoneName, IPrincipal user)
        {
            ContentType containerDefinition = Engine.ContentTypes.GetContentType(parentItem.GetType());

            foreach (ContentType childDefinition in containerDefinition.AllowedChildren)
                if (childDefinition.IsAllowedInZone(zoneName) && childDefinition.Enabled && childDefinition.IsAuthorized(user))
                    yield return childDefinition;
        }
		public override void UpdateEditor(ContentItem item, Control editor)
		{
			ItemSelector selector = (ItemSelector)editor;
			selector.SelectedItem = item[Name] as ContentItem;
			var pi = item.GetType().GetProperty(Name);
			if(pi != null)
				selector.RequiredType = pi.PropertyType;
			selector.SelectableTypes = string.Join(",", (SelectableTypes ?? new[] { selector.RequiredType ?? typeof(ContentItem) }).Select(t => t.Name).ToArray());
		}
Example #12
0
        /// <summary>Check if an item can be copied.</summary>
        /// <exception cref="NameOccupiedException"></exception>
        /// <exception cref="ZeusException"></exception>
        public virtual ZeusException GetCopyException(ContentItem source, ContentItem destination)
        {
            if (IsNameOccupiedOnDestination(source, destination))
                return new NameOccupiedException(source, destination);

            if (!IsTypeAllowedBelowDestination(source, destination))
                return new NotAllowedParentException(_contentTypeManager.GetContentType(source.GetType()), destination.GetType());

            return null;
        }
Example #13
0
 protected override IEnumerable<PropertyData> GetDetails(ContentItem item)
 {
     ContentType definition = definitions.GetContentType(item.GetType());
     foreach (PropertyData detail in item.Details.Values)
         foreach (IContentProperty property in definition.Properties)
             if (detail.Name == property.Name)
             {
                 yield return detail;
                 break;
             }
 }
Example #14
0
 protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item)
 {
     itemElement.WriteAttribute("id", item.ID);
     itemElement.WriteAttribute("name", item.Name);
     itemElement.WriteAttribute("parent", item.Parent != null ? item.Parent.ID.ToString() : string.Empty);
     itemElement.WriteAttribute("title", item.Title);
     if (item is WidgetContentItem)
         itemElement.WriteAttribute("zoneName", ((WidgetContentItem) item).ZoneName);
     itemElement.WriteAttribute("created", item.Created);
     itemElement.WriteAttribute("updated", item.Updated);
     itemElement.WriteAttribute("published", item.Published);
     itemElement.WriteAttribute("expires", item.Expires);
     itemElement.WriteAttribute("sortOrder", item.SortOrder);
     //itemElement.WriteAttribute("url", parser.BuildUrl(item));
     itemElement.WriteAttribute("visible", item.Visible);
     itemElement.WriteAttribute("savedBy", item.SavedBy);
     itemElement.WriteAttribute("language", item.Language);
     itemElement.WriteAttribute("translationOf", (item.TranslationOf != null) ? item.TranslationOf.ID.ToString() : string.Empty);
     itemElement.WriteAttribute("typeName", item.GetType().GetTypeAndAssemblyName());
     itemElement.WriteAttribute("discriminator", definitions.GetContentType(item.GetType()).Discriminator);
 }
Example #15
0
        public override void UpdateEditor(ContentItem item, Control editor)
        {
            ItemSelector selector = (ItemSelector)editor;

            selector.SelectedItem = item[Name] as ContentItem;
            var pi = item.GetType().GetProperty(Name);

            if (pi != null)
            {
                selector.RequiredType = pi.PropertyType;
            }
        }
Example #16
0
        private string GetTemplateUrl(ContentItem item)
        {
            var templateUrl = String.Empty;
            var pathData = PathDictionary.GetFinders(item.GetType())
                .Where(finder => !(finder is ActionResolver))
                .Select(finder => finder.GetPath(item, null))
                .FirstOrDefault(path => path != null && !path.IsEmpty());

            if (pathData != null)
                templateUrl = pathData.TemplateUrl;
            return templateUrl;
        }
Example #17
0
        public override bool IsEnabled(ContentItem contentItem)
        {
            if (!base.IsEnabled(contentItem))
                return false;

            // Check that this content item has allowed children
            IContentTypeManager contentTypeManager = Context.ContentTypes;
            ContentType contentType = contentTypeManager.GetContentType(contentItem.GetType());
            if (!contentTypeManager.GetAllowedChildren(contentType, null, Context.Current.WebContext.User).Any())
                return false;

            return true;
        }
Example #18
0
        public override void UpdateEditor(ContentItem item, Control editor)
        {
            ItemSelector selector = (ItemSelector)editor;

            selector.SelectedItem = item[Name] as ContentItem;
            var pi = item.GetType().GetProperty(Name);

            if (pi != null)
            {
                selector.RequiredType = pi.PropertyType;
            }
            selector.SelectableTypes = string.Join(",", (SelectableTypes ?? new[] { selector.RequiredType ?? typeof(ContentItem) }).Select(t => t.Name).ToArray());
        }
Example #19
0
        Control IDisplayable.AddTo(ContentItem item, string detailName, Control container)
        {
            if (!(item is IArticle)) throw new ArgumentException("The supplied item " + item.Path + "#" + item.ID + " of type '" + item.GetType().FullName + "' doesn't implement IArticle.", "item");

            WikiParser parser = Engine.Resolve<WikiParser>();
            WikiRenderer renderer = Engine.Resolve<WikiRenderer>();

            PlaceHolder ph = new PlaceHolder();
            container.Controls.Add(ph);

            renderer.AddTo(parser.Parse((string)item[detailName]), ph, item);

            return ph;
        }
Example #20
0
        protected override void AddControls(Control container)
        {
            // Create an overall properties control.

            Control properties = AddProperties(container);

            // Add a property for each piece of metadata.

            PropertyInfo propertyInfo = _item.GetType().GetProperty("IsEnabled");

            if (propertyInfo != null)
            {
                AddPropertyEditor(properties, _item, propertyInfo, "Enabled");
            }
        }
Example #21
0
        public static IContentEditor GetEditor(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            IItemContentEditorFactory factory;

            if (ItemEditorFactories.TryGetValue(item.GetType(), out factory))
            {
                return(factory.CreateEditor(item));
            }
            return(null);
        }
Example #22
0
        public static string GetDisplayerTemplateUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            string templateUrl;

            if (DisplayerTemplateUrls.TryGetValue(item.GetType(), out templateUrl))
            {
                return(templateUrl);
            }
            return(null);
        }
        // Used in code snippet 3.
        static void ProcessStructElement2(SElement element, Hashtable mcid_doc_map, int indent)
        {
            if (!element.IsValid())
            {
                return;
            }

            // Print out the type and title info, if any.
            PrintIndent(indent);
            Console.Write("<" + element.GetType());
            if (element.HasTitle())
            {
                Console.Write(" title=\"" + element.GetTitle() + "\"");
            }
            Console.Write(">");

            int num = element.GetNumKids();

            for (int i = 0; i < num; ++i)
            {
                if (element.IsContentItem(i))
                {
                    ContentItem cont = element.GetAsContentItem(i);
                    if (cont.GetType() == ContentItem.Type.e_MCID)
                    {
                        int page_num = cont.GetPage().GetIndex();
                        if (mcid_doc_map.ContainsKey(page_num))
                        {
                            Hashtable mcid_page_map = (Hashtable)(mcid_doc_map[page_num]);
                            int       mcid          = cont.GetMCID();
                            if (mcid_page_map.ContainsKey(mcid))
                            {
                                Console.Write(mcid_page_map[mcid]);
                            }
                        }
                    }
                }
                else                    // the kid is another StructElement node.
                {
                    ProcessStructElement2(element.GetAsStructElem(i), mcid_doc_map, indent + 1);
                }
            }

            PrintIndent(indent);
            Console.Write("</" + element.GetType() + ">");
        }
Example #24
0
        private static IContentDisplayer GetContentDisplayer(ContentItem parentItem, string propertyName)
        {
            // The property on the parent can define how to display the child.

            PropertyInfo propertyInfo = parentItem.GetType().GetProperty(propertyName);

            if (propertyInfo != null)
            {
                IContentDisplayer displayer = GetContentDisplayer(parentItem, propertyName, propertyInfo);
                if (displayer != null)
                {
                    return(displayer);
                }
            }

            // Look for a property on the parent.

            var item = parentItem.Children[propertyName];

            return(CreateDisplayer(item));
        }
Example #25
0
        protected override void AddControls(Control container)
        {
            // Create an overall properties control.

            Control properties = AddProperties(container);

            // Iterate through all the properties of the item.

            foreach (PropertyInfo propertyInfo in _parentItem.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                // Include it if it is derived from CmsContentItem or has a Content derived attribute.

                if (propertyInfo.PropertyType == typeof(ContentItem) || propertyInfo.PropertyType.IsSubclassOf(typeof(ContentItem)))
                {
                    AddPropertyEditor(properties, _parentItem, propertyInfo);
                }
                else if (IsContent(propertyInfo))
                {
                    AddPropertyEditor(properties, _parentItem, propertyInfo);
                }
            }
        }
Example #26
0
        public PathData GetPath(ContentItem item, string remainingUrl)
        {
            if (string.IsNullOrEmpty(remainingUrl) || string.Equals(remainingUrl, "default", StringComparison.InvariantCultureIgnoreCase))
                remainingUrl = DefaultAction;
            int slashIndex = remainingUrl.IndexOf('/');

            string action = remainingUrl;
            string arguments = null;
            if (slashIndex > 0)
            {
                action = remainingUrl.Substring(0, slashIndex);
                arguments = remainingUrl.Substring(slashIndex + 1);
            }

            var templateUrl = GetTemplateUrl(item);
            var controllerName = _controllerMapper.GetControllerName(item.GetType());

            foreach (string method in _methods)
                if (method.Equals(action, StringComparison.InvariantCultureIgnoreCase))
                    return new MvcPathData(item, templateUrl, action, arguments, controllerName);

            return null;
        }
Example #27
0
        public static void MapTo(this ContentItem item, ContentItemEntity entity)
        {
            // Set general properties.

            entity.name       = item.Name;
            entity.type       = item.GetType().Name;
            entity.enabled    = item.IsEnabled;
            entity.deleted    = false;
            entity.verticalId = item.VerticalId;

            // Set content.

            entity.ContentItemEntities.Clear();
            entity.ContentDetailEntities.Clear();

            foreach (var child in item.Children)
            {
                entity.ContentItemEntities.Add(child.Map());
            }
            foreach (var field in item.Fields)
            {
                entity.ContentDetailEntities.Add(Map(field.Key, field.Value));
            }
        }
Example #28
0
 /// <summary>
 /// Returns true if this content item can be translated. This method
 /// checks if the content type for this content item has been decorated
 /// with the [Translatable] attribute.
 /// </summary>
 /// <param name="contentItem"></param>
 /// <returns></returns>
 public bool CanBeTranslated(ContentItem contentItem)
 {
     return _contentTypeManager.GetContentType(contentItem.GetType()).Translatable;
 }
Example #29
0
 private string ParseItem(ContentItem item)
 {
     return((string)ParseMethod.MakeGenericMethod(item.GetType()).Invoke(this, new object[] { _template, item }));
 }
Example #30
0
 public static bool IsVisibleInTree(ContentItem contentItem)
 {
     return ((Context.ContentTypes[contentItem.GetType()].Visibility & AdminSiteTreeVisibility.Visible) == AdminSiteTreeVisibility.Visible)
             && (contentItem.Parent == null || (Context.ContentTypes[contentItem.Parent.GetType()].Visibility & AdminSiteTreeVisibility.ChildrenHidden) != AdminSiteTreeVisibility.ChildrenHidden);
 }
Example #31
0
 protected override string GetTemplateUrl(ContentItem item)
 {
     return DefaultTemplateFolderPath + item.GetType().Name + ".aspx";
 }
Example #32
0
		protected virtual void UpdateDetails(Collections.IContentList<ContentDetail> target, Collections.IContentList<ContentDetail> source, ContentItem targetItem)
		{
			ReplaceDetailsEnclosingItem(targetItem, source);
			
			List<string> keys = new List<string>(target.Keys);
			foreach (string key in keys)
			{
				
				ContentDetail detail = target[key];
				
				
				//Don't update Parent and Versionkey
				if (target[key].Name == "ParentID" || target[key].Name == "VersionKey")
					continue;

				
				//Update Values 
				if (source.Keys.Contains(key))
				{

						//Check Ignore Attribute
						var prop = targetItem.GetType().GetProperty(key);

						//Details left in db not used as property anymore check
						if (prop != null)
						{
							if (Attribute.IsDefined(prop, typeof(N2.Details.XMLUpdaterIgnoreAttribute)))
								continue;
						}

						target[key].ObjectValue = source[key].BoolValue;
						target[key].DateTimeValue = source[key].DateTimeValue;
						target[key].DoubleValue = source[key].DoubleValue;
						target[key].IntValue = source[key].IntValue;
						target[key].Meta = source[key].Meta;
						target[key].ObjectValue = source[key].ObjectValue;
						target[key].StringValue = source[key].StringValue;
						target[key].Value = source[key].Value;
				
				}
				else
				{
					target.Remove(detail);					
				}
			}

			//Add none existing Details from source
			keys = new List<string>(source.Keys);
			foreach (string key in keys)
			{
				ContentDetail detail = source[key];

				//Ignore Parent and Versionkey
				if (detail.Name == "ParentID" && detail.Name == "VersionKey")
					continue;

				if (target.Keys.Contains(key) == false)
				{
					detail.ID = 0;
					target.Add(detail);
				}
			}
		}
Example #33
0
        private MenuItem GetMenuItem(ContentItem contentItem, string clientPluginClass)
        {
            MenuItem menuItem = new MenuItem
            {
                Text = "New",
                IconUrl = Utility.GetCooliteIconUrl(Icon.PageAdd),
                Handler = GetJavascriptHandler(contentItem, clientPluginClass)
            };

            // Add child menu items for types that can be created under the current item.
            IContentTypeManager manager = Context.Current.Resolve<IContentTypeManager>();
            var childTypes = manager.GetAllowedChildren(manager.GetContentType(contentItem.GetType()), null, Context.Current.WebContext.User);

            if (childTypes.Any())
            {
                Menu childMenu = new Menu();
                menuItem.Menu.Add(childMenu);
                foreach (ContentType child in childTypes)
                {
                    MenuItem childMenuItem = new MenuItem
                    {
                        Text = child.Title,
                        IconUrl = child.IconUrl,
                        Handler = string.Format("function() {{ new top.{0}('New {1}', '{2}').execute(); }}", clientPluginClass,
                            child.Title, Context.AdminManager.GetEditNewPageUrl(contentItem, child, null, CreationPosition.Below))
                    };
                    childMenu.Items.Add(childMenuItem);
                }
            }

            return menuItem;
        }
Example #34
0
        protected virtual ContentItem GetChild(ContentItem item)
        {
            ContentItem childItem = Utility.GetProperty(item, Name) as ContentItem;

            if (childItem as AcceptArgsFromChildEditor != null)
            {
                if (((AcceptArgsFromChildEditor)childItem).arg1 != this.arg1 || ((AcceptArgsFromChildEditor)childItem).arg2 != this.arg2)
                {
                    //different values so save these to the object - not perfect, but without this mechanism the values would need to be edited manually...
                    //the content item needs to understand the crop it's being asked to perform
                    ((AcceptArgsFromChildEditor)childItem).arg1 = this.arg1;
                    ((AcceptArgsFromChildEditor)childItem).arg2 = this.arg2;
                    Zeus.Context.Persister.Save(childItem);
                }
            }

            if (childItem == null)
            {
                PropertyInfo pi = item.GetType().GetProperty(Name);

                if (pi == null)
                    throw new ZeusException("The item should have had a property named '{0}'", Name);
                childItem = CreateChild(item, pi.PropertyType);

                pi.SetValue(item, childItem, null);
            }
            return childItem;
        }
Example #35
0
        private TUser ToApplicationUser(ContentItem user)
        {
            var userT = user as TUser;

            if ((user != null) && (userT == null))
            {
                logger.WarnFormat("Unexpected user type found. Null user returned! Found: {0}, Expected: {1}", user.GetType().AssemblyQualifiedName, typeof(TUser).AssemblyQualifiedName);
            }
            return(userT); // will return null when not of required type (should be silently upgraded ?)
        }
 private PropertyDescriptorCollection GetProperties(ContentItem contentItem)
 {
     return TypeDescriptor.GetProperties(contentItem.GetType());
 }
Example #37
0
 private bool ShouldStoreVersion(ContentItem item)
 {
     return EnableVersioning && !IsNew(item) && item.GetType().GetCustomAttributes(typeof(NotVersionableAttribute), true).Length == 0;
 }
Example #38
0
 protected virtual void AddToContainer(Control container, ItemEditView itemEditor, ContentItem item)
 {
     FieldSet fs = new FieldSet();
     string status = (item.ID != 0) ? "ID #" + item.ID : "(Unsaved)";
     fs.Title = (item.ID != 0) ? Zeus.Context.Current.ContentTypes[item.GetType()].ContentTypeAttribute.Title + " " + status : "New Item " + status;
     container.Controls.Add(fs);
     fs.ContentControls.Add(itemEditor);
 }
Example #39
0
        /// <summary>Check if an item can be saved.</summary>
        /// <exception cref="NameOccupiedException"></exception>
        /// <exception cref="ZeusException"></exception>
        public virtual ZeusException GetSaveException(ContentItem item)
        {
            if (!IsLocallyUnique(item.Name, item))
                return new NameOccupiedException(item, item.GetParent());

            if (!IsTypeAllowedBelowDestination(item, item.Parent))
                return new NotAllowedParentException(_contentTypeManager.GetContentType(item.GetType()), item.GetParent().GetType());

            return null;
        }
Example #40
0
        /// <summary>Check that the source item type is allowed below the destination. Throws an exception if the item isn't allowed.</summary>
        /// <param name="source">The child item</param>
        /// <param name="destination">The parent item</param>
        private bool IsTypeAllowedBelowDestination(ContentItem source, ContentItem destination)
        {
            if (destination != null)
            {
                ContentType sourceDefinition = _contentTypeManager.GetContentType(source.GetType());
                ContentType destinationDefinition = _contentTypeManager.GetContentType(destination.GetType());

                return destinationDefinition.IsChildAllowed(sourceDefinition);
            }
            return true;
        }
Example #41
0
        private static void UpdateCurrentItemData(ContentItem currentItem, ContentItem replacementItem)
        {
            for (Type t = currentItem.GetType(); t.BaseType != null; t = t.BaseType)
            {
                foreach (PropertyInfo pi in t.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                    if (pi.GetCustomAttributes(typeof(CopyAttribute), true).Length > 0)
                        pi.SetValue(currentItem, pi.GetValue(replacementItem, null), null);

                foreach (FieldInfo fi in t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    if (fi.GetCustomAttributes(typeof(CopyAttribute), true).Length > 0)
                        fi.SetValue(currentItem, fi.GetValue(replacementItem));
                    if (fi.Name == "_url")
                        fi.SetValue(currentItem, null);
                }
            }

            foreach (PropertyData detail in replacementItem.Details.Values)
                currentItem[detail.Name] = detail.Value;

            foreach (PropertyCollection collection in replacementItem.DetailCollections.Values)
            {
                PropertyCollection newCollection = currentItem.GetDetailCollection(collection.Name, true);
                foreach (PropertyData detail in collection.Details)
                    newCollection.Add(detail.Value);
            }
        }
Example #42
0
        /// <summary>Updates the item by way of letting the defined editable attributes interpret the added editors.</summary>
        /// <param name="item">The item to update.</param>
        /// <param name="addedEditors">The previously added editors.</param>
        /// <param name="user">The user for filtering updatable editors.</param>
        /// <returns>Whether any property on the item was updated.</returns>
        public bool UpdateItem(ContentItem item, IDictionary<string, Control> addedEditors, IPrincipal user)
        {
            if (item == null) throw new ArgumentNullException("item");
            if (addedEditors == null) throw new ArgumentNullException("addedEditors");

            bool updated = false;
            ContentType contentType = _contentTypeManager.GetContentType(item.GetType());
            foreach (IEditor e in contentType.GetEditors(user))
            {
                if (addedEditors.ContainsKey(e.Name))
                {
                    updated = e.UpdateItem(item, addedEditors[e.Name]) || updated;
                    /*
                    if (updated)
                    {
                        System.Web.HttpContext.Current.Response.Write("Editor Name = " + e.Name + "<br/>");
                        System.Web.HttpContext.Current.Response.Write("Item Name = " + item.Name + "<br/>");
                        System.Web.HttpContext.Current.Response.Write("Item Url = " + item.Url + "<br/>");
                        System.Web.HttpContext.Current.Response.End();
                    }
                     */

                }
            }

            return updated;
        }