private void _addStringToHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId, string position)
        {
            bool   hasAspNetContentBeginning = false;
            string design    = "";
            string directive = "";

            if (tmp != null)
            {
                try
                {
                    XmlDocument templateXml = new XmlDocument();
                    templateXml.PreserveWhitespace = true;

                    //Make sure that directive is remove before hacked non html4 compatiple replacement action...
                    design = tmp.Design;


                    splitDesignAndDirective(ref design, ref directive);

                    //making sure that the template xml has a root node...
                    if (tmp.MasterTemplate > 0)
                    {
                        templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "<root>" + design + "</root>", true));
                    }
                    else
                    {
                        templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true));
                    }

                    XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']");

                    if (xmlElement != null)
                    {
                        if (position == "beginning")
                        {
                            xmlElement.InnerXml = "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n" + xmlElement.InnerXml;
                        }
                        else
                        {
                            xmlElement.InnerXml = xmlElement.InnerXml + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n";
                        }
                    }

                    tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false);
                    tmp.Save();
                }
                catch (Exception ex)
                {
                    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString());
                }
            }
            else
            {
                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "template not found");
            }
        }
Beispiel #2
0
        //Helper method to replace umbraco tags that breaks the xml format..
        public static string parseToValidXml(template.Template templateObj, ref bool hasAspNetContentBeginning, string template, bool toValid)
        {
            string retVal = template;

            if (toValid)
            {
                // test for asp:content as the first part of the design
                if (retVal.StartsWith("<asp:content", StringComparison.OrdinalIgnoreCase))
                {
                    hasAspNetContentBeginning = true;
                    retVal = retVal.Substring(retVal.IndexOf(">") + 1);
                    retVal = retVal.Substring(0, retVal.Length - 14);
                }
                //shorten empty macro tags..
                retVal = retVal.Replace("></umbraco:macro>", " />");
                retVal = retVal.Replace("></umbraco:Macro>", " />");

                retVal = retVal.Replace("<umbraco:", "<umbraco__");
                retVal = retVal.Replace("</umbraco:", "</umbraco__");
                retVal = retVal.Replace("<asp:", "<asp__");
                retVal = retVal.Replace("</asp:", "</asp__");

                retVal = retVal.Replace("?UMBRACO_GETITEM", "UMBRACO_GETITEM");
                retVal = retVal.Replace("?UMBRACO_TEMPLATE_LOAD_CHILD", "UMBRACO_TEMPLATE_LOAD_CHILD");
                retVal = retVal.Replace("?UMBRACO_MACRO", "UMBRACO_MACRO");
                retVal = retVal.Replace("?ASPNET_FORM", "ASPNET_FORM");
                retVal = retVal.Replace("?ASPNET_HEAD", "ASPNET_HEAD");
            }
            else
            {
                retVal = retVal.Replace("<umbraco__", "<umbraco:");
                retVal = retVal.Replace("</umbraco__", "</umbraco:");
                retVal = retVal.Replace("<asp__", "<asp:");
                retVal = retVal.Replace("</asp__", "</asp:");
                retVal = retVal.Replace("UMBRACO_GETITEM", "?UMBRACO_GETITEM");
                retVal = retVal.Replace("UMBRACO_TEMPLATE_LOAD_CHILD", "?UMBRACO_TEMPLATE_LOAD_CHILD");
                retVal = retVal.Replace("UMBRACO_MACRO", "?UMBRACO_MACRO");
                retVal = retVal.Replace("ASPNET_FORM", "?ASPNET_FORM");
                retVal = retVal.Replace("ASPNET_HEAD", "?ASPNET_HEAD");
                retVal = retVal.Replace("<root>", "");
                retVal = retVal.Replace("<root xmlns:asp=\"http://microsoft.com\">", "");
                retVal = retVal.Replace("</root>", "");

                // add asp content element
                if (hasAspNetContentBeginning)
                {
                    retVal = templateObj.GetMasterContentElement(templateObj.MasterTemplate) + retVal + "</asp:content>";
                }
            }

            return(retVal);
        }
