-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java example using SLF4J (so no Log4j2)
- Loading branch information
1 parent
d7324c0
commit 5dba99a
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Yet Another UserAgent Analyzer | ||
~ Copyright (C) 2013-2021 Niels Basjes | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>nl.basjes.parse.useragent</groupId> | ||
<artifactId>yauaa-example-parent</artifactId> | ||
<version>6.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<artifactId>yauaa-example-java-slf4j</artifactId> | ||
<name>Yauaa : Examples : Java (SLF4J)</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>nl.basjes.parse.useragent</groupId> | ||
<artifactId>yauaa</artifactId> | ||
<version>${yauaa.version}</version> | ||
</dependency> | ||
|
||
<!-- The default logging implementation for Yauaa --> | ||
<!-- Send all Log4j2 call to SLF4J --> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-to-slf4j</artifactId> | ||
<version>${log4j2.version}</version> | ||
</dependency> | ||
|
||
<!-- The included classes from org.apache.httpcomponents.client5:httpclient5 already expect SLF4J --> | ||
|
||
<!-- Needed for the included classes from org.springframework:spring-core --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
<!-- Just the simplest of logger for this demo. --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
40 changes: 40 additions & 0 deletions
40
examples/java-slf4j/src/main/java/nl/basjes/parse/useragent/example/Demo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2021 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nl.basjes.parse.useragent.example; | ||
|
||
import nl.basjes.parse.useragent.UserAgent; | ||
import nl.basjes.parse.useragent.UserAgentAnalyzer; | ||
|
||
public class Demo { | ||
|
||
private final UserAgentAnalyzer uaa; | ||
|
||
public Demo() { | ||
uaa = UserAgentAnalyzer | ||
.newBuilder() | ||
.withCache(1234) | ||
.withField("DeviceClass") | ||
.withAllFields() | ||
.build(); | ||
} | ||
|
||
public UserAgent parse(String userAgent) { | ||
return uaa.parse(userAgent); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
examples/java-slf4j/src/test/java/nl/basjes/parse/useragent/example/TestDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Yet Another UserAgent Analyzer | ||
* Copyright (C) 2013-2021 Niels Basjes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nl.basjes.parse.useragent.example; | ||
|
||
import nl.basjes.parse.useragent.UserAgent; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class TestDemo { | ||
@Test | ||
void testParser() { | ||
Demo demo = new Demo(); | ||
|
||
String userAgent = "Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) " + | ||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36"; | ||
|
||
UserAgent result = demo.parse(userAgent); | ||
|
||
assertTrue(result.toXML().contains("<DeviceName>Google Nexus 6</DeviceName>"), | ||
"The parser must extract the correct DeviceName"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters