use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class CreateDynamicProxy method _call.
public static Object _call(PageContext pc, Object oCFC, Object oInterfaces) throws PageException, IOException {
if (SystemUtil.getLoaderVersion() < 5.9D)
throw new ApplicationException("You need to update your lucee.jar to execute the function [createDynamicProxy], you can download the latest jar from http://download.lucee.org.");
// Component
Component cfc;
if (oCFC instanceof Component)
cfc = (Component) oCFC;
else
cfc = pc.loadComponent(Caster.toString(oCFC));
// string list to array
if (Decision.isString(oInterfaces)) {
String list = Caster.toString(oInterfaces);
oInterfaces = ListUtil.listToStringArray(list, ',');
}
Class[] interfaces = null;
if (Decision.isArray(oInterfaces)) {
Object[] arr = Caster.toNativeArray(oInterfaces);
ClassLoader cl = ((PageContextImpl) pc).getClassLoader();
interfaces = new Class[arr.length];
for (int i = 0; i < arr.length; i++) {
if (arr[i] instanceof JavaObject)
interfaces[i] = ((JavaObject) arr[i]).getClazz();
else
interfaces[i] = ClassUtil.loadClass(cl, Caster.toString(arr[i]));
}
// strInterfaces=ListUtil.toStringArray(Caster.toArray(oInterfaces));
} else if (oInterfaces instanceof JavaObject) {
interfaces = new Class[] { ((JavaObject) oInterfaces).getClazz() };
} else
throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "invalid type [" + Caster.toClassName(oInterfaces) + "] for class defintion");
// check if all classes are interfaces
for (int i = 0; i < interfaces.length; i++) {
if (!interfaces[i].isInterface())
throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "definition [" + interfaces[i].getClass() + "] is a class and not a interface");
}
return JavaProxyFactory.createProxy(pc, cfc, null, interfaces);
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class _GetSuperStaticScope method call.
public static Struct call(PageContext pc) throws PageException {
Component cfc = pc.getActiveComponent();
if (cfc == null)
throw new ApplicationException("[static::] is not supported outside a component.");
Component base = cfc.getBaseComponent();
if (base == null)
throw new ApplicationException("component [" + cfc.getCallName() + "] does not have a base component.");
return base.staticScope();
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class ESAPIEncode method encode.
public static String encode(String item, short encFor, boolean canonicalize) throws PageException {
if (StringUtil.isEmpty(item))
return item;
PrintStream out = System.out;
try {
System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
Encoder encoder = ESAPI.encoder();
if (canonicalize)
item = encoder.canonicalize(item, false);
switch(encFor) {
case ENC_CSS:
return encoder.encodeForCSS(item);
case ENC_DN:
return encoder.encodeForDN(item);
case ENC_HTML:
return encoder.encodeForHTML(item);
case ENC_HTML_ATTR:
return encoder.encodeForHTMLAttribute(item);
case ENC_JAVA_SCRIPT:
return encoder.encodeForJavaScript(item);
case ENC_LDAP:
return encoder.encodeForLDAP(item);
case ENC_URL:
return encoder.encodeForURL(item);
case ENC_VB_SCRIPT:
return encoder.encodeForVBScript(item);
case ENC_XML:
return encoder.encodeForXML(item);
case ENC_XML_ATTR:
return encoder.encodeForXMLAttribute(item);
case ENC_XPATH:
return encoder.encodeForXPath(item);
}
throw new ApplicationException("invalid target encoding defintion");
} catch (EncodingException ee) {
throw Caster.toPageException(ee);
} finally {
System.setOut(out);
}
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class RestSetResponse method call.
public static String call(PageContext pc, Struct rsp) throws ApplicationException {
HttpServletRequest req = pc.getHttpServletRequest();
Result result = (Result) req.getAttribute("rest-result");
if (result == null)
throw new ApplicationException("not inside a REST Request");
result.setCustomResponse(rsp);
return null;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class DatasourceResourceProvider method getCore.
private Core getCore(ConnectionData data) throws PageException {
Core core = (Core) cores.get(data.datasourceName);
if (core == null) {
DatasourceConnection dc = getManager().getConnection(ThreadLocalPageContext.get(), data.getDatasourceName(), data.getUsername(), data.getPassword());
try {
dc.getConnection().setAutoCommit(false);
dc.getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
if ("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("net.sourceforge.jtds.jdbc.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MSSQL(dc, data.getPrefix());
else if ("org.gjt.mm.mysql.Driver".equals(dc.getDatasource().getClassDefinition().getClassName()))
core = new MySQL(dc, data.getPrefix());
else
throw new ApplicationException("there is no DatasourceResource driver for this database [" + data.getPrefix() + "]");
cores.put(data.datasourceName, core);
} catch (SQLException e) {
throw new DatabaseException(e, dc);
} finally {
release(dc);
// manager.releaseConnection(CONNECTION_ID,dc);
}
}
return core;
}
Aggregations