Beispiel #3
0
        private void _removeStringFromHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId)
        {
            bool   hasAspNetContentBeginning = false;
            string design    = "";
            string directive = "";


            if (tmp != null)
            {
                try
                {
                    XmlDocument templateXml = new XmlDocument();
                    templateXml.PreserveWhitespace = true;

                    //Make sure that directive is remove before hacked non html4 compatiple replacement action...
                    design = tmp.Design;
                    splitDesignAndDirective(ref design, ref directive);

                    //making sure that the template xml has a root node...
                    if (tmp.MasterTemplate > 0)
                    {
                        templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "<root>" + design + "</root>", true));
                    }
                    else
                    {
                        templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true));
                    }

                    XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']");



                    if (xmlElement != null)
                    {
                        string repValue = helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true);
                        xmlElement.InnerXml = xmlElement.InnerXml.Replace(repValue, "");
                    }

                    tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false);
                    tmp.Save();
                }
                catch (Exception ex)
                {
                    LogHelper.Error <addStringToHtmlElement>("An error occurred", ex);
                }
            }
            else
            {
                LogHelper.Debug <addStringToHtmlElement>("template not found");
            }
        }
        /// <summary>
        /// Undoes the addStringToHtml Execute() method, by removing the same string from the same template.
        /// </summary>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="xmlData">The XML data.</param>
        /// <returns></returns>
        public bool Undo(string packageName, XmlNode xmlData)
        {
            string templateAlias = xmlData.Attributes["templateAlias"].Value;
            string htmlElementId = xmlData.Attributes["htmlElementId"].Value;
            string value         = xmlHelper.GetNodeValue(xmlData);

            template.Template tmp = template.Template.GetByAlias(templateAlias);

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                value = tmp.EnsureMasterPageSyntax(value);
            }

            _removeStringFromHtmlElement(tmp, value, templateAlias, htmlElementId);
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Executes the specified package action.
        /// </summary>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="xmlData">The XML data.</param>
        /// <example><code><code>
        ///     <Action runat="install" alias="addStringToHtmlElement" templateAlias="news" htmlElementId="newsSection" position="[beginning/end"><![CDATA[hello world!]]></action>
        /// </code></code></example>
        /// <returns>True if executed successfully</returns>
        public bool Execute(string packageName, XmlNode xmlData)
        {
            string templateAlias = xmlData.Attributes["templateAlias"].Value;
            string htmlElementId = xmlData.Attributes["htmlElementId"].Value;
            string position      = xmlData.Attributes["position"].Value;
            string value         = xmlHelper.GetNodeValue(xmlData);

            template.Template tmp = template.Template.GetByAlias(templateAlias);

            if (UmbracoConfig.For.UmbracoSettings().Templates.UseAspNetMasterPages)
            {
                value = tmp.EnsureMasterPageSyntax(value);
            }

            _addStringToHtmlElement(tmp, value, templateAlias, htmlElementId, position);

            return(true);
        }
        /// <summary>
        /// Executes the specified package action.
        /// </summary>
        /// <param name="packageName">Name of the package.</param>
        /// <param name="xmlData">The XML data.</param>
        /// <example><code><code>
        ///     <Action runat="install" alias="addStringToHtmlElement" templateAlias="news" htmlElementId="newsSection" position="[beginning/end"><![CDATA[hello world!]]></action>
        /// </code></code></example>
        /// <returns>True if executed successfully</returns>
        public bool Execute(string packageName, XmlNode xmlData)
        {
            BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "executing addStringToHtmlElement");

            string templateAlias = xmlData.Attributes["templateAlias"].Value;
            string htmlElementId = xmlData.Attributes["htmlElementId"].Value;
            string position      = xmlData.Attributes["position"].Value;
            string value         = xmlHelper.GetNodeValue(xmlData);

            template.Template tmp = template.Template.GetByAlias(templateAlias);

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                value = tmp.EnsureMasterPageSyntax(value);
            }

            _addStringToHtmlElement(tmp, value, templateAlias, htmlElementId, position);

            return(true);
        }
