<commit_before>/*
 * $Log: ErrorMessageFormatter.java,v $
 * Revision 1.7  2007-02-12 14:30:56  europe\L190409
 * corrected version string
 *
 * Revision 1.6  2007/02/12 13:44:29  <NAME> <<EMAIL>>
 * Logger from LogUtil
 *
 * Revision 1.5  2004/09/01 11:26:14  <NAME> <<EMAIL>>
 * made receivedTime optional (only used if non-zero)
 *
 * Revision 1.4  2004/03/30 07:30:00  <NAME> <<EMAIL>>
 * updated javadoc
 *
 */
package nl.nn.adapterframework.errormessageformatters;

import java.util.Date;

import nl.nn.adapterframework.core.IErrorMessageFormatter;
import nl.nn.adapterframework.core.INamedObject;
import nl.nn.adapterframework.util.AppConstants;
import nl.nn.adapterframework.util.LogUtil;
import nl.nn.adapterframework.util.XmlBuilder;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Logger;
/**
 * This <code>ErrorMessageFormatter</code> wraps an error in an XML string.
 *
 * <br/>
 * Sample xml:
 * <br/>
 * <code><pre>
 * &lt;errorMessage&gt;
 *    &lt;message timestamp="Mon Oct 13 12:01:57 CEST 2003" 
 *             originator="NN IOS AdapterFramework(set from 'application.name' and 'application.version')"
 *             message="<i>message describing the error that occurred</i>" &gt;
 *    &lt;location class="nl.nn.adapterframework.pipes.XmlSwitch" name="ServiceSwitch"/&gt
 *    &lt;details&gt<i>detailed information of the error</i>&lt;/details&gt
 *    &lt;originalMessage messageId="..." receivedTime="Mon Oct 27 12:10:18 CET 2003" &gt;
 *        &lt;![CDATA[<i>contents of message for which the error occurred</i>]]&gt;
 *    &lt;/originalMessage&gt;
 * &lt;/errorMessage&gt;
 * </pre></code>
 * 
 * @version Id
 * @author  <NAME>
 */
public class ErrorMessageFormatter implements IErrorMessageFormatter {
	public static final String version = "$RCSfile: ErrorMessageFormatter.java,v $ $Revision: 1.7 $ $Date: 2007-02-12 14:30:56 $";
    protected Logger log = LogUtil.getLogger(this);
	
	/**
	 * Format the available parameters into a XML-message.
	 *
	 * Override this method in descender-classes to obtain the required behaviour.
	 */
	public String format(
	    String message,
	    Throwable t,
	    INamedObject location,
	    String originalMessage,
	    String messageId,
	    long receivedTime) {
	
		String details = null;
		if (t != null) {
			if (message == null || message.equals("")) {
				message = t.getMessage();
			} else {
				message += ": "+t.getMessage();
			}
			details = ExceptionUtils.getStackTrace(t);
		}
		 
		String originator = AppConstants.getInstance().getProperty("application.name")+" "+
	            			AppConstants.getInstance().getProperty("application.version");
	    // Build a Base xml
	    XmlBuilder errorXml = new XmlBuilder("errorMessage");
	    errorXml.addAttribute("timestamp", new Date().toString());
	    errorXml.addAttribute("originator", originator);
	    errorXml.addAttribute("message", message);
	
	    if (location!=null) {
		    XmlBuilder locationXml = new XmlBuilder("location");
		    locationXml.addAttribute("class", location.getClass().getName());
		    locationXml.addAttribute("name", location.getName());
			errorXml.addSubElement(locationXml);
	    }
	    
	    if (details != null && !details.equals("")) {
		    XmlBuilder detailsXml = new XmlBuilder("details");
	    	detailsXml.setCdataValue(details);
		    errorXml.addSubElement(detailsXml);
		}
			
	    XmlBuilder originalMessageXml = new XmlBuilder("originalMessage");
	    originalMessageXml.addAttribute("messageId", messageId);
	    if (receivedTime!=0) {
			originalMessageXml.addAttribute("receivedTime", new Date(receivedTime).toString());
	    }
	   	originalMessageXml.setCdataValue(originalMessage);
	    errorXml.addSubElement(originalMessageXml);
	
	    return errorXml.toXML();
	}
}<commit_msg>fixed bug CDATA in CDATA<commit_after>/*
 * $Log: ErrorMessageFormatter.java,v $
 * Revision 1.8  2010-04-16 11:31:55  m168309
 * fixed bug CDATA in CDATA
 *
 * Revision 1.7  2007/02/12 14:30:56  <NAME> <<EMAIL>>
 * corrected version string
 *
 * Revision 1.6  2007/02/12 13:44:29  <NAME> <<EMAIL>>
 * Logger from LogUtil
 *
 * Revision 1.5  2004/09/01 11:26:14  <NAME> <<EMAIL>>
 * made receivedTime optional (only used if non-zero)
 *
 * Revision 1.4  2004/03/30 07:30:00  <NAME> <<EMAIL>>
 * updated javadoc
 *
 */
