Esempio n. 1
0
            public void Write()
            {
                // delete the file before attempting to write
                if (File.Exists(this.WriteFileName))
                {
                    File.Delete(this.WriteFileName);
                }

                m_Messages += SkinController.FormatMessage(FILE_WRITE, Path.GetFileName(this.WriteFileName), 2, false);
                StreamWriter objStreamWriter = new StreamWriter(this.WriteFileName);

                objStreamWriter.WriteLine(this.Contents);
                objStreamWriter.Flush();
                objStreamWriter.Close();
            }
Esempio n. 2
0
        public string ProcessList(ArrayList FileList, SkinParser ParseOption)
        {
            string FileName;

            // process each file in the list
            foreach (string tempLoopVar_FileName in FileList)
            {
                FileName = tempLoopVar_FileName;

                this.Message += SkinController.FormatMessage(FILE_BEGIN, Path.GetFileName(FileName), 0, false);

                // create a skin file object to aid in processing
                //TODO: Uncomment this:
                SkinFile objSkinFile = new SkinFile(this.SkinRoot, FileName, this.SkinAttributes);

                // choose processing based on type of file
                if (objSkinFile.FileExtension == ".htm")
                {
                    string    skinFileContents = objSkinFile.Contents;
                    ArrayList pathList         = this.PathFactory.HTMLList;
                    // replace paths, process control tokens and convert html to ascx format
                    this.Message += this.PathFactory.Parse(ref skinFileContents, ref pathList, objSkinFile.SkinRootPath, ParseOption);
                    this.Message += this.ControlFactory.Parse(ref skinFileContents, objSkinFile.Attributes);
                    this.Message += objSkinFile.PrependASCXDirectives(this.ControlFactory.Registrations);
                }
                else if (objSkinFile.FileExtension == ".html")
                {
                    string    skinFileContents = objSkinFile.Contents;
                    ArrayList pathList         = this.PathFactory.HTMLList;
                    // replace paths, process control tokens and convert html to ascx format
                    this.Message += this.PathFactory.Parse(ref skinFileContents, ref pathList, objSkinFile.SkinRootPath, ParseOption);
                    this.Message += this.ControlFactory.Parse(ref skinFileContents, objSkinFile.Attributes);
                    this.Message += objSkinFile.PrependASCXDirectives(this.ControlFactory.Registrations);
                }

                objSkinFile.Write();
                this.Message += objSkinFile.Messages;

                this.Message += SkinController.FormatMessage(FILE_END, Path.GetFileName(FileName), 1, false);
            }

            this.Message += SkinController.FormatMessage(FILES_END, this.SkinRoot + " :: " + this.SkinName, 0, false);

            return(this.Message);
        }
