public void GenerateDefaultTransformation(DefaultTransformationTypeEnum transformCode)
    {
        if (String.IsNullOrEmpty(ClassName))
        {
            ClassName = DataClassInfoProvider.GetClassName(ClassID);
        }

        // Gets Xml schema of the document type
        DataClassInfo dci     = DataClassInfoProvider.GetDataClassInfo(ClassName);
        string        formDef = string.Empty;

        if (dci != null)
        {
            formDef = dci.ClassFormDefinition;
        }

        // Gets transformation type
        TransformationTypeEnum transformType = TransformationInfoProvider.GetTransformationTypeEnum(drpType.SelectedValue);

        // Writes the result to the text box
        if (transformType == TransformationTypeEnum.Html)
        {
            txtCode.Visible         = false;
            tbWysiwyg.Visible       = true;
            tbWysiwyg.ResolvedValue = TransformationInfoProvider.GenerateTransformationCode(formDef, transformType, ClassName, transformCode);
        }
        else
        {
            tbWysiwyg.Visible = false;
            txtCode.Visible   = true;
            txtCode.Text      = TransformationInfoProvider.GenerateTransformationCode(formDef, transformType, ClassName, transformCode);
        }
    }
    private void ProcessTransformations(int classId, string className)
    {
        // Get the transformations
        DataSet transformationsDS = TransformationInfoProvider.GetTransformations(classId);

        if (!DataHelper.DataSourceIsEmpty(transformationsDS))
        {
            foreach (DataRow transformationRow in transformationsDS.Tables[0].Rows)
            {
                // Get the type
                string type = ValidationHelper.GetString(transformationRow["TransformationType"], "ascx");
                TransformationTypeEnum transformationType = TransformationInfoProvider.GetTransformationTypeEnum(type);

                // Only export ASCX transformations
                if (transformationType == TransformationTypeEnum.Ascx)
                {
                    string transformationName = ValidationHelper.GetString(transformationRow["TransformationName"], "");
                    string transformationCode = ValidationHelper.GetString(transformationRow["TransformationCode"], "");

                    int    checkedOutByUserId    = ValidationHelper.GetInteger(transformationRow["TransformationCheckedOutByUserID"], 0);
                    string checkedOutMachineName = ValidationHelper.GetString(transformationRow["TransformationCheckedOutMachineName"], "");

                    if ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower()))
                    {
                        string filename = TransformationInfoProvider.GetTransformationUrl(className + "." + transformationName, null, TransformationTypeEnum.Ascx);

                        // Prepare the code
                        string code = transformationCode;
                        code = TransformationInfoProvider.AddTransformationDirectives(code, true);

                        SiteManagerFunctions.SaveCodeFile(filename, code);
                    }
                }
            }
        }
    }
