Search in sources :

Example 1 with DumpWriter

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

the class Stopwatch method doEndTag.

@Override
public int doEndTag() throws PageException {
    long exe = (System.currentTimeMillis() - time);
    if (variable != null) {
        pageContext.setVariable(variable, new Double(exe));
    } else {
        DumpTable table = new DumpTable("#ff9900", "#ffcc00", "#000000");
        table.appendRow(1, new SimpleDumpData(label == null ? "Stopwatch" : label), new SimpleDumpData(exe));
        DumpWriter writer = pageContext.getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH);
        try {
            pageContext.forceWrite(writer.toString(pageContext, table, true));
        } catch (IOException e) {
        }
    }
    return EVAL_PAGE;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpWriter(lucee.runtime.dump.DumpWriter) IOException(java.io.IOException)

Example 2 with DumpWriter

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

the class XMLConfigWebFactory method loadDumpWriter.

private static void loadDumpWriter(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws ClassException {
    boolean hasCS = configServer != null;
    Element coll = getChildByName(doc.getDocumentElement(), "dump-writers");
    Element[] writers = getChildren(coll, "dump-writer");
    Struct sct = new StructImpl();
    boolean hasPlain = false;
    boolean hasRich = false;
    if (hasCS) {
        DumpWriterEntry[] entries = configServer.getDumpWritersEntries();
        if (entries != null)
            for (int i = 0; i < entries.length; i++) {
                if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_PLAIN)
                    hasPlain = true;
                if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_RICH)
                    hasRich = true;
                sct.put(entries[i].getName(), entries[i]);
            }
    }
    if (writers != null && writers.length > 0) {
        ClassDefinition cd;
        String strName;
        String strDefault;
        Class clazz;
        int def = HTMLDumpWriter.DEFAULT_NONE;
        for (int i = 0; i < writers.length; i++) {
            cd = getClassDefinition(writers[i], "", config.getIdentification());
            strName = getAttr(writers[i], "name");
            strDefault = getAttr(writers[i], "default");
            clazz = cd.getClazz(null);
            if (clazz != null && !StringUtil.isEmpty(strName)) {
                if (StringUtil.isEmpty(strDefault))
                    def = HTMLDumpWriter.DEFAULT_NONE;
                else if ("browser".equalsIgnoreCase(strDefault))
                    def = HTMLDumpWriter.DEFAULT_RICH;
                else if ("console".equalsIgnoreCase(strDefault))
                    def = HTMLDumpWriter.DEFAULT_PLAIN;
                sct.put(strName, new DumpWriterEntry(def, strName, (DumpWriter) ClassUtil.loadInstance(clazz)));
            }
        }
    } else {
        // print.err("yep");
        if (!hasRich)
            sct.setEL(KeyConstants._html, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_RICH, "html", new HTMLDumpWriter()));
        if (!hasPlain)
            sct.setEL(KeyConstants._text, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_PLAIN, "text", new TextDumpWriter()));
        sct.setEL(KeyConstants._classic, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "classic", new ClassicHTMLDumpWriter()));
        sct.setEL(KeyConstants._simple, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "simple", new SimpleHTMLDumpWriter()));
    }
    Iterator<Object> it = sct.valueIterator();
    java.util.List<DumpWriterEntry> entries = new ArrayList<DumpWriterEntry>();
    while (it.hasNext()) {
        entries.add((DumpWriterEntry) it.next());
    }
    config.setDumpWritersEntries(entries.toArray(new DumpWriterEntry[entries.size()]));
}
Also used : ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) Element(org.w3c.dom.Element) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) ArrayList(java.util.ArrayList) ClassDefinition(lucee.runtime.db.ClassDefinition) lucee.aprint(lucee.aprint) Struct(lucee.runtime.type.Struct) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) HTMLDumpWriter(lucee.runtime.dump.HTMLDumpWriter) ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) StructImpl(lucee.runtime.type.StructImpl) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) HTMLDumpWriter(lucee.runtime.dump.HTMLDumpWriter) TextDumpWriter(lucee.runtime.dump.TextDumpWriter) ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) DumpWriter(lucee.runtime.dump.DumpWriter) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) TextDumpWriter(lucee.runtime.dump.TextDumpWriter)

Example 3 with DumpWriter

use of lucee.runtime.dump.DumpWriter 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)

Aggregations

DumpWriter (lucee.runtime.dump.DumpWriter)3 IOException (java.io.IOException)2 DumpTable (lucee.runtime.dump.DumpTable)2 SimpleDumpData (lucee.runtime.dump.SimpleDumpData)2 ArrayList (java.util.ArrayList)1 lucee.aprint (lucee.aprint)1 Resource (lucee.commons.io.res.Resource)1 PageContextImpl (lucee.runtime.PageContextImpl)1 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)1 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)1 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)1 ClassDefinition (lucee.runtime.db.ClassDefinition)1 ClassicHTMLDumpWriter (lucee.runtime.dump.ClassicHTMLDumpWriter)1 DumpData (lucee.runtime.dump.DumpData)1 DumpProperties (lucee.runtime.dump.DumpProperties)1 DumpWriterEntry (lucee.runtime.dump.DumpWriterEntry)1 HTMLDumpWriter (lucee.runtime.dump.HTMLDumpWriter)1 SimpleHTMLDumpWriter (lucee.runtime.dump.SimpleHTMLDumpWriter)1 TextDumpWriter (lucee.runtime.dump.TextDumpWriter)1 Struct (lucee.runtime.type.Struct)1