Esempio n. 1
0
        public static SoftwareIdentity LoadHtml(string swidTagHtml)
        {
            using (var reader = new SgmlReader {
                DocType = "HTML",
                WhitespaceHandling = WhitespaceHandling.All,
                StripDocType = true,
                InputStream = new StringReader(swidTagHtml),
                CaseFolding = CaseFolding.ToLower
            }) {
                var document = XDocument.Load(reader);

                if (document.Root != null && document.Root.Name.LocalName == "html")
                {
                    var swidTag = new SoftwareIdentity {
                        Name          = "Anonymous",
                        Version       = "1.0",
                        VersionScheme = Schema.VersionScheme.MultipartNumeric
                    };

                    var html = document.Root;
                    var ns   = html.Name.Namespace;

                    var head = html.Element(ns + "head");
                    if (head != null)
                    {
                        var links = head.Elements(ns + "link");

                        foreach (var link in links)
                        {
                            var href = link.Attribute("href");
                            var rel  = link.Attribute("rel");

                            if (href != null && rel != null)
                            {
                                var l = swidTag.AddLink(new Uri(href.Value), rel.Value);
                                foreach (var attr in link.Attributes())
                                {
                                    l.SetAttribute(attr.Name, attr.Value);
                                }
                            }
                        }
                    }
                    return(swidTag);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static SoftwareIdentity LoadHtml(string swidTagHtml) {
            using (var reader = new SgmlReader {
                DocType = "HTML",
                WhitespaceHandling = WhitespaceHandling.All,
                StripDocType = true,
                InputStream = new StringReader(swidTagHtml),
                CaseFolding = CaseFolding.ToLower
            }) {
                var document = XDocument.Load(reader);

                if (document.Root != null && document.Root.Name.LocalName == "html") {
                    var swidTag = new SoftwareIdentity {
                        Name = "Anonymous",
                        Version = "1.0",
                        VersionScheme = Schema.VersionScheme.MultipartNumeric
                    };

                    var html = document.Root;
                    var ns = html.Name.Namespace;

                    var head = html.Element(ns + "head");
                    if (head != null) {
                        var links = head.Elements(ns + "link");

                        foreach (var link in links) {
                            var href = link.Attribute("href");
                            var rel = link.Attribute("rel");

                            if (href != null && rel != null) {
                                var l = swidTag.AddLink(new Uri(href.Value), rel.Value);
                                foreach (var attr in link.Attributes()) {
                                    l.SetAttribute(attr.Name, attr.Value);
                                }
                            }
                        }
                    }
                    return swidTag;
                }
            }
            return null;
        }
Esempio n. 3
0
        public static SoftwareIdentity LoadJson(string swidTagJson) {
            var swidTag = new SoftwareIdentity();
            Meta meta = null;

            var expanded = Normalize(swidTagJson);

            foreach (var member in expanded) {
                var memberName = member.Key;
                if (member.Value.Type == JTokenType.Array) {
                    foreach (var element in member.Value.Cast<JObject>()) {
                        var index = element.Index();
                        var value = element.Val();

                        if (index != null) {
                            if (value != null) {
                                if (memberName == JSonMembers.Meta) {
                                    meta = meta ?? swidTag.AddMeta();
                                    meta.SetAttribute(index, value);
                                }
                            } else {
                                var identity = IdentityIndex[memberName];

                                if (memberName == identity.JsonName || memberName == identity.ProperName ) {
                                    try {
                                        // create the new element
                                        var e = new XElement(identity.XmlName);
                                        swidTag.Element.Add(e);

                                        foreach (var property in element.Properties().Where(each => each.Name != "@index")) {
                                            e.SetAttribute(IdentityIndex[property.Name].XmlName, property.PropertyValue());
                                        }

                                        // set the index of the element
                                        if (identity.Index != null) {
                                            e.SetAttribute(identity.Index, index);
                                        }
                                    } catch (Exception e) {
                                        e.Dump();
                                    }
                                }
                            }
                        } else {
                            swidTag.SetAttribute(memberName.ToXName(), value);
                        }
                    }
                    continue;
                }
                // Console.WriteLine("'{0}' -- '{1}'", memberName, member.Value.Type);
            }
            return swidTag;

        }
Esempio n. 4
0
 public MetadataIndexer(SoftwareIdentity swidtag) {
     _swidtag = swidtag;
 }
Esempio n. 5
0
        public static SoftwareIdentity LoadJson(string swidTagJson)
        {
            var  swidTag = new SoftwareIdentity();
            Meta meta    = null;

            var expanded = Normalize(swidTagJson);

            foreach (var member in expanded)
            {
                var memberName = member.Key;
                if (member.Value.Type == JTokenType.Array)
                {
                    foreach (var element in member.Value.Cast <JObject>())
                    {
                        var index = element.Index();
                        var value = element.Val();

                        if (index != null)
                        {
                            if (value != null)
                            {
                                if (memberName == JSonMembers.Meta)
                                {
                                    meta = meta ?? swidTag.AddMeta();
                                    meta.SetAttribute(index, value);
                                }
                            }
                            else
                            {
                                var identity = IdentityIndex[memberName];

                                if (memberName == identity.JsonName || memberName == identity.ProperName)
                                {
                                    try {
                                        // create the new element
                                        var e = new XElement(identity.XmlName);
                                        swidTag.Element.Add(e);

                                        foreach (var property in element.Properties().Where(each => each.Name != "@index"))
                                        {
                                            e.SetAttribute(IdentityIndex[property.Name].XmlName, property.PropertyValue());
                                        }

                                        // set the index of the element
                                        if (identity.Index != null)
                                        {
                                            e.SetAttribute(identity.Index, index);
                                        }
                                    } catch (Exception e) {
                                        e.Dump();
                                    }
                                }
                            }
                        }
                        else
                        {
                            swidTag.SetAttribute(memberName.ToXName(), value);
                        }
                    }
                    continue;
                }
                // Console.WriteLine("'{0}' -- '{1}'", memberName, member.Value.Type);
            }
            return(swidTag);
        }
Esempio n. 6
0
 public MetadataIndexer(SoftwareIdentity swidtag)
 {
     _swidtag = swidtag;
 }