Search in sources :

Example 11 with ConfigWeb

use of lucee.runtime.config.ConfigWeb 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 12 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class ExpandPath method call.

public static String call(PageContext pc, String relPath) throws PageException {
    ConfigWeb config = pc.getConfig();
    relPath = prettifyPath(pc, relPath);
    String contextPath = pc.getHttpServletRequest().getContextPath();
    if (!StringUtil.isEmpty(contextPath) && relPath.startsWith(contextPath + "/")) {
        boolean sws = StringUtil.startsWith(relPath, '/');
        relPath = relPath.substring(contextPath.length());
        if (sws && !StringUtil.startsWith(relPath, '/'))
            relPath = "/" + relPath;
    }
    Resource res;
    if (StringUtil.startsWith(relPath, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) config;
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), relPath, false, pci.useSpecialMappings(), true);
        if (!ArrayUtil.isEmpty(sources)) {
            // first check for existing
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists()) {
                    return toReturnValue(relPath, sources[i].getResource());
                }
            }
            // no expand needed
            if (!SystemUtil.isWindows() && !sources[0].exists()) {
                res = pc.getConfig().getResource(relPath);
                if (res.exists()) {
                    return toReturnValue(relPath, res);
                }
            }
            for (int i = 0; i < sources.length; i++) {
                res = sources[i].getResource();
                if (res != null) {
                    return toReturnValue(relPath, res);
                }
            }
        } else // no expand needed
        if (!SystemUtil.isWindows()) {
            res = pc.getConfig().getResource(relPath);
            if (res.exists()) {
                return toReturnValue(relPath, res);
            }
        }
    // Resource[] reses = cwi.getPhysicalResources(pc,pc.getApplicationContext().getMappings(),realPath,false,pci.useSpecialMappings(),true);
    }
    relPath = ConfigWebUtil.replacePlaceholder(relPath, config);
    res = pc.getConfig().getResource(relPath);
    if (res.isAbsolute())
        return toReturnValue(relPath, res);
    PageSource ps = pc.getBasePageSource();
    res = ps == null ? ResourceUtil.getCanonicalResourceEL(ResourceUtil.toResourceExisting(pc.getConfig(), ReqRspUtil.getRootPath(pc.getServletContext()))) : ResourceUtil.getResource(pc, ps);
    if (!res.isDirectory())
        res = res.getParentResource();
    res = res.getRealResource(relPath);
    return toReturnValue(relPath, res);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) PageSource(lucee.runtime.PageSource)

Example 13 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class IsVideoFile method call.

public static boolean call(PageContext pc, String path) throws PageException {
    try {
        ConfigWeb config = pc.getConfig();
        VideoExecuter ve = VideoUtilImpl.createVideoExecuter(config);
        ve.info(config, new VideoInputImpl(Caster.toResource(pc, path, true)));
    } catch (Exception e) {
        if (StringUtil.contains(e.getMessage(), "missing ffmpeg installation"))
            throw Caster.toPageException(e);
        return false;
    }
    return true;
}
Also used : VideoExecuter(lucee.runtime.video.VideoExecuter) ConfigWeb(lucee.runtime.config.ConfigWeb) VideoInputImpl(lucee.runtime.video.VideoInputImpl) PageException(lucee.runtime.exp.PageException)

Example 14 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class CFMLResourceProvider method getPageContext.

private PageContext getPageContext(PageContext pc) {
    ThreadLocalPageContext.get(pc);
    if (pc != null)
        return pc;
    Config c = ThreadLocalPageContext.getConfig();
    if (c instanceof ConfigWeb) {
        return ThreadUtil.createPageContext((ConfigWeb) c, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", new Cookie[0], new Pair[0], null, new Pair[0], new StructImpl(), false, -1);
    }
    try {
        return CFMLEngineFactory.getInstance().createPageContext(new File("."), "localhost", "/", "", new Cookie[0], null, null, null, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, -1, false);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) Config(lucee.runtime.config.Config) ConfigWeb(lucee.runtime.config.ConfigWeb) File(java.io.File) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 15 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class Admin method doUpdateContext.

private void doUpdateContext() throws PageException, IOException {
    String strSrc = getString("admin", action, "source");
    String strRealpath = getString("admin", action, "destination");
    Resource src = ResourceUtil.toResourceExisting(pageContext, strSrc);
    ConfigServerImpl server = (ConfigServerImpl) ConfigImpl.getConfigServer(config, password);
    Resource trg, p;
    Resource deploy = server.getConfigDir().getRealResource("web-context-deployment");
    deploy.mkdirs();
    // deploy it
    trg = deploy.getRealResource(strRealpath);
    if (trg.exists())
        trg.remove(true);
    p = trg.getParentResource();
    if (!p.isDirectory())
        p.createDirectory(true);
    src.copyTo(trg, false);
    store();
    ConfigWeb[] webs = server.getConfigWebs();
    for (int i = 0; i < webs.length; i++) {
        ConfigWebUtil.deployWebContext(server, webs[i], true);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) ConfigServerImpl(lucee.runtime.config.ConfigServerImpl) ConfigWeb(lucee.runtime.config.ConfigWeb)

Aggregations

ConfigWeb (lucee.runtime.config.ConfigWeb)34 Resource (lucee.commons.io.res.Resource)9 PageContextImpl (lucee.runtime.PageContextImpl)9 StructImpl (lucee.runtime.type.StructImpl)7 PageSource (lucee.runtime.PageSource)6 ConfigServer (lucee.runtime.config.ConfigServer)6 IOException (java.io.IOException)5 CFMLFactory (lucee.runtime.CFMLFactory)5 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)5 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 PageException (lucee.runtime.exp.PageException)5 Struct (lucee.runtime.type.Struct)5 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)4 PageContext (lucee.runtime.PageContext)4 Config (lucee.runtime.config.Config)4 Log (lucee.commons.io.log.Log)3 Pair (lucee.commons.lang.Pair)3 Component (lucee.runtime.Component)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3