public static DatabaseException notFoundException(PageContext pc, String datasource) { List<String> list = new ArrayList<String>(); // application based datasources DataSource[] datasources = ((ApplicationContextPro) pc.getApplicationContext()).getDataSources(); if (datasources != null) for (int i = 0; i < datasources.length; i++) { list.add(datasources[i].getName()); } // config based datasources datasources = pc.getConfig().getDataSources(); if (datasources != null) for (int i = 0; i < datasources.length; i++) { list.add(datasources[i].getName()); } // create error detail DatabaseException de = new DatabaseException("datasource [" + datasource + "] doesn't exist", null, null, null); de.setDetail( ExceptionUtil.createSoundexDetail(datasource, list.iterator(), "datasource names")); de.setAdditional(KeyConstants._Datasource, datasource); return de; }
public static boolean call(PageContext pc, Object obj, boolean addNewLine, boolean doErrorStream) throws PageException { String string; if (Decision.isSimpleValue(obj)) string = Caster.toString(obj); else { try { string = Serialize.call(pc, obj); } catch (Throwable t) { string = obj.toString(); } } PrintStream stream = System.out; // string+=":"+Thread.currentThread().getId(); if (doErrorStream) stream = System.err; if (string != null) { if (StringUtil.indexOfIgnoreCase(string, "<print-stack-trace>") != -1) { String st = ExceptionUtil.getStacktrace(new Exception("Stack trace"), false); string = StringUtil.replace(string, "<print-stack-trace>", "\n" + st + "\n", true).trim(); } if (StringUtil.indexOfIgnoreCase(string, "<hash-code>") != -1) { String st = obj.hashCode() + ""; string = StringUtil.replace(string, "<hash-code>", st, true).trim(); } } if (addNewLine) stream.println(string); else stream.print(string); return true; }
@Override public void log() throws IOException { try { if (log == null) { log = monitor.getClass().getMethod("log", new Class[0]); } log.invoke(monitor, PARAMS_LOG); } catch (Exception e) { e.printStackTrace(); throw ExceptionUtil.toIOException(e); } }
public static String call(PageContext pc, String cacheName) throws FunctionException { if (StringUtil.isEmpty(cacheName, true) || "all".equals(cacheName = cacheName.trim().toLowerCase())) { PagePoolClear.call(pc); ComponentCacheClear.call(pc); CTCacheClear.call(pc); queryCache(pc); tagCache(pc); functionCache(pc); } else if ("template".equals(cacheName) || "page".equals(cacheName)) { PagePoolClear.call(pc); } else if ("component".equals(cacheName) || "cfc".equals(cacheName)) { ComponentCacheClear.call(pc); } else if ("customtag".equals(cacheName) || "ct".equals(cacheName)) { CTCacheClear.call(pc); } else if ("query".equals(cacheName) || "object".equals(cacheName)) { queryCache(pc); } else if ("tag".equals(cacheName)) { tagCache(pc); } else if ("function".equals(cacheName)) { functionCache(pc); } else throw new FunctionException( pc, "cacheClear", 1, "cacheName", ExceptionUtil.similarKeyMessage( new String[] { "all", "template", "component", "customtag", "query", "tag", "function" }, cacheName, "cache name", "cache names")); return null; }
private void err(PageContext pc, Throwable t) { String msg = ExceptionUtil.getStacktrace(t, true); SystemOut.print(pc.getConfig().getErrWriter(), msg); }