/*
 */
package org.dspace.statistics;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Utilities for checking/replacing review tokens in referer strings.
 * @author Dan Leehr <dan.leehr@nescent.org>
 */
public class SolrLoggerUtils {
    private static final Pattern REVIEW_TOKEN_PATTERN = Pattern.compile("(http.*token=)(.*)");
    static final String DUMMY_TOKEN = "00000000-0000-0000-0000-000000000000";

        /**
     * Replaces the review token with replacement text if token is present
     * @param refererUri A referer string
     * @param replacementText The text to replace the token with
     * @return a referer string, with the token replaced
     */
    static String replaceReviewToken(String refererUri, String replacementText) {
        Matcher matcher = REVIEW_TOKEN_PATTERN.matcher(refererUri);
        if(matcher.matches()) {
            return matcher.group(1) + replacementText;
        } else {
            return refererUri;
        }
    }

    /**
     * Returns true if a string looks like a URL and contains 'token=...'
     * @param refererUrl The string to test
     * @return True if a token is found, false if not.
     */
    static Boolean isReviewTokenPresent(String refererUrl) {
        if(refererUrl == null) {
            return false;
        } else {
            return REVIEW_TOKEN_PATTERN.matcher(refererUrl).matches();
        }
    }
}

@@ -155,24 +155,25 @@
 ens in refer
+r
 er strings.%0A
@@ -528,24 +528,25 @@
 @param refer
+r
 erUri A refe
@@ -542,24 +542,25 @@
 rUri A refer
+r
 er string%0A  
@@ -644,16 +644,17 @@
  a refer
+r
 er strin
@@ -733,24 +733,25 @@
 String refer
+r
 erUri, Strin
@@ -827,24 +827,25 @@
 atcher(refer
+r
 erUri);%0A    
@@ -964,24 +964,25 @@
 return refer
+r
 erUri;%0A     
@@ -1090,24 +1090,25 @@
 @param refer
+r
 erUrl The st
@@ -1231,24 +1231,25 @@
 String refer
+r
 erUrl) %7B%0A   
@@ -1257,24 +1257,25 @@
     if(refer
+r
 erUrl == nul
@@ -1375,16 +1375,17 @@
 er(refer
+r
 erUrl).m

Tweak spelling of referrer in SolrLoggerUtils