Search in sources :

Example 1 with DumpRow

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

the class ComponentImpl method thisScope.

static DumpTable thisScope(ComponentImpl ci, PageContext pc, int maxlevel, DumpProperties dp, int access) {
    DumpTable table = new DumpTable("#ffffff", "#cccccc", "#000000");
    DumpTable[] accesses = new DumpTable[4];
    accesses[Component.ACCESS_REMOTE] = new DumpTable("#ccffcc", "#ffffff", "#000000");
    accesses[Component.ACCESS_REMOTE].setTitle("remote");
    accesses[Component.ACCESS_PUBLIC] = new DumpTable("#ffcc99", "#ffffcc", "#000000");
    accesses[Component.ACCESS_PUBLIC].setTitle("public");
    accesses[Component.ACCESS_PACKAGE] = new DumpTable("#ff9966", "#ffcc99", "#000000");
    accesses[Component.ACCESS_PACKAGE].setTitle("package");
    accesses[Component.ACCESS_PRIVATE] = new DumpTable("#ff6633", "#ff9966", "#000000");
    accesses[Component.ACCESS_PRIVATE].setTitle("private");
    maxlevel--;
    ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ci);
    Collection.Key[] keys = cw.keys();
    List<DumpRow>[] drAccess = new List[4];
    for (int i = 0; i < drAccess.length; i++) // ACCESS_REMOTE=0, ACCESS_PUBLIC=1, ACCESS_PACKAGE=2, ACCESS_PRIVATE=3
    drAccess[i] = new ArrayList();
    Collection.Key key;
    for (int i = 0; i < keys.length; i++) {
        key = keys[i];
        List<DumpRow> box = drAccess[ci.getAccess(key)];
        Object o = cw.get(key, null);
        if (o == ci)
            o = "[this]";
        if (DumpUtil.keyValid(dp, maxlevel, key)) {
            String memberName = (o instanceof UDF) ? ((UDF) o).getFunctionName() : key.getString();
            box.add(new DumpRow(1, new SimpleDumpData(memberName), DumpUtil.toDumpData(o, pc, maxlevel, dp)));
        }
    }
    List<DumpRow> dumpRows;
    for (int i = 0; i < drAccess.length; i++) {
        dumpRows = drAccess[i];
        if (!dumpRows.isEmpty()) {
            Collections.sort(dumpRows, new Comparator<DumpRow>() {

                @Override
                public int compare(DumpRow o1, DumpRow o2) {
                    DumpData[] rowItems1 = o1.getItems();
                    DumpData[] rowItems2 = o2.getItems();
                    if (rowItems1.length >= 0 && rowItems2.length > 0 && rowItems1[0] instanceof SimpleDumpData && rowItems2[0] instanceof SimpleDumpData)
                        return String.CASE_INSENSITIVE_ORDER.compare(rowItems1[0].toString(), rowItems2[0].toString());
                    return 0;
                }
            });
            DumpTable dtAccess = accesses[i];
            dtAccess.setWidth("100%");
            for (DumpRow dr : dumpRows) dtAccess.appendRow(dr);
            table.appendRow(0, dtAccess);
        }
    }
    // properties
    if (ci.top.properties.persistent || ci.top.properties.accessors) {
        Property[] properties = ci.getProperties(false, true, false, false);
        DumpTable prop = new DumpTable("#99cc99", "#ccffcc", "#000000");
        prop.setTitle("Properties");
        prop.setWidth("100%");
        Property p;
        Object child;
        for (int i = 0; i < properties.length; i++) {
            p = properties[i];
            child = ci.scope.get(KeyImpl.init(p.getName()), null);
            DumpData dd;
            if (child instanceof Component) {
                DumpTable t = new DumpTable("component", "#99cc99", "#ffffff", "#000000");
                t.appendRow(1, new SimpleDumpData(((Component) child).getPageSource().getDialect() == CFMLEngine.DIALECT_CFML ? "Component" : "Class"), new SimpleDumpData(((Component) child).getCallName()));
                dd = t;
            } else {
                dd = DumpUtil.toDumpData(child, pc, maxlevel - 1, dp);
            }
            prop.appendRow(1, new SimpleDumpData(p.getName()), dd);
        }
        if (access >= ACCESS_PUBLIC && !prop.isEmpty()) {
            table.appendRow(0, prop);
        }
    }
    return table;
}
Also used : DumpRow(lucee.runtime.dump.DumpRow) ArrayList(java.util.ArrayList) DumpData(lucee.runtime.dump.DumpData) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpTable(lucee.runtime.dump.DumpTable) UDF(lucee.runtime.type.UDF) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Collection(lucee.runtime.type.Collection) List(java.util.List) ArrayList(java.util.ArrayList) EvaluateComponent(lucee.runtime.functions.dynamicEvaluation.EvaluateComponent) UDFGSProperty(lucee.runtime.type.UDFGSProperty) Property(lucee.runtime.component.Property) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 2 with DumpRow

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

