<commit_before>package org.owasp.esapi.reference.accesscontrol.policyloader;

import java.io.File;
import java.util.Collection;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Logger;
import org.owasp.esapi.errors.AccessControlException;

final public class ACRPolicyFileLoader {
	protected final Logger logger = ESAPI.getLogger("ACRPolicyFileLoader");
	
	public PolicyDTO load() throws AccessControlException {
		PolicyDTO policyDTO = new PolicyDTO();
		XMLConfiguration config;
		File file = ESAPI.securityConfiguration().getResourceFile("ESAPI-AccessControlPolicy.xml"); 
		try
		{
		    config = new XMLConfiguration(file);		    
		}
		catch(ConfigurationException cex)
		{
			if(file == null) {
				throw new AccessControlException("Unable to load configuration file from the following location: " + file, "", cex);
			}
		    throw new AccessControlException("Unable to load configuration file from the following location: " + file.getAbsolutePath(), "", cex);
		} 

		Object property = config.getProperty("AccessControlRules.AccessControlRule[@name]");
		logger.info(Logger.EVENT_SUCCESS, "Loading Property: " + property);
		int numberOfRules = 0;
		if(property instanceof Collection) {
			numberOfRules = ((Collection)property).size();
		} //implied else property == null -> return new PolicyDTO
				 <commit_msg>Replaced exception error msg that used known null value as part of message.<commit_after>package org.owasp.esapi.reference.accesscontrol.policyloader;

import java.io.File;
import java.util.Collection;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Logger;
import org.owasp.esapi.errors.AccessControlException;

final public class ACRPolicyFileLoader {
	protected final Logger logger = ESAPI.getLogger("ACRPolicyFileLoader");
	
	public PolicyDTO load() throws AccessControlException {
		PolicyDTO policyDTO = new PolicyDTO();
		XMLConfiguration config;
		File file = ESAPI.securityConfiguration().getResourceFile("ESAPI-AccessControlPolicy.xml"); 
		try
		{
		    config = new XMLConfiguration(file);		    
		}
		catch(ConfigurationException cex)
		{
			if(file == null) {
				throw new AccessControlException("Unable to load configuration file for the following: " + "ESAPI-AccessControlPolicy.xml", "", cex);
			}
		    throw new AccessControlException("Unable to load configuration file from the following location: " + file.getAbsolutePath(), "", cex);
		} 

		Object property = config.getProperty("AccessControlRules.AccessControlRule[@name]");
		logger.info(Logger.EVENT_SUCCESS, "Loading Property: " + property);
		int numberOfRules = 0;
		if(property instanceof Collection) {
			numberOfRules = ((Collection)property).size();
		} //implied else property == null -> return new PolicyDTO
				 
{'fraction_non_alphanumeric': 0.10178031575411488, 'fraction_numerical': 0.0006718172657037286, 'mean_word_length': 5.065173116089613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '4268821', 'n_tokens_mistral': 867, 'n_tokens_neox': 809, 'n_words': 201}