use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class XMLConfigWebFactory method loadApplication.
/**
* @param configServer
* @param config
* @param doc
* @throws IOException
* @throws PageException
*/
private static void loadApplication(ConfigServerImpl configServer, ConfigImpl config, Document doc, int mode) throws IOException, PageException {
boolean hasCS = configServer != null;
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
Element application = getChildByName(doc.getDocumentElement(), "application");
Element scope = getChildByName(doc.getDocumentElement(), "scope");
// Listener type
ApplicationListener listener;
if (mode == ConfigImpl.MODE_STRICT) {
listener = new ModernAppListener();
} else {
listener = ConfigWebUtil.loadListener(getAttr(application, "listener-type"), null);
if (listener == null) {
if (hasCS && configServer.getApplicationListener() != null)
listener = ConfigWebUtil.loadListener(configServer.getApplicationListener().getType(), null);
if (listener == null)
listener = new MixedAppListener();
}
}
String[] strTypes = new String[] { "function", "include", "query", "resource", "http", "file", "webservice" };
int[] types = new int[] { Config.CACHEDWITHIN_FUNCTION, Config.CACHEDWITHIN_INCLUDE, Config.CACHEDWITHIN_QUERY, Config.CACHEDWITHIN_RESOURCE, Config.CACHEDWITHIN_HTTP, Config.CACHEDWITHIN_FILE, Config.CACHEDWITHIN_WEBSERVICE };
// cachedwithin
for (int i = 0; i < types.length; i++) {
String cw = getAttr(application, "cached-within-" + strTypes[i]);
if (!StringUtil.isEmpty(cw, true))
config.setCachedWithin(types[i], cw);
else if (hasCS)
config.setCachedWithin(types[i], configServer.getCachedWithin(types[i]));
}
// Type Checking
Boolean typeChecking = Caster.toBoolean(getAttr(application, "type-checking"), null);
if (typeChecking != null)
config.setTypeChecking(typeChecking.booleanValue());
else if (hasCS)
config.setTypeChecking(configServer.getTypeChecking());
// Listener Mode
int listenerMode = ConfigWebUtil.toListenerMode(getAttr(application, "listener-mode"), -1);
if (listenerMode == -1) {
if (hasCS)
listenerMode = configServer.getApplicationListener() == null ? ApplicationListener.MODE_CURRENT2ROOT : configServer.getApplicationListener().getMode();
else
listenerMode = ApplicationListener.MODE_CURRENT2ROOT;
}
listener.setMode(listenerMode);
config.setApplicationListener(listener);
// Req Timeout URL
if (mode == ConfigImpl.MODE_STRICT) {
config.setAllowURLRequestTimeout(false);
} else {
String allowURLReqTimeout = getAttr(application, "allow-url-requesttimeout");
if (hasAccess && !StringUtil.isEmpty(allowURLReqTimeout)) {
config.setAllowURLRequestTimeout(Caster.toBooleanValue(allowURLReqTimeout, false));
} else if (hasCS)
config.setAllowURLRequestTimeout(configServer.isAllowURLRequestTimeout());
}
// Req Timeout
TimeSpan ts = null;
if (hasAccess) {
String reqTimeoutApplication = getAttr(application, "requesttimeout");
// deprecated
String reqTimeoutScope = getAttr(scope, "requesttimeout");
if (!StringUtil.isEmpty(reqTimeoutApplication))
ts = Caster.toTimespan(reqTimeoutApplication);
if (ts == null && !StringUtil.isEmpty(reqTimeoutScope))
ts = Caster.toTimespan(reqTimeoutScope);
}
if (ts != null && ts.getMillis() > 0)
config.setRequestTimeout(ts);
else if (hasCS)
config.setRequestTimeout(configServer.getRequestTimeout());
// script-protect
String strScriptProtect = getAttr(application, "script-protect");
if (hasAccess && !StringUtil.isEmpty(strScriptProtect)) {
// print.err("sp:"+strScriptProtect);
config.setScriptProtect(AppListenerUtil.translateScriptProtect(strScriptProtect));
} else if (hasCS)
config.setScriptProtect(configServer.getScriptProtect());
// classic-date-parsing
if (config instanceof ConfigServer) {
if (mode == ConfigImpl.MODE_STRICT) {
DateCaster.classicStyle = true;
} else {
String strClassicDateParsing = getAttr(application, "classic-date-parsing");
if (!StringUtil.isEmpty(strClassicDateParsing)) {
DateCaster.classicStyle = Caster.toBooleanValue(strClassicDateParsing, false);
}
}
}
// Cache
Resource configDir = config.getConfigDir();
String strCacheDirectory = application.getAttribute("cache-directory");
if (hasAccess && !StringUtil.isEmpty(strCacheDirectory)) {
strCacheDirectory = ConfigWebUtil.translateOldPath(strCacheDirectory);
Resource res = ConfigWebUtil.getFile(configDir, strCacheDirectory, "cache", configDir, FileUtil.TYPE_DIR, config);
config.setCacheDir(res);
} else {
config.setCacheDir(configDir.getRealResource("cache"));
}
String strMax = getAttr(application, "cache-directory-max-size");
if (hasAccess && !StringUtil.isEmpty(strMax)) {
config.setCacheDirSize(ByteSizeParser.parseByteSizeDefinition(strMax, config.getCacheDirSize()));
} else if (hasCS)
config.setCacheDirSize(configServer.getCacheDirSize());
// admin sync
ClassDefinition asc = getClassDefinition(application, "admin-sync-", config.getIdentification());
if (!asc.hasClass())
asc = getClassDefinition(application, "admin-synchronisation-", config.getIdentification());
if (hasAccess && asc.hasClass()) {
try {
Class clazz = asc.getClazz();
if (!Reflector.isInstaneOf(clazz, AdminSync.class))
throw new ApplicationException("class [" + clazz.getName() + "] does not implement interface [" + AdminSync.class.getName() + "]");
config.setAdminSyncClass(clazz);
} catch (Exception e) {
SystemOut.printDate(e);
}
} else if (hasCS)
config.setAdminSyncClass(configServer.getAdminSyncClass());
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class JSONConverter method _serializeUDF.
private void _serializeUDF(PageContext pc, Set test, UDF udf, StringBuilder sb, boolean serializeQueryByColumns, Set<Object> done) throws ConverterException {
Struct sct = new StructImpl();
try {
// Meta
Struct meta = udf.getMetaData(pc);
sct.setEL("Metadata", meta);
// Parameters
sct.setEL("MethodAttributes", meta.get("PARAMETERS"));
} catch (PageException e) {
throw toConverterException(e);
}
sct.setEL("Access", ComponentUtil.toStringAccess(udf.getAccess(), "public"));
sct.setEL("Output", Caster.toBoolean(udf.getOutput()));
sct.setEL("ReturnType", udf.getReturnTypeAsString());
try {
sct.setEL("PagePath", udf.getSource());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
_serializeStruct(pc, test, sct, sb, serializeQueryByColumns, true, done);
// TODO key SuperScope and next?
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ScriptConverter method _serializeQuery.
/**
* serialize a Query
* @param query Query to serialize
* @param sb
* @param done
* @throws ConverterException
*/
private void _serializeQuery(Query query, StringBuilder sb, Set<Object> done) throws ConverterException {
// Collection.Key[] keys = query.keys();
Iterator<Key> it = query.keyIterator();
Key k;
sb.append(goIn());
sb.append("query(");
deep++;
boolean oDoIt = false;
int len = query.getRecordcount();
while (it.hasNext()) {
k = it.next();
if (oDoIt)
sb.append(',');
oDoIt = true;
sb.append(goIn());
sb.append(QUOTE_CHR);
sb.append(escape(k.getString()));
sb.append(QUOTE_CHR);
sb.append(":[");
boolean doIt = false;
for (int y = 1; y <= len; y++) {
if (doIt)
sb.append(',');
doIt = true;
try {
_serialize(query.getAt(k, y), sb, done);
} catch (PageException e) {
_serialize(e.getMessage(), sb, done);
}
}
sb.append(']');
}
deep--;
sb.append(')');
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class WDDXConverter method _deserializeQuery.
/**
* Desirialize a Query Object
*
* @param recordset
* Query Object as XML Element
* @return Query Object
* @throws ConverterException
*/
private Object _deserializeQuery(Element recordset) throws ConverterException {
try {
// create Query Object
Query query = new QueryImpl(lucee.runtime.type.util.ListUtil.listToArray(recordset.getAttribute("fieldNames"), ','), Caster.toIntValue(recordset.getAttribute("rowCount")), "query");
NodeList list = recordset.getChildNodes();
int len = list.getLength();
for (int i = 0; i < len; i++) {
Node node = list.item(i);
if (node instanceof Element) {
_deserializeQueryField(query, (Element) node);
}
}
return query;
} catch (PageException e) {
throw toConverterException(e);
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class WDDXConverter method _serializeQuery.
/**
* serialize a Query
*
* @param query
* Query to serialize
* @param done
* @return serialized query
* @throws ConverterException
*/
private String _serializeQuery(Query query, Set<Object> done) throws ConverterException {
// fieldnames
PageContext pc = ThreadLocalPageContext.get();
boolean upperCase = false;
if (pc != null)
upperCase = pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !((ConfigWebImpl) pc.getConfig()).preserveCase();
StringBuilder fn = new StringBuilder();
Collection.Key[] keys = CollectionUtil.keys(query);
for (int i = 0; i < keys.length; i++) {
if (i > 0)
fn.append(',');
fn.append(XMLUtil.escapeXMLString(upperCase ? keys[i].getUpperString() : keys[i].getString()));
}
StringBuilder sb = new StringBuilder(goIn() + "<recordset rowCount=" + del + query.getRecordcount() + del + " fieldNames=" + del + fn + del + " type=" + del + "coldfusion.sql.QueryTable" + del + ">");
deep++;
int len = query.getRecordcount();
for (int i = 0; i < keys.length; i++) {
sb.append(goIn() + "<field name=" + del + XMLUtil.escapeXMLString(keys[i].getString()) + del + ">");
for (int y = 1; y <= len; y++) {
try {
sb.append(_serialize(query.getAt(keys[i], y), done));
} catch (PageException e) {
sb.append(_serialize(e.getMessage(), done));
}
}
sb.append(goIn() + "</field>");
}
deep--;
sb.append(goIn() + "</recordset>");
return sb.toString();
}
Aggregations