public static void _getTagContext( PageContext pc, Array tagContext, Throwable t, Collection.Key lineNumberName) { // Throwable root = t.getRootCause(); Throwable cause = t.getCause(); if (cause != null) _getTagContext(pc, tagContext, cause, lineNumberName); StackTraceElement[] traces = t.getStackTrace(); UDF[] udfs = ((PageContextImpl) pc).getUDFs(); int line = 0; String template; Struct item; StackTraceElement trace = null; String functionName, methodName; int index = udfs.length - 1; for (int i = 0; i < traces.length; i++) { trace = traces[i]; template = trace.getFileName(); if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java")) continue; methodName = trace.getMethodName(); if (methodName != null && methodName.startsWith("udfCall") && index > -1) functionName = udfs[index--].getFunctionName(); else functionName = ""; item = new StructImpl(); line = trace.getLineNumber(); item.setEL(KeyConstants._function, functionName); item.setEL(KeyConstants._template, template); item.setEL(lineNumberName, new Double(line)); tagContext.appendEL(item); } }
private static boolean validExtension(String[] extensions, String file) { String ext = ResourceUtil.getExtension(file, ""); ext = railo.runtime.type.util.ListUtil.first(ext, "/", true); if (StringUtil.isEmpty(ext)) return true; for (int i = 0; i < extensions.length; i++) { if (ext.equalsIgnoreCase(extensions[i])) return true; } return false; }
public static synchronized void log( Debugger debugger, int type, String category, String text, String varName, String varValue) { Throwable t = new Exception("Stack trace"); Throwable cause = t.getCause(); while (cause != null) { t = cause; cause = t.getCause(); } StackTraceElement[] traces = t.getStackTrace(); int line = 0; String template = null; StackTraceElement trace = null; for (int i = 0; i < traces.length; i++) { trace = traces[i]; template = trace.getFileName(); if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java") || template.endsWith("Dump.cfc") || template.endsWith("dump.cfm")) // MUST bad impl continue; line = trace.getLineNumber(); break; } // print.e(t); if (line == 0) return; /*String type=traces[2].getMethodName(); int row=qry.addRow(); qry.setAtEL(LABEL, row, label); qry.setAtEL(ACTION, row, type(type)); qry.setAtEL(PARAMS, row, addional); */ String action = type(traces[2].getMethodName()); if (debugger != null) debugger.addTrace(type, category, text, template, line, action, varName, varValue); }
protected void _onRequest( PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl) throws PageException { PageContextImpl pci = (PageContextImpl) pc; if (appPS != null) { String callPath = appPS.getComponentName(); ComponentAccess app = ComponentLoader.loadComponent(pci, null, appPS, callPath, false, false); // init initApplicationContext(pci, app); apps.put(pc.getApplicationContext().getName(), app); if (!pci.initApplicationContext()) return; if (rl != null) { requestedPage = rl.execute(pc, requestedPage); if (requestedPage == null) return; } String targetPage = requestedPage.getFullRealpath(); boolean doOnRequestEnd = true; // onRequestStart if (app.contains(pc, ON_REQUEST_START)) { Object rtn = call(app, pci, ON_REQUEST_START, new Object[] {targetPage}, true); if (!Caster.toBooleanValue(rtn, true)) return; } // onRequest boolean isCFC = ResourceUtil.getExtension(targetPage, "") .equalsIgnoreCase(pc.getConfig().getCFCExtension()); Object method; if (isCFC && app.contains(pc, ON_CFCREQUEST) && (method = pc.urlFormScope().get(ComponentPage.METHOD, null)) != null) { Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true); url.removeEL(KeyConstants._fieldnames); url.removeEL(ComponentPage.METHOD); Object args = url.get(KeyConstants._argumentCollection, null); Object returnFormat = url.removeEL(KeyConstants._returnFormat); 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 { pc.forceWrite( ComponentPage.convertResult( pc, app, method.toString(), returnFormat, queryFormat, rtn)); } catch (Exception e) { throw Caster.toPageException(e); } } } } // else if(!isCFC && app.contains(pc,ON_REQUEST)) {} else { // TODO impl die nicht so generisch ist try { if (!isCFC && app.contains(pc, ON_REQUEST)) call(app, pci, ON_REQUEST, new Object[] {targetPage}, false); else pci.doInclude(requestedPage); } catch (PageException pe) { if (!Abort.isSilentAbort(pe)) { if (pe instanceof MissingIncludeException) { if (((MissingIncludeException) pe).getPageSource().equals(requestedPage)) { if (app.contains(pc, ON_MISSING_TEMPLATE)) { if (!Caster.toBooleanValue( call(app, pci, ON_MISSING_TEMPLATE, new Object[] {targetPage}, true), true)) throw pe; } else throw pe; } else throw pe; } else throw pe; } else { doOnRequestEnd = false; if (app.contains(pc, ON_ABORT)) { call(app, pci, ON_ABORT, new Object[] {targetPage}, true); } } } } // onRequestEnd if (doOnRequestEnd && app.contains(pc, ON_REQUEST_END)) { call(app, pci, ON_REQUEST_END, new Object[] {targetPage}, true); } } else { apps.put(pc.getApplicationContext().getName(), null); pc.doInclude(requestedPage); } }