From ddc8527aead2d6cd2c1da0e542602b63120cc973 Mon Sep 17 00:00:00 2001 From: hartvig Date: Sun, 20 Jun 2010 09:31:33 +0000 Subject: [PATCH] Fixes 27585 [TFS Changeset #70183] --- umbraco/cms/businesslogic/web/DocumentType.cs | 24 +++++++++---- umbraco/presentation/content.cs | 36 +++++++++++++++++-- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/umbraco/cms/businesslogic/web/DocumentType.cs b/umbraco/cms/businesslogic/web/DocumentType.cs index c9650e8bed..c37eabaa6f 100644 --- a/umbraco/cms/businesslogic/web/DocumentType.cs +++ b/umbraco/cms/businesslogic/web/DocumentType.cs @@ -67,6 +67,15 @@ namespace umbraco.cms.businesslogic.web // (Alex N 20100212) dtd.AppendLine(""); + + return dtd.ToString(); + } + + public static string GenerateXmlDocumentType() + { + StringBuilder dtd = new StringBuilder(); if (UmbracoSettings.UseLegacyXmlSchema) { dtd.AppendLine(" "); @@ -101,9 +110,8 @@ namespace umbraco.cms.businesslogic.web } } - dtd.AppendLine("]>"); - return dtd.ToString(); + } public new static DocumentType GetByAlias(string Alias) @@ -253,15 +261,17 @@ namespace umbraco.cms.businesslogic.web public void RemoveTemplate(int templateId) { // remove if default template - if (this.DefaultTemplate == templateId) { + if (this.DefaultTemplate == templateId) + { RemoveDefaultTemplate(); } // remove from list of document type templates - if (_templateIds.Contains(templateId)) { - SqlHelper.ExecuteNonQuery("delete from cmsDocumentType where contentTypeNodeId = @id and templateNodeId = @templateId", - SqlHelper.CreateParameter("@id", this.Id), SqlHelper.CreateParameter("@templateId", templateId) - ); + if (_templateIds.Contains(templateId)) + { + SqlHelper.ExecuteNonQuery("delete from cmsDocumentType where contentTypeNodeId = @id and templateNodeId = @templateId", + SqlHelper.CreateParameter("@id", this.Id), SqlHelper.CreateParameter("@templateId", templateId) + ); _templateIds.Remove(templateId); } } diff --git a/umbraco/presentation/content.cs b/umbraco/presentation/content.cs index 3480e85c9b..31901c973e 100644 --- a/umbraco/presentation/content.cs +++ b/umbraco/presentation/content.cs @@ -200,7 +200,35 @@ namespace umbraco get { return Application.SqlHelper; } } - + protected static void ReGenerateSchema(XmlDocument xmlDoc) + { + string dtd = DocumentType.GenerateXmlDocumentType(); + + // remove current doctype + XmlNode n = xmlDoc.FirstChild; + while (n.NodeType != XmlNodeType.DocumentType && n.NextSibling != null) + { + n = n.NextSibling; + } + if (n.NodeType == XmlNodeType.DocumentType) + { + xmlDoc.RemoveChild(n); + } + XmlDocumentType docType = xmlDoc.CreateDocumentType("root", null, null, dtd); + xmlDoc.InsertAfter(docType, xmlDoc.FirstChild); + + } + + protected static void ValidateSchema(string docTypeAlias, XmlDocument xmlDoc) + { + // if doctype is not defined i)n schema, then regenerate it + if (!xmlDoc.DocumentType.InternalSubset.Contains(String.Format("", docTypeAlias))) + { + // we need to re-load the content, else the dtd changes won't be picked up by the XmlDocument + content.Instance.XmlContentInternal = content.Instance.LoadContentFromDatabase(); + } + } + #region Public Methods @@ -276,7 +304,11 @@ namespace umbraco public static void AppendDocumentXml(int id, int level, int parentId, XmlNode docXml, XmlDocument xmlContentCopy) { - + // Validate schema (that a definition of the current document type exists in the DTD + if (!UmbracoSettings.UseLegacyXmlSchema) + { + ValidateSchema(docXml.Name, xmlContentCopy); + } // Find the document in the xml cache XmlNode x = xmlContentCopy.GetElementById(id.ToString());