Example #3
0
    /// <summary>
    /// Saves new or edited transformation of the given name and returns to the transformation list.
    /// </summary>
    /// <returns>True if transformation was succesfully saved</returns>
    private bool SaveTransformation()
    {
        // Sets transformation object's properties
        ti.TransformationName = tbTransformationName.Text;

        DataClassInfo dci = DataClassInfoProvider.GetDataClass(mClassName);

        if (dci != null)
        {
            TransformationTypeEnum transformationType = TransformationInfoProvider.GetTransformationTypeEnum(drpType.SelectedValue);

            ti.TransformationClassID = dci.ClassID;
            ti.TransformationCSS     = txtCSS.Text;

            if (ti.TransformationCheckedOutByUserID <= 0)
            {
                // Save the code
                if ((transformationType != TransformationTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                {
                    ti.TransformationType = transformationType;
                    ti.TransformationCode = (transformationType == TransformationTypeEnum.Html) ? tbWysiwyg.ResolvedValue : txtCode.Text;
                }

                drpType.SelectedValue = ti.TransformationType.ToString();
            }

            TransformationInfoProvider.SetTransformation(ti);

            return(true);
        }
        else
        {
            ShowError(GetString("editedobject.notexists"));
            return(false);
        }
    }
Example #4
0
    protected void drpTransformationType_SelectedIndexChanged(object sender, EventArgs e)
    {
        UpdateDirectives();

        if (ti.TransformationCheckedOutByUserID <= 0)
        {
            // Show checkout info corresponding to selected type
            TransformationTypeEnum type = TransformationInfoProvider.GetTransformationTypeEnum(drpType.SelectedValue);
            string path = Server.MapPath(TransformationInfoProvider.GetTransformationUrl(ti.TransformationFullName, null, type));
            lblCheckOutInfo.Text = string.Format(GetString("Transformation.CheckOutInfo"), path);
        }

        // Get the current code
        string code = "";

        if (txtCode.Visible)
        {
            code = this.txtCode.Text;
        }
        else
        {
            code = this.tbWysiwyg.ResolvedValue;
        }

        switch (drpType.SelectedValue.ToLower())
        {
        case "ascx":
            // Convert to ASCX syntax
            if (string.Equals(drpType.SelectedValue, "ascx", StringComparison.OrdinalIgnoreCase))
            {
                code = MacroResolver.RemoveSecurityParameters(code, false, null);

                code = code.Replace("{% Register", "<%@ Register").Replace("{%", "<%#").Replace("%}", "%>");
            }
            break;

        case "xslt":
            // No transformation
            break;

        default:
            // Convert to macro syntax
            code = code.Replace("<%@", "{%").Replace("<%#", "{%").Replace("<%=", "{%").Replace("<%", "{%").Replace("%>", "%}");
            break;
        }

        // Move the content if necessary
        if (string.Equals(drpType.SelectedValue, "html", StringComparison.OrdinalIgnoreCase))
        {
            // Move from text to WYSIWYG
            if (txtCode.Visible)
            {
                this.tbWysiwyg.ResolvedValue = code;
                this.tbWysiwyg.Visible       = true;

                this.txtCode.Text    = string.Empty;
                this.txtCode.Visible = false;
            }
        }
        else
        {
            // Move from WYSIWYG to text
            if (tbWysiwyg.Visible)
            {
                code = HttpUtility.HtmlDecode(code);

                this.txtCode.Text    = code;
                this.txtCode.Visible = true;

                this.tbWysiwyg.ResolvedValue = string.Empty;
                this.tbWysiwyg.Visible       = false;
            }
            else
            {
                this.txtCode.Text = code;
            }
        }
    }
Example #5
0
    /// <summary>
    /// Generates transformation code depending on the transformation type (Xslt, Ascx).
    /// </summary>
    private void DefaultTransformation()
    {
        if (String.IsNullOrEmpty(mClassName) && UseClassSelector)
        {
            mClassName = DataClassInfoProvider.GetClassName(filter.ClassId);
        }

        // Gets Xml schema of the document type
        DataClassInfo dci     = DataClassInfoProvider.GetDataClass(mClassName);
        string        formDef = string.Empty;

        if (dci != null)
        {
            formDef = dci.ClassFormDefinition;
        }

        // Gets transformation type
        TransformationTypeEnum transformType = TransformationInfoProvider.GetTransformationTypeEnum(drpType.SelectedValue);

        DefaultTransformationTypeEnum transformCode = DefaultTransformationTypeEnum.Default;

        if (transformType == TransformationTypeEnum.Ascx)
        {
            switch (drpTransformationCode.SelectedValue)
            {
            // Atom transformation code
            case "Atom":
                transformCode = DefaultTransformationTypeEnum.Atom;
                break;

            // RSS transformation code
            case "RSS":
                transformCode = DefaultTransformationTypeEnum.RSS;
                break;

            // XML transformation code
            case "XML":
                transformCode = DefaultTransformationTypeEnum.XML;
                break;

            // Default ASCX transformation code
            default:
                transformCode = DefaultTransformationTypeEnum.Default;
                break;
            }
        }

        // Writes the result to the text box
        if (transformType == TransformationTypeEnum.Html)
        {
            txtCode.Visible         = false;
            tbWysiwyg.Visible       = true;
            tbWysiwyg.ResolvedValue = TransformationInfoProvider.GenerateTransformationCode(formDef, transformType, mClassName, transformCode);
        }
        else
        {
            tbWysiwyg.Visible = false;
            txtCode.Visible   = true;
            txtCode.Text      = TransformationInfoProvider.GenerateTransformationCode(formDef, transformType, mClassName, transformCode);
        }
    }