private FictionBook ReadFictionBook(TextReader stream)
        {
            SgmlReader reader = new SgmlReader();
            reader.InputStream = stream;

            if (this.fb2Dtd == null)
            {
                reader.SystemLiteral = options.dtdFile;
                this.fb2Dtd = reader.Dtd;
            }
            else
            {
                reader.Dtd = this.fb2Dtd;
            }

            FictionBook fictionBook = ReadFictionBook(reader);

            if(reader.MarkupErrorsCount > 0)
            {
                fictionBook.ModificationType = ModificationType.Body;
            }

            return fictionBook;
        }
Exemple #2
0
        public bool CanContain(string name, SgmlDtd dtd)
        {
            // return true if this element is allowed to contain the given element.
            if (this.exclusions != null)
            {
                if(this.exclusions.Contains(name))
                {
                    return false;
                }
            }

            if (this.inclusions != null)
            {
                if(this.inclusions.Contains(name))
                {
                    return true;
                }
            }

            return ContentModel.CanContain(name, dtd);
        }
Exemple #3
0
        public static SgmlDtd Parse(Uri baseUri, string name, string pubid, TextReader input, string subset, string proxy, XmlNameTable nt)
        {
            SgmlDtd dtd = new SgmlDtd(name, nt);
            dtd.PushEntity(baseUri, new Entity(dtd.Name, baseUri, input, proxy));

            if (!string.IsNullOrEmpty(subset))
            {
                dtd.PushEntity(baseUri, new Entity(name, subset));
            }

            try
            {
                dtd.Parse();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + dtd.current.Context());
            }
            return dtd;
        }
Exemple #4
0
 public bool CanContain(string name, SgmlDtd dtd)
 {
     if (DeclaredContent != DeclaredContent.Default)
     {
         return false;
     } // empty or text only node.
     return Model.CanContain(name, dtd);
 }
Exemple #5
0
        // Rough approximation - this is really assuming an "Or" group
        public bool CanContain(string name, SgmlDtd dtd)
        {
            //foreach (object obj in this.members)
            //{
            //    if (obj is String)
            //    {
            //        if (obj == (object) name) // XmlNameTable optimization
            //        {
            //            return true;
            //        }
            //    }
            //}

            // Do a simple search of members.
            if (this.symbols.Contains(name))
            {
                return true;
            }

            // didn't find it, so do a more expensive search over child elements
            // that have optional start tags and over child groups.
            foreach (object obj in this.members)
            {
                string symbol = obj as String;

                if (symbol != null)
                {
                    ElementDecl elementDecl = dtd.FindElement(symbol);

                    if (elementDecl != null)
                    {
                        if (elementDecl.StartTagOptional)
                        {
                            // tricky case, the start tag is optional so element may be allowed inside this guy!
                            if (elementDecl.CanContain(name, dtd))
                            {
                                return true;
                            }
                        }
                    }
                }
                else
                {
                    Group group = (Group) obj;
                    if (group.CanContain(name, dtd))
                    {
                        return true;
                    }
                }
            }

            return false;
        }