<commit_before>package se.lagrummet.rinfo.store.supply;

import java.util.*;

import org.restlet.Context;
import org.restlet.Finder;
import org.restlet.Handler;
import org.restlet.data.Language;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.resource.FileRepresentation;
import org.restlet.resource.Resource;
import org.restlet.resource.Variant;

import se.lagrummet.rinfo.store.depot.DeletedDepotEntryException;
import se.lagrummet.rinfo.store.depot.DepotContent;
import se.lagrummet.rinfo.store.depot.DepotReadException;
import se.lagrummet.rinfo.store.depot.FileDepot;
import se.lagrummet.rinfo.store.depot.LockedDepotEntryException;


public class DepotFinder extends Finder {

    private FileDepot fileDepot;

    public DepotFinder() { super(); }
    public DepotFinder(Context context) { super(context); }
    public DepotFinder(Context context, FileDepot fileDepot) {
        this(context);
        this.fileDepot = fileDepot;
    }

    @Override
    public Handler findTarget(Request request, Response response) {
        List<DepotContent> results = null;
        try {
            // TODO:? E.g in a servlet container, how to handle </webapp/> base?
            // fileDepot may not want such an "instrumental" base segment,
            // in case it should reinterpret non-full url as e.g. a tag uri..?
            results = fileDepot.find(
                    request.getResourceRef().getPath().toString());<commit_msg>DepotFinder now uses relativeRef for depot uri:s (works if proxied to and deployed under named context).<commit_after>package se.lagrummet.rinfo.store.supply;

import java.util.*;

import org.restlet.Context;
import org.restlet.Finder;
import org.restlet.Handler;
import org.restlet.data.Language;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.resource.FileRepresentation;
import org.restlet.resource.Resource;
import org.restlet.resource.Variant;

import se.lagrummet.rinfo.store.depot.DeletedDepotEntryException;
import se.lagrummet.rinfo.store.depot.DepotContent;
import se.lagrummet.rinfo.store.depot.DepotReadException;
import se.lagrummet.rinfo.store.depot.FileDepot;
import se.lagrummet.rinfo.store.depot.LockedDepotEntryException;


public class DepotFinder extends Finder {

    private FileDepot fileDepot;

    public DepotFinder() { super(); }
    public DepotFinder(Context context) { super(context); }
    public DepotFinder(Context context, FileDepot fileDepot) {
        this(context);
        this.fileDepot = fileDepot;
    }

    @Override
    public Handler findTarget(Request request, Response response) {
        List<DepotContent> results = null;
        try {
            // TODO:? E.g in a servlet container, how to handle </webapp/> base?
            // fileDepot may not want such an "instrumental" base segment,
            // in case it should reinterpret non-full url as e.g. a tag uri..?
            // Is resourceRef.relativeRef ok? Only if we *don't* want the public ref!
            // See also resourceRef.baseRef

            String relativePath =
                    request.getResourceRef().getRelativeRef().getPath().toString();
            if (!relativePath.startsWith("/")) {
                relativePath = "/" + relativePath;
            }
            results = fileDepot.find(relativePath);
{'fraction_non_alphanumeric': 0.1014367816091954, 'fraction_numerical': 0.0, 'mean_word_length': 3.3403990024937658, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6004248', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1042, 'n_words': 244}