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);
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations