<commit_before>/*
 * Copyright 2005-2007 The Kuali Foundation.
 * 
 * 
 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 * 
 * 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.kuali.rice.kew.routemodule;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.kuali.rice.core.reflect.ObjectDefinition;
import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
import org.kuali.rice.kew.actionrequest.ActionRequestValue;
import org.kuali.rice.kew.engine.RouteContext;
import org.kuali.rice.kew.engine.node.RouteNodeInstance;
import org.kuali.rice.kew.rule.RuleAttribute;
import org.kuali.rice.kew.rule.RuleBaseValues;
import org.kuali.rice.kew.rule.RuleExtension;
import org.kuali.rice.kew.rule.RuleResponsibility;
import org.kuali.rice.kew.rule.WorkflowAttribute;
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute;
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.util.KEWConstants;
import org.kuali.rice.kew.util.XmlHelper;
import org.kuali.rice.kew.xml.RuleXmlParser;
import org.kuali.rice.kew.xml.XmlConstants;


/**
 * A RouteModule that generates requests for responsibilities statically defined
 * in the config block of the node.
 * @author <NAME> (<EMAIL>)
 */
public class InlineRequestsRouteModule extends FlexRMAdapter {
    private static final Logger LOG = Logger.getLogger(InlineRequestsRouteModule.class);

    /**
     * This overridden method is used to decipher the inline xpath and responsibilities of a route node definition and use
     * them to create action reqeusts
     * 
     * @see org.kuali.rice.kew.routemodule.FlexRMAdapter#findActionRequests(org.kuali.rice.kew.engine.RouteContext)
     */
    @Override
    public List<ActionRequestValue> findActionRequests(RouteContext context) throws Exception {
        // comment this out while implementing the meta-rules stuff
        // re-implement later
        List<ActionRequestValue> actionRequests = new ArrayList<ActionRequestValue>();
        RouteNodeInstance currentNode = context.getNodeInstance();
        String contentFragment = currentNode.getRouteNode().getContentFragment();
        // parse with JDOM to reuse RuleXmlParser
        Document doc = XmlHelper.trimSAXXml(new ByteArrayInputStream(contentFragment.getBytes()));
        Element root = doc.getRootElement();
        List<String> ruleAttributeNames = new ArrayList<String>();
        List<String> ruleAttributeClassNames = new ArrayList<String>();
        List<String> xpathExpressions = new ArrayList<String>();
        // get the list of ruleAttributes to use
        Element ruleAttributes = root.getChild("ruleAttributes");
        if (ruleAttributes != null) {
            for (Object o : ruleAttributes.getChildren("name")) {
                Element e = (Element) o;
                ruleAttributeNames.add(e.getText());
            }
            for (Object o : ruleAttributes.getChildren("className")) {
                Element e = (Element) o;
                ruleAttributeClassNames.add(e.getText());
            }
        }
        // get the list of xpath expressions to verify
        for (Object o: root.getChildren("match")) {
            Element e = (Element) o;
            xpathExpressions.add(e.getText());
        }
        if ( (ruleAttributeNames.isEmpty()) && (ruleAttributeClassNames.isEmpty()) && (xpathExpressions.isEmpty()) ) {
            throw new RuntimeException("Match xpath expression not specified (should be parse-time exception...)");
        }
<commit_msg>KULRICE-2179 replaced EN_RTE_NODE_T.CONTENT_FRAGMENT by contentFragment<commit_after>/*
 * Copyright 2005-2007 The Kuali Foundation.
 * 
 * 
 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 * 
 * 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.kuali.rice.kew.routemodule;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.kuali.rice.core.reflect.ObjectDefinition;
import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
import org.kuali.rice.kew.actionrequest.ActionRequestFactory;
import org.kuali.rice.kew.actionrequest.ActionRequestValue;
import org.kuali.rice.kew.engine.RouteContext;
import org.kuali.rice.kew.engine.node.RouteNodeInstance;
import org.kuali.rice.kew.rule.RuleAttribute;
import org.kuali.rice.kew.rule.RuleBaseValues;
import org.kuali.rice.kew.rule.RuleExtension;
import org.kuali.rice.kew.rule.RuleResponsibility;
import org.kuali.rice.kew.rule.WorkflowAttribute;
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute;
import org.kuali.rice.kew.rule.xmlrouting.XPathHelper;
import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.util.KEWConstants;
import org.kuali.rice.kew.util.Utilities;
import org.kuali.rice.kew.util.XmlHelper;
import org.kuali.rice.kew.xml.RuleXmlParser;
import org.kuali.rice.kew.xml.XmlConstants;


/**
 * A RouteModule that generates requests for responsibilities statically defined
 * in the config block of the node.
 * @author Kuali Rice Team (<EMAIL>)
 */
public class InlineRequestsRouteModule extends FlexRMAdapter {
    private static final Logger LOG = Logger.getLogger(InlineRequestsRouteModule.class);

    /**
     * This overridden method is used to decipher the inline xpath and responsibilities of a route node definition and use
     * them to create action reqeusts
     * 
     * @see org.kuali.rice.kew.routemodule.FlexRMAdapter#findActionRequests(org.kuali.rice.kew.engine.RouteContext)
     */
    @Override
    public List<ActionRequestValue> findActionRequests(RouteContext context) throws Exception {
        // comment this out while implementing the meta-rules stuff
        // re-implement later
        List<ActionRequestValue> actionRequests = new ArrayList<ActionRequestValue>();
        RouteNodeInstance currentNode = context.getNodeInstance();
        Map<String, String> cfgMap = Utilities.getKeyValueCollectionAsMap(currentNode.getRouteNode().getConfigParams());
        String contentFragment = cfgMap.get("contentFragment");
        // parse with JDOM to reuse RuleXmlParser
        Document doc = XmlHelper.trimSAXXml(new ByteArrayInputStream(contentFragment.getBytes()));
        Element root = doc.getRootElement();
        List<String> ruleAttributeNames = new ArrayList<String>();
        List<String> ruleAttributeClassNames = new ArrayList<String>();
        List<String> xpathExpressions = new ArrayList<String>();
        // get the list of ruleAttributes to use
        Element ruleAttributes = root.getChild("ruleAttributes");
        if (ruleAttributes != null) {
            for (Object o : ruleAttributes.getChildren("name")) {
                Element e = (Element) o;
                ruleAttributeNames.add(e.getText());
            }
            for (Object o : ruleAttributes.getChildren("className")) {
                Element e = (Element) o;
                ruleAttributeClassNames.add(e.getText());
            }
        }
        // get the list of xpath expressions to verify
        for (Object o: root.getChildren("match")) {
            Element e = (Element) o;
            xpathExpressions.add(e.getText());
        }
        if ( (ruleAttributeNames.isEmpty()) && (ruleAttributeClassNames.isEmpty()) && (xpathExpressions.isEmpty()) ) {
            throw new RuntimeException("Match xpath expression not specified (should be parse-time exception...)");
        }

{'fraction_non_alphanumeric': 0.098607367475292, 'fraction_numerical': 0.0031446540880503146, 'mean_word_length': 3.6452790818988, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, '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': '5328713', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2514, 'n_words': 638}