<commit_before>/*
 * $Log: DigesterPipe.java,v $
 * Revision 1.8  2004-03-26 10:42:34  NNVZNL01#L180564
 * added @version tag in javadoc
 *
 * Revision 1.7  2004/03/24 13:53:36  <NAME> <<EMAIL>>
 * cosmetic changes
 *
 */
package nl.nn.adapterframework.pipes;

import java.io.ByteArrayInputStream;
import java.net.URL;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.PipeLineSession;
import nl.nn.adapterframework.core.PipeRunException;
import nl.nn.adapterframework.core.PipeRunResult;
import nl.nn.adapterframework.util.ClassUtils;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;

/**
 * Converts an XML string (input) to a set of java objects using the
 * <a href="http://jakarta.apache.org/commons/digester">digester</a>.
 * <p>The result is an anonymous object. Your digester-rules file should specify
 * how the xml file is parsed, and what the root object will be.</p>
  * <p><b>Configuration:</b>
 * <table border="1">
 * <tr><th>attributes</th><th>description</th><th>default</th></tr>
 * <tr><td>{@link #setName(String) name}</td><td>name of the Pipe</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setMaxThreads(int) maxThreads}</td><td>maximum number of threads that may call {@link #doPipe(Object, nl.nn.adapterframework.core.PipeLineSession)} simultaneously</td><td>0 (unlimited)</td></tr>
 * <tr><td>{@link #setForwardName(String) forwardName}</td>  <td>name of forward returned upon completion</td><td>"success"</td></tr>
 * <tr><td>{@link #setDigesterRulesFile(String) digesterRulesFile}</td><td>name of file that containts the rules for xml parsing</td><td>(none)</td></tr>
 * </table>
 
 * <p><b>Exits:</b>
 * <table border="1">
 * <tr><th>state</th><th>condition</th></tr>
 * <tr><td>"success"</td><td>default</td></tr>
 * </table></p>
 * @version Id 
 * @author <NAME>
 * @since 4.0.1 : adjustments to support multi-threading
 */

public class DigesterPipe extends FixedForwardPipe {
	public static final String version="$Id: DigesterPipe.java,v 1.8 2004-03-26 10:42:34 NNVZNL01#L180564 Exp $";

	private PipeRunResult pipeRunResult;
	private String digesterRulesFile;
	private URL rulesURL;

	public void configure() throws ConfigurationException {
		super.configure();

		try {
     		 rulesURL = ClassUtils.getResourceURL(this, digesterRulesFile);
 			 DigesterLoader.createDigester(rulesURL); // load rules to check if they can be loaded when needed
		} catch (Exception e) {
			throw new ConfigurationException(getLogPrefix(null)+"Digester rules file ["+digesterRulesFile+"] not found", e); 
		}
		log.debug(getLogPrefix(null)+"End of configuration");
	}

	public PipeRunResult doPipe(Object input, PipeLineSession session)
		throws PipeRunException {

		//Multi threading: instantiate digester for each request as the digester is NOT thread-safe.		
		Digester digester = DigesterLoader.createDigester(rulesURL);
			
		try {
			ByteArrayInputStream xmlInputStream =
				new ByteArrayInputStream(input.toString().getBytes());

			return new PipeRunResult(getForward(), digester.parse(xmlInputStream));
				
		} catch (Exception e) {
			throw new PipeRunException(this, getLogPrefix(session)+"exception in digesting", e);
		}
	}


	/**
	 * Sets the location of the resource with digester rules used for processing messages. 
	 */
	public void setDigesterRulesFile(String digesterRulesFile) {
		this.digesterRulesFile = digesterRulesFile;
	}
	public String getDigesterRulesFile() {
		return digesterRulesFile;
	}

}
<commit_msg>removed unused code<commit_after>/*
 * $Log: DigesterPipe.java,v $
 * Revision 1.9  2004-10-05 10:49:32  L190409
 * removed unused code
 *
 * Revision 1.8  2004/03/26 10:42:34  <NAME> <<EMAIL>>
 * added @version tag in javadoc
 *
 * Revision 1.7  2004/03/24 13:53:36  <NAME> <<EMAIL>>
 * cosmetic changes
 *
 */
