use of lucee.runtime.type.Collection in project Lucee by lucee.
the class InternalRequest method call.
public static Struct call(final PageContext pc, String template, String method, Struct urls, Struct forms, Struct cookies, Struct headers, Object body, String strCharset, boolean addToken) throws PageException {
// add token
if (addToken) {
// if(true) throw new ApplicationException("addtoken==true");
if (cookies == null)
cookies = new StructImpl();
cookies.set(KeyConstants._cfid, pc.getCFID());
cookies.set(KeyConstants._cftoken, pc.getCFToken());
String jsessionid = pc.getJSessionId();
if (jsessionid != null)
cookies.set("jsessionid", jsessionid);
}
// charset
Charset reqCharset = StringUtil.isEmpty(strCharset) ? pc.getWebCharset() : CharsetUtil.toCharset(strCharset);
String ext = ResourceUtil.getExtension(template, null);
// welcome files
if (StringUtil.isEmpty(ext)) {
throw new FunctionException(pc, "Invoke", 1, "url", "welcome file listing not supported, please define the template name.");
}
// dialect
int dialect = ((CFMLFactoryImpl) pc.getConfig().getFactory()).toDialect(ext, -1);
if (dialect == -1)
dialect = pc.getCurrentTemplateDialect();
// CFMLEngine.DIALECT_LUCEE
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] _barr = null;
if (Decision.isBinary(body))
_barr = Caster.toBinary(body);
else if (body != null) {
Charset cs = null;
// get charset
if (headers != null) {
String strCT = Caster.toString(headers.get(CONTENT_TYPE), null);
if (strCT != null) {
ContentType ct = HTTPUtil.toContentType(strCT, null);
if (ct != null) {
String strCS = ct.getCharset();
if (!StringUtil.isEmpty(strCS))
cs = CharsetUtil.toCharSet(strCS, CharSet.UTF8).toCharset();
}
}
}
if (cs == null)
cs = CharsetUtil.UTF8;
String str = Caster.toString(body);
_barr = str.getBytes(cs);
}
PageContextImpl _pc = createPageContext(pc, template, urls, cookies, headers, _barr, reqCharset, baos);
fillForm(_pc, forms);
Collection cookie, request, session = null;
int status;
long exeTime;
boolean isText = false;
Charset _charset = null;
try {
if (CFMLEngine.DIALECT_LUCEE == dialect)
_pc.execute(template, true, false);
else
_pc.executeCFML(template, true, false);
} finally {
_pc.flush();
cookie = _pc.cookieScope().duplicate(false);
request = _pc.requestScope().duplicate(false);
session = sessionEnabled(_pc) ? _pc.sessionScope().duplicate(false) : null;
exeTime = System.currentTimeMillis() - pc.getStartTime();
// debugging=_pc.getDebugger().getDebuggingData(_pc).duplicate(false);
HttpServletResponseDummy rsp = (HttpServletResponseDummy) _pc.getHttpServletResponse();
// headers
Collection.Key name;
headers = new StructImpl();
Iterator<String> it = rsp.getHeaderNames().iterator();
java.util.Collection<String> values;
while (it.hasNext()) {
name = KeyImpl.init(it.next());
values = rsp.getHeaders(name.getString());
if (values == null || values.size() == 0)
continue;
if (values.size() > 1)
headers.set(name, Caster.toArray(values));
else
headers.set(name, values.iterator().next());
}
// status
status = rsp.getStatus();
ContentType ct = HTTPUtil.toContentType(rsp.getContentType(), null);
if (ct != null) {
isText = HTTPUtil.isTextMimeType(ct.getMimeType());
if (ct.getCharset() != null)
_charset = CharsetUtil.toCharset(ct.getCharset(), null);
}
releasePageContext(_pc, pc);
}
Struct rst = new StructImpl();
byte[] barr = baos.toByteArray();
if (isText)
rst.set(KeyConstants._filecontent, new String(barr, _charset == null ? reqCharset : _charset));
else
rst.set(FILECONTENT_BYNARY, barr);
rst.set(KeyConstants._cookies, cookie);
rst.set(KeyConstants._request, request);
if (session != null)
rst.set(KeyConstants._session, session);
rst.set(KeyConstants._headers, headers);
// rst.put(KeyConstants._debugging, debugging);
rst.set(KeyConstants._executionTime, new Double(exeTime));
rst.set(KeyConstants._status, new Double(status));
rst.set(STATUS_CODE, new Double(status));
return rst;
}
use of lucee.runtime.type.Collection in project Lucee by lucee.
the class Arch method sizeOf.
private static void sizeOf(Creation creator, Size size, Object obj, Set<Object> parents) throws PageException {
if (obj == null)
return;
Object raw = obj;
// TODO this is just a patch solution, find a better way to handle this kind of situation (Wrapper classes)
if (isInstaneOf(obj.getClass(), "lucee.runtime.text.xml.struct.XMLStruct")) {
try {
Method toNode = raw.getClass().getMethod("toNode", new Class[0]);
raw = toNode.invoke(obj, new Object[0]);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
if (parents.contains(raw))
return;
parents.add(raw);
try {
if (obj instanceof Collection) {
if (obj instanceof Query)
sizeOf(creator, size, (Query) obj, parents);
else
sizeOf(creator, size, ((Collection) obj).valueIterator(), parents);
return;
} else // Map
if (obj instanceof Map) {
sizeOf(creator, size, ((Map) obj).values().iterator(), parents);
return;
} else // List
if (obj instanceof List) {
sizeOf(creator, size, ((List) obj).iterator(), parents);
return;
} else // String
if (obj instanceof String) {
size.size += (CHAR_SIZE * ((String) obj).length()) + REF_SIZE;
} else // Number
if (obj instanceof Number) {
if (obj instanceof Double)
size.size += DOUBLE_SIZE + REF_SIZE;
else if (obj instanceof Float)
size.size += FLOAT_SIZE + REF_SIZE;
else if (obj instanceof Long)
size.size += LONG_SIZE + REF_SIZE;
else if (obj instanceof Integer)
size.size += INT_SIZE + REF_SIZE;
else if (obj instanceof Short)
size.size += SHORT_SIZE + REF_SIZE;
else if (obj instanceof Byte)
size.size += BYTE_SIZE + REF_SIZE;
} else if (obj instanceof Boolean)
size.size += REF_SIZE + BOOLEAN_SIZE;
else if (obj instanceof Character)
size.size += REF_SIZE + CHAR_SIZE;
else
size.size += _sizeOf(obj);
size.count++;
} finally {
// parents.remove(raw);// TODO should we not remove, to see if sister is me.
}
}
Aggregations