Fixes 27585

[TFS Changeset #70183]
This commit is contained in:
hartvig
2010-06-20 09:31:33 +00:00
parent da6e8105a2
commit ddc8527aea
2 changed files with 51 additions and 9 deletions

View File

@@ -67,6 +67,15 @@ namespace umbraco.cms.businesslogic.web
// (Alex N 20100212)
dtd.AppendLine("<!DOCTYPE root [ ");
dtd.AppendLine(GenerateXmlDocumentType());
dtd.AppendLine("]>");
return dtd.ToString();
}
public static string GenerateXmlDocumentType()
{
StringBuilder dtd = new StringBuilder();
if (UmbracoSettings.UseLegacyXmlSchema)
{
dtd.AppendLine("<!ELEMENT node ANY> <!ATTLIST node id ID #REQUIRED> <!ELEMENT data ANY>");
@@ -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);
}
}

View File

@@ -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("<!ATTLIST {0} id ID #REQUIRED>", 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());