Beispiel #7
0
        public static void ImportDocumentType(XmlNode n, BusinessLogic.User u, bool ImportStructure)
        {
            DocumentType dt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")));
            if (dt == null)
            {
                dt = DocumentType.MakeNew(u, XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name")));
                dt.Alias = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias"));
            }
            else
            {
                dt.Text = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name"));
            }

            // Info
            dt.IconUrl = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Icon"));
            dt.Thumbnail = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Thumbnail"));
            dt.Description = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Description"));

            // Templates	
            ArrayList templates = new ArrayList();
            foreach (XmlNode tem in n.SelectNodes("Info/AllowedTemplates/Template"))
            {
                template.Template t = template.Template.GetByAlias(XmlHelper.GetNodeValue(tem));
                if (t != null)
                    templates.Add(t);
            }

            try
            {
                template.Template[] at = new template.Template[templates.Count];
                for (int i = 0; i < templates.Count; i++)
                    at[i] = (template.Template)templates[i];
                dt.allowedTemplates = at;
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error handling allowed templates: " + ee.ToString());
            }

            // Default template
            try
            {
                if (XmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate")) != "")
                    dt.DefaultTemplate = template.Template.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate"))).Id;
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning default template: " + ee.ToString());
            }

            // Tabs
            Cms.BusinessLogic.ContentType.TabI[] tabs = dt.getVirtualTabs;
            string tabNames = ";";
            for (int t = 0; t < tabs.Length; t++)
                tabNames += tabs[t].Caption + ";";

            Hashtable ht = new Hashtable();
            foreach (XmlNode t in n.SelectNodes("Tabs/Tab"))
            {
                if (tabNames.IndexOf(";" + XmlHelper.GetNodeValue(t.SelectSingleNode("Caption")) + ";") == -1)
                {
                    ht.Add(int.Parse(XmlHelper.GetNodeValue(t.SelectSingleNode("Id"))),
                        dt.AddVirtualTab(XmlHelper.GetNodeValue(t.SelectSingleNode("Caption"))));
                }
            }


            // Get all tabs in hashtable
            Hashtable tabList = new Hashtable();
            foreach (Cms.BusinessLogic.ContentType.TabI t in dt.getVirtualTabs)
            {
                if (!tabList.ContainsKey(t.Caption))
                    tabList.Add(t.Caption, t.Id);
            }

            // Generic Properties
            datatype.controls.Factory f = new datatype.controls.Factory();
            foreach (XmlNode gp in n.SelectNodes("GenericProperties/GenericProperty"))
            {

                Guid dtId = new Guid(XmlHelper.GetNodeValue(gp.SelectSingleNode("Type")));
                int dfId = 0;
                foreach (datatype.DataTypeDefinition df in datatype.DataTypeDefinition.GetAll())
                    if (df.DataType.Id == dtId)
                    {
                        dfId = df.Id;
                        break;
                    }
                if (dfId != 0)
                {
                    PropertyType pt = dt.getPropertyType(XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    if (pt == null)
                    {
                        dt.AddPropertyType(
                            datatype.DataTypeDefinition.GetDataTypeDefinition(dfId),
                            XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")),
                            XmlHelper.GetNodeValue(gp.SelectSingleNode("Name"))
                            );
                        pt = dt.getPropertyType(XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    }
                    else
                    {
                        pt.DataTypeDefinition = datatype.DataTypeDefinition.GetDataTypeDefinition(dfId);
                        pt.Name = XmlHelper.GetNodeValue(gp.SelectSingleNode("Name"));
                    }

                    pt.Mandatory = bool.Parse(XmlHelper.GetNodeValue(gp.SelectSingleNode("Mandatory")));
                    pt.ValidationRegExp = XmlHelper.GetNodeValue(gp.SelectSingleNode("Validation"));
                    pt.Description = XmlHelper.GetNodeValue(gp.SelectSingleNode("Description"));

                    // tab
                    try
                    {
                        if (tabList.ContainsKey(XmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))))
                            pt.TabId = (int)tabList[XmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))];
                    }
                    catch (Exception ee)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning property to tab: " + ee.ToString());
                    }
                }
            }

            if (ImportStructure)
            {
                if (dt != null)
                {
                    ArrayList allowed = new ArrayList();
                    foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType"))
                    {
                        DocumentType dtt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(structure));
                        if (dtt != null)
                            allowed.Add(dtt.Id);
                    }
                    int[] adt = new int[allowed.Count];
                    for (int i = 0; i < allowed.Count; i++)
                        adt[i] = (int)allowed[i];
                    dt.AllowedChildContentTypeIDs = adt;
                }
            }

            // clear caching
            foreach(DocumentType.TabI t in dt.getVirtualTabs)
                DocumentType.FlushTabCache(t.Id);

        }