Esempio n. 3
0
            /// <summary>
            /// Prepend ascx control directives to file contents.
            /// </summary>
            /// <param name="Registrations">ArrayList of registration directives.</param>
            /// <remarks>
            /// This procedure formats the @Control directive and prepends it and all
            /// registration directives to the file contents.
            /// </remarks>
            public string PrependASCXDirectives(ArrayList Registrations)
            {
                string Messages = "";
                string Prefix   = "";

                // if the skin source is an HTML document, extract the content within the <body> tags
                string strPattern = "<\\s*body[^>]*>(?<skin>.*)<\\s*/\\s*body\\s*>";
                Match  objMatch   = Regex.Match(this.Contents, strPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                if (objMatch.Groups[1].Value != "")
                {
                    this.Contents = objMatch.Groups[1].Value;
                }

                // format and save @Control directive
                if (this.SkinRoot == SkinInfo.RootSkin)
                {
                    //Prefix += "<%@ Control language=\"vb\" CodeBehind=\"~/admin/" + SkinRoot + "/skin.vb\" AutoEventWireup=\"false\" Explicit=\"True\" Inherits=\"DotNetNuke.UI.Skins.Skin\" %>" + Environment.NewLine;
                    Prefix += "<%@ Control language=\"c#\" CodeBehind=\"~/Admin/" + SkinRoot + "/Skin.cs\" AutoEventWireup=\"true\" Inherits=\"DotNetNuke.UI.Skins.Skin\" %>" + Environment.NewLine;
                }
                else if (this.SkinRoot == SkinInfo.RootContainer)
                {
                    //Prefix += "<%@ Control language=\"vb\" CodeBehind=\"~/admin/" + SkinRoot + "/container.vb\" AutoEventWireup=\"false\" Explicit=\"True\" Inherits=\"DotNetNuke.UI.Containers.Container\" %>" + Environment.NewLine;
                    Prefix += "<%@ Control language=\"c#\" CodeBehind=\"~/Admin/" + SkinRoot + "/Container.cs\" AutoEventWireup=\"true\" Inherits=\"DotNetNuke.UI.Containers.Container\" %>" + Environment.NewLine;
                }

                Messages += SkinController.FormatMessage(CONTROL_DIR, HttpUtility.HtmlEncode(Prefix), 2, false);

                // add preformatted Control Registrations
                foreach (string Item in Registrations)
                {
                    Messages += SkinController.FormatMessage(CONTROL_REG, HttpUtility.HtmlEncode(Item), 2, false);
                    Prefix   += Item;
                }

                // update file contents to include ascx header information
                this.Contents = Prefix + this.Contents;

                return(Messages);
            }
Esempio n. 4
0
            /// <summary>
            /// Process regular expression matches.
            /// </summary>
            /// <param name="m">Regular expression match for path information which requires processing.</param>
            /// <returns>Properly formatted path information.</returns>
            /// <remarks>
            /// The handler is invoked by the Regex.Replace method once for each match that
            /// it encounters.  The returned value of the handler is substituted for the
            /// original match.  So the handler properly formats the path information and
            /// returns it in favor of the improperly formatted match.
            /// </remarks>
            private string MatchHandler(Match m)
            {
                string strOldTag = m.Groups["tag"].Value + m.Groups["content"].Value + m.Groups["endtag"].Value;
                string strNewTag = strOldTag;

                switch (this.ParseOption)
                {
                case SkinParser.Localized:

                    // if the tag does not contain the localized path
                    if (strNewTag.IndexOf(this.SkinPath) == -1)
                    {
                        // insert the localized path
                        strNewTag = m.Groups["tag"].Value + this.SkinPath + m.Groups["content"].Value + m.Groups["endtag"].Value;
                    }
                    break;

                case SkinParser.Portable:

                    // if the tag does not contain a reference to the skinpath
                    if (strNewTag.ToLower().IndexOf("<%= skinpath %>") == -1)
                    {
                        // insert the skinpath
                        strNewTag = m.Groups["tag"].Value + "<%= SkinPath %>" + m.Groups["content"].Value + m.Groups["endtag"].Value;
                    }
                    // if the tag contains the localized path
                    if (strNewTag.IndexOf(this.SkinPath) != -1)
                    {
                        // remove the localized path
                        strNewTag = strNewTag.Replace(this.SkinPath, "");
                    }
                    break;
                }

                m_Messages += SkinController.FormatMessage(SUBST, string.Format(SUBST_DETAIL, HttpUtility.HtmlEncode(strOldTag), HttpUtility.HtmlEncode(strNewTag)), 2, false);
                return(strNewTag);
            }
Esempio n. 5
0
        /// <summary>
        /// SkinFileProcessor class constructor.
        /// </summary>
        /// <param name="SkinPath">File path to the portals upload directory.</param>
        /// <param name="SkinRoot">Specifies type of skin (Skins or Containers)</param>
        /// <param name="SkinName">Name of folder in which skin will reside (Zip file name)</param>
        /// <remarks>
        /// The constructor primes the file processor with path information and
        /// control data that should only be retrieved once.  It checks for the
        /// existentce of a skin level attribute file and read it in, if found.
        /// It also sorts through the complete list of controls and creates
        /// a hashtable which contains only the skin objects and their source paths.
        /// These are recognized by their ControlKey's which are formatted like
        /// tokens ("[TOKEN]").  The hashtable is required for speed as it will be
        /// processed for each token found in the source file by the Control Parser.
        /// </remarks>
        public SkinFileProcessor(string SkinPath, string SkinRoot, string SkinName)
        {
            this.Message += SkinController.FormatMessage(INITIALIZE_PROCESSOR, SkinRoot + " :: " + SkinName, 0, false);

            // Save path information for future use
            m_SkinRoot = SkinRoot;
            m_SkinPath = SkinPath;
            m_SkinName = SkinName;

            // Check for and read skin package level attribute information file
            string FileName = this.SkinPath + this.SkinRoot + "\\" + this.SkinName + "\\" + SkinRoot.Substring(0, SkinRoot.Length - 1) + ".xml";

            if (File.Exists(FileName))
            {
                try
                {
                    this.SkinAttributes.Load(FileName);
                    this.Message += SkinController.FormatMessage(PACKAGE_LOAD, Path.GetFileName(FileName), 2, false);
                }
                catch (Exception ex)
                {
                    // could not load XML file
                    this.Message += SkinController.FormatMessage(string.Format(PACKAGE_LOAD_ERROR, ex.Message), Path.GetFileName(FileName), 2, true);
                }
            }

            // Retrieve a list of available controls
            ModuleControlController objModuleControls = new ModuleControlController();
            ArrayList arrModuleControls = objModuleControls.GetModuleControls(Null.NullInteger);

            // Look at every control
            string            Token;
            int               i;
            ModuleControlInfo objModuleControl;

            for (i = 0; i <= arrModuleControls.Count - 1; i++)
            {
                objModuleControl = (ModuleControlInfo)arrModuleControls[i];
                // If the control is a skin object, save the key and source in the hash table
                if (objModuleControl.ControlType == SecurityAccessLevel.SkinObject)
                {
                    Token = objModuleControl.ControlKey.ToUpper();

                    // If the control is already in the hash table
                    if (m_ControlList.ContainsKey(Token))
                    {
                        // Record an error message and skip it
                        this.Message += SkinController.FormatMessage(string.Format(DUPLICATE_ERROR, objModuleControl.ControlKey.ToString().ToUpper()), string.Format(DUPLICATE_DETAIL, ((string)m_ControlList[Token]), objModuleControl.ControlSrc.ToString()), 2, true);
                    }
                    else
                    {
                        // Add it
                        this.Message += SkinController.FormatMessage(string.Format(LOAD_SKIN_TOKEN, objModuleControl.ControlKey.ToString().ToUpper()), objModuleControl.ControlSrc.ToString(), 2, false);
                        m_ControlList.Add(Token, objModuleControl.ControlSrc);
                    }
                }
            }

            // Instantiate the control parser with the list of skin objects
            m_ControlFactory = new ControlParser(m_ControlList);
        }
Esempio n. 6
0
            /// <summary>
            /// SkinFile class constructor.
            /// </summary>
            /// <param name="SkinRoot"></param>
            /// <param name="FileName"></param>
            /// <param name="SkinAttributes"></param>
            /// <remarks>
            /// The constructor primes the utility class with basic file information.
            /// It also checks for the existentce of a skinfile level attribute file
            /// and read it in, if found.
            /// </remarks>
            public SkinFile(string SkinRoot, string FileName, XmlDocument SkinAttributes)
            {
                // capture file information
                m_FileName       = FileName;
                m_FileExtension  = Path.GetExtension(FileName);
                m_SkinRoot       = SkinRoot;
                m_FileAttributes = SkinAttributes;

                // determine and store path to portals skin root folder
                string strTemp = FileName.Replace(Path.GetFileName(FileName), "");

                strTemp        = strTemp.Replace("\\", "/");
                m_SkinRootPath = Globals.ApplicationPath + strTemp.Substring(Strings.InStr(1, strTemp.ToUpper(), "/PORTALS", 0) - 1);

                // read file contents
                this.Contents = Read(FileName);

                // setup some attributes based on file extension
                switch (this.FileExtension)
                {
                case ".htm":
                    // set output file name to <filename>.ASCX
                    m_WriteFileName = FileName.Replace(Path.GetExtension(FileName), ".ascx");
                    // capture warning if file does not contain a id="ContentPane" or [CONTENTPANE]
                    Regex PaneCheck1 = new Regex("\\s*id\\s*=\\s*\"" + Globals.glbDefaultPane + "\"", RegexOptions.IgnoreCase);
                    Regex PaneCheck2 = new Regex("\\s*[" + Globals.glbDefaultPane + "]", RegexOptions.IgnoreCase);
                    if (PaneCheck1.IsMatch(this.Contents) == false && PaneCheck2.IsMatch(this.Contents) == false)
                    {
                        m_Messages += SkinController.FormatMessage(FILE_FORMAT_ERROR, string.Format(FILE_FORMAT_ERROR, FileName), 2, true);
                    }

                    // Check for existence of and load skin file level attribute information
                    if (File.Exists(FileName.Replace(this.FileExtension, ".xml")))
                    {
                        try
                        {
                            m_FileAttributes.Load(FileName.Replace(this.FileExtension, ".xml"));
                            m_Messages += SkinController.FormatMessage(FILE_LOAD, FileName, 2, false);
                        }
                        catch (Exception)      // could not load XML file
                        {
                            m_FileAttributes = SkinAttributes;
                            m_Messages      += SkinController.FormatMessage(FILE_LOAD_ERROR, FileName, 2, true);
                        }
                    }
                    break;

                case ".html":

                    // set output file name to <filename>.ASCX
                    m_WriteFileName = FileName.Replace(Path.GetExtension(FileName), ".ascx");
                    // capture warning if file does not contain a id="ContentPane" or [CONTENTPANE]
                    PaneCheck1 = new Regex("\\s*id\\s*=\\s*\"" + Globals.glbDefaultPane + "\"", RegexOptions.IgnoreCase);
                    PaneCheck2 = new Regex("\\s*[" + Globals.glbDefaultPane + "]", RegexOptions.IgnoreCase);
                    if (PaneCheck1.IsMatch(this.Contents) == false && PaneCheck2.IsMatch(this.Contents) == false)
                    {
                        m_Messages += SkinController.FormatMessage(FILE_FORMAT_ERROR, string.Format(FILE_FORMAT_ERROR, FileName), 2, true);
                    }

                    // Check for existence of and load skin file level attribute information
                    if (File.Exists(FileName.Replace(this.FileExtension, ".xml")))
                    {
                        try
                        {
                            m_FileAttributes.Load(FileName.Replace(this.FileExtension, ".xml"));
                            m_Messages += SkinController.FormatMessage(FILE_LOAD, FileName, 2, false);
                        }
                        catch (Exception)      // could not load XML file
                        {
                            m_FileAttributes = SkinAttributes;
                            m_Messages      += SkinController.FormatMessage(FILE_LOAD_ERROR, FileName, 2, true);
                        }
                    }
                    break;

                default:

                    // output file name is same as input file name
                    m_WriteFileName = FileName;
                    break;
                }
            }
Esempio n. 7
0
            /// <summary>
            /// Process regular expression matches.
            /// </summary>
            /// <param name="m">Regular expression match for token which requires processing.</param>
            /// <returns>Properly formatted token.</returns>
            /// <remarks>
            /// The handler is invoked by the Regex.Replace method once for each match that
            /// it encounters.  The returned value of the handler is substituted for the
            /// original match.  So the handler properly formats the replacement for the
            /// token and returns it instead.  If an unknown token is encountered, the token
            /// is unmodified.  This can happen if a token is used for a skin object which
            /// has not yet been installed.
            /// </remarks>
            private string TokenMatchHandler(Match m)
            {
                string TOKEN_PROC            = Localization.GetString("ProcessToken", Globals.GetPortalSettings());
                string TOKEN_SKIN            = Localization.GetString("SkinToken", Globals.GetPortalSettings());
                string TOKEN_PANE            = Localization.GetString("PaneToken", Globals.GetPortalSettings());
                string TOKEN_FOUND           = Localization.GetString("TokenFound", Globals.GetPortalSettings());
                string TOKEN_FORMAT          = Localization.GetString("TokenFormat", Globals.GetPortalSettings());
                string TOKEN_NOTFOUND_INFILE = Localization.GetString("TokenNotFoundInFile", Globals.GetPortalSettings());
                string CONTROL_FORMAT        = Localization.GetString("ControlFormat", Globals.GetPortalSettings());
                string TOKEN_NOTFOUND        = Localization.GetString("TokenNotFound", Globals.GetPortalSettings());

                string Token       = m.Groups["token"].Value.ToUpper();
                string ControlName = Token + m.Groups["instance"].Value;

                // if the token has an instance name, use it to look for the corresponding attributes
                string AttributeNode = Token + Convert.ToString((m.Groups["instance"].Value == "") ? "" : (":" + m.Groups["instance"].Value));

                this.Messages += SkinController.FormatMessage(TOKEN_PROC, "[" + AttributeNode + "]", 2, false);

                // if the token is a recognized skin control
                if (this.ControlList.ContainsKey(Token) == true || Token.IndexOf("CONTENTPANE") != -1)
                {
                    string SkinControl = "";

                    if (this.ControlList.ContainsKey(Token))
                    {
                        this.Messages += SkinController.FormatMessage(TOKEN_SKIN, ((string)this.ControlList[Token]), 2, false);
                    }
                    else
                    {
                        this.Messages += SkinController.FormatMessage(TOKEN_PANE, Token, 2, false);
                    }

                    // if there is an attribute file
                    if (this.Attributes.DocumentElement != null)
                    {
                        // look for the the node of this instance of the token
                        XmlNode xmlSkinAttributeRoot = this.Attributes.DocumentElement.SelectSingleNode("descendant::Object[Token='[" + AttributeNode + "]']");
                        // if the token is found
                        if (xmlSkinAttributeRoot != null)
                        {
                            this.Messages += SkinController.FormatMessage(TOKEN_FOUND, "[" + AttributeNode + "]", 2, false);
                            // process each token attribute
                            XmlNode xmlSkinAttribute;
                            foreach (XmlNode tempLoopVar_xmlSkinAttribute in xmlSkinAttributeRoot.SelectNodes(".//Settings/Setting"))
                            {
                                xmlSkinAttribute = tempLoopVar_xmlSkinAttribute;
                                if (xmlSkinAttribute.SelectSingleNode("Value").InnerText != "")
                                {
                                    // append the formatted attribute to the inner contents of the control statement
                                    this.Messages += SkinController.FormatMessage(TOKEN_FORMAT, xmlSkinAttribute.SelectSingleNode("Name").InnerText + "=\"" + xmlSkinAttribute.SelectSingleNode("Value").InnerText + "\"", 2, false);
                                    SkinControl   += " " + xmlSkinAttribute.SelectSingleNode("Name").InnerText + "=\"" + xmlSkinAttribute.SelectSingleNode("Value").InnerText.Replace("\"", "&quot;") + "\"";
                                }
                            }
                        }
                        else
                        {
                            this.Messages += SkinController.FormatMessage(TOKEN_NOTFOUND_INFILE, "[" + AttributeNode + "]", 2, false);
                        }
                    }

                    if (this.ControlList.ContainsKey(Token))
                    {
                        // create the skin object user control tag
                        SkinControl = "dnn:" + ControlName + " runat=\"server\" id=\"dnn" + ControlName + "\"" + SkinControl;

                        // Save control registration statement
                        RegisterList.Add("<%@ Register TagPrefix=\"dnn\" TagName=\"" + ControlName + "\" Src=\"~/" + ((string)this.ControlList[Token]) + "\" %>" + "\r\n");

                        // return the control statement
                        this.Messages += SkinController.FormatMessage(CONTROL_FORMAT, "&lt;" + SkinControl + " /&gt;", 2, false);

                        SkinControl = "<" + SkinControl + " />";
                    }
                    else // CONTENTPANE
                    {
                        if (SkinControl.ToLower().IndexOf("id=") == -1)
                        {
                            SkinControl = " id=\"ContentPane\"";
                        }
                        SkinControl = "div runat=\"server\"" + SkinControl + "></div";

                        // return the control statement
                        this.Messages += SkinController.FormatMessage(CONTROL_FORMAT, "&lt;" + SkinControl + "&gt;", 2, false);

                        SkinControl = "<" + SkinControl + ">";
                    }

                    return(SkinControl);
                }
                else
                {
                    // return the unmodified token
                    // note that this is currently protecting array syntax in embedded javascript
                    // should be fixed in the regular expressions but is not, currently.
                    this.Messages += SkinController.FormatMessage(TOKEN_NOTFOUND, "[" + m.Groups["token"].Value + "]", 2, false);
                    return("[" + m.Groups["token"].Value + "]");
                }
            }