<commit_before>/*
 * IzPack - Copyright 2001-2007 <NAME>, All Rights Reserved.
 *
 * http://www.izforge.com/izpack/
 * http://developer.berlios.de/projects/izpack/
 *
 * Copyright 2007 <NAME>
 *
 * 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 com.izforge.izpack.rules;

import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

import com.izforge.izpack.installer.InstallData;
import com.izforge.izpack.util.Debug;

import net.n3.nanoxml.XMLElement;

/**
 * The rules engine class is the central point for checking conditions
 * 
 * @author <NAME>, <<EMAIL>> created: 09.11.2006, 13:48:39
 */
public class RulesEngine
{

    protected Map panelconditions;

    protected Map packconditions;

    protected Map optionalpackconditions;

    protected XMLElement conditionsspec;

    protected static Map conditionsmap = new Hashtable();

    protected InstallData installdata;

    /**
     * 
     */
    public RulesEngine(XMLElement conditionsspecxml, InstallData installdata)
    {
        this.conditionsspec = conditionsspecxml;
        conditionsmap = new Hashtable();
        this.panelconditions = new Hashtable();
        this.packconditions = new Hashtable();
        this.optionalpackconditions = new Hashtable();
        this.installdata = installdata;
        this.readConditions();
    }

    /**
     * Checks if an attribute for an xmlelement is set.
     * 
     * @param val value of attribute to check
     * @param attribute the attribute which is checked
     * @param element the element
     * @return true value was set false no value was set
     */
    protected boolean checkAttribute(String val, String attribute, String element)
    {
        if ((val != null) && (val.length() > 0))
        {
            return true;
        }
        else
        {
            Debug.trace("Element " + element + " has to specify an attribute " + attribute);
            return false;
        }
    }

    public static Condition analyzeCondition(XMLElement condition)
    {
        String condid = condition.getAttribute("id");
        String condtype = condition.getAttribute("type");
        Condition result = null;
        if (condtype != null)
        {

            String conditiontype = condtype.toLowerCase();
            // TODO: externalize package name
            String conditionclassname = "com.izforge.izpack.rules."
                    + conditiontype.substring(0, 1).toUpperCase()
                    + conditiontype.substring(1, conditiontype.length());
            conditionclassname += "Condition";
            ClassLoader loader = ClassLoader.getSystemClassLoader();
            try
            {
                Class conditionclass = loader.loadClass(conditionclassname);<commit_msg>Allow fully specified condition class names<commit_after>/*
 * IzPack - Copyright 2001-2007 <NAME>, All Rights Reserved.
 *
 * http://www.izforge.com/izpack/
 * http://developer.berlios.de/projects/izpack/
 *
 * Copyright 2007 <NAME>
 *
 * 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 com.izforge.izpack.rules;

import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

import com.izforge.izpack.installer.InstallData;
import com.izforge.izpack.util.Debug;

import net.n3.nanoxml.XMLElement;

/**
 * The rules engine class is the central point for checking conditions
 * 
 * @author <NAME>, <<EMAIL>> created: 09.11.2006, 13:48:39
 */
public class RulesEngine
{

    protected Map panelconditions;

    protected Map packconditions;

    protected Map optionalpackconditions;

    protected XMLElement conditionsspec;

    protected static Map conditionsmap = new Hashtable();

    protected InstallData installdata;

    /**
     * 
     */
    public RulesEngine(XMLElement conditionsspecxml, InstallData installdata)
    {
        this.conditionsspec = conditionsspecxml;
        conditionsmap = new Hashtable();
        this.panelconditions = new Hashtable();
        this.packconditions = new Hashtable();
        this.optionalpackconditions = new Hashtable();
        this.installdata = installdata;
        this.readConditions();
    }

    /**
     * Checks if an attribute for an xmlelement is set.
     * 
     * @param val value of attribute to check
     * @param attribute the attribute which is checked
     * @param element the element
     * @return true value was set false no value was set
     */
    protected boolean checkAttribute(String val, String attribute, String element)
    {
        if ((val != null) && (val.length() > 0))
        {
            return true;
        }
        else
        {
            Debug.trace("Element " + element + " has to specify an attribute " + attribute);
            return false;
        }
    }

    public static Condition analyzeCondition(XMLElement condition)
    {
        String condid = condition.getAttribute("id");
        String condtype = condition.getAttribute("type");
        Condition result = null;
        if (condtype != null)
        {
            String conditionclassname = "";
            if (condtype.indexOf('.')> -1){
                conditionclassname = condtype;
            }
            else {
                String conditiontype = condtype.toLowerCase();
                //  TODO: externalize package name
                conditionclassname = "com.izforge.izpack.rules."
                    + conditiontype.substring(0, 1).toUpperCase()
                    + conditiontype.substring(1, conditiontype.length());
                conditionclassname += "Condition";
            }
            ClassLoader loader = ClassLoader.getSystemClassLoader();
            try
            {
                Class conditionclass = loader.loadClass(conditionclassname);
{'fraction_non_alphanumeric': 0.09092246579373253, 'fraction_numerical': 0.010445784905105194, 'mean_word_length': 2.5332640332640333, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, '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': '5556960', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1749, 'n_words': 557}