|
@@ -1,55 +1,55 @@ |
1 |
|
- |
package org.litesoft.useragent; |
2 |
|
- |
|
3 |
|
- |
public class UserAgentFormFactorDeterminerImpl implements UserAgentFormFactorDeterminer |
4 |
|
- |
{ |
5 |
|
- |
@Override |
6 |
|
- |
public UserAgentFormFactor determine( String pUserAgent ) |
7 |
|
- |
{ |
8 |
|
- |
return ((pUserAgent.length() > 15) && containsAnyOf( pUserAgent, |
9 |
|
- |
"iPhone", "iPod", "Mobile", "Android", "iPad", "IEMobile", "Tablet", |
10 |
|
- |
"Kindle", "Silk", |
11 |
|
- |
"SymbianOS", "Symbian", |
12 |
|
- |
"Opera Mini", "Opera Mobi", |
13 |
|
- |
"Fennec" )) ? |
14 |
|
- |
UserAgentFormFactor.SingleViewOnly : |
15 |
|
- |
UserAgentFormFactor.MultiViewable; |
16 |
|
- |
} |
17 |
|
- |
|
18 |
|
- |
/** |
19 |
|
- |
* Look for the Find Words (where the Word may not start the User Agent). |
20 |
|
- |
*/ |
21 |
|
- |
private boolean containsAnyOf( String pUserAgent, String... pFindWords ) |
22 |
|
- |
{ |
23 |
|
- |
for ( String zWord : pFindWords ) |
24 |
|
- |
{ |
25 |
|
- |
if ( containsWord( pUserAgent, zWord ) ) |
26 |
|
- |
{ |
27 |
|
- |
return true; |
28 |
|
- |
} |
29 |
|
- |
} |
30 |
|
- |
return false; |
31 |
|
- |
} |
32 |
|
- |
|
33 |
|
- |
/** |
34 |
|
- |
* Look for the Find Word (where the Word may not start the User Agent). |
35 |
|
- |
*/ |
36 |
|
- |
private boolean containsWord( String pUserAgent, String pWord ) |
37 |
|
- |
{ |
38 |
|
- |
for ( int zAt, zFrom = 1; -1 != (zAt = pUserAgent.indexOf( pWord, zFrom )); ) |
39 |
|
- |
{ |
40 |
|
- |
zFrom = zAt + pWord.length(); |
41 |
|
- |
if ( isWordSep( pUserAgent, zAt - 1 ) && isWordSep( pUserAgent, zFrom ) ) |
42 |
|
- |
{ |
43 |
|
- |
return true; |
44 |
|
- |
} |
45 |
|
- |
} |
46 |
|
- |
return false; |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
private boolean isWordSep( String pUserAgent, int pAt ) |
50 |
|
- |
{ |
51 |
|
- |
return (pAt == pUserAgent.length()) || !Character.isLetterOrDigit( pUserAgent.charAt( pAt ) ); |
52 |
|
- |
} |
53 |
|
- |
} |
54 |
|
- |
|
55 |
|
- |
|
|
1 |
+ |
package org.litesoft.useragent; |
|
2 |
+ |
|
|
3 |
+ |
public class UserAgentFormFactorDeterminerImpl implements UserAgentFormFactorDeterminer |
|
4 |
+ |
{ |
|
5 |
+ |
@Override |
|
6 |
+ |
public UserAgentFormFactor determine( String pUserAgent ) |
|
7 |
+ |
{ |
|
8 |
+ |
return ((pUserAgent.length() > 15) && containsAnyOf( pUserAgent, |
|
9 |
+ |
"iPhone", "iPod", "Mobile", "Android", "iPad", "IEMobile", "Tablet", |
|
10 |
+ |
"Kindle", "Silk", |
|
11 |
+ |
"SymbianOS", "Symbian", |
|
12 |
+ |
"Opera Mini", "Opera Mobi", |
|
13 |
+ |
"Fennec" )) ? |
|
14 |
+ |
UserAgentFormFactor.SingleViewOnly : |
|
15 |
+ |
UserAgentFormFactor.MultiViewable; |
|
16 |
+ |
} |
|
17 |
+ |
|
|
18 |
+ |
/** |
|
19 |
+ |
* Look for the Find Words (where the Word may not start the User Agent). |
|
20 |
+ |
*/ |
|
21 |
+ |
private boolean containsAnyOf( String pUserAgent, String... pFindWords ) |
|
22 |
+ |
{ |
|
23 |
+ |
for ( String zWord : pFindWords ) |
|
24 |
+ |
{ |
|
25 |
+ |
if ( containsWord( pUserAgent, zWord ) ) |
|
26 |
+ |
{ |
|
27 |
+ |
return true; |
|
28 |
+ |
} |
|
29 |
+ |
} |
|
30 |
+ |
return false; |
|
31 |
+ |
} |
|
32 |
+ |
|
|
33 |
+ |
/** |
|
34 |
+ |
* Look for the Find Word (where the Word may not start the User Agent). |
|
35 |
+ |
*/ |
|
36 |
+ |
private boolean containsWord( String pUserAgent, String pWord ) |
|
37 |
+ |
{ |
|
38 |
+ |
for ( int zAt, zFrom = 1; -1 != (zAt = pUserAgent.indexOf( pWord, zFrom )); ) |
|
39 |
+ |
{ |
|
40 |
+ |
zFrom = zAt + pWord.length(); |
|
41 |
+ |
if ( isWordSep( pUserAgent, zAt - 1 ) && isWordSep( pUserAgent, zFrom ) ) |
|
42 |
+ |
{ |
|
43 |
+ |
return true; |
|
44 |
+ |
} |
|
45 |
+ |
} |
|
46 |
+ |
return false; |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
private boolean isWordSep( String pUserAgent, int pAt ) |
|
50 |
+ |
{ |
|
51 |
+ |
return (pAt == pUserAgent.length()) || !Character.isLetterOrDigit( pUserAgent.charAt( pAt ) ); |
|
52 |
+ |
} |
|
53 |
+ |
} |
|
54 |
+ |
|
|
55 |
+ |
|