<commit_before>package railo.runtime.dump;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;

import org.apache.xerces.dom.AttributeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import railo.commons.date.TimeZoneUtil;
import railo.commons.io.res.Resource;
import railo.commons.lang.IDGenerator;
import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.converter.WDDXConverter;
import railo.runtime.exp.PageException;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;
import railo.runtime.text.xml.XMLAttributes;
import railo.runtime.text.xml.XMLCaster;
import railo.runtime.type.Array;
import railo.runtime.type.Collection;
import railo.runtime.type.ObjectWrap;
import railo.runtime.type.QueryImpl;
import railo.runtime.type.dt.DateTimeImpl;

public class DumpUtil {

	
	public static DumpData toDumpData(Object o,PageContext pageContext, int maxlevel, DumpProperties props) {
		if(maxlevel<=0) {
			return new SimpleDumpData("maximal dump level reached");
		}
		// null
		if(o == null) {
			DumpTable table=new DumpTablePro("null","#ff6600","#ffcc99","#000000");
			table.appendRow(new DumpRow(0,new SimpleDumpData("Empty:null")));
			return table;
		}
		if(o instanceof DumpData) {
			return ((DumpData)o);
		}
		// Date
		if(o instanceof Date) {
			return new DateTimeImpl((Date) o).toDumpData(pageContext,maxlevel,props);
		}
		// Calendar
		if(o instanceof Calendar) {
			Calendar c=(Calendar)o;
			
			SimpleDateFormat df = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss zz",Locale.ENGLISH);
			df.setTimeZone(c.getTimeZone());
			
			DumpTable table=new DumpTablePro("date","#ff9900","#ffcc00","#000000");
			table.setTitle("java.util.Calendar");
			table.appendRow(1, new SimpleDumpData("Timezone"), new SimpleDumpData(TimeZoneUtil.toString(c.getTimeZone())));
			table.appendRow(1, new SimpleDumpData("Time"), new SimpleDumpData(df.format(c.getTime())));
	        
			return table;
		}
		// StringBuffer
		if(o instanceof StringBuffer) {
			DumpTable dt=(DumpTable)toDumpData(o.toString(), pageContext, maxlevel, props);
			if(StringUtil.isEmpty(dt.getTitle()))
				dt.setTitle(Caster.toClassName(o));
			return dt;
		}
		// String
		if(o instanceof String) {
			String str=(String) o;
			if(str.trim().startsWith("<wddxPacket ")) {
				try {
					WDDXConverter converter =new WDDXConverter(pageContext.getTimeZone(),false,true);
					converter.setTimeZone(pageContext.getTimeZone());
					Object rst = converter.deserialize(str,false);
					DumpData data = toDumpData(rst, pageContext, maxlevel, props);
					
					DumpTable table = new DumpTablePro("string","#cc9999","#ffffff","#000000");
					table.setTitle("WDDX");
					table.appendRow(1,new SimpleDumpData("encoded"),data);
					table.appendRow(1,new SimpleDumpData("raw"),new SimpleDumpData(str));
					return table;
				}
				catch(Throwable t) {}
			}
			DumpTable table = new DumpTablePro("string","#ff6600","#ffcc99","#000000");
			table.appendRow(1,new SimpleDumpData("string"),new SimpleDumpData(str));
			return table;
		}
		// Character
		if(o instanceof Character) {
			DumpTable table = new DumpTablePro("character","#ff6600","#ffcc99","#000000");
			table.appendRow(1,new SimpleDumpData("character"),new SimpleDumpData(o.toString()));
			return table;
		}<commit_msg>add native support for stringBuilder dump<commit_after>package railo.runtime.dump;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;

import org.apache.xerces.dom.AttributeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import railo.commons.date.TimeZoneUtil;
import railo.commons.io.res.Resource;
import railo.commons.lang.IDGenerator;
import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.converter.WDDXConverter;
import railo.runtime.exp.PageException;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;
import railo.runtime.text.xml.XMLAttributes;
import railo.runtime.text.xml.XMLCaster;
import railo.runtime.type.Array;
import railo.runtime.type.Collection;
import railo.runtime.type.ObjectWrap;
import railo.runtime.type.QueryImpl;
import railo.runtime.type.dt.DateTimeImpl;

public class DumpUtil {

	
	public static DumpData toDumpData(Object o,PageContext pageContext, int maxlevel, DumpProperties props) {
		if(maxlevel<=0) {
			return new SimpleDumpData("maximal dump level reached");
		}
		// null
		if(o == null) {
			DumpTable table=new DumpTablePro("null","#ff6600","#ffcc99","#000000");
			table.appendRow(new DumpRow(0,new SimpleDumpData("Empty:null")));
			return table;
		}
		if(o instanceof DumpData) {
			return ((DumpData)o);
		}
		// Date
		if(o instanceof Date) {
			return new DateTimeImpl((Date) o).toDumpData(pageContext,maxlevel,props);
		}
		// Calendar
		if(o instanceof Calendar) {
			Calendar c=(Calendar)o;
			
			SimpleDateFormat df = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss zz",Locale.ENGLISH);
			df.setTimeZone(c.getTimeZone());
			
			DumpTable table=new DumpTablePro("date","#ff9900","#ffcc00","#000000");
			table.setTitle("java.util.Calendar");
			table.appendRow(1, new SimpleDumpData("Timezone"), new SimpleDumpData(TimeZoneUtil.toString(c.getTimeZone())));
			table.appendRow(1, new SimpleDumpData("Time"), new SimpleDumpData(df.format(c.getTime())));
	        
			return table;
		}
		// StringBuffer
		if(o instanceof StringBuffer) {
			DumpTable dt=(DumpTable)toDumpData(o.toString(), pageContext, maxlevel, props);
			if(StringUtil.isEmpty(dt.getTitle()))
				dt.setTitle(Caster.toClassName(o));
			return dt;
		}
		// StringBuilder
		if(o instanceof StringBuilder) {
			DumpTable dt=(DumpTable)toDumpData(o.toString(), pageContext, maxlevel, props);
			if(StringUtil.isEmpty(dt.getTitle()))
				dt.setTitle(Caster.toClassName(o));
			return dt;
		}
		// String
		if(o instanceof String) {
			String str=(String) o;
			if(str.trim().startsWith("<wddxPacket ")) {
				try {
					WDDXConverter converter =new WDDXConverter(pageContext.getTimeZone(),false,true);
					converter.setTimeZone(pageContext.getTimeZone());
					Object rst = converter.deserialize(str,false);
					DumpData data = toDumpData(rst, pageContext, maxlevel, props);
					
					DumpTable table = new DumpTablePro("string","#cc9999","#ffffff","#000000");
					table.setTitle("WDDX");
					table.appendRow(1,new SimpleDumpData("encoded"),data);
					table.appendRow(1,new SimpleDumpData("raw"),new SimpleDumpData(str));
					return table;
				}
				catch(Throwable t) {}
			}
			DumpTable table = new DumpTablePro("string","#ff6600","#ffcc99","#000000");
			table.appendRow(1,new SimpleDumpData("string"),new SimpleDumpData(str));
			return table;
		}
		// Character
		if(o instanceof Character) {
			DumpTable table = new DumpTablePro("character","#ff6600","#ffcc99","#000000");
			table.appendRow(1,new SimpleDumpData("character"),new SimpleDumpData(o.toString()));
			return table;
		}
{'fraction_non_alphanumeric': 0.13988559542381696, 'fraction_numerical': 0.01768070722828913, 'mean_word_length': 5.028996865203761, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1460130', 'n_tokens_mistral': 2941, 'n_tokens_neox': 2565, 'n_words': 458}