public override bool controlExists(string controlNameOrPath)
 {
     return(CmsControlUtils.ControlExists(controlNameOrPath));
 }
        private void renderCommand(System.Web.UI.UserControl parentUserControl, string command)
        {
            // command is the full command, such as ##Placeholder(HtmlContent id="1")## or ##RenderContro(_system/PageTitle)##.

            int    parseFrom     = command.IndexOf("(", StringComparison.CurrentCultureIgnoreCase);
            int    parseTo       = command.Length - ")".Length - COMMAND_DELIMITER.Length;
            string rawParameters = "";
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if (command.IndexOf("StartPageBody", StringComparison.CurrentCultureIgnoreCase) < 0 && command.IndexOf("EndPageBody", StringComparison.CurrentCultureIgnoreCase) < 0)
            {
                if (parseFrom < 0 || parseTo < 0)
                {
                    throw new TemplateExecutionException(templateName, "Template statement \"" + command + "\" is not formatted properly.");
                }
                parseFrom += "(".Length;

                rawParameters = command.Substring(parseFrom, (parseTo - parseFrom));

                parameters = tokenizeCommandParameters(rawParameters);
            }

            string langShortCode = "";

            if (currentLangIndex < CmsConfig.Languages.Length)
            {
                langShortCode = CmsConfig.Languages[currentLangIndex].shortCode.ToLower().Trim();
            }

            string langDivId = "lang_" + langShortCode; // note: this divId is used (hard-coded) all over the place!!!

            // -- only output multiple languages if we are in Edit mode
            bool outputMultipleLanguages = (CmsContext.currentEditMode == CmsEditMode.Edit);

            if (outputMultipleLanguages && command.StartsWith(COMMAND_DELIMITER + "StartPageBody", StringComparison.CurrentCultureIgnoreCase))
            {
                // -- if the first StartPageBody, start the form - the same as in StartEditForm.ascx
                if (currentLangIndex == 0)
                {
                    RenderTextToPage(parentUserControl, COMMAND_DELIMITER + "RenderControl(_system/StartEditForm)" + COMMAND_DELIMITER);
                }

                string      cssStyle     = "display: none;";
                CmsLanguage langToRender = CmsConfig.Languages[currentLangIndex];
                // -- default to view the current Language first
                if (langToRender == CmsContext.currentLanguage)
                {
                    cssStyle = "display: block;";
                }

                parentUserControl.Controls.Add(new LiteralControl("<!-- Start Language " + langDivId + " --> "));
                parentUserControl.Controls.Add(new LiteralControl("<div id=\"" + langDivId + "\" class=\"" + langDivId + " PageLanguageBody\" style=\"" + cssStyle + "\">"));
            }
            else if (outputMultipleLanguages && command.StartsWith(COMMAND_DELIMITER + "EndPageBody", StringComparison.CurrentCultureIgnoreCase))
            {
                parentUserControl.Controls.Add(new LiteralControl("</div>"));
                parentUserControl.Controls.Add(new LiteralControl("<!-- End Language " + langDivId + " --> "));
                currentLangIndex++; // increment to the next language
                if (currentLangIndex < CmsConfig.Languages.Length)
                {
                    string pageBody = getPageBodyText();
                    RenderTextToPage(parentUserControl, pageBody);
                }
                else
                {
                    // -- the last EndPageBody, so close the edit form using the EndEditForm control
                    RenderTextToPage(parentUserControl, COMMAND_DELIMITER + "RenderControl(_system/EndEditForm)" + COMMAND_DELIMITER);
                }
            }
            else if (command.StartsWith(COMMAND_DELIMITER + "PlaceholderRegion", StringComparison.CurrentCultureIgnoreCase))
            {
                if (!parameters.ContainsKey("##commandname##"))
                {
                    throw new TemplateExecutionException(templateName, "Template statement \"" + command + "\" must have at least one parameter!");
                }

                string regionName = parameters["##commandname##"];

                string regionCommands = getTemplatePlaceholderRegionText(regionName);
                RenderTextToPage(parentUserControl, regionCommands);
            }
            else if (command.StartsWith(COMMAND_DELIMITER + "placeholder", StringComparison.CurrentCultureIgnoreCase))
            {
                // AddControlToPage(new LiteralControl("placeholder: " + rawParameters));

                if (!parameters.ContainsKey("##commandname##"))
                {
                    throw new TemplateExecutionException(templateName, "Template statement \"" + command + "\" must have at least one parameter!");
                }

                string placeholderName = parameters["##commandname##"];
                if (!parameters.ContainsKey("id"))
                {
                    throw new TemplateExecutionException(templateName, "The placeholder statement must have an id attribute (\"" + command + "\").");
                }

                int identifier = -1;
                try
                {
                    identifier = Convert.ToInt32(parameters["id"]);
                }
                catch
                {
                    throw new TemplateExecutionException(templateName, "The placeholder statement must have an integer id attribute (\"" + command + "\").");
                }


                // do not output if:
                //  1) we are making a printer friendly version, and the placeholder has its printer friendly parameter name set to false.
                //  2) we are making an offline version, and the placeholder has its offline version parameter name set to false.
                bool doNotOutput = (
                    /* print friendly version: */
                    (CmsContext.currentUserIsRequestingPrintFriendlyVersion &&
                     parameters.ContainsKey(PRINTER_FRIENDLY_VERSION_OUTPUT_CONTROL_PARAMETERNAME) &&
                     String.Compare(parameters[PRINTER_FRIENDLY_VERSION_OUTPUT_CONTROL_PARAMETERNAME], "false", true) == 0) ||
                    /* offline version: */
                    (CmsContext.currentUserIsRequestingPrintFriendlyVersion &&
                     parameters.ContainsKey(OFFLINE_VERSION_OUTPUT_CONTROL_PARAMETERNAME) &&
                     String.Compare(parameters[OFFLINE_VERSION_OUTPUT_CONTROL_PARAMETERNAME], "false", true) == 0));

                if (!doNotOutput)
                {
                    // params[0] contains the rawParameters
                    string[] subParamsArray = new string[] { rawParameters };

                    System.Text.StringBuilder sb     = new System.Text.StringBuilder();
                    HtmlTextWriter            writer = new HtmlTextWriter(new StringWriter(sb));

                    CmsLanguage langToRender = CmsConfig.Languages[currentLangIndex]; // the currentLangIndex is incremented when the EndPageBody statement is found in the template
                    // dynamically load the Placeholder class and call its Render method
                    switch (CmsContext.currentEditMode)
                    {
                    case CmsEditMode.Edit:
                        PlaceholderUtils.RenderInEditMode(placeholderName, writer, page, identifier, langToRender, subParamsArray, templateName);
                        break;

                    case CmsEditMode.View:
                        PlaceholderUtils.RenderInViewMode(placeholderName, writer, page, identifier, langToRender, subParamsArray, templateName);
                        break;
                    }


                    string txt = sb.ToString();

                    // -- Run Placeholder Filters
                    txt = CmsOutputFilterUtils.RunPlaceholderFilters(placeholderName, page, txt);

                    LiteralControl literal = new LiteralControl(txt);
                    parentUserControl.Controls.Add(literal);
                }
            }
            else if (command.StartsWith(COMMAND_DELIMITER + "rendercontrol", StringComparison.CurrentCultureIgnoreCase))
            {
                if (!parameters.ContainsKey("##commandname##"))
                {
                    throw new TemplateExecutionException(templateName, "Template statement \"" + command + "\" must have at least one parameter!");
                }

                string controlNameOrPath = parameters["##commandname##"];
                // -- try to dynamically load the control onto the page from the ASCX file.
                //    if the ASCX file is not found, we try to load the control as a class. If that fails, throw an Exception

                if (CmsControlUtils.ControlExists(controlNameOrPath))
                {
                    // do not output if:
                    //  1) we are making a printer friendly version, and the control has its printer friendly parameter name set to false.
                    //  2) we are making an offline version, and the control has its offline version parameter name set to false.
                    bool doNotOutput = (
                        /* print friendly version: */
                        (CmsContext.currentUserIsRequestingPrintFriendlyVersion &&
                         parameters.ContainsKey(PRINTER_FRIENDLY_VERSION_OUTPUT_CONTROL_PARAMETERNAME) &&
                         String.Compare(parameters[PRINTER_FRIENDLY_VERSION_OUTPUT_CONTROL_PARAMETERNAME], "false", true) == 0) ||
                        /* offline version: */
                        (CmsContext.currentUserIsRequestingPrintFriendlyVersion &&
                         parameters.ContainsKey(OFFLINE_VERSION_OUTPUT_CONTROL_PARAMETERNAME) &&
                         String.Compare(parameters[OFFLINE_VERSION_OUTPUT_CONTROL_PARAMETERNAME], "false", true) == 0));


                    if (!doNotOutput)
                    {
                        int langIndex = currentLangIndex;
                        if (langIndex >= CmsConfig.Languages.Length)
                        {
                            langIndex = 0;
                        }
                        CmsLanguage          langToRender = CmsConfig.Languages[langIndex]; // the currentLangIndex is incremented when the EndPageBody statement is found in the template
                        CmsControlDefinition controlDef   = new CmsControlDefinition(controlNameOrPath, rawParameters);
                        CmsControlUtils.AddControlToPage(controlNameOrPath, controlDef, parentUserControl, langToRender);
                    }
                }
                else
                {
                    string ControlNotFoundMessage = "Could not find or load Control: \"" + controlNameOrPath + "\"";
                    throw new TemplateExecutionException(templateName, ControlNotFoundMessage);
                }
            } // renderRonctol
        }