Пример #1
0
        public void UseDtd(StreamReader dtd)
        {
            DTDParser parser = new DTDParser(dtd);

            m_Dtd = parser.Parse(true);
            ParseDtdIntoHashmap();
        }
Пример #2
0
        public void Attach(XmlDocument doc, Uri baseUri)
        {
            Detach();
            this.document = doc;
            if (doc.DocumentType == null)
            {
                return;
            }

            DTDParser dtp = new DTDParser();

            bool hasInternalSubset  = doc.DocumentType.InternalSubset != null;
            bool internalSubsetOnly = doc.DocumentType.SystemId == null;

            if (baseUri == null && !doc.BaseURI.Equals(""))
            {
                baseUri = new Uri(doc.BaseURI);
            }

            // TODO: H: shouldn't this use the doc's resolver?
            CustomXmlResolver cxr = new CustomXmlResolver(baseUri);

            dtp.XmlResolver = cxr;

            if (hasInternalSubset)
            {
                InputSource ii = new InputSource(doc.DocumentType.InternalSubset);
                documentType = dtp.parseInternalSubset(ii, internalSubsetOnly);
            }

            if (!internalSubsetOnly)
            {
                Uri         doctypeUri = cxr.ResolveUri(baseUri, doc.DocumentType.SystemId);
                InputSource i          = new InputSource(doctypeUri);
                if (hasInternalSubset)
                {
                    documentType = dtp.parseExternalSubset(i);
                }
                else
                {
                    documentType = dtp.parseExternalSubset(i, true);
                }
            }

            validationEngine = new ValidationEngine(documentType, this);
            quickFixer       = new QuickFixer(documentType);

            GetAllIdAndIdRefs();
            ValidateAllIdAndIdRefs();

            document.NodeChanging += new XmlNodeChangedEventHandler(NodeChanging);
            document.NodeChanged  += new XmlNodeChangedEventHandler(NodeChanged);
            document.NodeInserted += new XmlNodeChangedEventHandler(NodeInserted);
            document.NodeRemoved  += new XmlNodeChangedEventHandler(NodeRemoved);
        }
Пример #3
0
        public static ElementInfo[] GetAllElements(Uri dtdUri)
        {
            DTDParser    p   = new DTDParser();
            InputSource  ins = new InputSource(dtdUri, dtdUri.AbsoluteUri);
            DocumentType t   = p.parseExternalSubset(ins, true);

            ElementInfo[] ret = new ElementInfo[t.ElementTypes.Length];
            int           n   = 0;

            foreach (ElementType et in t.ElementTypes)
            {
                ret[n].LocalName     = et.Name.LocalName;
                ret[n].IsRootElement = et.IsRootElement;
                n++;
            }

            return(ret);
        }
        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);
     
   }
 }
Пример #6
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();
 }