Exemplo n.º 1
0
        /// <summary>
        /// Loads the tag and attribute definitions
        /// </summary>
        private static void TryLoadDeclaration(string ext)
        {
            try
            {
                XmlDocument document = null;
                String      path     = Path.Combine(PathHelper.DataDir, "XMLCompletion");
                String      file     = Path.Combine(path, ext + ".xml");
                try
                {
                    if (!File.Exists(file) && !WriteDefaultDeclarations(ext, file))
                    {
                        languageTags[ext] = null;
                        return;
                    }
                    document = new XmlDocument();
                    document.PreserveWhitespace = false;
                    document.Load(file);
                }
                catch (Exception ex)
                {
                    ErrorManager.ShowError(ex);
                    return;
                }
                if (document != null && document.FirstChild.Name == "declarations")
                {
                    bool    toUpper  = (ext == "html" && PluginSettings.UpperCaseHtmlTags);
                    Char[]  coma     = { ',' };
                    XmlNode language = document.FirstChild;
                    Int32   index    = 0;
                    knownTags  = new List <HTMLTag>();
                    namespaces = new List <string>();
                    Dictionary <string, string> groups = new Dictionary <string, string>();
                    XmlNode defs = language.ChildNodes[index];
                    if (defs.Name == "groups")
                    {
                        foreach (XmlNode group in defs.ChildNodes)
                        {
                            if (group.Name == "group")
                            {
                                groups.Add(group.Attributes["id"].Value, group.Attributes["at"].Value);
                            }
                        }
                        index++;
                    }

                    HTMLTag      htag;
                    String       temp; String[] attributes;
                    XmlAttribute isLeaf; XmlAttribute ns;
                    defs = language.ChildNodes[index];
                    if (defs.Name != "tags")
                    {
                        return;
                    }
                    if (defs.Attributes["defaultNS"] == null)
                    {
                        defaultNS = null;
                    }
                    else
                    {
                        defaultNS = defs.Attributes["defaultNS"].Value;
                    }

                    foreach (XmlNode tag in defs.ChildNodes)
                    {
                        if (tag.Name != null && tag.Name.Length > 0 && tag.Name[0] != '#')
                        {
                            isLeaf = tag.Attributes["leaf"];
                            ns     = tag.Attributes["ns"];
                            htag   = new HTMLTag(
                                (toUpper) ? tag.Name.ToUpper() : tag.Name,
                                (ns != null) ? ns.Value : null, isLeaf != null && isLeaf.Value == "yes");
                            if (htag.NS != null && htag.NS.Length > 0 && !namespaces.Contains(htag.NS))
                            {
                                namespaces.Add(htag.NS);
                            }
                            htag.Attributes = new List <string>();
                            temp            = tag.Attributes["at"].Value;
                            if (temp.IndexOf('@') >= 0)
                            {
                                attributes = temp.Split(coma);
                                temp       = "";
                                foreach (String attribute in attributes)
                                {
                                    if (attribute.StartsWith("@"))
                                    {
                                        if (groups.ContainsKey(attribute))
                                        {
                                            temp += "," + groups[attribute];
                                        }
                                        continue;
                                    }
                                    temp += "," + attribute;
                                }
                                temp = temp.Substring(1);
                            }
                            attributes = temp.Split(coma);
                            foreach (String attribute in attributes)
                            {
                                string aname = attribute.Trim();
                                if (aname.Length > 0)
                                {
                                    htag.Attributes.Add(aname);
                                }
                            }
                            htag.Attributes.Sort();
                            knownTags.Add(htag);
                        }
                    }
                    knownTags.Sort();
                    namespaces.Sort();
                    languageTags[ext] = new LanguageDef(knownTags, namespaces, defaultNS);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.ShowError(ex);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Load tags/attributes definitions
		/// </summary>
		static private void LoadDeclarations()
		{
			// HTML tags & attributes
			try
			{
				languageTags = new Hashtable();
				
				XmlDocument document = null;
				string file = Path.GetDirectoryName(Application.ExecutablePath)+"\\Data\\XMLCompletion.xml";
				try
				{
					// create default html definition file
					if (!File.Exists(file)) WriteDefaultDeclarations(file);
					// read definitions
					document = new XmlDocument();
					document.PreserveWhitespace = false;
					document.Load(file);
					// old definitions file
					if (document.FirstChild == null || document.FirstChild.Name != "xmlcompletion")
					{
						if (File.Exists(file+".bak")) File.Delete(file+".bak");
						File.Move(file, file+".bak");
						WriteDefaultDeclarations(file);
						document.Load(file);
					}
				}
				catch (Exception ex)
				{
					ErrorHandler.ShowError("Error while opening file:\n"+file, ex);
					return;
				}
				
				if (document != null && document.FirstChild.Name == "xmlcompletion")
				{
					char[] coma = {','};
					foreach(XmlNode language in document.FirstChild.ChildNodes)
					if (language.Name != null && language.Name.Length > 0 && language.Name[0] != '#')
					{
						knownTags = new ArrayList();
						// groupes d'attributs
						Hashtable groups = new Hashtable();
						int index = 0;
						if (language.ChildNodes[index].Name == "groups")
						{
							foreach(XmlNode group in language.ChildNodes[index].ChildNodes)
							if (group.Name == "group") 
							{
								groups.Add(group.Attributes["id"].Value, group.Attributes["at"].Value);
							}
							index++;
						}
						// tags
						HTMLTag htag;
						string temp;
						string[] attributes;
						XmlAttribute isLeaf;
						XmlAttribute ns;
						foreach(XmlNode tag in language.ChildNodes[index].ChildNodes)
						if (tag.Name != null && tag.Name.Length > 0 && tag.Name[0] != '#')
						{
							isLeaf = tag.Attributes["leaf"];
							ns = tag.Attributes["ns"];
							htag = new HTMLTag(tag.Name, 
							                   (ns != null) ? ns.Value : null, 
							                   isLeaf != null && isLeaf.Value == "yes");
							htag.Attributes = new ArrayList();
							temp = tag.Attributes["at"].Value;
							foreach(string key in groups.Keys)
							{
								temp = temp.Replace(key, groups[key].ToString());
							}
							attributes = temp.Split(coma);
							foreach(string attribute in attributes)
							{
								htag.Attributes.Add(attribute);
							}
							htag.Attributes.Sort();
							knownTags.Add(htag);
						}
						// tri et stockage
						knownTags.Sort();
						languageTags[language.Name] = knownTags;
					}
				}
			}
			catch(Exception ex)
			{
				ErrorHandler.ShowError("Error while reading XML tags definitions.\n"+ex.Message, ex);
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Loads the tag and attribute definitions
        /// </summary>
        private static void TryLoadDeclaration(string ext)
        {
            try
            {
                XmlDocument document = null;
                String path = Path.Combine(PathHelper.DataDir, "XMLCompletion");
                String file = Path.Combine(path, ext + ".xml");
                try
                {
                    if (!File.Exists(file) && !WriteDefaultDeclarations(ext, file))
                    {
                        languageTags[ext] = null;
                        return;
                    }
                    document = new XmlDocument();
                    document.PreserveWhitespace = false;
                    document.Load(file);
                }
                catch (Exception ex)
                {
                    ErrorManager.ShowError(ex);
                    return;
                }
                if (document != null && document.FirstChild.Name == "declarations")
                {
                    bool toUpper = (ext == "html" && PluginSettings.UpperCaseHtmlTags);
                    Char[] coma = {','};
                    XmlNode language = document.FirstChild;
                    Int32 index = 0;
                    knownTags = new List<HTMLTag>();
                    namespaces = new List<string>();
                    Dictionary<string, string> groups = new Dictionary<string, string>();
                    XmlNode defs = language.ChildNodes[index];
                    if (defs.Name == "groups")
                    {
                        foreach(XmlNode group in defs.ChildNodes)
                        if (group.Name == "group") 
                        {
                            groups.Add(group.Attributes["id"].Value, group.Attributes["at"].Value);
                        }
                        index++;
                    }
                    
                    HTMLTag htag;
                    String temp; String[] attributes;
                    XmlAttribute isLeaf; XmlAttribute ns;
                    defs = language.ChildNodes[index];
                    if (defs.Name != "tags") 
                        return;
                    if (defs.Attributes["defaultNS"] == null) defaultNS = null;
                    else defaultNS = defs.Attributes["defaultNS"].Value;

                    foreach(XmlNode tag in defs.ChildNodes)
                    if (!string.IsNullOrEmpty(tag.Name) && tag.Name[0] != '#')
                    {
                        isLeaf = tag.Attributes["leaf"];
                        ns = tag.Attributes["ns"];
                        htag = new HTMLTag(
                            (toUpper) ? tag.Name.ToUpper() : tag.Name, 
                            (ns != null) ? ns.Value : null, isLeaf != null && isLeaf.Value == "yes");
                        if (!string.IsNullOrEmpty(htag.NS) && !namespaces.Contains(htag.NS))
                            namespaces.Add(htag.NS);
                        htag.Attributes = new List<string>();
                        temp = tag.Attributes["at"].Value;
                        if (temp.IndexOf('@') >= 0)
                        {
                            attributes = temp.Split(coma);
                            temp = "";
                            foreach (String attribute in attributes)
                            {
                                if (attribute.StartsWith("@"))
                                {
                                    if (groups.ContainsKey(attribute))
                                        temp += "," + groups[attribute];
                                    continue;
                                }
                                temp += "," + attribute;
                            }
                            temp = temp.Substring(1);
                        }
                        attributes = temp.Split(coma);
                        foreach (String attribute in attributes)
                        {
                            string aname = attribute.Trim();
                            if (aname.Length > 0) htag.Attributes.Add(aname);
                        }
                        htag.Attributes.Sort();
                        knownTags.Add(htag);
                    }
                    knownTags.Sort();
                    namespaces.Sort();
                    languageTags[ext] = new LanguageDef(knownTags, namespaces, defaultNS);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.ShowError(ex);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load tags/attributes definitions
        /// </summary>
        static private void LoadDeclarations()
        {
            // HTML tags & attributes
            try
            {
                languageTags = new Hashtable();

                XmlDocument document = null;
                string      file     = Path.GetDirectoryName(Application.ExecutablePath) + "\\Data\\XMLCompletion.xml";
                try
                {
                    // create default html definition file
                    if (!File.Exists(file))
                    {
                        WriteDefaultDeclarations(file);
                    }
                    // read definitions
                    document = new XmlDocument();
                    document.PreserveWhitespace = false;
                    document.Load(file);
                    // old definitions file
                    if (document.FirstChild == null || document.FirstChild.Name != "xmlcompletion")
                    {
                        if (File.Exists(file + ".bak"))
                        {
                            File.Delete(file + ".bak");
                        }
                        File.Move(file, file + ".bak");
                        WriteDefaultDeclarations(file);
                        document.Load(file);
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler.ShowError("Error while opening file:\n" + file, ex);
                    return;
                }

                if (document != null && document.FirstChild.Name == "xmlcompletion")
                {
                    char[] coma = { ',' };
                    foreach (XmlNode language in document.FirstChild.ChildNodes)
                    {
                        if (language.Name != null && language.Name.Length > 0 && language.Name[0] != '#')
                        {
                            knownTags = new ArrayList();
                            // groupes d'attributs
                            Hashtable groups = new Hashtable();
                            int       index  = 0;
                            if (language.ChildNodes[index].Name == "groups")
                            {
                                foreach (XmlNode group in language.ChildNodes[index].ChildNodes)
                                {
                                    if (group.Name == "group")
                                    {
                                        groups.Add(group.Attributes["id"].Value, group.Attributes["at"].Value);
                                    }
                                }
                                index++;
                            }
                            // tags
                            HTMLTag      htag;
                            string       temp;
                            string[]     attributes;
                            XmlAttribute isLeaf;
                            XmlAttribute ns;
                            foreach (XmlNode tag in language.ChildNodes[index].ChildNodes)
                            {
                                if (tag.Name != null && tag.Name.Length > 0 && tag.Name[0] != '#')
                                {
                                    isLeaf = tag.Attributes["leaf"];
                                    ns     = tag.Attributes["ns"];
                                    htag   = new HTMLTag(tag.Name,
                                                         (ns != null) ? ns.Value : null,
                                                         isLeaf != null && isLeaf.Value == "yes");
                                    htag.Attributes = new ArrayList();
                                    temp            = tag.Attributes["at"].Value;
                                    foreach (string key in groups.Keys)
                                    {
                                        temp = temp.Replace(key, groups[key].ToString());
                                    }
                                    attributes = temp.Split(coma);
                                    foreach (string attribute in attributes)
                                    {
                                        htag.Attributes.Add(attribute);
                                    }
                                    htag.Attributes.Sort();
                                    knownTags.Add(htag);
                                }
                            }
                            // tri et stockage
                            knownTags.Sort();
                            languageTags[language.Name] = knownTags;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.ShowError("Error while reading XML tags definitions.\n" + ex.Message, ex);
            }
        }