<commit_before>/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you 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 org.apache.james.container.spring.adaptor;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.phoenix.tools.configuration.ConfigurationBuilder;
import org.apache.james.container.spring.configuration.ConfigurationInterceptor;
import org.springframework.core.io.Resource;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.BeansException;
import org.xml.sax.InputSource;

import java.util.Iterator;
import java.util.List;
import java.io.InputStream;
import java.io.IOException;

/**
 * loads the well-known classic James configuration file
 *
  * TODO make this thing be based on Resource class and inject resource.getInputStream() into InputSource 
 */
public class AvalonConfigurationFileProvider implements ConfigurationProvider, ApplicationContextAware {

    private String absoluteFilePath;
    private List configurationInterceptors;
    private ApplicationContext applicationContext;
    private String configuration;

    public void setConfigurationResource(String configuration) {
        this.configuration = configuration;
    }


    public Configuration getConfiguration() {
        Resource resource = applicationContext.getResource(configuration);
        InputStream inputStream;
        try {
            inputStream = applicationContext.getResource(configuration).getInputStream();
        } catch (IOException e) {
            throw new RuntimeException("could not locate configuration file " + configuration, e);
        }
        InputSource inputSource = new InputSource(inputStream);
        Configuration configuration;
        try
        {
            configuration = ConfigurationBuilder.build(inputSource, null, null);
        }<commit_msg>no need to inline xml entity configuration files if you make them available to the XML configuration loader properly. simple but great patch by Zsombor (spring.patch) [JAMES-803]<commit_after>/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you 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 org.apache.james.container.spring.adaptor;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.phoenix.tools.configuration.ConfigurationBuilder;
import org.apache.james.container.spring.configuration.ConfigurationInterceptor;
import org.springframework.core.io.Resource;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.BeansException;
import org.xml.sax.InputSource;

import java.util.Iterator;
import java.util.List;
import java.io.InputStream;
import java.io.IOException;

/**
 * loads the well-known classic James configuration file
 *
  * TODO make this thing be based on Resource class and inject resource.getInputStream() into InputSource 
 */
public class AvalonConfigurationFileProvider implements ConfigurationProvider, ApplicationContextAware {

    private String absoluteFilePath;
    private List configurationInterceptors;
    private ApplicationContext applicationContext;
    private String configuration;

    public void setConfigurationResource(String configuration) {
        this.configuration = configuration;
    }


    public Configuration getConfiguration() {
        Resource resource = applicationContext.getResource(configuration);
        InputStream inputStream;
        try {
            inputStream = resource.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException("could not locate configuration file " + configuration, e);
        }
        InputSource inputSource = new InputSource(inputStream);
        Configuration configuration;
        try
        {
            inputSource.setSystemId(resource.getURL().toString());
            configuration = ConfigurationBuilder.build(inputSource, null, null);
        }
{'fraction_non_alphanumeric': 0.10534767946041433, 'fraction_numerical': 0.0017665007226593866, 'mean_word_length': 3.0103026400515134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '989403', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1284, 'n_words': 463}