forked from atsushieno/monodroid-schema-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-hierarchy-importer.cs
executable file
·98 lines (82 loc) · 2.78 KB
/
type-hierarchy-importer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Xml;
using Sgml;
public class Driver
{
public static void Main (string [] args)
{
new Driver ().Run (args);
}
const string android_ns = "http://schemas.android.com/apk/res/android";
List<string> atts = new List<string> ();
TextWriter fs1;
public void Run (string [] args)
{
fs1 = File.CreateText ("type-hierarchy.xml");
fs1.WriteLine ("<android-hierarchy xmlns:android='" + android_ns + "'>");
foreach (var arg in new string [] {"http://developer.android.com/reference/android/view/View.html"}) {
var baseUrl = resolver.ResolveUri (null, arg);
var doc = FetchXmlDocument (baseUrl);
ProcessDocument (baseUrl);
foreach (XmlElement node in doc.SelectNodes ("//div[@id='subclasses-direct' or @id='subclasses-indirect']")) {
foreach (XmlElement link in node.SelectNodes ("div/table[@class='jd-sumtable-expando']/tr/td[@class='jd-linkcol']/a[@href]")) {
if (link.PreviousSibling != null && link.PreviousSibling.Value.Contains ("extends"))
continue; // it is a link to generic type argument.
var durl = resolver.ResolveUri (baseUrl, link.GetAttribute ("href"));
ProcessDocument (durl);
}
}
}
fs1.WriteLine ("</android-hierarchy>");
fs1.Close ();
}
string GetName (Uri baseUrl)
{
var url = baseUrl.ToString ();
url = url.Substring (0, url.Length - ".html".Length);
return url.Substring (url.LastIndexOf ('/') + 1);
}
XmlResolver resolver = new XmlUrlResolver ();
StreamReader FetchWebText (Uri url)
{
var wc = new WebClient ();
return new StreamReader (new XmlUrlResolver ().GetEntity (url, null, typeof (Stream)) as Stream);
}
XmlDocument FetchXmlDocument (Uri url)
{
var sr = FetchWebText (url);
var xr = new SgmlReader () { InputStream = sr };
var doc = new XmlDocument ();
doc.Load (xr);
sr.Close ();
xr.Close ();
return doc;
}
void ProcessDocument (Uri url)
{
Console.Error.WriteLine ("Processing {0}...", url);
var doc = FetchXmlDocument (url);
var baseTable = doc.SelectSingleNode ("//table[@class='jd-inheritance-table']");
var baseTypeName = baseTable.SelectSingleNode ("tr[last() - 1]/td[last()]").InnerText;
fs1.WriteLine ("<class name='{0}' url='{1}' base='{2}'>", GetName (url), url, baseTypeName);
/*
var table = doc.SelectSingleNode ("//table[@id='lattrs']");
if (table != null) {
var nodes = table.SelectNodes ("tr[contains(@class,'api')]");
foreach (XmlNode node in nodes) {
var attr = node.SelectSingleNode ("td[1]//text()");
var method = node.SelectSingleNode ("td[2]//text()");
var a = attr.InnerText;
fs1.WriteLine ("<a>{0}</a>", a);//node.SelectSingleNode ("td[1]"));
if (!atts.Contains (a))
atts.Add (a);
}
}
*/
fs1.WriteLine ("</class>");
fs1.Flush ();
}
}