package nl.nn.adapterframework.pipes;

import java.io.ByteArrayInputStream;
import java.net.URL;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.PipeLineSession;
import nl.nn.adapterframework.core.PipeRunException;
import nl.nn.adapterframework.core.PipeRunResult;
import nl.nn.adapterframework.util.ClassUtils;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.xmlrules.DigesterLoader;

/**
 * Converts an XML string (input) to a set of java objects using the
 * <a href="http://jakarta.apache.org/commons/digester">digester</a>.
 * <p>The result is an anonymous object. Your digester-rules file should specify
 * how the xml file is parsed, and what the root object will be.</p>
  * <p><b>Configuration:</b>
 * <table border="1">
 * <tr><th>attributes</th><th>description</th><th>default</th></tr>
 * <tr><td>{@link #setName(String) name}</td><td>name of the Pipe</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setMaxThreads(int) maxThreads}</td><td>maximum number of threads that may call {@link #doPipe(Object, nl.nn.adapterframework.core.PipeLineSession)} simultaneously</td><td>0 (unlimited)</td></tr>
 * <tr><td>{@link #setForwardName(String) forwardName}</td>  <td>name of forward returned upon completion</td><td>"success"</td></tr>
 * <tr><td>{@link #setDigesterRulesFile(String) digesterRulesFile}</td><td>name of file that containts the rules for xml parsing</td><td>(none)</td></tr>
 * </table>
 
 * <p><b>Exits:</b>
 * <table border="1">
 * <tr><th>state</th><th>condition</th></tr>
 * <tr><td>"success"</td><td>default</td></tr>
 * </table></p>
 * @version Id 
 * @author <NAME>
 * @since 4.0.1 : adjustments to support multi-threading
 */

public class DigesterPipe extends FixedForwardPipe {
	public static final String version="$Id: DigesterPipe.java,v 1.9 2004-10-05 10:49:32 L190409 Exp $";

	private String digesterRulesFile;
	private URL rulesURL;

	public void configure() throws ConfigurationException {
		super.configure();

		try {
     		 rulesURL = ClassUtils.getResourceURL(this, digesterRulesFile);
 			 DigesterLoader.createDigester(rulesURL); // load rules to check if they can be loaded when needed
		} catch (Exception e) {
			throw new ConfigurationException(getLogPrefix(null)+"Digester rules file ["+digesterRulesFile+"] not found", e); 
		}
		log.debug(getLogPrefix(null)+"End of configuration");
	}

	public PipeRunResult doPipe(Object input, PipeLineSession session)
		throws PipeRunException {

		//Multi threading: instantiate digester for each request as the digester is NOT thread-safe.
		//TODO: make a pool of digesters		
		Digester digester = DigesterLoader.createDigester(rulesURL);
			
		try {
			ByteArrayInputStream xmlInputStream =
				new ByteArrayInputStream(input.toString().getBytes());

			return new PipeRunResult(getForward(), digester.parse(xmlInputStream));
				
		} catch (Exception e) {
			throw new PipeRunException(this, getLogPrefix(session)+"exception in digesting", e);
		}
	}


	/**
	 * Sets the location of the resource with digester rules used for processing messages. 
	 */
	public void setDigesterRulesFile(String digesterRulesFile) {
		this.digesterRulesFile = digesterRulesFile;
	}
	public String getDigesterRulesFile() {
		return digesterRulesFile;
	}

}

{'fraction_non_alphanumeric': 0.13915947676036738, 'fraction_numerical': 0.021152240467575842, 'mean_word_length': 4.994161801501251, 'pattern_counts': {'":': 0, '<': 148, '<?xml version=': 0, '>': 148, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '3519057', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2281, 'n_words': 556}