Example #1
0
        public void UseDtd(StreamReader dtd)
        {
            DTDParser parser = new DTDParser(dtd);

            m_Dtd = parser.Parse(true);
            ParseDtdIntoHashmap();
        }
        private void initMixedContentXmlElementNamesFromDTD(string dtdUniqueResourceId, Stream dtdStream)
        {
            List <string> list;

            m_listOfMixedContentXmlElementNames.TryGetValue(dtdUniqueResourceId, out list);

            DebugFix.Assert(list != null);

            if (list == null)
            {
                return;
            }

            DTD dtd = null;

            try
            {
                // NOTE: the Stream is automatically closed by the parser, see Scanner.ReadNextChar()
                DTDParser parser = new DTDParser(new StreamReader(dtdStream, Encoding.UTF8));
                dtd = parser.Parse(true);
            }
            catch (Exception ex)
            {
#if DEBUG
                Debugger.Break();
#endif
                dtdStream.Close();
            }

            if (dtd != null)
            {
                foreach (DictionaryEntry entry in dtd.Elements)
                {
                    DTDElement dtdElement = (DTDElement)entry.Value;
                    DTDItem    item       = dtdElement.Content;
                    if (isMixedContent(item))
                    {
                        if (!list.Contains(dtdElement.Name))
                        {
                            list.Add(dtdElement.Name);
                        }
                    }
                }


                foreach (DictionaryEntry entry in dtd.Entities)
                {
                    DTDEntity dtdEntity = (DTDEntity)entry.Value;

                    if (dtdEntity.ExternalId == null)
                    {
                        continue;
                    }

                    string system = dtdEntity.ExternalId.System;
                    if (dtdEntity.ExternalId is DTDPublic)
                    {
                        string pub = ((DTDPublic)dtdEntity.ExternalId).Pub;
                        if (!string.IsNullOrEmpty(pub))
                        {
                            system = pub; //.Replace(" ", "%20");
                        }
                    }

                    string normalisedUri = system.Replace("%20", " ").Replace(" //", "//").Replace("// ", "//");

                    foreach (String key in DTDs.DTDs.ENTITIES_MAPPING.Keys)
                    {
                        if (normalisedUri.Contains(key))
                        {
                            string subResource = DTDs.DTDs.ENTITIES_MAPPING[key];
                            Stream stream      = DTDs.DTDs.Fetch(subResource);

                            if (stream != null)
                            {
                                initMixedContentXmlElementNamesFromDTD(dtdUniqueResourceId, stream);
                            }
                            else
                            {
#if DEBUG
                                Debugger.Break();
#endif
                            }

                            break;
                        }
                    }
                }
            }
        }
 public void RunPlugin(XmlDocument xmlParameters)
 {
   MessageBox.Show("Menü szerkesztő elindult.");
   XmlNodeList nodes = xmlParameters.DocumentElement.GetElementsByTagName("ROFSDIR");
   string xmlmenu;
   if (!System.IO.Directory.Exists(nodes[0].FirstChild.Value))
   {
     MessageBox.Show("A megadott ROFS útvonal érvénytelen!", "HIBA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     return;
   }
   xmlmenu = nodes[0].FirstChild.Value + @"\private\101f4cd2\content\appshelldata.xml";
   string dtdfile = nodes[0].FirstChild.Value + @"\private\101f4cd2\content\";
   //xMenu = new XElement();
   StreamReader rXml = new StreamReader(xmlmenu);
   string xmlcontent = rXml.ReadToEnd();
   Regex reRemoveDTD = new Regex(@"<!DOC[^>]+>");
   xmlcontent = reRemoveDTD.Replace(xmlcontent, "");
   if (Regex.Match(xmlcontent, @"&qtn[^;]+;").Success)
   {
     // Nem kifejtett nemzetközi menü
     DTDParser myParser = new DTDParser(dtdfile);
     xmlcontent = myParser.Parse(xmlcontent);
   }
   xMenu = XElement.Parse(xmlcontent);
   var xFolders = from xItem in xMenu.Elements("appshell:folder")
                  select new
                  {
                    name = (string)xItem.Attribute("short_name").Value
                  };
   foreach (var x in xFolders)
   {
     TreeNode trnFolder = new TreeNode(x.name);
     
   }
 }
Example #4
0
        public DTD UseDtd(string dtdIdentifier)
        {
            string dtdCache = dtdIdentifier + ".cache";

            //check to see if we have a cached version of this file
#if USE_ISOLATED_STORAGE
            Stream stream = null;
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string[] filenames = store.GetFileNames(dtdCache);
                if (filenames.Length > 0)
                {
                    stream = new IsolatedStorageFileStream(dtdCache, FileMode.Open, FileAccess.Read, FileShare.None, store);
                }
            }
            if (stream != null)
            {
                try
                {
                    m_DtdRegex.ReadFromCache(new StreamReader(stream, Encoding.UTF8));
                }
                finally
                {
                    stream.Close();
                }
            }

            // NOTE: we could actually use the same code as below, which gives more control over the subdirectory and doesn't have any size limits:
#else
            string dirpath = Path.Combine(ExternalFilesDataManager.STORAGE_FOLDER_PATH, m_DtdStoreDirName);
            //if (!Directory.Exists(dirpath))
            //{
            //    Directory.CreateDirectory(dirpath);
            //}

            string path = Path.Combine(dirpath, dtdCache);
            if (File.Exists(path))
            {
                Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                try
                {
                    m_DtdRegex.ReadFromCache(new StreamReader(stream, Encoding.UTF8));
                }
                finally
                {
                    stream.Close();
                }

                return(null);
            }
#endif //USE_ISOLATED_STORAGE
            else
            {
                //else read the .dtd file
                Stream dtdStream = DTDs.DTDs.Fetch(dtdIdentifier);
                if (dtdStream == null)
                {
                    //DebugFix.Assert(false);
#if DEBUG
                    Debugger.Break();
#endif // DEBUG
                    MissingDtdValidationError error = new MissingDtdValidationError()
                    {
                        DtdIdentifier = dtdIdentifier
                    };
                    addValidationItem(error);
                    return(null);
                }

                // NOTE: the Stream is automatically closed by the parser, see Scanner.ReadNextChar()
                DTDParser parser = new DTDParser(new StreamReader(dtdStream, Encoding.UTF8));
                DTD       dtd    = parser.Parse(true);

                m_DtdRegex.ParseDtdIntoHashtable(dtd);

                return(dtd);
            }
        }
 public void RunPlugin(XmlDocument xmlParameters)
 {
   CheckMyDirs();
   //MessageBox.Show("Menü szerkesztő elindult.");
   XmlNodeList nodes = xmlParameters.DocumentElement.GetElementsByTagName("ROFSDIR");
   string xmlmenu;
   if (!System.IO.Directory.Exists(nodes[0].FirstChild.Value))
   {
     MessageBox.Show("A megadott ROFS útvonal érvénytelen!", "HIBA!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     return;
   }
   xmlmenu = nodes[0].FirstChild.Value + @"\private\101f4cd2\content\appshelldata.xml";
   string dtdfile = nodes[0].FirstChild.Value + @"\private\101f4cd2\content\";
   //xMenu = new XElement();
   StreamReader rXml = new StreamReader(xmlmenu);
   string xmlcontent = rXml.ReadToEnd();
   Regex reRemoveDTD = new Regex(@"<!DOC[^>]+>");
   xmlcontent = reRemoveDTD.Replace(xmlcontent, "");
   if (Regex.Match(xmlcontent, @"&qtn[^;]+;").Success)
   {
     // Nem kifejtett nemzetközi menü
     DTDParser myParser = new DTDParser(dtdfile);
     xmlcontent = myParser.Parse(xmlcontent);
   }
   xmlcontent = Regex.Replace( xmlcontent, "appshell:", "", RegexOptions.Multiline );
   xMenu = XElement.Parse(xmlcontent);
   TreeNode trn = GenerateNodes( xMenu, null );
   frmEditor.AddMenuFolder( trn );
   frmEditor.MainMenuStrip.Items["mnuSave"].Click += SaveMenu;
   frmEditor.Show();
 }