public void Add(string name, DTDEntityDeclaration decl)
 {
     if (base.Contains(name))
     {
         throw new InvalidOperationException(string.Format("Entity declaration for {0} was already added.", name));
     }
     decl.SetRoot(base.Root);
     base.BaseAdd(name, decl);
 }
        internal string GenerateEntityAttributeText(string entityName)
        {
            DTDEntityDeclaration entity = EntityDecls [entityName] as DTDEntityDeclaration;

            if (entity == null)
            {
                return(null);
            }
            return(entity.EntityValue);
        }
Example #3
0
        internal string GenerateEntityAttributeText(string entityName)
        {
            DTDEntityDeclaration dtdentityDeclaration = this.EntityDecls[entityName];

            if (dtdentityDeclaration == null)
            {
                return(null);
            }
            return(dtdentityDeclaration.EntityValue);
        }
Example #4
0
        public string ResolveEntity(string name)
        {
            DTDEntityDeclaration dtdentityDeclaration = this.EntityDecls[name];

            if (dtdentityDeclaration == null)
            {
                this.AddError(new XmlException(string.Format("Required entity was not found: {0}", name), null, this.LineNumber, this.LinePosition));
                return(" ");
            }
            return(dtdentityDeclaration.EntityValue);
        }
Example #5
0
        internal Mono.Xml2.XmlTextReader GenerateEntityContentReader(string entityName, XmlParserContext context)
        {
            DTDEntityDeclaration dtdentityDeclaration = this.EntityDecls[entityName];

            if (dtdentityDeclaration == null)
            {
                return(null);
            }
            if (dtdentityDeclaration.SystemId != null)
            {
                Uri    baseUri     = (!(dtdentityDeclaration.BaseURI == string.Empty)) ? new Uri(dtdentityDeclaration.BaseURI) : null;
                Stream xmlFragment = this.resolver.GetEntity(this.resolver.ResolveUri(baseUri, dtdentityDeclaration.SystemId), null, typeof(Stream)) as Stream;
                return(new Mono.Xml2.XmlTextReader(xmlFragment, XmlNodeType.Element, context));
            }
            return(new Mono.Xml2.XmlTextReader(dtdentityDeclaration.EntityValue, XmlNodeType.Element, context));
        }
        internal XmlTextReaderImpl GenerateEntityContentReader(string entityName, XmlParserContext context)
        {
            DTDEntityDeclaration entity = EntityDecls [entityName] as DTDEntityDeclaration;

            if (entity == null)
            {
                return(null);
            }

            if (entity.SystemId != null)
            {
                Uri    baseUri = entity.BaseURI == String.Empty ? null : new Uri(entity.BaseURI);
                Stream stream  = resolver.GetEntity(resolver.ResolveUri(baseUri, entity.SystemId), null, typeof(Stream)) as Stream;
                return(new XmlTextReaderImpl(stream, XmlNodeType.Element, context));
            }
            else
            {
                return(new XmlTextReaderImpl(entity.EntityValue, XmlNodeType.Element, context));
            }
        }
        public string ResolveEntity(string name)
        {
            DTDEntityDeclaration decl = EntityDecls [name]
                                        as DTDEntityDeclaration;

            if (decl == null)
            {
#if NET_2_1
                AddError(new XmlSchemaException(String.Format("Required entity was not found: {0}", name), null, this.LineNumber, this.LinePosition));
#else
                AddError(new XmlSchemaException("Required entity was not found.",
                                                this.LineNumber, this.LinePosition, null, this.BaseURI, null));
#endif
                return(" ");
            }
            else
            {
                return(decl.EntityValue);
            }
        }
        // It returns whether the entity contains references to external entities.
        public void ScanEntityValue(ArrayList refs)
        {
            // To modify this code, beware nesting between this and EntityValue.
            string value = EntityValue;

            if (this.SystemId != null)
            {
                hasExternalReference = true;
            }

            if (recursed)
            {
                throw NotWFError("Entity recursion was found.");
            }
            recursed = true;

            if (scanned)
            {
                foreach (string referenced in refs)
                {
                    if (this.ReferencingEntities.Contains(referenced))
                    {
                        throw NotWFError(String.Format(
                                             "Nested entity was found between {0} and {1}",
                                             referenced, Name));
                    }
                }
                recursed = false;
                return;
            }

            int len   = value.Length;
            int start = 0;

            for (int i = 0; i < len; i++)
            {
                switch (value [i])
                {
                case '&':
                    start = i + 1;
                    break;

                case ';':
                    if (start == 0)
                    {
                        break;
                    }
                    string name = value.Substring(start, i - start);
                    if (name.Length == 0)
                    {
                        throw NotWFError("Entity reference name is missing.");
                    }
                    if (name [0] == '#')
                    {
                        break;                          // character reference
                    }
                    if (XmlChar.GetPredefinedEntity(name) >= 0)
                    {
                        break;                          // predefined reference
                    }
                    this.ReferencingEntities.Add(name);
                    DTDEntityDeclaration decl = Root.EntityDecls [name];
                    if (decl != null)
                    {
                        if (decl.SystemId != null)
                        {
                            hasExternalReference = true;
                        }
                        refs.Add(Name);
                        decl.ScanEntityValue(refs);
                        foreach (string str in decl.ReferencingEntities)
                        {
                            ReferencingEntities.Add(str);
                        }
                        refs.Remove(Name);
                        value = value.Remove(start - 1, name.Length + 2);
                        value = value.Insert(start - 1, decl.EntityValue);
                        i    -= name.Length + 1;                      // not +2, because of immediate i++ .
                        len   = value.Length;
                    }
                    start = 0;
                    break;
                }
            }
            if (start != 0)
#if NET_2_1
            { Root.AddError(new XmlSchemaException(this, this.BaseURI, "Invalid reference character '&' is specified.")); }
#else
            { Root.AddError(new XmlSchemaException("Invalid reference character '&' is specified.",
                                                   this.LineNumber, this.LinePosition, null, this.BaseURI, null)); }
#endif
            scanned  = true;
            recursed = false;
        }
