Esempio n. 1
0
        public override bool Equals(object ob)
        {
            if (ob == this)
            {
                return(true);
            }
            if (!(ob is DTDPublic))
            {
                return(false);
            }

            if (!base.Equals(ob))
            {
                return(false);
            }

            DTDPublic other = (DTDPublic)ob;

            if (Pub == null)
            {
                if (other.Pub != null)
                {
                    return(false);
                }
            }
            else
            {
                if (!Pub.Equals(other.Pub))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        protected void ParseNotation()
        {
            Token       token    = Expect(Scanner.IDENTIFIER);
            DTDNotation notation = new DTDNotation(token.Value);

            Dtd.Notations[notation.Name] = notation;
            Dtd.Items.Add(notation);

            token = Expect(Scanner.IDENTIFIER);

            if (token.Value.Equals("SYSTEM"))
            {
                DTDSystem sys = new DTDSystem();
                token = Expect(Scanner.STRING);

                sys.System          = token.Value;
                notation.ExternalId = sys;
            }
            else if (token.Value.Equals("PUBLIC"))
            {
                DTDPublic pub = new DTDPublic();
                token = Expect(Scanner.STRING);

                pub.Pub    = token.Value;
                pub.System = null;

                // For <!NOTATION>, you can have PUBLIC PubidLiteral without
                // a SystemLiteral
                token = Scanner.Peek();
                if (token.Type == Scanner.STRING)
                {
                    token      = Scanner.Get();
                    pub.System = token.Value;
                }

                notation.ExternalId = pub;
            }
            Expect(Scanner.GT);
        }
Esempio n. 3
0
        public static void TestParseDtd(string file, bool writeToLog)
        {
            try
            {
                DTDParser parser = null;
                // MAW Version 1.17
                // If it looks like the filename may be a URL, use the URL class
                if (file.IndexOf("://") > 0)
                {
                    parser = new DTDParser(new Uri(file), true);
                }
                else
                {
                    parser = new DTDParser(file, true);
                }


                // Parse the DTD and ask the parser to guess the root element
                DTD dtd = parser.Parse(true);

                FileStream   ostrm  = null;
                StreamWriter writer = null;
                TextWriter   oldOut = null;

                if (writeToLog)
                {
                    oldOut = Console.Out;
                    ostrm  = new FileStream("./log.txt", FileMode.OpenOrCreate, FileAccess.Write);
                    writer = new StreamWriter(ostrm);
                    Console.SetOut(writer);
                }
                if (dtd.RootElement != null)
                {
                    Console.WriteLine("Root element is probably: " +
                                      dtd.RootElement.Name);
                }

                foreach (DictionaryEntry de in dtd.Elements)
                {
                    DTDElement elem = (DTDElement)de.Value;

                    Console.WriteLine("Element: " + elem.Name);
                    Console.Write("   Content: ");
                    DumpDtdItem(elem.Content);
                    Console.WriteLine();

                    if (elem.Attributes.Count > 0)
                    {
                        Console.WriteLine("   Attributes: ");
                        foreach (DictionaryEntry attr_de in elem.Attributes)
                        {
                            Console.Write("        ");
                            DTDAttribute attr = (DTDAttribute)attr_de.Value;
                            DumpAttribute(attr);
                        }
                        Console.WriteLine();
                    }
                }


                foreach (DictionaryEntry de in dtd.Entities)
                {
                    DTDEntity entity = (DTDEntity)de.Value;

                    if (entity.IsParsed)
                    {
                        Console.Write("Parsed ");
                    }

                    Console.WriteLine("Entity: " + entity.Name);

                    if (entity.Value != null)
                    {
                        Console.WriteLine("    Value: " + entity.Value);
                    }

                    if (entity.ExternalId != null)
                    {
                        if (entity.ExternalId is DTDSystem)
                        {
                            Console.WriteLine("    System: " + entity.ExternalId.System);
                        }
                        else
                        {
                            DTDPublic pub = (DTDPublic)entity.ExternalId;
                            Console.WriteLine("    Public: " + pub.Pub + " " + pub.System);
                        }
                    }

                    if (entity.Ndata != null)
                    {
                        Console.WriteLine("    NDATA " + entity.Ndata);
                    }
                }
                foreach (DictionaryEntry de in dtd.Notations)
                {
                    DTDNotation notation = (DTDNotation)de.Value;

                    Console.WriteLine("Notation: " + notation.Name);

                    if (notation.ExternalId != null)
                    {
                        if (notation.ExternalId is DTDSystem)
                        {
                            Console.WriteLine("    System: " +
                                              notation.ExternalId.System);
                        }
                        else
                        {
                            DTDPublic pub = (DTDPublic)notation.ExternalId;

                            Console.Write("    Public: " +
                                          pub.Pub + " ");
                            if (pub.System != null)
                            {
                                Console.WriteLine(pub.System);
                            }
                            else
                            {
                                Console.WriteLine();
                            }
                        }
                    }
                }
                if (writeToLog)
                {
                    Console.SetOut(oldOut);
                    writer.Close();
                    ostrm.Close();
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc.StackTrace);
                Console.WriteLine(exc.Message);
            }


            Console.WriteLine("Done");
            Console.ReadKey(); //keep the console open
        }
Esempio n. 4
0
        protected void ParseEntityDef(DTDEntity entity)
        {
            Token token = Scanner.Get();

            if (token.Type == Scanner.STRING)
            {
                // Only set the entity value if it hasn't been set yet
                // XML 1.0 spec says that you use the first value of
                // an entity, not the most recent.
                if (entity.Value == null)
                {
                    entity.Value = token.Value;
                }
            }
            else if (token.Type == Scanner.IDENTIFIER)
            {
                if (token.Value.Equals("SYSTEM"))
                {
                    DTDSystem sys = new DTDSystem();
                    token = Expect(Scanner.STRING);

                    sys.System        = token.Value;
                    entity.ExternalId = sys;
                }
                else if (token.Value.Equals("PUBLIC"))
                {
                    DTDPublic pub = new DTDPublic();

                    token             = Expect(Scanner.STRING);
                    pub.Pub           = token.Value;
                    token             = Expect(Scanner.STRING);
                    pub.System        = token.Value;
                    entity.ExternalId = pub;
                }
                else
                {
                    throw new DTDParseException(Scanner.GetUriId(),
                                                "Invalid External ID specification",
                                                Scanner.GetLineNumber(), Scanner.GetColumn());
                }


                // ISSUE: isParsed is set to TRUE if this is a Parameter Entity
                //     Reference (assuming this is because Parameter Entity
                //     external references are parsed, whereas General Entity
                //     external references are irrelevant for this product).
                //     However, NDATA is only valid if this is
                //     a General Entity Reference. So, "if" conditional should
                //     be (!entity.isParsed) rather than (entity.isParsed).
                //
                //Entity Declaration
                // [70] EntityDecl ::= GEDecl | PEDecl
                // [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
                // [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
                // [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
                // [74] PEDef ::= EntityValue | ExternalID
                //External Entity Declaration
                // [75] ExternalID ::= 'SYSTEM' S SystemLiteral
                //          | 'PUBLIC' S PubidLiteral S SystemLiteral
                // [76] NDataDecl ::= S 'NDATA' S Name [ VC: Notation Declared ]

                if (!entity.IsParsed) // CHANGE 1
                {
                    token = Scanner.Peek();
                    if (token.Type == Scanner.IDENTIFIER)
                    {
                        if (!token.Value.Equals("NDATA"))
                        {
                            throw new DTDParseException(Scanner.GetUriId(),
                                                        "Invalid NData declaration",
                                                        Scanner.GetLineNumber(), Scanner.GetColumn());
                        }
                        // CHANGE 2: Add call to scanner.get.
                        //      This gets "NDATA" IDENTIFIER.
                        token = Scanner.Get();
                        // Get the NDATA "Name" IDENTIFIER.
                        token = Expect(Scanner.IDENTIFIER);
                        // Save the ndata value
                        entity.Ndata = token.Value;
                    }
                }
            }
            else
            {
                throw new DTDParseException(Scanner.GetUriId(),
                                            "Invalid entity definition",
                                            Scanner.GetLineNumber(), Scanner.GetColumn());
            }

            Expect(Scanner.GT);
        }