the class UDFUtil method toDumpData.

public static DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp, UDF udf, short type) {
    if (!dp.getShowUDFs()) {
        if (TYPE_UDF == type)
            return new SimpleDumpData("<UDF>");
        if (TYPE_BIF == type)
            return new SimpleDumpData("<BIF>");
        if (TYPE_CLOSURE == type)
            return new SimpleDumpData("<Closure>");
        if (TYPE_LAMBDA == type)
            return new SimpleDumpData("<Lambda>");
    }
    // arguments
    FunctionArgument[] args = udf.getFunctionArguments();
    DumpTable atts;
    if (TYPE_UDF == type)
        atts = new DumpTable("udf", "#ca5095", "#e9accc", "#000000");
    else if (TYPE_CLOSURE == type)
        atts = new DumpTable("udf", "#9cb770", "#c7e1ba", "#000000");
    else if (TYPE_BIF == type)
        atts = new DumpTable("udf", "#e1c039", "#f1e2a3", "#000000");
    else
        atts = new DumpTable("udf", "#f3d5bd", "#f6e4cc", "#000000");
    atts.appendRow(new DumpRow(63, new DumpData[] { new SimpleDumpData("label"), new SimpleDumpData("name"), new SimpleDumpData("required"), new SimpleDumpData("type"), new SimpleDumpData("default"), new SimpleDumpData("hint") }));
    for (int i = 0; i < args.length; i++) {
        FunctionArgument arg = args[i];
        DumpData def;
        try {
            Object oa = udf.getDefaultValue(pageContext, i, null);
            if (oa == null)
                oa = "null";
            def = new SimpleDumpData(Caster.toString(oa));
        } catch (PageException e) {
            def = new SimpleDumpData("");
        }
        atts.appendRow(new DumpRow(0, new DumpData[] { new SimpleDumpData(arg.getDisplayName()), new SimpleDumpData(arg.getName().getString()), new SimpleDumpData(arg.isRequired()), new SimpleDumpData(arg.getTypeAsString()), def, new SimpleDumpData(arg.getHint()) }));
    // atts.setRow(0,arg.getHint());
    }
    DumpTable func;
    String label = udf.getDisplayName();
    if (TYPE_CLOSURE == type) {
        func = new DumpTable("#9cb770", "#c7e1ba", "#000000");
        func.setTitle(StringUtil.isEmpty(label) ? "Closure" : "Closure " + label);
    } else if (TYPE_UDF == type) {
        func = new DumpTable("#ca5095", "#e9accc", "#000000");
        String f = "Function ";
        try {
            f = StringUtil.ucFirst(ComponentUtil.toStringAccess(udf.getAccess()).toLowerCase()) + " " + f;
        } catch (ApplicationException e) {
        }
        f += udf.getFunctionName();
        if (udf instanceof UDFGSProperty)
            f += " (generated)";
        func.setTitle(f);
    } else if (TYPE_BIF == type) {
        String f = "Build in Function " + (!StringUtil.isEmpty(label) ? label : udf.getFunctionName());
        func = new DumpTable("#e1c039", "#f1e2a3", "#000000");
        func.setTitle(f);
    } else {
        func = new DumpTable("#f3d5bd", "#f6e4cc", "#000000");
        func.setTitle(StringUtil.isEmpty(label) ? "Lambda" : "Lambda " + label);
    }
    // Source
    String src = udf.getSource();
    if (!StringUtil.isEmpty(src))
        func.setComment("source:" + src);
    String hint = udf.getHint();
    String desc = udf.getDescription();
    if (!StringUtil.isEmpty(desc))
        addComment(func, desc);
    if (!StringUtil.isEmpty(hint))
        addComment(func, hint);
    if (Component.MODIFIER_NONE != udf.getModifier())
        func.appendRow(1, new SimpleDumpData("modifier"), new SimpleDumpData(ComponentUtil.toModifier(udf.getModifier(), "")));
    func.appendRow(1, new SimpleDumpData("arguments"), atts);
    func.appendRow(1, new SimpleDumpData("return type"), new SimpleDumpData(udf.getReturnTypeAsString()));
    return func;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) DumpRow(lucee.runtime.dump.DumpRow) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) UDFGSProperty(lucee.runtime.type.UDFGSProperty) FunctionArgument(lucee.runtime.type.FunctionArgument) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpData(lucee.runtime.dump.DumpData)

Example 3 with DumpRow

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

the class QueryUtil method toDumpData.

