<commit_before>package com.amee.base.resource;

import org.jdom.Document;
import org.jdom.Element;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class ResponseHelper {

    public static Object getOK(RequestWrapper requestWrapper) {
        if (requestWrapper.getAcceptedMediaTypes().contains("application/json")) {
            return getStatusJSONObject("OK");
        } else {
            return getStatusDocument("OK");
        }
    }

    public static Object getNotFound(RequestWrapper requestWrapper) {
        if (requestWrapper.getAcceptedMediaTypes().contains("application/json")) {
            return getStatusJSONObject("NOT_FOUND");
        } else {
            return getStatusDocument("NOT_FOUND");
        }
    }

    public static JSONObject getStatusJSONObject(String status) {
        try {
            JSONObject o = new JSONObject();
            o.put("status", status);
            return o;
        } catch (JSONException e) {
            throw new RuntimeException("Caught JSONException: " + e.getMessage(), e);
        }
    }

    public static Document getStatusDocument(String status) {
        Element rootElem = new Element("Representation");
        rootElem.addContent(new Element("Status").setText(status));
        return new Document(rootElem);
    }
}<commit_msg>PL-1892 - Added support for Location header to framework and used this in ReturnValueDefinitionsFormAcceptor. PL-1893 - Create RVD integration tests.<commit_after>package com.amee.base.resource;

import org.jdom.Document;
import org.jdom.Element;
import org.json.JSONException;
import org.json.JSONObject;

public abstract class ResponseHelper {

    public static Object getOK(RequestWrapper requestWrapper) {
        return getOK(requestWrapper, null);
    }

    public static Object getOK(RequestWrapper requestWrapper, String location) {
        if (requestWrapper.getAcceptedMediaTypes().contains("application/json")) {
            return getStatusJSONObject("OK", location);
        } else {
            return getStatusDocument("OK", location);
        }
    }

    public static Object getNotFound(RequestWrapper requestWrapper) {
        if (requestWrapper.getAcceptedMediaTypes().contains("application/json")) {
            return getStatusJSONObject("NOT_FOUND");
        } else {
            return getStatusDocument("NOT_FOUND");
        }
    }

    public static JSONObject getStatusJSONObject(String status) {
        return getStatusJSONObject(status, null);
    }

    public static JSONObject getStatusJSONObject(String status, String location) {
        try {
            JSONObject o = new JSONObject();
            o.put("status", status);
            if (location != null) {
                o.put("location", location);
            }
            return o;
        } catch (JSONException e) {
            throw new RuntimeException("Caught JSONException: " + e.getMessage(), e);
        }
    }

    public static Document getStatusDocument(String status) {
        return getStatusDocument(status, null);
    }

    public static Document getStatusDocument(String status, String location) {
        Element rootElem = new Element("Representation");
        rootElem.addContent(new Element("Status").setText(status));
        if (location != null) {
            rootElem.addContent(new Element("Location").setText(location));
        }
        return new Document(rootElem);
    }
}
{'fraction_non_alphanumeric': 0.09810771470160116, 'fraction_numerical': 0.0023289665211062593, 'mean_word_length': 2.8008849557522124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2365925', 'n_tokens_mistral': 866, 'n_tokens_neox': 848, 'n_words': 209}