Beispiel #1
0
        private NodeEntries GetEntryNodesFromXML(XmlNode w, XmlNamespaceManager atomNsMgr)
        {
            NodeEntries entries = new NodeEntries();

            XmlNodeList collectionList = w.SelectNodes("app:collection", atomNsMgr);

            if (collectionList == null)
            {
                System.Diagnostics.Debug.WriteLine("app:collection is null.");
                return(entries);
            }

            foreach (XmlNode n in collectionList)
            {
                var hrefAttr = n.Attributes["href"].Value;
                if (hrefAttr == null)
                {
                    System.Diagnostics.Debug.WriteLine("href Attr is null.");
                    continue;
                }
                XmlNode title = n.SelectSingleNode("atom:title", atomNsMgr);
                if (title == null)
                {
                    System.Diagnostics.Debug.WriteLine("atom:title is null.");
                    continue;
                }
                XmlNodeList acceptList = n.SelectNodes("app:accept", atomNsMgr);
                if (acceptList == null)
                {
                    System.Diagnostics.Debug.WriteLine("app:accept is null.");
                    continue;
                }

                foreach (XmlNode a in acceptList)
                {
                    if (a.InnerText == "application/atom+xml;type=entry")
                    {
                        NodeEntryCollection entry = new NodeEntryCollection(title.InnerText, new Uri(hrefAttr));
                        entry.AcceptTypes.Add(a.InnerText);
                        entries.Children.Add(entry);
                    }
                    else
                    {
                        // TODO.
                        // application/atomcat+xml

                        System.Diagnostics.Debug.WriteLine("app:accept type " + a.InnerText + " not implemented (yet).");
                    }
                }

                if (entries.Children.Count > 0)
                {
                    entries.Expanded = true;
                }
            }
            return(entries);
        }
Beispiel #2
0
        public override async Task <NodeCollections> GetBlogs()
        {
            NodeCollections blogs = new NodeCollections();

            var HTTPResponseMessage = await _HTTPConn.Client.GetAsync(_endpoint);

            if (HTTPResponseMessage.IsSuccessStatusCode)
            {
                string s = await HTTPResponseMessage.Content.ReadAsStringAsync();

                System.Diagnostics.Debug.WriteLine("GET blogs(collection): " + s);

                /*
                 *                  <?xml version="1.0" encoding="utf-8"?>
                 *                  <service xmlns="http://www.w3.org/2007/app">
                 *                    <workspace>
                 *                      <atom:title xmlns:atom="http://www.w3.org/2005/Atom">hoge</atom:title>
                 *                      <collection href="https://127.0.0.1/atom/entry">
                 *                        <atom:title xmlns:atom="http://www.w3.org/2005/Atom">fuga</atom:title>
                 *                        <accept>application/atom+xml;type=entry</accept>
                 *                      </collection>
                 *                    </workspace>
                 *                  </service>
                 */
                XmlDocument xdoc = new XmlDocument();
                try
                {
                    xdoc.LoadXml(s);
                }
                catch (Exception e)
                {
                    // TODO:
                    System.Diagnostics.Debug.WriteLine("LoadXml failed: " + e.Message);
                    return(blogs);
                }

                XmlNamespaceManager atomNsMgr = new XmlNamespaceManager(xdoc.NameTable);
                atomNsMgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
                atomNsMgr.AddNamespace("app", "http://www.w3.org/2007/app");

                XmlNodeList workspaceList;
                workspaceList = xdoc.SelectNodes("//app:service/app:workspace", atomNsMgr);
                if (workspaceList == null)
                {
                    return(blogs);
                }

                foreach (XmlNode n in workspaceList)
                {
                    XmlNode accountTitle = n.SelectSingleNode("atom:title", atomNsMgr);
                    if (accountTitle == null)
                    {
                        System.Diagnostics.Debug.WriteLine("atom:title is null. ");
                        continue;
                    }

                    NodeCollection blog = new NodeCollection(accountTitle.InnerText);

                    NodeEntries entries = GetEntryNodesFromXML(n, atomNsMgr);
                    foreach (var item in entries.Children)
                    {
                        item.Parent = blog;
                        blog.Children.Add(item);
                    }

                    blog.Expanded = true;

                    blogs.Children.Add(blog);
                    blogs.Expanded = true;
                }
            }

            return(blogs);
        }