use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class GatewayEngineImpl method call.
public Object call(String cfcPath, String id, String functionName, Struct arguments, boolean cfcPeristent, Object defaultValue) throws PageException {
String requestURI = toRequestURI(cfcPath);
PageContext oldPC = ThreadLocalPageContext.get();
PageContextImpl pc = null;
try {
pc = createPageContext(requestURI, id, functionName, arguments, cfcPeristent, true);
String ext = ResourceUtil.getExtension(cfcPath, null);
ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
int dialect = ext == null ? CFMLEngine.DIALECT_CFML : config.getFactory().toDialect(ext);
// ThreadLocalPageContext.register(pc);
Component cfc = getCFC(pc, requestURI);
if (cfc.containsKey(functionName)) {
if (dialect == CFMLEngine.DIALECT_LUCEE)
pc.execute(requestURI, true, false);
else
pc.executeCFML(requestURI, true, false);
// Result
return pc.variablesScope().get(AMF_FORWARD, null);
}
} finally {
CFMLFactory f = config.getFactory();
f.releaseLuceePageContext(pc, true);
ThreadLocalPageContext.register(oldPC);
}
return defaultValue;
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class GatewayEngineImpl method getComponent.
public Object getComponent(String cfcPath, String id) throws PageException {
String requestURI = toRequestURI(cfcPath);
PageContext oldPC = ThreadLocalPageContext.get();
PageContextImpl pc = null;
try {
pc = createPageContext(requestURI, id, "init", null, false, true);
// ThreadLocalPageContext.register(pc);
return getCFC(pc, requestURI);
} finally {
CFMLFactory f = config.getFactory();
f.releaseLuceePageContext(pc, true);
ThreadLocalPageContext.register(oldPC);
}
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Caster method toString.
/**
* cast a Object to a String
* @param o Object to cast
* @return casted String
* @throws PageException
*/
public static String toString(Object o) throws PageException {
if (o instanceof String)
return (String) o;
else if (o instanceof Number)
return toString(((Number) o));
else if (o instanceof Boolean)
return toString(((Boolean) o).booleanValue());
else if (o instanceof Castable)
return ((Castable) o).castToString();
else if (o instanceof Date) {
if (o instanceof DateTime)
return ((DateTime) o).castToString();
return new DateTimeImpl((Date) o).castToString();
} else if (o instanceof Clob)
return toString((Clob) o);
else if (o instanceof Locale)
return toString((Locale) o);
else if (o instanceof TimeZone)
return toString((TimeZone) o);
else if (o instanceof Node)
return XMLCaster.toString((Node) o);
else if (o instanceof Reader) {
Reader r = null;
try {
return IOUtil.toString(r = (Reader) o);
} catch (IOException e) {
throw Caster.toPageException(e);
} finally {
IOUtil.closeEL(r);
}
} else if (o instanceof InputStream) {
PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
InputStream r = null;
try {
return IOUtil.toString(r = (InputStream) o, pc.getWebCharset());
} catch (IOException e) {
throw Caster.toPageException(e);
} finally {
IOUtil.closeEL(r);
}
} else if (o instanceof byte[]) {
PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
try {
return new String((byte[]) o, pc.getWebCharset());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
return new String((byte[]) o);
}
} else if (o instanceof char[])
return new String((char[]) o);
else if (o instanceof ObjectWrap)
return toString(((ObjectWrap) o).getEmbededObject());
else if (o instanceof Calendar)
return toString(((Calendar) o).getTime());
else if (o == null)
return "";
// INFO Collection is new of type Castable
if (o instanceof Map || o instanceof List || o instanceof Function)
throw new CasterException(o, "string");
return o.toString();
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Dump method call.
public static String call(PageContext pc, Object object, String label, boolean expand, double maxLevel, String show, String hide, String output, String format, double keys, boolean metainfo, boolean showUDFs) throws PageException {
if (show != null && "all".equalsIgnoreCase(show.trim()))
show = null;
if (hide != null && "all".equalsIgnoreCase(hide.trim()))
hide = null;
// PageContext pcc = pc;
try {
// output
int defType = DumpWriter.DEFAULT_RICH;
int outputType = OUTPUT_TYPE_NONE;
Resource outputRes = null;
if (!StringUtil.isEmpty(output, true)) {
output = output.trim();
if ("browser".equalsIgnoreCase(output)) {
outputType = OUTPUT_TYPE_BROWSER;
defType = DumpWriter.DEFAULT_RICH;
} else if ("console".equalsIgnoreCase(output)) {
outputType = OUTPUT_TYPE_CONSOLE;
defType = DumpWriter.DEFAULT_PLAIN;
} else {
outputType = OUTPUT_TYPE_RESOURCE;
defType = DumpWriter.DEFAULT_RICH;
outputRes = ResourceUtil.toResourceNotExisting(pc, output);
}
}
// format
DumpWriter writer = pc.getConfig().getDumpWriter(format, defType);
Set<String> setShow = (show != null) ? ListUtil.listToSet(show.toLowerCase(), ",", true) : null;
Set<String> setHide = (hide != null) ? ListUtil.listToSet(hide.toLowerCase(), ",", true) : null;
DumpProperties properties = new DumpProperties((int) maxLevel, setShow, setHide, (int) keys, metainfo, showUDFs);
DumpData dd = DumpUtil.toDumpData(object, pc, (int) maxLevel, properties);
if (!StringUtil.isEmpty(label)) {
DumpTable table = new DumpTable("#ffffff", "#cccccc", "#000000");
table.appendRow(1, new SimpleDumpData(label));
// table.appendRow(1,new SimpleDumpData(getContext()));
table.appendRow(0, dd);
dd = table;
}
// formatType==FORMAT_TYPE_TEXT
boolean isText = "text".equalsIgnoreCase(format);
if (OUTPUT_TYPE_BROWSER == outputType || outputType == OUTPUT_TYPE_NONE) {
if (isText)
pc.forceWrite("<pre>");
pc.forceWrite(writer.toString(pc, dd, expand));
if (isText)
pc.forceWrite("</pre>");
} else if (OUTPUT_TYPE_CONSOLE == outputType)
System.out.println(writer.toString(pc, dd, expand));
else if (OUTPUT_TYPE_RESOURCE == outputType)
IOUtil.write(outputRes, writer.toString(pc, dd, expand) + "\n************************************************************************************\n", ((PageContextImpl) pc).getResourceCharset(), true);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return "";
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class JavaProxy method loadClassByPath.
private static Class<?> loadClassByPath(PageContext pc, String className, String[] paths) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
java.util.List<Resource> resources = new ArrayList<Resource>();
if (paths != null && paths.length > 0) {
// load resources
for (int i = 0; i < paths.length; i++) {
Resource res = ResourceUtil.toResourceExisting(pc, paths[i]);
if (res.isDirectory()) {
// a directory was passed, add all of the jar files from it
FileResource dir = (FileResource) res;
Resource[] jars = dir.listResources((ResourceNameFilter) new WildCardFilter("*.jar"));
for (Resource jar : jars) {
resources.add(jar);
}
} else {
resources.add(res);
}
}
// throw new FunctionException(pc, "JavaProxy", 2, "path", "argument path has to be a array of strings or a single string, where every string is defining a path");
}
// load class
try {
ClassLoader cl = resources.isEmpty() ? pci.getClassLoader() : pci.getClassLoader(resources.toArray(new Resource[resources.size()]));
Class clazz = null;
try {
clazz = ClassUtil.loadClass(cl, className);
} catch (ClassException ce) {
// try java.lang if no package definition
if (className.indexOf('.') == -1) {
try {
clazz = ClassUtil.loadClass(cl, "java.lang." + className);
} catch (ClassException e) {
throw ce;
}
} else
throw ce;
}
return clazz;
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
Aggregations