internal void CreateNewWorkspace() { try { var state = WizardState; var newName = state.WorkspaceNewName; var sourceNodePath = state.SelectedWorkspacePath; var targetNode = PortalContext.Current.ContextNodeHead ?? NodeHead.Get(TargetPath); var sourceNode = Node.LoadNode(sourceNodePath); var contentTypeName = sourceNode.Name; Content workspace = null; workspace = ContentTemplate.HasTemplate(contentTypeName) ? ContentTemplate.CreateTemplated(Node.LoadNode(targetNode.Id), ContentTemplate.GetTemplate(contentTypeName), newName) : Content.CreateNew(contentTypeName, Node.LoadNode(targetNode.Id), newName); workspace.Fields["Description"].SetData(state.WorkspaceNewDescription); workspace.Save(); var newPath = new StringBuilder(PortalContext.Current.OriginalUri.GetLeftPart(UriPartial.Authority)).Append(targetNode.Path).Append("/").Append(newName); NewWorkspaceLink.HRef = newPath.ToString(); } catch (Exception exc) //logged { Logger.WriteException(exc); HasError = true; ErrorMessageControl.Visible = true; ErrorMessageControl.Text = exc.Message; // log exception } }
protected static Content CreateContentInternal(string contentTypeName, string contentName, string parentPath) { if (string.IsNullOrEmpty(contentTypeName)) { throw new ArgumentNullException(nameof(contentTypeName)); } if (string.IsNullOrEmpty(parentPath)) { throw new ArgumentNullException(nameof(parentPath)); } var parentNode = Node.LoadNode(parentPath); if (parentNode == null) { throw new ApplicationException($"Cannot create new content: invalid parent ({parentPath})"); } if (string.IsNullOrEmpty(contentName)) { contentName = contentTypeName; } var contentType = ContentType.GetByName(contentTypeName); if (contentType == null) { // full template path is given as content type name return(ContentTemplate.CreateTemplated(parentNode.Path, contentTypeName)); } return(Content.CreateNew(contentTypeName, parentNode, contentName)); }
private void AddSelectedNewContentView(string selectedContentTypeName) { var placeHolder = _currentUserControl.FindControl("ContentViewPlaceHolder") as PlaceHolder; if (placeHolder == null) { return; } var currentContextNode = GetContextNode(); if (_currentContent != null) { _contentView = GetContentView(_currentContent); // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons _contentView.UserAction += NewContentViewUserAction; placeHolder.Visible = true; placeHolder.Controls.Clear(); placeHolder.Controls.Add(_contentView); return; } if (String.IsNullOrEmpty(selectedContentTypeName)) { selectedContentTypeName = SelectedContentType; } Content newContent = null; var ctd = ContentType.GetByName(selectedContentTypeName); if (ctd == null) { // // In this case, the selectedContentTypeName contains only the templatePath. It is maybe a security issue because path is rendered into value attribute of html option tag. // string parentPath = currentContextNode.Path; string templatePath = selectedContentTypeName; newContent = ContentTemplate.CreateTemplated(parentPath, templatePath); _contentView = GetContentView(newContent); } else { // // Yes it is a valid contentTypeName // newContent = ContentManager.CreateContentFromRequest(selectedContentTypeName, null, currentContextNode.Path, true); _contentView = GetContentView(newContent); } // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons _contentView.UserAction += NewContentViewUserAction; placeHolder.Visible = true; placeHolder.Controls.Clear(); placeHolder.Controls.Add(_contentView); }
public static Content CreateContentFromRequest(string contentTypeName, string contentName, string parentPath, bool templated) { // TODO: templated parameter has become unused. Node parentNode; if (String.IsNullOrEmpty(contentTypeName ?? (contentTypeName = GetContentTypeNameFromRequest()))) { return(null); } if (String.IsNullOrEmpty(parentPath ?? (parentPath = GetRequestParameter("ParentPath")))) { parentNode = PortalContext.Current.ContextNode; } else { parentNode = Node.LoadNode(parentPath); } if (parentNode == null) { throw new ApplicationException("Cannot create a new Content: invalid parent"); } if (String.IsNullOrEmpty(contentName ?? (contentName = GetRequestParameter("ContentName")))) { contentName = contentTypeName; } var fieldData = RecognizeFieldParameters(contentTypeName); var contentType = ContentType.GetByName(contentTypeName); if (contentType == null) { // full template path is given as content type name if (fieldData.Count == 0) { return(ContentTemplate.CreateTemplated(parentNode.Path, contentTypeName)); } else { var template = Node.LoadNode(contentTypeName); if (template != null) { return(ContentTemplate.CreateTemplatedAndParse(parentNode, template, template.Name, fieldData)); } } } return(Content.CreateNewAndParse(contentTypeName, parentNode, contentName, fieldData)); }
public void ContentTemplate_UpdateReferences() { CreateTemplateWithLocalReferences(); var newContent = ContentTemplate.CreateTemplated(TestRoot, TestWorkspaceTemplate, "WsWithLocalReferences"); newContent.Save(); var g2 = Node.Load <Group>(RepositoryPath.Combine(newContent.Path, "Groups/g2")); var g1 = g2.Members.First() as Group; Assert.IsTrue(g1 != null && g1.InTree(newContent.ContentHandler), "Referenced group is not in the newly created subtree."); Assert.IsTrue(g1.Name == "g1", "Name of referenced group is not correct."); Assert.IsTrue(g2.Members.Count() == 1, "Members property contains too many nodes."); }
public ActionResult CreateContent(string node, string contentName, string contentType, string templateName, string back) { AssertPermission(); node = HttpUtility.UrlDecode(node); contentName = HttpUtility.UrlDecode(contentName); contentType = HttpUtility.UrlDecode(contentType); templateName = HttpUtility.UrlDecode(templateName); back = HttpUtility.UrlDecode(back); if (string.IsNullOrEmpty(contentName)) { contentName = !string.IsNullOrEmpty(templateName) ? templateName : contentType; } var parent = Node.LoadNode(node); if (parent == null) { return(this.Redirect(back)); } //var template = SNCR.ContentTemplateResolver.Instance.GetNamedTemplate(contentType, templateName); var template = ContentTemplate.GetNamedTemplate(contentType, templateName); SNCR.Content newContent = null; if (template != null) { newContent = ContentTemplate.CreateTemplated(parent, template, contentName); } //else // SNCR.Content.CreateNew(contentType, parent, contentName, null); try { if (newContent != null) { newContent.Save(); } } catch (Exception ex) { Logger.WriteException(ex); } return(this.Redirect(back)); }
public ActionResult CreateContentByTemplate(string node, string contentName, string templatePath, string back) { AssertPermission(); node = HttpUtility.UrlDecode(node); contentName = HttpUtility.UrlDecode(contentName); templatePath = HttpUtility.UrlDecode(templatePath); back = HttpUtility.UrlDecode(back); var parent = string.IsNullOrEmpty(node) ? null : Node.LoadNode(node); if (parent == null) { return(this.Redirect(back)); } var template = string.IsNullOrEmpty(templatePath) ? null : Node.LoadNode(templatePath); if (template == null) { return(this.Redirect(back)); } if (string.IsNullOrEmpty(contentName)) { contentName = template.Name; } try { var newContent = ContentTemplate.CreateTemplated(parent, template, contentName); newContent.Save(); } catch (Exception ex) { Logger.WriteException(ex); } return(this.Redirect(back)); }
private void StartWorkflow(WorkflowHandlerBase wfTemplate, Node currentNode) { var list = (ContentList)currentNode.LoadContentList(); var targetFolder = list.GetWorkflowContainer(); // Node.LoadNode(targetFolderPath); var wfInstance = (WorkflowHandlerBase)ContentTemplate.CreateTemplated(targetFolder, wfTemplate, wfTemplate.Name).ContentHandler; wfInstance.RelatedContent = currentNode; if (!ValidateWorkflow(wfInstance, currentNode)) { wfInstance.Save(); return; } wfInstance["OwnerSiteUrl"] = PortalContext.Current.RequestedUri.GetLeftPart(UriPartial.Authority); using (new SystemAccount()) { // We need to save the wf instance before the engine starts it to have everything persisted to the repo. // Please do not remove this line. wfInstance.Save(); } InstanceManager.Start(wfInstance); }