package nl.nn.adapterframework.errormessageformatters;

import java.util.Date;

import nl.nn.adapterframework.core.IErrorMessageFormatter;
import nl.nn.adapterframework.core.INamedObject;
import nl.nn.adapterframework.util.AppConstants;
import nl.nn.adapterframework.util.LogUtil;
import nl.nn.adapterframework.util.XmlBuilder;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Logger;
/**
 * This <code>ErrorMessageFormatter</code> wraps an error in an XML string.
 *
 * <br/>
 * Sample xml:
 * <br/>
 * <code><pre>
 * &lt;errorMessage&gt;
 *    &lt;message timestamp="Mon Oct 13 12:01:57 CEST 2003" 
 *             originator="NN IOS AdapterFramework(set from 'application.name' and 'application.version')"
 *             message="<i>message describing the error that occurred</i>" &gt;
 *    &lt;location class="nl.nn.adapterframework.pipes.XmlSwitch" name="ServiceSwitch"/&gt
 *    &lt;details&gt<i>detailed information of the error</i>&lt;/details&gt
 *    &lt;originalMessage messageId="..." receivedTime="Mon Oct 27 12:10:18 CET 2003" &gt;
 *        &lt;![CDATA[<i>contents of message for which the error occurred</i>]]&gt;
 *    &lt;/originalMessage&gt;
 * &lt;/errorMessage&gt;
 * </pre></code>
 * 
 * @version Id
 * @author  <NAME>
 */
public class ErrorMessageFormatter implements IErrorMessageFormatter {
	public static final String version = "$RCSfile: ErrorMessageFormatter.java,v $ $Revision: 1.8 $ $Date: 2010-04-16 11:31:55 $";
    protected Logger log = LogUtil.getLogger(this);
	
	/**
	 * Format the available parameters into a XML-message.
	 *
	 * Override this method in descender-classes to obtain the required behaviour.
	 */
	public String format(
	    String message,
	    Throwable t,
	    INamedObject location,
	    String originalMessage,
	    String messageId,
	    long receivedTime) {
	
		String details = null;
		if (t != null) {
			if (message == null || message.equals("")) {
				message = t.getMessage();
			} else {
				message += ": "+t.getMessage();
			}
			details = ExceptionUtils.getStackTrace(t);
		}
		 
		String originator = AppConstants.getInstance().getProperty("application.name")+" "+
	            			AppConstants.getInstance().getProperty("application.version");
	    // Build a Base xml
	    XmlBuilder errorXml = new XmlBuilder("errorMessage");
	    errorXml.addAttribute("timestamp", new Date().toString());
	    errorXml.addAttribute("originator", originator);
	    errorXml.addAttribute("message", message);
	
	    if (location!=null) {
		    XmlBuilder locationXml = new XmlBuilder("location");
		    locationXml.addAttribute("class", location.getClass().getName());
		    locationXml.addAttribute("name", location.getName());
			errorXml.addSubElement(locationXml);
	    }
	    
	    if (details != null && !details.equals("")) {
		    XmlBuilder detailsXml = new XmlBuilder("details");
	    	//detailsXml.setCdataValue(details);
	    	detailsXml.setValue(details, true);
		    errorXml.addSubElement(detailsXml);
		}
			
	    XmlBuilder originalMessageXml = new XmlBuilder("originalMessage");
	    originalMessageXml.addAttribute("messageId", messageId);
	    if (receivedTime!=0) {
			originalMessageXml.addAttribute("receivedTime", new Date(receivedTime).toString());
	    }
	   	//originalMessageXml.setCdataValue(originalMessage);
		originalMessageXml.setValue(originalMessage, true);
	    errorXml.addSubElement(originalMessageXml);
	
	    return errorXml.toXML();
	}
}
{'fraction_non_alphanumeric': 0.1364805762799074, 'fraction_numerical': 0.030872137895549268, 'mean_word_length': 3.889937106918239, 'pattern_counts': {'":': 2, '<': 54, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1922549', 'n_tokens_mistral': 2655, 'n_tokens_neox': 2334, 'n_words': 523}