<commit_before>package de.akquinet.chameria.web.exposer;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Property;
import org.apache.felix.ipojo.annotations.Unbind;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Component(immediate=true)
@Instantiate
public class WebExposer {

    public class ExposerHttpContext implements HttpContext {

        private String m_prefix;

        public ExposerHttpContext() {
            if (m_alias.startsWith("/")) {
                m_prefix = m_alias.substring(1) + "/";
            } else {
                m_prefix = m_alias + "/";
            }
        }

        public boolean handleSecurity(HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            return true;
        }

        public URL getResource(String name) {

            if (name.startsWith(m_prefix)) {
                name = name.substring(m_prefix.length());
            }

            File file = new File(m_root, name);
            m_logger.info("Looking for " + file.getAbsolutePath());
            try {
                return file.toURI().toURL();
            } catch (MalformedURLException e) {
                // Cannot happen.<commit_msg>If the targeted resource is a directory, served the index.html file is it exists.<commit_after>package de.akquinet.chameria.web.exposer;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Property;
import org.apache.felix.ipojo.annotations.Unbind;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Component(immediate=true)
@Instantiate
public class WebExposer {

    public class ExposerHttpContext implements HttpContext {

        private String m_prefix;

        public ExposerHttpContext() {
            if (m_alias.startsWith("/")) {
                m_prefix = m_alias.substring(1) + "/";
            } else {
                m_prefix = m_alias + "/";
            }
        }

        public boolean handleSecurity(HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            return true;
        }

        public URL getResource(String name) {

            if (name.startsWith(m_prefix)) {
                name = name.substring(m_prefix.length());
            }

            File file = new File(m_root, name);

            if (file.isDirectory()) {
                File index = new File(file, "index.html");
                if (index.exists()) {
                    file = index;
                }
            }

            m_logger.info("Looking for " + file.getAbsolutePath());
            try {
                return file.toURI().toURL();
            } catch (MalformedURLException e) {
                // Cannot happen.
{'fraction_non_alphanumeric': 0.10078782939418636, 'fraction_numerical': 0.0016299918500407497, 'mean_word_length': 2.4411214953271028, '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': '5453884', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1025, 'n_words': 205}