Skip to content

Commit

Permalink
Show classifications in webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed May 25, 2021
1 parent 1b9406c commit ce4b99e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ v6.0-SNAPSHOT
- Elastic Search/Logstash 7.12.1
- WebServlet:
- Cleaning up the code
- Also show the classifications based upon the DeviceClass
- Build:
- Disabling usage of docker hub in CI build to avoid random failures over "You have reached your pull rate limit."

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.servlet.api;

import nl.basjes.parse.useragent.UserAgent;

import java.util.ArrayList;
import java.util.List;

import static nl.basjes.parse.useragent.classify.UserAgentClassifier.isDeliberateMisuse;
import static nl.basjes.parse.useragent.classify.UserAgentClassifier.isHuman;
import static nl.basjes.parse.useragent.classify.UserAgentClassifier.isMobile;
import static nl.basjes.parse.useragent.classify.UserAgentClassifier.isNormalConsumerDevice;

public final class DetermineUserAgentTags {

private DetermineUserAgentTags() {
// Utility class
}

public static List<String> getTags(UserAgent userAgent) {
List<String> tags = new ArrayList<>();
if (isHuman(userAgent)) {
tags.add("Human");
} else {
tags.add("NOT Human");
}
if (isNormalConsumerDevice(userAgent)) {
tags.add("Normal consumer device");
}
if (isMobile(userAgent)) {
tags.add("Mobile");
}
if (isDeliberateMisuse(userAgent)) {
tags.add("Deliberate Misuse");
}

return tags;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
import java.util.Locale;
import java.util.Map;

import static nl.basjes.parse.useragent.UserAgent.DEVICE_CLASS;
import static nl.basjes.parse.useragent.servlet.ParseService.getInitStartMoment;
import static nl.basjes.parse.useragent.servlet.ParseService.getUserAgentAnalyzer;
import static nl.basjes.parse.useragent.servlet.ParseService.getUserAgentAnalyzerFailureMessage;
import static nl.basjes.parse.useragent.servlet.ParseService.userAgentAnalyzerIsAvailable;
import static nl.basjes.parse.useragent.servlet.api.DetermineUserAgentTags.getTags;
import static nl.basjes.parse.useragent.servlet.api.Utils.splitPerFilledLine;
import static nl.basjes.parse.useragent.servlet.utils.Constants.GIT_REPO_URL;
import static nl.basjes.parse.useragent.utils.YauaaVersion.getVersion;
Expand Down Expand Up @@ -124,6 +126,12 @@ private String doHTML(String userAgentString) {
sb.append("<h2 class=\"title\">The UserAgent</h2>");
sb.append("<p class=\"input\">").append(escapeHtml4(userAgent.getUserAgentString())).append("</p>");
sb.append("<h2 class=\"title\">The analysis result</h2>");

List<String> tags = getTags(userAgent);
sb.append("<p class=\"tags\">")
.append("DeviceClass : ").append(userAgent.getValue(DEVICE_CLASS)).append("<br/>")
.append(String.join(" - ", tags)).append("</p>");

sb.append("<table id=\"result\">");
sb.append("<tr><th colspan=2>Field</th><th>Value</th></tr>");

Expand Down
30 changes: 29 additions & 1 deletion webapp/src/main/resources/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,39 @@ body {
border-width: 2px;
border-style: dashed;
text-align: center;
width: 80%;
width: max-content;
margin-left: auto;
margin-right: auto;
padding: 1em;
}

.tags {
background-repeat: no-repeat;
background-size: 3em 3em;
background-position: 2em;
padding: 2em 2em 2em 7em;
margin: 1em;

background-image: url(microscope.svg);

font-weight: bold;
font-size: large;
/*font-variant: small-caps;*/
vertical-align: center;

border-radius: 5px;
border-color: dodgerblue;
border-width: 2px;
border-style: dotted;
text-align: center;
width: max-content;
margin-left: auto;
margin-right: auto;

text-shadow: 0.05em 0.05em #aaaaaa ;
}


#result {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border: 0 solid dodgerblue;
Expand Down

0 comments on commit ce4b99e

Please sign in to comment.