aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/ru/sape/SapePageLinks.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-21 20:24:45 +0300
committerGravatar Vitaly Takmazov2018-06-21 20:24:45 +0300
commit248c05840275516cbc5c99c8e5d87d007ca37284 (patch)
treeda6a298a000eea580d8dfecf643f226cfd5f5dca /juick-server/src/main/java/ru/sape/SapePageLinks.java
parent7866553d3fb28f6a18795a0129ea4a6661870d09 (diff)
www project disabled, all new web development moved to separate repo
Diffstat (limited to 'juick-server/src/main/java/ru/sape/SapePageLinks.java')
-rw-r--r--juick-server/src/main/java/ru/sape/SapePageLinks.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/juick-server/src/main/java/ru/sape/SapePageLinks.java b/juick-server/src/main/java/ru/sape/SapePageLinks.java
new file mode 100644
index 00000000..e89b4e71
--- /dev/null
+++ b/juick-server/src/main/java/ru/sape/SapePageLinks.java
@@ -0,0 +1,76 @@
+package ru.sape;
+
+import java.util.*;
+
+public class SapePageLinks {
+
+ private boolean showCode;
+
+ public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, String sapeCookie) {
+ this(sapeConnection, sapeUser, requestUri, sapeCookie, false);
+ }
+
+ @SuppressWarnings("unchecked")
+ public SapePageLinks(SapeConnection sapeConnection, String sapeUser, String requestUri, String sapeCookie, boolean showCode) {
+ if (sapeUser.equals(sapeCookie)) {
+ showCode = true;
+ }
+
+ Map<String, Object> data = sapeConnection.getData();
+
+ if (data.containsKey("__sape_delimiter__")) {
+ linkDelimiter = (String) data.get("__sape_delimiter__");
+ }
+
+ if (data.containsKey(requestUri)) {
+ pageLinks = new ArrayList<>(((Map<Object, String>) data.get(requestUri)).values());
+ }
+
+ if (data.containsKey("__sape_new_url__")) {
+ if (showCode) {
+ Object newUrl = data.get("__sape_new_url__");
+
+ if (newUrl instanceof Map) {
+ pageLinks = new ArrayList<>(((Map<Object, String>) newUrl).values());
+ } else {
+ pageLinks = new ArrayList<>(Collections.singletonList((String) newUrl));
+ }
+ }
+ }
+
+ this.showCode = showCode;
+ }
+ private String linkDelimiter = ".";
+ private List<String> pageLinks = new ArrayList<>();
+
+ public String render() {
+ return render(-1);
+ }
+
+ public String render(int count) {
+ StringBuilder s = new StringBuilder();
+
+ if (count < 0) {
+ count = pageLinks.size();
+ }
+
+ for (Iterator<String> i = pageLinks.iterator(); i.hasNext() && count > 0; count--) {
+ if (s.length() > 0) {
+ s.append(linkDelimiter);
+ }
+
+ String l = i.next();
+
+ s.append(l);
+
+ i.remove();
+ }
+
+ if (showCode) {
+ s.insert(0, "<sape_noindex>");
+ s.append("</sape_noindex>");
+ }
+
+ return s.toString();
+ }
+}