This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
forked from lunny/axmlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appnamelistener.go
157 lines (142 loc) · 4.28 KB
/
appnamelistener.go
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package axmlParser
type AppNameListener struct {
PackageName string
VersionName string
VersionCode string
ActivityName string
tempActivityName string
findMainActivity bool
}
func (listener *AppNameListener) StartDocument() {
}
/**
* Receive notification of the end of a document.
*/
func (listener *AppNameListener) EndDocument() {
}
/**
* Begin the scope of a prefix-URI Namespace mapping.
*
* @param prefix
* the Namespace prefix being declared. An empty string is used
* for the default element namespace, which has no prefix.
* @param uri
* the Namespace URI the prefix is mapped to
*/
func (listener *AppNameListener) StartPrefixMapping(prefix, uri string) {
}
/**
* End the scope of a prefix-URI mapping.
*
* @param prefix
* the prefix that was being mapped. This is the empty string
* when a default mapping scope ends.
* @param uri
* the Namespace URI the prefix is mapped to
*/
func (listener *AppNameListener) EndPrefixMapping(prefix, uri string) {}
/**
* Receive notification of the beginning of an element.
*
* @param uri
* the Namespace URI, or the empty string if the element has no
* Namespace URI or if Namespace processing is not being
* performed
* @param localName
* the local name (without prefix), or the empty string if
* Namespace processing is not being performed
* @param qName
* the qualified name (with prefix), or the empty string if
* qualified names are not available
* @param atts
* the attributes attached to the element. If there are no
* attributes, it shall be an empty Attributes object. The value
* of this object after startElement returns is undefined
*/
func (listener *AppNameListener) StartElement(uri, localName, qName string,
attrs []*Attribute) {
if listener.findMainActivity {
return
}
if localName == "manifest" {
for _, attr := range attrs {
switch attr.Name {
case "package":
listener.PackageName = attr.Value
break
case "versionCode":
listener.VersionCode = attr.Value
break
case "versionName":
listener.VersionName = attr.Value
break
}
}
return
}
if localName == "activity" {
for _, attr := range attrs {
if attr.Name == "name" && attr.Prefix == "android" &&
attr.Namespace == "http://schemas.android.com/apk/res/android" {
listener.tempActivityName = attr.Value
break
}
}
}
if localName != "action" {
return
}
//fmt.Println(uri, localName, qName)
for _, attr := range attrs {
if attr.Name == "name" && attr.Prefix == "android" &&
attr.Namespace == "http://schemas.android.com/apk/res/android" &&
attr.Value == "android.intent.action.MAIN" {
listener.ActivityName = listener.tempActivityName
listener.findMainActivity = true
break
}
}
}
/**
* Receive notification of the end of an element.
*
* @param uri
* the Namespace URI, or the empty string if the element has no
* Namespace URI or if Namespace processing is not being
* performed
* @param localName
* the local name (without prefix), or the empty string if
* Namespace processing is not being performed
* @param qName
* the qualified XML name (with prefix), or the empty string if
* qualified names are not available
*/
func (listener *AppNameListener) EndElement(uri, localName, qName string) {}
/**
* Receive notification of text.
*
* @param data
* the text data
*/
func (listener *AppNameListener) Text(data string) {}
/**
* Receive notification of character data (in a <![CDATA[ ]]> block).
*
* @param data
* the text data
*/
func (listener *AppNameListener) CharacterData(data string) {}
/**
* Receive notification of a processing instruction.
*
* @param target
* the processing instruction target
* @param data
* the processing instruction data, or null if none was supplied.
* The data does not include any whitespace separating it from
* the target
* @throws org.xml.sax.SAXException
* any SAX exception, possibly wrapping another exception
*/
func (listener *AppNameListener) ProcessingInstruction(target, data string) {
}