Example #1
0
        private bool TestValidProtocol(iText.StyledXmlParser.Jsoup.Nodes.Element el, iText.StyledXmlParser.Jsoup.Nodes.Attribute
                                       attr, ICollection <Whitelist.Protocol> protocols)
        {
            // try to resolve relative urls to abs, and optionally update the attribute so output html has abs.
            // rels without a baseuri get removed
            String value = el.AbsUrl(attr.Key);

            if (value.Length == 0)
            {
                value = attr.Value;
            }
            // if it could not be made abs, run as-is to allow custom unknown protocols
            if (!preserveRelativeLinks)
            {
                attr.SetValue(value);
            }
            foreach (Whitelist.Protocol protocol in protocols)
            {
                String prot = protocol.ToString();
                if (prot.Equals("#"))
                {
                    // allows anchor links
                    if (IsValidAnchor(value))
                    {
                        return(true);
                    }
                    else
                    {
                        continue;
                    }
                }
                prot += ":";
                if (value.ToLowerInvariant().StartsWith(prot))
                {
                    return(true);
                }
            }
            return(false);
        }