public void ReplaceContentClass(IContentClass replacement, IDictionary<string, string> oldToNewMapping, Replace replace) { const string REPLACE_CC = @"<PAGE action=""changetemplate"" guid=""{0}"" changeall=""{1}"" holdreferences=""1"" holdexportsettings=""1"" holdauthorizations=""1"" holdworkflow=""1""><TEMPLATE originalguid=""{2}"" changeguid=""{3}"">{4}</TEMPLATE></PAGE>"; const string REPLACE_ELEMENT = @"<ELEMENT originalguid=""{0}"" changeguid=""{1}""/>"; var oldElements = ContentClass.Elements; var newElements = replacement.Elements; var unmappedElements = oldElements.Where(element => !oldToNewMapping.ContainsKey(element.Name)); var unmappedStr = unmappedElements.Aggregate( "", (s, element) => s + REPLACE_ELEMENT.RQLFormat(element, RQL.SESSIONKEY_PLACEHOLDER)); var mappedStr = string.Join( "", from entry in oldToNewMapping let oldElement = oldElements[entry.Key] let newElement = newElements.GetByName(entry.Value) select REPLACE_ELEMENT.RQLFormat(oldElement, newElement)); var isReplacingAll = replace == Replace.ForAllPagesOfContentClass; var query = REPLACE_CC.RQLFormat(this, isReplacingAll, ContentClass, replacement, mappedStr + unmappedStr); Project.ExecuteRQL(query, RqlType.SessionKeyInProject); _contentClass = null; _ccGuid = default(Guid); }
public override void Refresh() { _contentClass = null; _ccGuid = default(Guid); _mainLinkElement = null; base.Refresh(); }
/// <summary> /// Copy this template over to another content class /// </summary> /// <param name="target"> </param> public void CopyToContentClass(IContentClass target) { const string ADD_TEMPLATE_VARIANT = @"<TEMPLATE action=""assign"" guid=""{0}""> <TEMPLATEVARIANTS action=""addnew""> <TEMPLATEVARIANT name=""{1}"" description=""{2}"" code=""{3}"" fileextension=""{4}"" insertstylesheetinpage=""{5}"" nostartendmarkers=""{6}"" containerpagereference=""{7}"" pdforientation=""{8}"">{3}</TEMPLATEVARIANT></TEMPLATEVARIANTS></TEMPLATE>"; XmlDocument xmlDoc = target.Project.ExecuteRQL( string.Format(ADD_TEMPLATE_VARIANT, target.Guid.ToRQLString(), HttpUtility.HtmlEncode(Name), HttpUtility.HtmlEncode(Description), HttpUtility.HtmlEncode(Data), HttpUtility.HtmlEncode(FileExtension), IsStylesheetIncludedInHeader.ToRQLString(), ContainsAreaMarksInPage.ToRQLString(), HasContainerPageReference.ToRQLString(), PdfOrientation), RqlType.SessionKeyInProject); if (xmlDoc.DocumentElement.InnerText.Trim().Length == 0) { return; } string errorMsg = string.Format("Error during addition of template variant '{0}' to content class '{1}'.", Name, target.Name); //sometimes it's <IODATA><ERROR>Reason</ERROR></IODATA> and sometimes just <IODATA>ERROR</IODATA> XmlNodeList errorElements = xmlDoc.GetElementsByTagName("ERROR"); if (errorElements.Count > 0) { throw new SmartAPIException(Session.ServerLogin, errorMsg + string.Format(" Reason: {0}.", errorElements[0].FirstChild.Value)); } throw new SmartAPIException(Session.ServerLogin, errorMsg); }
/// <summary> /// Copies the element to another content class by creating a new element and copying the attribute values to it. /// Make sure to set the language variant in the target project into which the element should be copied, first. /// </summary> /// <param name="contentClass"> target content class, into which the element should be copied </param> /// <returns> the created copy </returns> /// <remarks> /// <list type="bullet"> /// <item> /// <description>Override this method, if you need to set other values than the direct attributes of the element (e.g. setting text values of TextHtml elements)</description> /// </item> /// <item> /// <description> /// The target content class is only modified on the server, thus the content class object does not contain the newly created element. /// If you need an updated version of the content class, you have to retrieve it again with /// <code>new ContentClass(Project, Guid);</code> /// </description> /// </item> /// </list> /// </remarks> public IContentClassElement CopyToContentClass(IContentClass contentClass) { var newContentClassElement = CreateElement(contentClass, Type); var assign = new AttributeAssignment(); assign.AssignAllRedDotAttributesForLanguage(this, newContentClassElement, Project.LanguageVariants.Current.Abbreviation); var node = (XmlElement)newContentClassElement.XmlElement.Clone(); node.Attributes.RemoveNamedItem("guid"); string creationString = GetSaveString(node); // <summary> // RQL for creating an element from a content class. // Two parameters: // 1. Content class guid // 2. Element to create, make sure it contains an attribute "action" with the value "save"! // </summary> const string CREATE_ELEMENT = @"<TEMPLATE guid=""{0}"">{1}</TEMPLATE>"; XmlDocument rqlResult = contentClass.Project.ExecuteRQL(string.Format(CREATE_ELEMENT, contentClass.Guid.ToRQLString(), creationString)); var resultElementNode = (XmlElement)rqlResult.GetElementsByTagName("ELEMENT")[0]; if (resultElementNode == null) { throw new SmartAPIException(Session.ServerLogin, string.Format("Error during creation of element {0}", this)); } newContentClassElement.Guid = resultElementNode.GetGuid(); return(newContentClassElement); }
internal ProjectVariantAssignment(IContentClass contentClass, IProjectVariant projectVariant, ITemplateVariant templateVariant) { _contentClass = contentClass; _projectVariant = projectVariant; _templateVariant = templateVariant; }
protected ContentClassElement(IContentClass contentClass, XmlElement xmlElement) : base(contentClass.Project, xmlElement) { // CreateAttributes("eltname", LANGUAGEVARIANTID); ContentClass = contentClass; LoadXml(); _originalName = Name; }
/// <summary> /// Create a new page in the current language variant and link it. /// </summary> /// <param name="cc"> Content class of the page </param> /// <param name="linkGuid"> Guid of the link the page should be linked to </param> /// <param name="headline"> The headline, or null (default) for the default headline </param> /// <returns> The newly created (and linked) page </returns> public IPage CreateAndConnect(IContentClass cc, Guid linkGuid, string headline = null) { const string CREATE_AND_LINK_PAGE = @"<LINK action=""assign"" guid=""{0}"">{1}</LINK>"; XmlDocument xmlDoc = _project.ExecuteRQL(string.Format(CREATE_AND_LINK_PAGE, linkGuid.ToRQLString(), PageCreationString(cc, headline))); return(CreatePageFromCreationReply(xmlDoc)); }
private static string PageCreationString(IContentClass cc, string headline = null) { const string PAGE_CREATION_STRING = @"<PAGE action=""addnew"" templateguid=""{0}"" {1}/>"; string headlineString = headline == null ? "" : string.Format(@"headline=""{0}""", HttpUtility.HtmlEncode(headline)); return(string.Format(PAGE_CREATION_STRING, cc.Guid.ToRQLString(), headlineString)); }
public Result(IPage page, DateTime creationDate, IUser originalAuthor, DateTime dateOfLastChange, IUser lastEditor, IContentClass contentClass) { Page = page; CreationDate = creationDate; OriginalAuthor = originalAuthor; DateOfLastChange = dateOfLastChange; LastEditor = lastEditor; ContentClass = contentClass; }
internal TemplateVariant(IContentClass contentClass, XmlElement xmlElement) : base(contentClass.Project, xmlElement) { ContentClass = contentClass; LoadXml(); if (IsOnlyPartiallyInitialized(xmlElement)) { IsInitialized = false; } }
internal OptionList(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { if (xmlElement.SelectSingleNode(@"//SELECTIONS") == null) { IsInitialized = false; } // ReSharper disable ObjectCreationAsStatement //TODO neu implementieren: //new OptionListSelectionAttribute(this, "eltoptionlistdata", xmlElement); // ReSharper restore ObjectCreationAsStatement }
/// <summary> /// Create an empty element of a specific type as child of a content class. Does not insert the element into the contentclass itself, but just provides a vanilla element with an XML node that contains only the "elttype" and the empty "guid" attribute. /// </summary> /// <param name="contentClass"> parent content class of the element </param> /// <param name="elementType"> type of the element </param> /// <returns> </returns> private static ContentClassElement CreateElement(IContentClass contentClass, ElementType elementType) { var doc = new XmlDocument(); XmlElement element = doc.CreateElement("ELEMENT"); XmlAttribute typeAttr = doc.CreateAttribute("elttype"); XmlAttribute guidAttr = doc.CreateAttribute("guid"); typeAttr.Value = ((int)elementType).ToString(CultureInfo.InvariantCulture); guidAttr.Value = new Guid().ToRQLString(); element.Attributes.Append(typeAttr); element.Attributes.Append(guidAttr); return(CreateElement(contentClass, element)); }
private void CopyPreassignedKeywordsToCC(IContentClass targetCC) { try { List <IKeyword> keywordsToAssign = PreassignedKeywords.Select( x => targetCC.Project.Categories.GetByName(x.Category.Name).Keywords.GetByName(x.Name)).ToList(); targetCC.PreassignedKeywords.Set(keywordsToAssign); } catch (Exception e) { throw new SmartAPIException(Session.ServerLogin, string.Format("Could not copy preassigned keywords for content class {0}", Name), e); } }
public IContentClassElement ConvertFrom(IProjectObject parent, XmlElement element, RedDotAttribute attribute) { Guid projectGuid, ccGuid, elementGuid; if (!element.TryGetGuid("eltprojectguid", out projectGuid) || !element.TryGetGuid("elttemplateguid", out ccGuid) || !element.TryGetGuid("eltelementguid", out elementGuid)) { return(null); } string langId = element.GetAttributeValue("eltlanguagevariantid"); IProject project = parent.Session.ServerManager.Projects.GetByGuid(projectGuid); IContentClass contentClass = project.ContentClasses.GetByGuid(ccGuid); return(contentClass.Elements.GetByGuid(elementGuid)); }
private void CopyAttributesToCC(IContentClass targetCC) { var assignment = new AttributeAssignment(); assignment.AssignAllLanguageIndependentRedDotAttributes(EditableAreaSettings, targetCC.EditableAreaSettings); targetCC.EditableAreaSettings.Commit(); targetCC.Refresh(); try { assignment.AssignAllLanguageIndependentRedDotAttributes(this, targetCC); } catch (AttributeChangeException e) { throw new SmartAPIException(Session.ServerLogin, string.Format( "Unable to assign attribute {0} in content class {1} of project {2} to content class {3} of project {4}", e.AttributeName, Name, Project.Name, targetCC.Name, targetCC.Project.Name), e); } targetCC.Commit(); }
/// <summary> /// Copy selected elements from this content class to another target content class. /// </summary> /// <param name="targetCC"> Target content class to copy the elements to </param> /// <param name="elementNames"> Names of the elements to copy </param> public void CopyElementsToContentClass(IContentClass targetCC, params string[] elementNames) { if (elementNames == null || elementNames.Length == 0) { return; } var createdElements = new Dictionary <string, IContentClassElement>(); using (new LanguageContext(Project)) { var assign = new AttributeAssignment(); foreach (var languageVariant in Project.LanguageVariants) { ILanguageVariant targetLanguageVariant = targetCC.Project.LanguageVariants[languageVariant.Abbreviation]; foreach (var curElementName in elementNames) { IContentClassElement curTargetContentClassElement; languageVariant.Select(); var curSourceContentClassElement = Elements[curElementName]; if (createdElements.TryGetValue(curElementName, out curTargetContentClassElement)) { targetLanguageVariant.Select(); assign.AssignAllRedDotAttributesForLanguage(curSourceContentClassElement, curTargetContentClassElement, targetLanguageVariant.Abbreviation); curTargetContentClassElement.CommitInCurrentLanguage(); } else { targetLanguageVariant.Select(); curTargetContentClassElement = curSourceContentClassElement.CopyToContentClass(targetCC); createdElements.Add(curElementName, curTargetContentClassElement); } } } } }
internal Headline(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal HitList(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal PageDefinition(IContentClass contentClass, XmlElement element) : base(contentClass.Project, element) { _contentClass = contentClass; LoadXml(); }
internal ProjectContent(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
/// <summary> /// Create a new page. /// </summary> /// <param name="cc"> Content class of the page </param> /// <param name="headline"> The headline, or null (default) for the default headline </param> /// <returns> The newly created page </returns> public IPage Create(IContentClass cc, string headline = null) { XmlDocument xmlDoc = _project.ExecuteRQL(PageCreationString(cc, headline)); return(CreatePageFromCreationReply(xmlDoc)); }
private void CopyAllElementsToCC(IContentClass targetCC) { CopyElementsToContentClass(targetCC, Elements.Select(element => element.Name).ToArray()); }
/// <summary> /// Copy selected elements from this content class to another target content class. /// </summary> /// <param name="targetCC"> Target content class to copy the elements to </param> /// <param name="elementNames"> Names of the elements to copy </param> public void CopyElementsToContentClass(IContentClass targetCC, params string[] elementNames) { if (elementNames == null || elementNames.Length == 0) { return; } var createdElements = new Dictionary<string, IContentClassElement>(); using (new LanguageContext(Project)) { var assign = new AttributeAssignment(); foreach (var languageVariant in Project.LanguageVariants) { ILanguageVariant targetLanguageVariant = targetCC.Project.LanguageVariants[languageVariant.Abbreviation]; foreach (var curElementName in elementNames) { IContentClassElement curTargetContentClassElement; languageVariant.Select(); var curSourceContentClassElement = Elements[curElementName]; if (createdElements.TryGetValue(curElementName, out curTargetContentClassElement)) { targetLanguageVariant.Select(); assign.AssignAllRedDotAttributesForLanguage(curSourceContentClassElement, curTargetContentClassElement, targetLanguageVariant.Abbreviation); curTargetContentClassElement.CommitInCurrentLanguage(); } else { targetLanguageVariant.Select(); curTargetContentClassElement = curSourceContentClassElement.CopyToContentClass(targetCC); createdElements.Add(curElementName, curTargetContentClassElement); } } } } }
internal Attribute(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal TextAnchor(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal Media(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal StandardFieldNumeric(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal Area(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { PreassignedContentClasses = new PreassignedContentClassesAndPageDefinitions(this); _targetContainerPreassignment = new TargetContainerPreassignment(this); }
protected AbstractWorkflowAssignments(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { _workflowAssignments = new WorkflowAssignments(this); }
private void CopyPreassignedKeywordsToCC(IContentClass targetCC) { try { List<IKeyword> keywordsToAssign = PreassignedKeywords.Select( x => targetCC.Project.Categories.GetByName(x.Category.Name).Keywords.GetByName(x.Name)).ToList(); targetCC.PreassignedKeywords.Set(keywordsToAssign); } catch (Exception e) { throw new SmartAPIException(Session.ServerLogin, string.Format("Could not copy preassigned keywords for content class {0}", Name), e); } }
/// <summary> /// Copies the element to another content class by creating a new element and copying the attribute values to it. /// Make sure to set the language variant in the target project into which the element should be copied, first. /// </summary> /// <param name="contentClass"> target content class, into which the element should be copied </param> /// <returns> the created copy </returns> /// <remarks> /// <list type="bullet"> /// <item> /// <description>Override this method, if you need to set other values than the direct attributes of the element (e.g. setting text values of TextHtml elements)</description> /// </item> /// <item> /// <description> /// The target content class is only modified on the server, thus the content class object does not contain the newly created element. /// If you need an updated version of the content class, you have to retrieve it again with /// <code>new ContentClass(Project, Guid);</code> /// </description> /// </item> /// </list> /// </remarks> public IContentClassElement CopyToContentClass(IContentClass contentClass) { var newContentClassElement = CreateElement(contentClass, Type); var assign = new AttributeAssignment(); assign.AssignAllRedDotAttributesForLanguage(this, newContentClassElement, Project.LanguageVariants.Current.Abbreviation); var node = (XmlElement) newContentClassElement.XmlElement.Clone(); node.Attributes.RemoveNamedItem("guid"); string creationString = GetSaveString(node); // <summary> // RQL for creating an element from a content class. // Two parameters: // 1. Content class guid // 2. Element to create, make sure it contains an attribute "action" with the value "save"! // </summary> const string CREATE_ELEMENT = @"<TEMPLATE guid=""{0}"">{1}</TEMPLATE>"; XmlDocument rqlResult = contentClass.Project.ExecuteRQL(string.Format(CREATE_ELEMENT, contentClass.Guid.ToRQLString(), creationString)); var resultElementNode = (XmlElement) rqlResult.GetElementsByTagName("ELEMENT")[0]; if (resultElementNode == null) { throw new SmartAPIException(Session.ServerLogin, string.Format("Error during creation of element {0}", this)); } newContentClassElement.Guid = resultElementNode.GetGuid(); return newContentClassElement; }
internal ContentClassVersion(IContentClass parent, XmlElement xmlElement) : base(parent.Project, xmlElement) { ContentClass = parent; }
internal DatabaseContent(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { //We need to add eltsrc with sessionkey, because otherwise eltalt won't get stored (setting alt through the smart tree doesn't work for that reason). XmlElement.SetAttributeValue("eltsrc", RQL.SESSIONKEY_PLACEHOLDER); }
internal List(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { _targetContainerPreassignment = new TargetContainerPreassignment(this); PreassignedContentClasses = new PreassignedContentClassesAndPageDefinitions(this); _referencePreassignment = new ReferencePreassignment(this); }
internal Browse(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal StandardFieldURL(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal ImageAnchor(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal PageDefinitions(IContentClass contentClass, Caching caching) : base(caching) { _contentClass = contentClass; RetrieveFunc = GetPageDefinitions; }
protected ContentClassContentElement(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal Frame(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { PreassignedContentClasses = new PreassignedContentClassesAndPageDefinitions(this); }
/// <summary> /// Create an element out of its XML representation (uses the attribute "elttype") to determine the element type and create the appropriate object. /// </summary> /// <param name="contentClass"> parent content class that contains the element </param> /// <param name="xmlElement"> XML representation of the element </param> /// <exception cref="ArgumentException">if the "elttype" attribute of the XML node contains an unknown value</exception> internal static ContentClassElement CreateElement(IContentClass contentClass, XmlElement xmlElement) { var type = (ElementType) int.Parse(xmlElement.GetAttributeValue("elttype")); switch (type) { case ElementType.DatabaseContent: return new DatabaseContent(contentClass, xmlElement); case ElementType.TextHtml: return new TextHtml(contentClass, xmlElement); case ElementType.TextAscii: return new TextAscii(contentClass, xmlElement); case ElementType.StandardFieldText: case ElementType.StandardFieldTextLegacy: return new StandardFieldText(contentClass, xmlElement); case ElementType.StandardFieldNumeric: return new StandardFieldNumeric(contentClass, xmlElement); case ElementType.StandardFieldDate: return new StandardFieldDate(contentClass, xmlElement); case ElementType.StandardFieldTime: return new StandardFieldTime(contentClass, xmlElement); case ElementType.StandardFieldUserDefined: return new StandardFieldUserDefined(contentClass, xmlElement); case ElementType.StandardFieldEmail: return new StandardFieldEmail(contentClass, xmlElement); case ElementType.StandardFieldUrl: return new StandardFieldURL(contentClass, xmlElement); case ElementType.Headline: return new Headline(contentClass, xmlElement); case ElementType.Background: return new Background(contentClass, xmlElement); case ElementType.Image: return new Image(contentClass, xmlElement); case ElementType.Media: return new Media(contentClass, xmlElement); case ElementType.ListEntry: return new ListEntry(contentClass, xmlElement); case ElementType.Transfer: return new Transfer(contentClass, xmlElement); case ElementType.Ivw: return new IVW(contentClass, xmlElement); case ElementType.OptionList: return new OptionList(contentClass, xmlElement); case ElementType.Attribute: return new Attribute(contentClass, xmlElement); case ElementType.Info: return new Info(contentClass, xmlElement); case ElementType.Browse: return new Browse(contentClass, xmlElement); case ElementType.Area: return new Area(contentClass, xmlElement); case ElementType.AnchorAsImage: return new ImageAnchor(contentClass, xmlElement); case ElementType.AnchorAsText: return new TextAnchor(contentClass, xmlElement); case ElementType.Container: return new Container(contentClass, xmlElement); case ElementType.Frame: return new Frame(contentClass, xmlElement); case ElementType.SiteMap: return new SiteMap(contentClass, xmlElement); case ElementType.HitList: return new HitList(contentClass, xmlElement); case ElementType.List: return new List(contentClass, xmlElement); case ElementType.ProjectContent: return new ProjectContent(contentClass, xmlElement); case ElementType.ConditionRedDotLiveOrDeliveryServer: return new DeliveryServerConstraint(contentClass, xmlElement); default: throw new ArgumentException("unknown element type: " + type); } }
protected Text(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
/// <summary> /// Create an empty element of a specific type as child of a content class. Does not insert the element into the contentclass itself, but just provides a vanilla element with an XML node that contains only the "elttype" and the empty "guid" attribute. /// </summary> /// <param name="contentClass"> parent content class of the element </param> /// <param name="elementType"> type of the element </param> /// <returns> </returns> private static ContentClassElement CreateElement(IContentClass contentClass, ElementType elementType) { var doc = new XmlDocument(); XmlElement element = doc.CreateElement("ELEMENT"); XmlAttribute typeAttr = doc.CreateAttribute("elttype"); XmlAttribute guidAttr = doc.CreateAttribute("guid"); typeAttr.Value = ((int) elementType).ToString(CultureInfo.InvariantCulture); guidAttr.Value = new Guid().ToRQLString(); element.Attributes.Append(typeAttr); element.Attributes.Append(guidAttr); return CreateElement(contentClass, element); }
internal DeliveryServerConstraint(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal static IContentClassElement CreateElement(IContentClass contentClass, Guid elementGuid) { var xmlElement = GetRQLRepresentation(contentClass.Project, elementGuid); return CreateElement(contentClass, xmlElement); }
internal StandardFieldEmail(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal ListEntry(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { }
internal TextHtml(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { //TODO checken, ob die werte in editoroptions nicht invertiert enthalten sind }
internal Container(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement) { PreassignedContentClasses = new PreassignedContentClassesAndPageDefinitions(this); _referencePreassignment = new ReferencePreassignment(this); }
public TemplateVariant(IContentClass contentClass, Guid guid) : base(contentClass.Project, guid) { ContentClass = contentClass; }