Search in sources :

Example 6 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class PageContextUtil method getPageContext.

public static PageContext getPageContext(Config config, ServletConfig servletConfig, File contextRoot, String host, String scriptName, String queryString, Cookie[] cookies, Map<String, Object> headers, Map<String, String> parameters, Map<String, Object> attributes, OutputStream os, boolean register, long timeout, boolean ignoreScopes) throws ServletException {
    boolean callOnStart = ThreadLocalPageContext.callOnStart.get();
    try {
        ThreadLocalPageContext.callOnStart.set(false);
        if (contextRoot == null)
            contextRoot = new File(".");
        // Engine
        CFMLEngine engine = null;
        try {
            engine = CFMLEngineFactory.getInstance();
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        if (engine == null)
            throw new ServletException("there is no ServletContext");
        if (headers == null)
            headers = new HashMap<String, Object>();
        if (parameters == null)
            parameters = new HashMap<String, String>();
        if (attributes == null)
            attributes = new HashMap<String, Object>();
        // Request
        HttpServletRequest req = CreationImpl.getInstance(engine).createHttpServletRequest(contextRoot, host, scriptName, queryString, cookies, headers, parameters, attributes, null);
        // Response
        HttpServletResponse rsp = CreationImpl.getInstance(engine).createHttpServletResponse(os);
        if (config == null)
            config = ThreadLocalPageContext.getConfig();
        CFMLFactory factory = null;
        HttpServlet servlet;
        if (config instanceof ConfigWeb) {
            ConfigWeb cw = (ConfigWeb) config;
            factory = cw.getFactory();
            servlet = factory.getServlet();
        } else {
            if (servletConfig == null) {
                ServletConfig[] configs = engine.getServletConfigs();
                String rootDir = contextRoot.getAbsolutePath();
                for (ServletConfig conf : configs) {
                    if (lucee.commons.io.SystemUtil.arePathsSame(rootDir, conf.getServletContext().getRealPath("/"))) {
                        servletConfig = conf;
                        break;
                    }
                }
                if (servletConfig == null)
                    servletConfig = configs[0];
            }
            factory = engine.getCFMLFactory(servletConfig, req);
            servlet = new HTTPServletImpl(servletConfig, servletConfig.getServletContext(), servletConfig.getServletName());
        }
        return factory.getLuceePageContext(servlet, req, rsp, null, false, -1, false, register, timeout, false, ignoreScopes);
    } finally {
        ThreadLocalPageContext.callOnStart.set(callOnStart);
    }
}
Also used : HashMap(java.util.HashMap) HttpServlet(javax.servlet.http.HttpServlet) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) CFMLFactory(lucee.runtime.CFMLFactory) ConfigWeb(lucee.runtime.config.ConfigWeb) ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) CFMLEngine(lucee.loader.engine.CFMLEngine) HTTPServletImpl(lucee.cli.servlet.HTTPServletImpl) File(java.io.File)

Example 7 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class DevNullOutputStream method _invoke.

private Object _invoke(final String methodName, final Object[] args, HttpServletRequest req, HttpServletResponse rsp, OutputStream out) throws PageException {
    final CFMLEngine engine = CFMLEngineFactory.getInstance();
    final Creation creator = engine.getCreationUtil();
    final PageContext originalPC = engine.getThreadPageContext();
    // no OutputStream
    if (out == null)
        out = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
    // no Request
    if (req == null)
        // TODO new File
        req = creator.createHttpServletRequest(new File("."), "Lucee", "/", "", null, null, null, null, null);
    // noRespone
    if (rsp == null)
        rsp = creator.createHttpServletResponse(out);
    final PageContext pc = creator.createPageContext(req, rsp, out);
    try {
        engine.registerThreadPageContext(pc);
        initCFC(pc);
        return cfc.call(pc, methodName, args);
    } finally {
        if (autoFlush)
            try {
                pc.getRootWriter().flush();
            } catch (final Throwable t) {
            }
        engine.registerThreadPageContext(originalPC);
    }
}
Also used : Creation(lucee.runtime.util.Creation) PageContext(lucee.runtime.PageContext) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File)

Example 8 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class LuceeServletContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    try {
        CFMLEngine engine = CFMLEngineFactory.getInstance();
        // FUTURE add exeServletContextEvent
        engine.addServletConfig(new LuceeServletContextListenerImpl(sce, "init"));
    } catch (Exception se) {
        se.printStackTrace();
    }
}
Also used : CFMLEngine(lucee.loader.engine.CFMLEngine) ServletException(javax.servlet.ServletException)

Example 9 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class LuceeServletContextListener method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    try {
        CFMLEngine engine = CFMLEngineFactory.getInstance();
        // FUTURE add addServletContextEvent
        engine.addServletConfig(new LuceeServletContextListenerImpl(sce, "release"));
    } catch (Exception se) {
        se.printStackTrace();
    }
}
Also used : CFMLEngine(lucee.loader.engine.CFMLEngine) ServletException(javax.servlet.ServletException)

Example 10 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class Page method str.

public String str(PageContext pc, int off, int len) throws IOException, PageException {
    if (staticTextLocation == null) {
        PageSource ps = getPageSource();
        Mapping m = ps.getMapping();
        staticTextLocation = m.getClassRootDirectory();
        staticTextLocation = staticTextLocation.getRealResource(ps.getJavaName() + ".txt");
    }
    CFMLEngine e = CFMLEngineFactory.getInstance();
    IO io = e.getIOUtil();
    Reader reader = io.getReader(staticTextLocation, e.getCastUtil().toCharset("UTF-8"));
    char[] carr = new char[len];
    try {
        if (off > 0)
            reader.skip(off);
        reader.read(carr);
    } finally {
        io.closeSilent(reader);
    }
    // print.e(carr);
    return new String(carr);
}
Also used : IO(lucee.runtime.util.IO) Reader(java.io.Reader) CFMLEngine(lucee.loader.engine.CFMLEngine)

Aggregations

CFMLEngine (lucee.loader.engine.CFMLEngine)31 File (java.io.File)10 IOException (java.io.IOException)9 CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)9 Bundle (org.osgi.framework.Bundle)9 Resource (lucee.commons.io.res.Resource)6 BundleFile (lucee.runtime.osgi.BundleFile)5 BundleException (org.osgi.framework.BundleException)5 ServletException (javax.servlet.ServletException)4 BundleContext (org.osgi.framework.BundleContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Reader (java.io.Reader)3 BundleCollection (lucee.loader.osgi.BundleCollection)3 PageContext (lucee.runtime.PageContext)3 Struct (lucee.runtime.type.Struct)3 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2