Search in sources :

Example 6 with DumpData

use of lucee.runtime.dump.DumpData in project Lucee by lucee.

the class Dump method call.

public static String call(PageContext pc, Object object, String label, boolean expand, double maxLevel, String show, String hide, String output, String format, double keys, boolean metainfo, boolean showUDFs) throws PageException {
    if (show != null && "all".equalsIgnoreCase(show.trim()))
        show = null;
    if (hide != null && "all".equalsIgnoreCase(hide.trim()))
        hide = null;
    // PageContext pcc = pc;
    try {
        // output
        int defType = DumpWriter.DEFAULT_RICH;
        int outputType = OUTPUT_TYPE_NONE;
        Resource outputRes = null;
        if (!StringUtil.isEmpty(output, true)) {
            output = output.trim();
            if ("browser".equalsIgnoreCase(output)) {
                outputType = OUTPUT_TYPE_BROWSER;
                defType = DumpWriter.DEFAULT_RICH;
            } else if ("console".equalsIgnoreCase(output)) {
                outputType = OUTPUT_TYPE_CONSOLE;
                defType = DumpWriter.DEFAULT_PLAIN;
            } else {
                outputType = OUTPUT_TYPE_RESOURCE;
                defType = DumpWriter.DEFAULT_RICH;
                outputRes = ResourceUtil.toResourceNotExisting(pc, output);
            }
        }
        // format
        DumpWriter writer = pc.getConfig().getDumpWriter(format, defType);
        Set<String> setShow = (show != null) ? ListUtil.listToSet(show.toLowerCase(), ",", true) : null;
        Set<String> setHide = (hide != null) ? ListUtil.listToSet(hide.toLowerCase(), ",", true) : null;
        DumpProperties properties = new DumpProperties((int) maxLevel, setShow, setHide, (int) keys, metainfo, showUDFs);
        DumpData dd = DumpUtil.toDumpData(object, pc, (int) maxLevel, properties);
        if (!StringUtil.isEmpty(label)) {
            DumpTable table = new DumpTable("#ffffff", "#cccccc", "#000000");
            table.appendRow(1, new SimpleDumpData(label));
            // table.appendRow(1,new SimpleDumpData(getContext()));
            table.appendRow(0, dd);
            dd = table;
        }
        // formatType==FORMAT_TYPE_TEXT
        boolean isText = "text".equalsIgnoreCase(format);
        if (OUTPUT_TYPE_BROWSER == outputType || outputType == OUTPUT_TYPE_NONE) {
            if (isText)
                pc.forceWrite("<pre>");
            pc.forceWrite(writer.toString(pc, dd, expand));
            if (isText)
                pc.forceWrite("</pre>");
        } else if (OUTPUT_TYPE_CONSOLE == outputType)
            System.out.println(writer.toString(pc, dd, expand));
        else if (OUTPUT_TYPE_RESOURCE == outputType)
            IOUtil.write(outputRes, writer.toString(pc, dd, expand) + "\n************************************************************************************\n", ((PageContextImpl) pc).getResourceCharset(), true);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return "";
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) DumpWriter(lucee.runtime.dump.DumpWriter) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Resource(lucee.commons.io.res.Resource) DumpProperties(lucee.runtime.dump.DumpProperties) PageContextImpl(lucee.runtime.PageContextImpl) IOException(java.io.IOException) DumpData(lucee.runtime.dump.DumpData) SimpleDumpData(lucee.runtime.dump.SimpleDumpData)

Example 7 with DumpData

use of lucee.runtime.dump.DumpData in project Lucee by lucee.

the class DumpStruct method toCFML.

private static Struct toCFML(DumpTable dt, Object object, RefBoolean hasReference, Struct colors) {
    Struct sct = new StructImpl();
    if (colors == null) {
        colors = new StructImpl();
        sct.setEL("colors", colors);
    }
    Collection.Key type;
    if (dt.getType() != null)
        type = KeyImpl.init(dt.getType());
    else if (object != null)
        type = KeyImpl.init(object.getClass().getName());
    else
        type = KeyConstants._null;
    // colors
    String borderColor = toShortColor(dt.getBorderColor());
    String fontColor = toShortColor(dt.getFontColor());
    String highLightColor = toShortColor(dt.getHighLightColor());
    String normalColor = toShortColor(dt.getNormalColor());
    // create color id
    Key colorId = KeyImpl.init(Long.toString(HashUtil.create64BitHash(new StringBuilder(borderColor).append(':').append(fontColor).append(':').append(highLightColor).append(':').append(normalColor)), Character.MAX_RADIX));
    if (!colors.containsKey(colorId)) {
        Struct color = new StructImpl();
        StructUtil.setELIgnoreWhenNull(color, "borderColor", borderColor);
        StructUtil.setELIgnoreWhenNull(color, "fontColor", fontColor);
        StructUtil.setELIgnoreWhenNull(color, "highLightColor", highLightColor);
        StructUtil.setELIgnoreWhenNull(color, "normalColor", normalColor);
        colors.setEL(colorId, color);
    }
    /*StructUtil.setELIgnoreWhenNull(sct,"borderColor", borderColor);
		StructUtil.setELIgnoreWhenNull(sct,"fontColor", fontColor);
		StructUtil.setELIgnoreWhenNull(sct,"highLightColor", highLightColor);
		StructUtil.setELIgnoreWhenNull(sct,"normalColor", normalColor);
		*/
    StructUtil.setELIgnoreWhenNull(sct, "colorId", colorId.getString());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._comment, dt.getComment());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._height, dt.getHeight());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._width, dt.getWidth());
    StructUtil.setELIgnoreWhenNull(sct, KeyConstants._title, dt.getTitle());
    sct.setEL(KeyConstants._type, type.getString());
    if (!StringUtil.isEmpty(dt.getId()))
        sct.setEL(KeyConstants._id, dt.getId());
    if ("ref".equals(dt.getType())) {
        hasReference.setValue(true);
        sct.setEL(KeyConstants._ref, dt.getRef());
    }
    DumpRow[] drs = dt.getRows();
    DumpRow dr;
    Query qry = null;
    DumpData[] items;
    for (int r = 0; r < drs.length; r++) {
        dr = drs[r];
        items = dr.getItems();
        if (qry == null)
            qry = new QueryImpl(toColumns(items), drs.length, "data");
        for (int c = 1; c <= items.length; c++) {
            qry.setAtEL("data" + c, r + 1, toCFML(items[c - 1], object, hasReference, colors));
        }
        qry.setAtEL("highlight", r + 1, new Double(dr.getHighlightType()));
    }
    if (qry != null)
        sct.setEL(KeyConstants._data, qry);
    return sct;
}
Also used : DumpRow(lucee.runtime.dump.DumpRow) Query(lucee.runtime.type.Query) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpData(lucee.runtime.dump.DumpData) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) QueryImpl(lucee.runtime.type.QueryImpl) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) Key(lucee.runtime.type.Collection.Key)

Aggregations

DumpData (lucee.runtime.dump.DumpData)7 DumpTable (lucee.runtime.dump.DumpTable)6 SimpleDumpData (lucee.runtime.dump.SimpleDumpData)6 DumpRow (lucee.runtime.dump.DumpRow)4 PageException (lucee.runtime.exp.PageException)3 DumpProperties (lucee.runtime.dump.DumpProperties)2 Collection (lucee.runtime.type.Collection)2 Key (lucee.runtime.type.Collection.Key)2 Query (lucee.runtime.type.Query)2 Struct (lucee.runtime.type.Struct)2 UDFGSProperty (lucee.runtime.type.UDFGSProperty)2 IOException (java.io.IOException)1 Clob (java.sql.Clob)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Resource (lucee.commons.io.res.Resource)1 RefBoolean (lucee.commons.lang.types.RefBoolean)1 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)1 PageContextImpl (lucee.runtime.PageContextImpl)1