Beispiel #8
0
        public static void ImportDocumentType(XmlNode n, BusinessLogic.User u, bool ImportStructure)
        {
            DocumentType dt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")));

            if (dt == null)
            {
                dt       = DocumentType.MakeNew(u, XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name")));
                dt.Alias = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias"));
            }
            else
            {
                dt.Text = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name"));
            }

            // Info
            dt.IconUrl     = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Icon"));
            dt.Thumbnail   = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Thumbnail"));
            dt.Description = XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Description"));

            // Templates
            ArrayList templates = new ArrayList();

            foreach (XmlNode tem in n.SelectNodes("Info/AllowedTemplates/Template"))
            {
                template.Template t = template.Template.GetByAlias(XmlHelper.GetNodeValue(tem));
                if (t != null)
                {
                    templates.Add(t);
                }
            }

            try
            {
                template.Template[] at = new template.Template[templates.Count];
                for (int i = 0; i < templates.Count; i++)
                {
                    at[i] = (template.Template)templates[i];
                }
                dt.allowedTemplates = at;
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error handling allowed templates: " + ee.ToString());
            }

            // Default template
            try
            {
                if (XmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate")) != "")
                {
                    dt.DefaultTemplate = template.Template.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate"))).Id;
                }
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning default template: " + ee.ToString());
            }

            // Tabs
            Cms.BusinessLogic.ContentType.TabI[] tabs = dt.getVirtualTabs;
            string tabNames = ";";

            for (int t = 0; t < tabs.Length; t++)
            {
                tabNames += tabs[t].Caption + ";";
            }

            Hashtable ht = new Hashtable();

            foreach (XmlNode t in n.SelectNodes("Tabs/Tab"))
            {
                if (tabNames.IndexOf(";" + XmlHelper.GetNodeValue(t.SelectSingleNode("Caption")) + ";") == -1)
                {
                    ht.Add(int.Parse(XmlHelper.GetNodeValue(t.SelectSingleNode("Id"))),
                           dt.AddVirtualTab(XmlHelper.GetNodeValue(t.SelectSingleNode("Caption"))));
                }
            }


            // Get all tabs in hashtable
            Hashtable tabList = new Hashtable();

            foreach (Cms.BusinessLogic.ContentType.TabI t in dt.getVirtualTabs)
            {
                if (!tabList.ContainsKey(t.Caption))
                {
                    tabList.Add(t.Caption, t.Id);
                }
            }

            // Generic Properties
            datatype.controls.Factory f = new datatype.controls.Factory();
            foreach (XmlNode gp in n.SelectNodes("GenericProperties/GenericProperty"))
            {
                Guid dtId = new Guid(XmlHelper.GetNodeValue(gp.SelectSingleNode("Type")));
                int  dfId = 0;
                foreach (datatype.DataTypeDefinition df in datatype.DataTypeDefinition.GetAll())
                {
                    if (df.DataType.Id == dtId)
                    {
                        dfId = df.Id;
                        break;
                    }
                }
                if (dfId != 0)
                {
                    PropertyType pt = dt.getPropertyType(XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    if (pt == null)
                    {
                        dt.AddPropertyType(
                            datatype.DataTypeDefinition.GetDataTypeDefinition(dfId),
                            XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")),
                            XmlHelper.GetNodeValue(gp.SelectSingleNode("Name"))
                            );
                        pt = dt.getPropertyType(XmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    }
                    else
                    {
                        pt.DataTypeDefinition = datatype.DataTypeDefinition.GetDataTypeDefinition(dfId);
                        pt.Name = XmlHelper.GetNodeValue(gp.SelectSingleNode("Name"));
                    }

                    pt.Mandatory        = bool.Parse(XmlHelper.GetNodeValue(gp.SelectSingleNode("Mandatory")));
                    pt.ValidationRegExp = XmlHelper.GetNodeValue(gp.SelectSingleNode("Validation"));
                    pt.Description      = XmlHelper.GetNodeValue(gp.SelectSingleNode("Description"));

                    // tab
                    try
                    {
                        if (tabList.ContainsKey(XmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))))
                        {
                            pt.TabId = (int)tabList[XmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))];
                        }
                    }
                    catch (Exception ee)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning property to tab: " + ee.ToString());
                    }
                }
            }

            if (ImportStructure)
            {
                if (dt != null)
                {
                    ArrayList allowed = new ArrayList();
                    foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType"))
                    {
                        DocumentType dtt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(structure));
                        if (dtt != null)
                        {
                            allowed.Add(dtt.Id);
                        }
                    }
                    int[] adt = new int[allowed.Count];
                    for (int i = 0; i < allowed.Count; i++)
                    {
                        adt[i] = (int)allowed[i];
                    }
                    dt.AllowedChildContentTypeIDs = adt;
                }
            }

            // clear caching
            foreach (DocumentType.TabI t in dt.getVirtualTabs)
            {
                DocumentType.FlushTabCache(t.Id);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Invoking this method installs the current package
        /// </summary>
        /// <param Name="tempDir">Temporary folder where the package's content are extracted to</param>
        public void Install(string tempDir)
        {
            callCommands("start");

            // Install macros
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("//macro"))
            {
                Cms.BusinessLogic.macro.Macro m = Cms.BusinessLogic.macro.Macro.MakeNew(XmlHelper.GetNodeValue(n.SelectSingleNode("Name")));
                m.Alias       = XmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
                m.Assembly    = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = XmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));
                try
                {
                    m.UseInEditor = bool.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch
                { }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        Cms.BusinessLogic.macro.MacroProperty.MakeNew(
                            m,
                            bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                            mp.Attributes.GetNamedItem("alias").Value,
                            mp.Attributes.GetNamedItem("Name").Value,
                            new Cms.BusinessLogic.macro.MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                            );
                    }
                    catch (Exception macroPropertyExp)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroPropertyExp.ToString());
                    }
                }
            }

            // Copy files
            string appPath = System.Web.HttpContext.Current.Request.ApplicationPath;

            if (appPath == "/")
            {
                appPath = "";
            }
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("//file"))
            {
                if (!Directory.Exists(HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")))))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath"))));
                }
                File.Copy(tempDir + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("guid")), HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName"))), true);
                File.Delete(tempDir + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
            }


            // Get current user
            BasePages.UmbracoEnsuredPage uep = new Umbraco.BasePages.UmbracoEnsuredPage();
            BusinessLogic.User           u   = uep.ValidatedUser;

            // Add Templates
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Templates/Template"))
            {
                template.Template t = template.Template.MakeNew(XmlHelper.GetNodeValue(n.SelectSingleNode("Name")), u);
                t.Alias  = XmlHelper.GetNodeValue(n.SelectSingleNode("Alias"));
                t.Design = XmlHelper.GetNodeValue(n.SelectSingleNode("Design"));
            }

            // Add master templates
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Templates/Template"))
            {
                string master = XmlHelper.GetNodeValue(n.SelectSingleNode("Master"));
                if (master.Trim() != "")
                {
                    template.Template t = template.Template.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Alias")));
                    template.Template masterTemplate = template.Template.GetByAlias(master);
                    if (masterTemplate != null)
                    {
                        t.MasterTemplate = template.Template.GetByAlias(master).Id;
                    }
                }
            }

            // Add documenttypes

            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("DocumentTypes/DocumentType"))
            {
                ImportDocumentType(n, u, false);
            }

            // Add documenttype structure
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("DocumentTypes/DocumentType"))
            {
                DocumentType dt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")));
                if (dt != null)
                {
                    ArrayList allowed = new ArrayList();
                    foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType"))
                    {
                        DocumentType dtt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(structure));
                        allowed.Add(dtt.Id);
                    }
                    int[] adt = new int[allowed.Count];
                    for (int i = 0; i < allowed.Count; i++)
                    {
                        adt[i] = (int)allowed[i];
                    }
                    dt.AllowedChildContentTypeIDs = adt;
                }
            }

            // Stylesheets
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Stylesheets/Stylesheet"))
            {
                StyleSheet s = StyleSheet.MakeNew(
                    u,
                    XmlHelper.GetNodeValue(n.SelectSingleNode("Name")),
                    XmlHelper.GetNodeValue(n.SelectSingleNode("FileName")),
                    XmlHelper.GetNodeValue(n.SelectSingleNode("Content")));

                foreach (XmlNode prop in n.SelectNodes("Properties/Property"))
                {
                    StylesheetProperty sp = StylesheetProperty.MakeNew(
                        XmlHelper.GetNodeValue(prop.SelectSingleNode("Name")),
                        s,
                        u);
                    sp.Alias = XmlHelper.GetNodeValue(prop.SelectSingleNode("Alias"));
                    sp.value = XmlHelper.GetNodeValue(prop.SelectSingleNode("Value"));
                }
                s.saveCssToFile();
            }

            // Documents
            foreach (XmlElement n in _packageConfig.DocumentElement.SelectNodes("Documents/DocumentSet [@importMode = 'root']/node"))
            {
                Cms.BusinessLogic.web.Document.Import(-1, u, n);
            }

            callCommands("end");
        }
