@@ -23,6 +23,7 @@ public class SingleThreadedUASparser extends UASparser {
23
23
24
24
protected Map <Matcher , Long > compiledBrowserMatcherMap ;
25
25
protected Map <Matcher , Long > compiledOsMatcherMap ;
26
+ protected Map <Matcher , Long > compiledDeviceMatcherMap ;
26
27
27
28
public SingleThreadedUASparser (InputStream inputStreamToDefinitionFile ) throws IOException {
28
29
super (inputStreamToDefinitionFile );
@@ -62,6 +63,24 @@ protected void preCompileOsRegMap() {
62
63
this .compiledOsMatcherMap = compiledOsMatcherMap ;
63
64
}
64
65
66
+ /**
67
+ * Precompile device regexes
68
+ */
69
+ @ Override
70
+ protected void preCompileDeviceRegMap () {
71
+ if (deviceRegMap == null ) {
72
+ return ; // skip for older ini files
73
+ }
74
+ LinkedHashMap <Matcher , Long > compiledDeviceMatcherMap =
75
+ new LinkedHashMap <Matcher , Long >(deviceRegMap .size ());
76
+
77
+ for (Map .Entry <String , Long > entry : deviceRegMap .entrySet ()) {
78
+ Pattern pattern = new Pattern (entry .getKey (), Pattern .IGNORE_CASE | Pattern .DOTALL );
79
+ compiledDeviceMatcherMap .put (pattern .matcher (), entry .getValue ());
80
+ }
81
+ this .compiledDeviceMatcherMap = compiledDeviceMatcherMap ;
82
+ }
83
+
65
84
/**
66
85
* Searches in the os regex table. if found a match copies the os data
67
86
*
@@ -113,6 +132,27 @@ protected void processBrowserRegex(String useragent, UserAgentInfo retObj) {
113
132
}
114
133
}
115
134
135
+ /**
136
+ * Searches in the devices regex table. if found a match copies the device data
137
+ *
138
+ * @param useragent
139
+ * @param uaInfo
140
+ */
141
+ @ Override
142
+ protected void processDeviceRegex (String useragent , UserAgentInfo uaInfo ) {
143
+ if (compiledDeviceMatcherMap == null || deviceMap == null ) {
144
+ return ;
145
+ }
146
+ for (Map .Entry <Matcher , Long > entry : compiledDeviceMatcherMap .entrySet ()) {
147
+ Matcher matcher = entry .getKey ();
148
+ matcher .setTarget (useragent );
149
+ if (matcher .find ()) {
150
+ uaInfo .setDeviceEntry (deviceMap .get (entry .getValue ()));
151
+ return ;
152
+ }
153
+ }
154
+ }
155
+
116
156
protected Set <Entry <Matcher , Long >> getOsMatcherSet () {
117
157
return compiledOsMatcherMap .entrySet ();
118
158
}
0 commit comments