aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/www/ad/models/Page.java19
-rw-r--r--src/main/java/com/juick/www/ad/models/Site.java30
-rw-r--r--src/main/java/ru/sape/SapePageLinks.java8
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java6
4 files changed, 11 insertions, 52 deletions
diff --git a/src/main/java/com/juick/www/ad/models/Page.java b/src/main/java/com/juick/www/ad/models/Page.java
index d5bb8ae3..6beb49d3 100644
--- a/src/main/java/com/juick/www/ad/models/Page.java
+++ b/src/main/java/com/juick/www/ad/models/Page.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2022, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -19,19 +19,4 @@ package com.juick.www.ad.models;
import java.util.List;
-public class Page {
- private final String uri;
- private final List<String> links;
-
- public Page(String uri, List<String> links) {
- this.uri = uri;
- this.links = links;
- }
-
- public String getUri() {
- return uri;
- }
- public List<String> getLinks() {
- return links;
- }
-}
+public record Page(String uri, List<String> links) { }
diff --git a/src/main/java/com/juick/www/ad/models/Site.java b/src/main/java/com/juick/www/ad/models/Site.java
index fbe1c033..d2cb773f 100644
--- a/src/main/java/com/juick/www/ad/models/Site.java
+++ b/src/main/java/com/juick/www/ad/models/Site.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2022, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -32,33 +32,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-public class Site {
- private final String siteUrl;
- private final String delimiter;
- private final List<Page> pages;
- private final String code;
-
- public Site(String siteUrl, String code, String delimiter, List<Page> pages) {
- this.siteUrl = siteUrl;
- this.code = code;
- this.delimiter = delimiter;
- this.pages = pages;
- }
-
- public String getSiteUrl() {
- return siteUrl;
- }
- public String getDelimiter() {
- return delimiter;
- }
- public List<Page> getPages() {
- return pages;
- }
-
- public String getCode() {
- return code;
- }
-
+public record Site(String siteUrl, String code, String delimiter, List<Page> pages) {
public static Site fromXMLData(String data) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
diff --git a/src/main/java/ru/sape/SapePageLinks.java b/src/main/java/ru/sape/SapePageLinks.java
index 285d38f6..2bd5464e 100644
--- a/src/main/java/ru/sape/SapePageLinks.java
+++ b/src/main/java/ru/sape/SapePageLinks.java
@@ -35,15 +35,15 @@ public class SapePageLinks {
String req = StringUtils.isNotEmpty(request.getQuery()) ? request.getPath() + "?" + request.getQuery()
: request.getPath();
- linkDelimiter = site.getDelimiter();
+ linkDelimiter = site.delimiter();
this.showCode = sapeUser.equals(sapeCookie);
if (showCode) {
- pageLinks = Collections.singletonList(site.getCode());
+ pageLinks = Collections.singletonList(site.code());
} else {
- pageLinks = site.getPages().stream().filter(page -> page.getUri().equals(req))
- .flatMap(page -> page.getLinks().stream()).collect(Collectors.toList());
+ pageLinks = site.pages().stream().filter(page -> page.uri().equals(req))
+ .flatMap(page -> page.links().stream()).collect(Collectors.toList());
}
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 2ea94d2f..76146dd9 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2710,9 +2710,9 @@ public class ServerTests {
public void linksTest() throws IOException, ParserConfigurationException, SAXException {
Site site = Site.fromXMLData(IOUtils.toString(sapeOutput.getInputStream(), StandardCharsets.UTF_8));
- assertThat(site.getPages().size(), is(3));
- assertThat(site.getPages().get(0).getLinks().size(), is(2));
- assertThat(site.getCode(), is("<!--1234567890123-->"));
+ assertThat(site.pages().size(), is(3));
+ assertThat(site.pages().get(0).links().size(), is(2));
+ assertThat(site.code(), is("<!--1234567890123-->"));
SapePageLinks botLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), "ugnich");
assertThat(botLinks.render(), is("<sape_noindex><!--1234567890123--></sape_noindex>"));
SapePageLinks visitorLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), null);