Ejemplo 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 (!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);
            }
        }
Ejemplo n.º 2
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);
            }
        }