use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class XMLConfigAdmin method _updateWebContexts.
private static void _updateWebContexts(Config config, InputStream is, String realpath, boolean closeStream, List<Resource> filesDeployed, boolean store) throws PageException, IOException, SAXException, BundleException {
if (!(config instanceof ConfigServer))
throw new ApplicationException("invalid context, you can only call this method from server context");
ConfigServer cs = (ConfigServer) config;
Resource wcd = cs.getConfigDir().getRealResource("web-context-deployment");
Resource trg = wcd.getRealResource(realpath);
if (trg.exists())
trg.remove(true);
Resource p = trg.getParentResource();
if (!p.isDirectory())
p.createDirectory(true);
IOUtil.copy(is, trg.getOutputStream(false), closeStream, true);
filesDeployed.add(trg);
if (store)
_storeAndReload((ConfigImpl) config);
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class XMLConfigAdmin method updateAPIKey.
public void updateAPIKey(String key) throws SecurityException, ApplicationException {
checkWriteAccess();
key = key.trim();
if (!Decision.isGUId(key))
throw new ApplicationException("passed API Key [" + key + "] is not valid");
Element root = doc.getDocumentElement();
root.setAttribute("api-key", key);
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class XMLConfigAdmin method updateClusterClass.
public void updateClusterClass(ClassDefinition cd) throws PageException {
if (cd.getClassName() == null)
cd = new ClassDefinitionImpl(ClusterNotSupported.class.getName(), null, null, null);
Class clazz = null;
try {
clazz = cd.getClazz();
} catch (Exception e) {
throw Caster.toPageException(e);
}
if (!Reflector.isInstaneOf(clazz, Cluster.class) && !Reflector.isInstaneOf(clazz, ClusterRemote.class))
throw new ApplicationException("class [" + clazz.getName() + "] does not implement interface [" + Cluster.class.getName() + "] or [" + ClusterRemote.class.getName() + "]");
Element scope = _getRootElement("scope");
setClass(scope, null, "cluster-", cd);
ScopeContext.clearClusterScope();
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class XMLConfigAdmin method validateStorage.
private String validateStorage(String storage) throws ApplicationException {
storage = storage.trim().toLowerCase();
// empty
if (StringUtil.isEmpty(storage, true))
return "";
// standard storages
if ("cookie".equals(storage) || "memory".equals(storage) || "file".equals(storage))
return storage;
// aliases
if ("ram".equals(storage))
return "memory";
if ("registry".equals(storage))
return "file";
// datasource
DataSource ds = config.getDataSource(storage, null);
if (ds != null) {
if (ds.isStorage())
return storage;
throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage");
}
// cache
CacheConnection cc = CacheUtil.getCacheConnection(ThreadLocalPageContext.get(config), storage, null);
if (cc != null) {
if (cc.isStorage())
return storage;
throw new ApplicationException("cache [" + storage + "] is not enabled to be used as session/client storage");
}
String sdx = StringUtil.soundex(storage);
// check if a datasource has a similar name
DataSource[] sources = config.getDataSources();
for (int i = 0; i < sources.length; i++) {
if (StringUtil.soundex(sources[i].getName()).equals(sdx))
throw new ApplicationException("no matching storage for [" + storage + "] found, did you mean [" + sources[i].getName() + "]");
}
// check if a cache has a similar name
Iterator<String> it = config.getCacheConnections().keySet().iterator();
String name;
while (it.hasNext()) {
name = it.next();
if (StringUtil.soundex(name).equals(sdx))
throw new ApplicationException("no matching storage for [" + storage + "] found, did you mean [" + name + "]");
}
throw new ApplicationException("no matching storage for [" + storage + "] found");
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class XMLConfigAdmin method updateCachedWithin.
public void updateCachedWithin(int type, Object value) throws SecurityException, ApplicationException {
checkWriteAccess();
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);
if (!hasAccess)
throw new SecurityException("no access to update cachedwithin setting");
String t = AppListenerUtil.toCachedWithinType(type, "");
if (t == null)
throw new ApplicationException("invalid cachedwithin type defintion");
String v = Caster.toString(value, null);
Element app = _getRootElement("application");
if (v != null)
app.setAttribute("cached-within-" + t, v);
else
app.removeAttribute("cached-within-" + t);
}
Aggregations