<commit_before>package org.drools.compiler.xml.processes;

/*
 * Copyright 2005 JBoss Inc
 * 
 * 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.
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;


import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


/*******************************************************************************
 * Class the migrates drools version 4 .rfm and .rf ruleflow files to version
 * 5 .rf and .rfm ruleflows.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 ******************************************************************************/
public class RuleFlowMigrator 
{
    /**
     * XSL file that transforms drools 4 .rfm ruleflow files to version 5
     */
    private static final String  XSL_RFM_FROM_4_TO_5 = "/org/drools/xml/processes/RuleFlowFrom4To5.xsl";
    
    /**
     * XSL file that transforms drools 4 .rf (graphical) ruleflow files to 
     * version 5
     */
    private static final String  XSL_RF_FROM_4_TO_5  = "/org/drools/xml/processes/RuleFlowGraphicalFrom4To5.xsl";
    
    /**
     * String containing namespace header for migrtated ruleflow files
     */
    private static final String  PROCESS_ELEMENT_WITH_NAMESPACE = "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
                                                                           + "    xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
    
    /*************************************************************************
     * Returns a drools 5 version of a given drools 4 .rf (Graphical) ruleflow
     * in string format. Note that this method assumes the given ruleflow 
     * is a valid version 4 .rf ruleflow - this can be checked using the
     * needToMigrateRF method.
     * 
     * @param xml Drools 4 ruleflow (.rf) in xml format
     * @return drools 5 version of a given drools 4 .rf (Graphical) ruleflow
     * in string format.
     * @throws Exception
     ************************************************************************/
    public static String portRFToCurrentVersion(String xml) throws Exception 
    {
    	return portToCurrentVersion(xml, XSL_RF_FROM_4_TO_5);
    }
    
    /*************************************************************************
     * Returns a drools 5 version of a given drools 4 .rfm ruleflow
     * in string format. Note that this method assumes the given ruleflow 
     * is a valid version 4 .rfm ruleflow - this can be checked using the<commit_msg>JBRULES-2351 OSGi Ready  -refactored xml and util directories to avoid split packages<commit_after>package org.drools.compiler.xml.processes;

/*
 * Copyright 2005 JBoss Inc
 * 
 * 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.
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;


import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


/*******************************************************************************
 * Class the migrates drools version 4 .rfm and .rf ruleflow files to version
 * 5 .rf and .rfm ruleflows.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 ******************************************************************************/
public class RuleFlowMigrator 
{
    /**
     * XSL file that transforms drools 4 .rfm ruleflow files to version 5
     */
    private static final String  XSL_RFM_FROM_4_TO_5 = "/org/drools/compiler/xml/processes/RuleFlowFrom4To5.xsl";
    
    /**
     * XSL file that transforms drools 4 .rf (graphical) ruleflow files to 
     * version 5
     */
    private static final String  XSL_RF_FROM_4_TO_5  = "/org/drools/compiler/xml/processes/RuleFlowGraphicalFrom4To5.xsl";
    
    /**
     * String containing namespace header for migrtated ruleflow files
     */
    private static final String  PROCESS_ELEMENT_WITH_NAMESPACE = "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
                                                                           + "    xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
    
    /*************************************************************************
     * Returns a drools 5 version of a given drools 4 .rf (Graphical) ruleflow
     * in string format. Note that this method assumes the given ruleflow 
     * is a valid version 4 .rf ruleflow - this can be checked using the
     * needToMigrateRF method.
     * 
     * @param xml Drools 4 ruleflow (.rf) in xml format
     * @return drools 5 version of a given drools 4 .rf (Graphical) ruleflow
     * in string format.
     * @throws Exception
     ************************************************************************/
    public static String portRFToCurrentVersion(String xml) throws Exception 
    {
    	return portToCurrentVersion(xml, XSL_RF_FROM_4_TO_5);
    }
    
    /*************************************************************************
     * Returns a drools 5 version of a given drools 4 .rfm ruleflow
     * in string format. Note that this method assumes the given ruleflow 
     * is a valid version 4 .rfm ruleflow - this can be checked using the
{'fraction_non_alphanumeric': 0.18444693992139247, 'fraction_numerical': 0.01291409320606401, 'mean_word_length': 3.4282162834058423, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 31}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '683623', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1880, 'n_words': 626}