use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class ModernAppListener method _onRequest.
protected void _onRequest(PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
pci.setAppListenerType(ApplicationListener.TYPE_MODERN);
if (appPS != null) {
String callPath = appPS.getComponentName();
Component app = ComponentLoader.loadComponent(pci, appPS, callPath, false, false);
// init
ModernApplicationContext appContext = initApplicationContext(pci, app);
apps.put(appContext.getName(), app);
if (!pci.initApplicationContext(this))
return;
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
String targetPage = requestedPage.getRealpathWithVirtual();
RefBoolean goon = new RefBooleanImpl(true);
// onRequestStart
if (app.contains(pc, ON_REQUEST_START)) {
try {
Object rtn = call(app, pci, ON_REQUEST_START, new Object[] { targetPage }, false);
if (!Caster.toBooleanValue(rtn, true))
return;
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
// onRequest
if (goon.toBooleanValue()) {
boolean isComp = isComponent(pc, requestedPage);
Object method;
if (isComp && app.contains(pc, ON_CFCREQUEST) && (method = pc.urlFormScope().get(KeyConstants._method, null)) != null) {
Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);
url.removeEL(KeyConstants._fieldnames);
url.removeEL(KeyConstants._method);
Object args = url.get(KeyConstants._argumentCollection, null);
// url returnFormat
Object oReturnFormat = url.removeEL(KeyConstants._returnFormat);
int urlReturnFormat = -1;
if (oReturnFormat != null)
urlReturnFormat = UDFUtil.toReturnFormat(Caster.toString(oReturnFormat, null), -1);
// request header accept
List<MimeType> accept = ReqRspUtil.getAccept(pc);
int headerReturnFormat = MimeType.toFormat(accept, -1, -1);
Object queryFormat = url.removeEL(KeyConstants._queryFormat);
if (args == null) {
args = pc.getHttpServletRequest().getAttribute("argumentCollection");
}
if (args instanceof String) {
args = new JSONExpressionInterpreter().interpret(pc, (String) args);
}
if (args != null) {
if (Decision.isCastableToStruct(args)) {
Struct sct = Caster.toStruct(args, false);
// Key[] keys = url.keys();
Iterator<Entry<Key, Object>> it = url.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
sct.setEL(e.getKey(), e.getValue());
}
args = sct;
} else if (Decision.isCastableToArray(args)) {
args = Caster.toArray(args);
} else {
Array arr = new ArrayImpl();
arr.appendEL(args);
args = arr;
}
} else
args = url;
Object rtn = call(app, pci, ON_CFCREQUEST, new Object[] { requestedPage.getComponentName(), method, args }, true);
if (rtn != null) {
if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
pc.variablesScope().setEL("AMF-Forward", rtn);
// ThreadLocalWDDXResult.set(rtn);
} else {
try {
ComponentPageImpl.writeToResponseStream(pc, app, method.toString(), urlReturnFormat, headerReturnFormat, queryFormat, rtn);
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
}
} else {
// TODO impl die nicht so generisch ist
try {
if (!isComp && app.contains(pc, ON_REQUEST))
call(app, pci, ON_REQUEST, new Object[] { targetPage }, false);
else
pci._doInclude(new PageSource[] { requestedPage }, false, null);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
}
// onRequestEnd
if (goon.toBooleanValue() && app.contains(pc, ON_REQUEST_END)) {
try {
call(app, pci, ON_REQUEST_END, new Object[] { targetPage }, false);
} catch (PageException pe) {
pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
if (pe != null)
throw pe;
}
}
} else {
apps.put(pc.getApplicationContext().getName(), null);
if (rl != null) {
requestedPage = rl.execute(pc, requestedPage);
if (requestedPage == null)
return;
}
pci._doInclude(new PageSource[] { requestedPage }, false, null);
}
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class Image method info.
public Struct info() throws PageException {
if (sctInfo != null)
return sctInfo;
Struct sctInfo = new StructImpl(), sct;
ImageMetaDrew.addInfo(format, source, sctInfo);
sctInfo = ImageGetEXIFMetadata.flatten(sctInfo);
sctInfo.setEL(KeyConstants._height, new Double(getHeight()));
sctInfo.setEL(KeyConstants._width, new Double(getWidth()));
sctInfo.setEL(KeyConstants._source, source == null ? "" : source.getAbsolutePath());
// sct.setEL("mime_type",getMimeType());
ColorModel cm = image().getColorModel();
sct = new StructImpl();
sctInfo.setEL("colormodel", sct);
sct.setEL("alpha_channel_support", Caster.toBoolean(cm.hasAlpha()));
sct.setEL("alpha_premultiplied", Caster.toBoolean(cm.isAlphaPremultiplied()));
sct.setEL("transparency", toStringTransparency(cm.getTransparency()));
sct.setEL("pixel_size", Caster.toDouble(cm.getPixelSize()));
sct.setEL("num_components", Caster.toDouble(cm.getNumComponents()));
sct.setEL("num_color_components", Caster.toDouble(cm.getNumColorComponents()));
sct.setEL("colorspace", toStringColorSpace(cm.getColorSpace()));
// bits_component
int[] bitspercomponent = cm.getComponentSize();
Array arr = new ArrayImpl();
Double value;
for (int i = 0; i < bitspercomponent.length; i++) {
sct.setEL("bits_component_" + (i + 1), value = new Double(bitspercomponent[i]));
arr.appendEL(value);
}
sct.setEL("bits_component", arr);
// colormodel_type
if (cm instanceof ComponentColorModel)
sct.setEL("colormodel_type", "ComponentColorModel");
else if (cm instanceof IndexColorModel)
sct.setEL("colormodel_type", "IndexColorModel");
else if (cm instanceof PackedColorModel)
sct.setEL("colormodel_type", "PackedColorModel");
else
sct.setEL("colormodel_type", ListUtil.last(cm.getClass().getName(), '.'));
getMetaData(sctInfo);
// Metadata.addInfo(format,source,sctInfo);
Metadata.addExifInfo(format, source, sctInfo);
this.sctInfo = sctInfo;
return sctInfo;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class GetCurrentContext method call.
public static Array call(PageContext pc) {
Array arr = new ArrayImpl();
CallStackGet._getTagContext(pc, arr, new Exception("Stack trace"), KeyConstants._line);
return arr;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class PagePoolList method call.
public static Array call(PageContext pc) throws PageException {
ArrayImpl arr = new ArrayImpl();
fill(arr, ConfigWebUtil.getAllMappings(pc));
return arr;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class Caster method castTo.
/**
* cast a value to a value defined by type argument
* @param pc
* @param type type of the returning Value
* @param o Object to cast
* @return casted Value
* @throws PageException
*/
public static Object castTo(PageContext pc, String type, Object o, boolean alsoPattern) throws PageException {
type = StringUtil.toLowerCase(type).trim();
if (type.length() > 2) {
char first = type.charAt(0);
switch(first) {
case 'a':
if (type.equals("any")) {
return o;
} else if (type.equals("array")) {
return toArray(o);
}
break;
case 'b':
if (type.equals("boolean") || type.equals("bool")) {
return toBoolean(o);
} else if (type.equals("binary")) {
return toBinary(o);
} else if (type.equals("base64")) {
return toBase64(o, null);
} else if (type.equals("bigdecimal") || type.equals("big_decimal")) {
return toBigDecimal(o);
} else if (type.equals("biginteger") || type.equals("big_integer")) {
return toBigInteger(o);
}
break;
case 'c':
if (alsoPattern && type.equals("creditcard")) {
return toCreditCard(o);
}
break;
case 'd':
if (type.equals("date")) {
return DateCaster.toDateAdvanced(o, pc.getTimeZone());
} else if (type.equals("datetime")) {
return DateCaster.toDateAdvanced(o, pc.getTimeZone());
} else if (type.equals("double")) {
return toDouble(o);
} else if (type.equals("decimal")) {
return toDecimal(o);
}
break;
case 'e':
if (type.equals("eurodate")) {
return DateCaster.toEuroDate(o, pc.getTimeZone());
} else if (alsoPattern && type.equals("email")) {
return toEmail(o);
}
break;
case 'f':
if (type.equals("float")) {
return toDouble(o);
} else if (type.equals("function")) {
return toFunction(o);
}
break;
case 'g':
if (type.equals("guid")) {
return toGUId(o);
}
break;
case 'i':
if (type.equals("integer") || type.equals("int")) {
return toInteger(o);
}
break;
case 'l':
if (type.equals("long")) {
return toLong(o);
}
break;
case 'n':
if (type.equals("numeric")) {
return toDouble(o);
} else if (type.equals("number")) {
return toDouble(o);
} else if (type.equals("node")) {
return toXML(o);
}
break;
case 'o':
if (type.equals("object")) {
return o;
} else if (type.equals("other")) {
return o;
}
break;
case 'p':
if (alsoPattern && type.equals("phone")) {
return toPhone(o);
}
break;
case 'q':
if (type.equals("query")) {
return toQuery(o);
}
break;
case 's':
if (type.equals("string")) {
return toString(o);
} else if (type.equals("struct")) {
return toStruct(o);
} else if (type.equals("short")) {
return toShort(o);
} else if (alsoPattern && (type.equals("ssn") || type.equals("social_security_number"))) {
return toSSN(o);
}
break;
case 't':
if (type.equals("timespan")) {
return toTimespan(o);
}
if (type.equals("time")) {
return DateCaster.toDateAdvanced(o, pc.getTimeZone());
}
if (alsoPattern && type.equals("telephone")) {
return toPhone(o);
}
break;
case 'u':
if (type.equals("uuid")) {
return toUUId(o);
}
if (alsoPattern && type.equals("url")) {
return toURL(o);
}
if (type.equals("usdate")) {
return DateCaster.toUSDate(o, pc.getTimeZone());
// return DateCaster.toDate(o,pc.getTimeZone());
}
break;
case 'v':
if (type.equals("variablename")) {
return toVariableName(o);
} else if (type.equals("void")) {
return toVoid(o);
} else if (type.equals("variable_name")) {
return toVariableName(o);
} else if (type.equals("variable-name")) {
return toVariableName(o);
}
break;
case 'x':
if (type.equals("xml")) {
return toXML(o);
}
case 'z':
if (alsoPattern && (type.equals("zip") || type.equals("zipcode"))) {
return toZip(o);
}
break;
}
}
// <type>[]
if (type.endsWith("[]")) {
String componentType = type.substring(0, type.length() - 2);
Object[] src = toNativeArray(o);
Array trg = new ArrayImpl();
for (int i = 0; i < src.length; i++) {
if (src[i] == null) {
continue;
}
trg.setE(i + 1, castTo(pc, componentType, src[i], alsoPattern));
}
return trg;
}
return _castTo(pc, type, o);
}
Aggregations