<commit_before>package uk.gov.register.presentation;

import org.markdownj.MarkdownProcessor;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.UriBuilder;
import java.util.Map;

@SuppressWarnings("unused, methods of this class are used from html")
public class HtmlViewSupport {
    private static final MarkdownProcessor markdownProcessor = new MarkdownProcessor();

    public static String representationLink(HttpServletRequest httpServletRequest, String representation) {
        String representationUrlSuffix = representation.equals("html") ? "" : "." + representation;
        String requestPath = httpServletRequest.getRequestURI().replaceAll("([^\\.]+)(\\.[a-z]+)?", "$1" + representationUrlSuffix);

        UriBuilder uriBuilder = UriBuilder.fromPath(requestPath);

        Map<String, String[]> parameterMap = httpServletRequest.getParameterMap();
        parameterMap.keySet().stream().forEach(key ->
                        uriBuilder.queryParam(key, parameterMap.get(key)[0])
        );

        return uriBuilder.build().toString();
    }

    public static String fieldLink(String fieldName) {
        return UriBuilder.fromPath("http://field.openregister.org/field").path(fieldName).build().toString();
    }

    public static String publicBodyLink(String publicBodyId){
        return UriBuilder.fromPath("http://public-body.openregister.org/public-body").path(publicBodyId).build().toString();<commit_msg>Using LinkValue instead of duplicating the link logic<commit_after>package uk.gov.register.presentation;

import org.markdownj.MarkdownProcessor;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.UriBuilder;
import java.util.Map;

@SuppressWarnings("unused, methods of this class are used from html")
public class HtmlViewSupport {
    private static final MarkdownProcessor markdownProcessor = new MarkdownProcessor();

    public static String representationLink(HttpServletRequest httpServletRequest, String representation) {
        String representationUrlSuffix = representation.equals("html") ? "" : "." + representation;
        String requestPath = httpServletRequest.getRequestURI().replaceAll("([^\\.]+)(\\.[a-z]+)?", "$1" + representationUrlSuffix);

        UriBuilder uriBuilder = UriBuilder.fromPath(requestPath);

        Map<String, String[]> parameterMap = httpServletRequest.getParameterMap();
        parameterMap.keySet().stream().forEach(key ->
                        uriBuilder.queryParam(key, parameterMap.get(key)[0])
        );

        return uriBuilder.build().toString();
    }

    public static String fieldLink(String fieldName) {
        return new LinkValue("field", fieldName).link();
    }

    public static String publicBodyLink(String publicBodyId){
        return new LinkValue("public-body", publicBodyId).link();
{'fraction_non_alphanumeric': 0.1193342776203966, 'fraction_numerical': 0.00141643059490085, 'mean_word_length': 4.241187384044527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7249081', 'n_tokens_mistral': 729, 'n_tokens_neox': 709, 'n_words': 152}