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