public static DumpData toDumpData(Query query, PageContext pageContext, int maxlevel, DumpProperties dp) {
    maxlevel--;
    Collection.Key[] keys = CollectionUtil.keys(query);
    DumpData[] heads = new DumpData[keys.length + 1];
    // int tmp=1;
    heads[0] = new SimpleDumpData("");
    for (int i = 0; i < keys.length; i++) {
        heads[i + 1] = new SimpleDumpData(keys[i].getString());
    }
    StringBuilder comment = new StringBuilder();
    // table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
    String template = query.getTemplate();
    if (!StringUtil.isEmpty(template))
        comment.append("Template: ").append(template).append("\n");
    // table.appendRow(1, new SimpleDumpData("Template"), new SimpleDumpData(template));
    // in Query dump maxlevel is used as Top
    int top = dp.getMaxlevel();
    comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(query.getExecutionTime()))).append(" ms \n");
    comment.append("Record Count: ").append(Caster.toString(query.getRecordcount()));
    if (query.getRecordcount() > top)
        comment.append(" (showing top ").append(Caster.toString(top)).append(")");
    comment.append("\n");
    comment.append("Cached: ").append(query.isCached() ? "Yes\n" : "No\n");
    if (query.isCached() && query instanceof Query) {
        comment.append("Cache Type: ").append(query.getCacheType()).append("\n");
    }
    comment.append("Lazy: ").append(query instanceof SimpleQuery ? "Yes\n" : "No\n");
    SQL sql = query.getSql();
    if (sql != null)
        comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
    // table.appendRow(1, new SimpleDumpData("Execution Time (ms)"), new SimpleDumpData(exeTime));
    // table.appendRow(1, new SimpleDumpData("recordcount"), new SimpleDumpData(getRecordcount()));
    // table.appendRow(1, new SimpleDumpData("cached"), new SimpleDumpData(isCached()?"Yes":"No"));
    DumpTable recs = new DumpTable("query", "#cc99cc", "#ffccff", "#000000");
    recs.setTitle("Query");
    if (dp.getMetainfo())
        recs.setComment(comment.toString());
    recs.appendRow(new DumpRow(-1, heads));
    // body
    DumpData[] items;
    int recordcount = query.getRecordcount();
    int columncount = query.getColumnNames().length;
    for (int i = 0; i < recordcount; i++) {
        items = new DumpData[columncount + 1];
        items[0] = new SimpleDumpData(i + 1);
        for (int y = 0; y < keys.length; y++) {
            try {
                Object o = query.getAt(keys[y], i + 1);
                if (o instanceof String)
                    items[y + 1] = new SimpleDumpData(o.toString());
                else if (o instanceof Number)
                    items[y + 1] = new SimpleDumpData(Caster.toString(((Number) o)));
                else if (o instanceof Boolean)
                    items[y + 1] = new SimpleDumpData(((Boolean) o).booleanValue());
                else if (o instanceof Date)
                    items[y + 1] = new SimpleDumpData(Caster.toString(o));
                else if (o instanceof Clob)
                    items[y + 1] = new SimpleDumpData(Caster.toString(o));
                else
                    items[y + 1] = DumpUtil.toDumpData(o, pageContext, maxlevel, dp);
            } catch (PageException e) {
                items[y + 1] = new SimpleDumpData("[empty]");
            }
        }
        recs.appendRow(new DumpRow(1, items));
        if (i == top - 1)
            break;
    }
    if (!dp.getMetainfo())
        return recs;
    // table.appendRow(1, new SimpleDumpData("result"), recs);
    return recs;
}
Also used : PageException(lucee.runtime.exp.PageException) Query(lucee.runtime.type.Query) SimpleQuery(lucee.runtime.type.query.SimpleQuery) SimpleQuery(lucee.runtime.type.query.SimpleQuery) DumpRow(lucee.runtime.dump.DumpRow) DumpData(lucee.runtime.dump.DumpData) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Date(java.util.Date) SQL(lucee.runtime.db.SQL) DumpTable(lucee.runtime.dump.DumpTable) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Clob(java.sql.Clob) Key(lucee.runtime.type.Collection.Key)

Example 4 with DumpRow

use of lucee.runtime.dump.DumpRow 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)4 DumpRow (lucee.runtime.dump.DumpRow)4 SimpleDumpData (lucee.runtime.dump.SimpleDumpData)4 DumpTable (lucee.runtime.dump.DumpTable)3 PageException (lucee.runtime.exp.PageException)2 Collection (lucee.runtime.type.Collection)2 Key (lucee.runtime.type.Collection.Key)2 Query (lucee.runtime.type.Query)2 UDFGSProperty (lucee.runtime.type.UDFGSProperty)2 Clob (java.sql.Clob)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Property (lucee.runtime.component.Property)1 SQL (lucee.runtime.db.SQL)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 EvaluateComponent (lucee.runtime.functions.dynamicEvaluation.EvaluateComponent)1 FunctionArgument (lucee.runtime.type.FunctionArgument)1 QueryImpl (lucee.runtime.type.QueryImpl)1 Struct (lucee.runtime.type.Struct)1