Beispiel #10
0
        public static void ImportDocumentType(XmlNode n, BusinessLogic.User u, bool ImportStructure)
        {
            DocumentType dt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")));
            if (dt == null)
            {
                dt = DocumentType.MakeNew(u, xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name")));
                dt.Alias = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias"));

            
                //Master content type
                DocumentType mdt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Master")));
                if (mdt != null)
                    dt.MasterContentType = mdt.Id;
            }
            else
            {
                dt.Text = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name"));
            }

            
            // Info
            dt.IconUrl = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Icon"));
            dt.Thumbnail = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Thumbnail"));
            dt.Description = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Description"));

            // Templates	
            ArrayList templates = new ArrayList();
            foreach (XmlNode tem in n.SelectNodes("Info/AllowedTemplates/Template"))
            {
                template.Template t = template.Template.GetByAlias(xmlHelper.GetNodeValue(tem));
                if (t != null)
                    templates.Add(t);
            }

            try
            {
                template.Template[] at = new template.Template[templates.Count];
                for (int i = 0; i < templates.Count; i++)
                    at[i] = (template.Template)templates[i];
                dt.allowedTemplates = at;
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error handling allowed templates: " + ee.ToString());
            }

            // Default template
            try
            {
                if (xmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate")) != "")
                    dt.DefaultTemplate = template.Template.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate"))).Id;
            }
            catch (Exception ee)
            {
                BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning default template: " + ee.ToString());
            }

            // Tabs
            cms.businesslogic.ContentType.TabI[] tabs = dt.getVirtualTabs;
            string tabNames = ";";
            for (int t = 0; t < tabs.Length; t++)
                tabNames += tabs[t].Caption + ";";

           

            Hashtable ht = new Hashtable();
            foreach (XmlNode t in n.SelectNodes("Tabs/Tab"))
            {
                if (tabNames.IndexOf(";" + xmlHelper.GetNodeValue(t.SelectSingleNode("Caption")) + ";") == -1)
                {
                    ht.Add(int.Parse(xmlHelper.GetNodeValue(t.SelectSingleNode("Id"))),
                        dt.AddVirtualTab(xmlHelper.GetNodeValue(t.SelectSingleNode("Caption"))));
                }
            }

            dt.ClearVirtualTabs();
            // Get all tabs in hashtable
            Hashtable tabList = new Hashtable();
            foreach (cms.businesslogic.ContentType.TabI t in dt.getVirtualTabs.ToList())
            {
                if (!tabList.ContainsKey(t.Caption))
                    tabList.Add(t.Caption, t.Id);
            }

            // Generic Properties
            datatype.controls.Factory f = new datatype.controls.Factory();
            foreach (XmlNode gp in n.SelectNodes("GenericProperties/GenericProperty"))
            {   
                int dfId = 0;
                Guid dtId = new Guid(xmlHelper.GetNodeValue(gp.SelectSingleNode("Type")));

                if (gp.SelectSingleNode("Definition") != null && !string.IsNullOrEmpty(xmlHelper.GetNodeValue(gp.SelectSingleNode("Definition")))) {
                    Guid dtdId = new Guid(xmlHelper.GetNodeValue(gp.SelectSingleNode("Definition")));
                    if (CMSNode.IsNode(dtdId))
                        dfId = new CMSNode(dtdId).Id;
                } 
                if (dfId == 0) {
                    try {
                        dfId = findDataTypeDefinitionFromType(ref dtId);
                    } catch {
                        throw new Exception(String.Format("Could not find datatype with id {0}.", dtId));
                    }
                }

                // Fix for rich text editor backwards compatibility 
                if (dfId == 0 && dtId == new Guid("a3776494-0574-4d93-b7de-efdfdec6f2d1"))
                {
                    dtId = new Guid("83722133-f80c-4273-bdb6-1befaa04a612");
                    dfId = findDataTypeDefinitionFromType(ref dtId);
                }

                if (dfId != 0)
                {
                    PropertyType pt = dt.getPropertyType(xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    if (pt == null)
                    {
                        dt.AddPropertyType(
                            datatype.DataTypeDefinition.GetDataTypeDefinition(dfId),
                            xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")),
                            xmlHelper.GetNodeValue(gp.SelectSingleNode("Name"))
                            );
                        pt = dt.getPropertyType(xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")));
                    }
                    else
                    {
                        pt.DataTypeDefinition = datatype.DataTypeDefinition.GetDataTypeDefinition(dfId);
                        pt.Name = xmlHelper.GetNodeValue(gp.SelectSingleNode("Name"));
                    }

                    pt.Mandatory = bool.Parse(xmlHelper.GetNodeValue(gp.SelectSingleNode("Mandatory")));
                    pt.ValidationRegExp = xmlHelper.GetNodeValue(gp.SelectSingleNode("Validation"));
                    pt.Description = xmlHelper.GetNodeValue(gp.SelectSingleNode("Description"));

                    // tab
                    try
                    {
                        if (tabList.ContainsKey(xmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))))
                            pt.TabId = (int)tabList[xmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))];
                    }
                    catch (Exception ee)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, u, dt.Id, "Packager: Error assigning property to tab: " + ee.ToString());
                    }
                }
            }

            if (ImportStructure)
            {
                if (dt != null)
                {
                    ArrayList allowed = new ArrayList();
                    foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType"))
                    {
                        DocumentType dtt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(structure));
                        if (dtt != null)
                            allowed.Add(dtt.Id);
                    }
                    int[] adt = new int[allowed.Count];
                    for (int i = 0; i < allowed.Count; i++)
                        adt[i] = (int)allowed[i];
                    dt.AllowedChildContentTypeIDs = adt;
                }
            }

            // clear caching
            foreach (DocumentType.TabI t in dt.getVirtualTabs.ToList())
                DocumentType.FlushTabCache(t.Id, dt.Id);

        }