Example #9
0
        public void ScanEntityValue(ArrayList refs)
        {
            string text = this.EntityValue;

            if (base.SystemId != null)
            {
                this.hasExternalReference = true;
            }
            if (this.recursed)
            {
                throw base.NotWFError("Entity recursion was found.");
            }
            this.recursed = true;
            if (this.scanned)
            {
                foreach (object obj in refs)
                {
                    string text2 = (string)obj;
                    if (this.ReferencingEntities.Contains(text2))
                    {
                        throw base.NotWFError(string.Format("Nested entity was found between {0} and {1}", text2, base.Name));
                    }
                }
                this.recursed = false;
                return;
            }
            int length = text.Length;
            int num    = 0;

            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if (c != '&')
                {
                    if (c == ';')
                    {
                        if (num != 0)
                        {
                            string text3 = text.Substring(num, i - num);
                            if (text3.Length == 0)
                            {
                                throw base.NotWFError("Entity reference name is missing.");
                            }
                            if (text3[0] != '#')
                            {
                                if (XmlChar.GetPredefinedEntity(text3) < 0)
                                {
                                    this.ReferencingEntities.Add(text3);
                                    DTDEntityDeclaration dtdentityDeclaration = base.Root.EntityDecls[text3];
                                    if (dtdentityDeclaration != null)
                                    {
                                        if (dtdentityDeclaration.SystemId != null)
                                        {
                                            this.hasExternalReference = true;
                                        }
                                        refs.Add(base.Name);
                                        dtdentityDeclaration.ScanEntityValue(refs);
                                        foreach (object obj2 in dtdentityDeclaration.ReferencingEntities)
                                        {
                                            string value = (string)obj2;
                                            this.ReferencingEntities.Add(value);
                                        }
                                        refs.Remove(base.Name);
                                        text   = text.Remove(num - 1, text3.Length + 2);
                                        text   = text.Insert(num - 1, dtdentityDeclaration.EntityValue);
                                        i     -= text3.Length + 1;
                                        length = text.Length;
                                    }
                                    num = 0;
                                }
                            }
                        }
                    }
                }
                else
                {
                    num = i + 1;
                }
            }
            if (num != 0)
            {
                base.Root.AddError(new XmlException(this, this.BaseURI, "Invalid reference character '&' is specified."));
            }
            this.scanned  = true;
            this.recursed = false;
        }