<commit_before>/*
 Created as part of the StratusLab project (http://stratuslab.eu),
 co-funded by the European Commission under the Grant Agreement
 INFSO-RI-261552.

 Copyright (c) 2011, Centre National de la Recherche Scientifique (CNRS)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package eu.stratuslab.registration.resources;

import java.util.HashMap;
import java.util.Map;

import org.restlet.Request;
import org.restlet.data.MediaType;
import org.restlet.ext.freemarker.TemplateRepresentation;
import org.restlet.resource.ServerResource;

import eu.stratuslab.registration.utils.RequestUtils;
import freemarker.template.Configuration;

public class BaseResource extends ServerResource {

    protected static final String NO_TITLE = null;

    protected TemplateRepresentation templateRepresentation(String tpl,
            Map<String, Object> info, MediaType mediaType) {

        Request request = getRequest();

        Configuration freeMarkerConfig = RequestUtils
                .extractFreeMarkerConfig(request);

        return new TemplateRepresentation(tpl, freeMarkerConfig, info,
                mediaType);
    }

    public static String getBaseUrl(Request request) {
        String url = request.getRootRef().toString();
        if (url.endsWith("/")) {
            return url;
        } else {
            return url + "/";
        }
    }

    protected Map<String, Object> createInfoStructure(String title) {
        return createInfoStructure(title, getRequest());
    }

    public static Map<String, Object> createInfoStructure(String title,
            Request request) {

        Map<String, Object> info = new HashMap<String, Object>();

        // Add the standard base URL declaration.
        info.put("baseurl", getBaseUrl(request));

        // Add the title if appropriate.
        if (title != null && !"".equals(title)) {
            info.put("title", title);
        }

        return info;
    }<commit_msg>hardcode proxy switch to https scheme<commit_after>/*
 Created as part of the StratusLab project (http://stratuslab.eu),
 co-funded by the European Commission under the Grant Agreement
 INFSO-RI-261552.

 Copyright (c) 2011, Centre National de la Recherche Scientifique (CNRS)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package eu.stratuslab.registration.resources;

import java.util.HashMap;
import java.util.Map;

import org.restlet.Request;
import org.restlet.data.MediaType;
import org.restlet.ext.freemarker.TemplateRepresentation;
import org.restlet.resource.ServerResource;

import eu.stratuslab.registration.utils.RequestUtils;
import freemarker.template.Configuration;

public class BaseResource extends ServerResource {

    protected static final String NO_TITLE = null;

    protected TemplateRepresentation templateRepresentation(String tpl,
            Map<String, Object> info, MediaType mediaType) {

        Request request = getRequest();

        Configuration freeMarkerConfig = RequestUtils
                .extractFreeMarkerConfig(request);

        return new TemplateRepresentation(tpl, freeMarkerConfig, info,
                mediaType);
    }

    // FIXME: The switch from http to https needs to be signaled 
    // via a header indicating the proxy value.
    public static String getBaseUrl(Request request) {
        String url = request.getRootRef().toString();
        url = url.replaceFirst("http:", "https:")
        if (url.endsWith("/")) {
            return url;
        } else {
            return url + "/";
        }
    }

    protected Map<String, Object> createInfoStructure(String title) {
        return createInfoStructure(title, getRequest());
    }

    public static Map<String, Object> createInfoStructure(String title,
            Request request) {

        Map<String, Object> info = new HashMap<String, Object>();

        // Add the standard base URL declaration.
        info.put("baseurl", getBaseUrl(request));

        // Add the title if appropriate.
        if (title != null && !"".equals(title)) {
            info.put("title", title);
        }

        return info;
    }
{'fraction_non_alphanumeric': 0.08468219502566127, 'fraction_numerical': 0.005527043031977891, 'mean_word_length': 3.143090760425184, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3319523', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1250, 'n_words': 458}