Search in sources :

Example 1 with ExecutionLog

use of lucee.runtime.engine.ExecutionLog in project Lucee by lucee.

the class XMLConfigWebFactory method loadExeLog.

private static void loadExeLog(ConfigServerImpl configServer, ConfigImpl config, Document doc) {
    boolean hasServer = configServer != null;
    Element el = getChildByName(doc.getDocumentElement(), "execution-log");
    // enabled
    Boolean bEnabled = Caster.toBoolean(getAttr(el, "enabled"), null);
    if (bEnabled == null) {
        if (hasServer)
            config.setExecutionLogEnabled(configServer.getExecutionLogEnabled());
    } else
        config.setExecutionLogEnabled(bEnabled.booleanValue());
    boolean hasChanged = false;
    String val = Caster.toString(config.getExecutionLogEnabled());
    try {
        Resource contextDir = config.getConfigDir();
        Resource exeLog = contextDir.getRealResource("exe-log");
        if (!exeLog.exists()) {
            exeLog.createNewFile();
            IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
            hasChanged = true;
        } else if (!IOUtil.toString(exeLog, SystemUtil.getCharset()).equals(val)) {
            IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
            hasChanged = true;
        }
    } catch (IOException e) {
        e.printStackTrace(config.getErrWriter());
    }
    if (hasChanged) {
        try {
            if (config.getClassDirectory().exists())
                config.getClassDirectory().remove(true);
        } catch (IOException e) {
            e.printStackTrace(config.getErrWriter());
        }
    }
    // class
    String strClass = getAttr(el, "class");
    Class clazz;
    if (!StringUtil.isEmpty(strClass)) {
        try {
            if ("console".equalsIgnoreCase(strClass))
                clazz = ConsoleExecutionLog.class;
            else {
                ClassDefinition cd = getClassDefinition(el, "", config.getIdentification());
                Class c = cd.getClazz();
                if ((c.newInstance() instanceof ExecutionLog)) {
                    clazz = c;
                } else {
                    clazz = ConsoleExecutionLog.class;
                    SystemOut.printDate(config.getErrWriter(), "class [" + strClass + "] must implement the interface " + ExecutionLog.class.getName());
                }
            }
        } catch (Exception e) {
            SystemOut.printDate(e);
            clazz = ConsoleExecutionLog.class;
        }
        if (clazz != null)
            SystemOut.printDate(config.getOutWriter(), "loaded ExecutionLog class " + clazz.getName());
        // arguments
        String strArgs = getAttr(el, "arguments");
        if (StringUtil.isEmpty(strArgs))
            strArgs = getAttr(el, "class-arguments");
        Map<String, String> args = toArguments(strArgs, true);
        config.setExecutionLogFactory(new ExecutionLogFactory(clazz, args));
    } else {
        if (hasServer)
            config.setExecutionLogFactory(configServer.getExecutionLogFactory());
        else
            config.setExecutionLogFactory(new ExecutionLogFactory(ConsoleExecutionLog.class, new HashMap<String, String>()));
    }
}
Also used : ConsoleExecutionLog(lucee.runtime.engine.ConsoleExecutionLog) Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) ConsoleExecutionLog(lucee.runtime.engine.ConsoleExecutionLog) ExecutionLog(lucee.runtime.engine.ExecutionLog) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) ExecutionLogFactory(lucee.runtime.engine.ExecutionLogFactory)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1 Resource (lucee.commons.io.res.Resource)1 ClassException (lucee.commons.lang.ClassException)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 ConsoleExecutionLog (lucee.runtime.engine.ConsoleExecutionLog)1 ExecutionLog (lucee.runtime.engine.ExecutionLog)1 ExecutionLogFactory (lucee.runtime.engine.ExecutionLogFactory)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 PageException (lucee.runtime.exp.PageException)1 SecurityException (lucee.runtime.exp.SecurityException)1 FunctionLibException (lucee.transformer.library.function.FunctionLibException)1 TagLibException (lucee.transformer.library.tag.TagLibException)1