<commit_before>/*
 * Copyright 2006 Wyona
 */

package org.wyona.yanel.impl.resources.updatefinder.utils;

import org.apache.log4j.Category;

import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import javax.servlet.http.HttpServletRequest;



public class TomcatContextHandler {
    private static Category log = Category.getInstance(TomcatContextHandler.class);
    private String webappsDirectoryPath;
    private File webappsDirectory;
    private String contextConfPath;
    private File contextConfDirectory;
    
    public TomcatContextHandler(HttpServletRequest request) throws Exception {
        this.webappsDirectoryPath = request.getSession().getServletContext().getRealPath(".") + File.separator + ".." + File.separator;
        this.webappsDirectory = new File(webappsDirectoryPath);
        this.contextConfPath = webappsDirectoryPath  + ".." + File.separator + "conf" + File.separator + "Catalina" + File.separator + "localhost" + File.separator;
        this.contextConfDirectory = new File(contextConfPath);
    }
    
    public String[] getWebappNames() {
        String[] webapps = new String[this.webappsDirectory.listFiles().length];
        for (int i = 0; i < this.webappsDirectory.listFiles().length; i++) {
            webapps[i] = this.webappsDirectory.listFiles()[i].getName();
        }
        return webapps;
    }
    
    public String[] getContextNames() {
        String[] contexts = new String[this.contextConfDirectory.listFiles().length];
        for (int i = 0; i < this.contextConfDirectory.listFiles().length; i++) {
            contexts[i] = this.contextConfDirectory.listFiles()[i].getName().replaceAll(".xml", "");
            if (contexts[i].equals("ROOT")) {
                contexts[i] = "/";
            }
        }
        return contexts;
    }
    <commit_msg>comment added re how to implement context listing differently<commit_after>/*
 * Copyright 2006 Wyona
 */

package org.wyona.yanel.impl.resources.updatefinder.utils;

import org.apache.log4j.Category;

import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import javax.servlet.http.HttpServletRequest;



public class TomcatContextHandler {
    private static Category log = Category.getInstance(TomcatContextHandler.class);
    private String webappsDirectoryPath;
    private File webappsDirectory;
    private String contextConfPath;
    private File contextConfDirectory;
    
    public TomcatContextHandler(HttpServletRequest request) throws Exception {
        this.webappsDirectoryPath = request.getSession().getServletContext().getRealPath(".") + File.separator + ".." + File.separator;
        this.webappsDirectory = new File(webappsDirectoryPath);

        // TODO: This directory should not be hardcoded here, but rather configurable somewhere!
        // resp. see
        // http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
        // http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
        // which generates the context overview: http://127.0.0.1:8080/manager/html (whereas add roles manager to conf/tomcat-users.xml and restart Tomcat)
        this.contextConfPath = webappsDirectoryPath  + ".." + File.separator + "conf" + File.separator + "Catalina" + File.separator + "localhost" + File.separator;
        this.contextConfDirectory = new File(contextConfPath);
    }
    
    public String[] getWebappNames() {
        String[] webapps = new String[this.webappsDirectory.listFiles().length];
        for (int i = 0; i < this.webappsDirectory.listFiles().length; i++) {
            webapps[i] = this.webappsDirectory.listFiles()[i].getName();
        }
        return webapps;
    }
    
    public String[] getContextNames() {
        String[] contexts = new String[this.contextConfDirectory.listFiles().length];
        for (int i = 0; i < this.contextConfDirectory.listFiles().length; i++) {
            contexts[i] = this.contextConfDirectory.listFiles()[i].getName().replaceAll(".xml", "");
            if (contexts[i].equals("ROOT")) {
                contexts[i] = "/";
            }
        }
        return contexts;
    }
    
{'fraction_non_alphanumeric': 0.11881394863228231, 'fraction_numerical': 0.005011484652328252, 'mean_word_length': 3.398530762167126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 1, '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': '7065923', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1323, 'n_words': 273}