use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class ThreadTag method doTerminate.
private void doTerminate() throws ApplicationException {
// PageContextImpl mpc=(PageContextImpl)getMainPageContext(pc);
// mpc.getThreadScope(nameAsString(false));
Threads ts = ThreadTag.getThreadScope(pc, KeyImpl.init(nameAsString(false)), ThreadTag.LEVEL_CURRENT + ThreadTag.LEVEL_KIDS);
if (ts == null)
throw new ApplicationException("there is no thread running with the name [" + nameAsString(false) + "]");
ChildThread ct = ts.getChildThread();
if (ct.isAlive()) {
ct.terminated();
SystemUtil.stop(ct);
}
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class Admin method doBuildBundle.
private void doBuildBundle() throws PageException {
String name = getString("admin", action, "name");
String symName = getString("symbolicname", null);
String existingRelation = getString("existingrelation", null);
// boolean doDyn=StringUtil.isEmpty(existingRelation) || (existingRelation=existingRelation.trim()).equalsIgnoreCase("dynamic");
// print.e("dynamic:"+existingRelation+"<>"+doDyn);
boolean ignoreExistingManifest = getBoolV("ignoreExistingManifest", false);
Resource dest = ResourceUtil.toResourceNotExisting(pageContext, getString("admin", action, "destination"));
String strJar = getString("admin", action, "jar");
if (StringUtil.isEmpty(strJar, true))
throw new ApplicationException("missing valid jar path");
Resource jar = ResourceUtil.toResourceExisting(pageContext, strJar.trim());
Set<String> relatedPackages = null;
try {
// OSGiUtil.getBootdelegation()
relatedPackages = JarUtil.getExternalImports(jar, new String[0]);
} catch (IOException e1) {
SystemOut.printDate(e1);
}
if (relatedPackages == null)
relatedPackages = new HashSet<String>();
// org.osgi.framework.bootdelegation
BundleBuilderFactory factory;
try {
symName = StringUtil.isEmpty(symName, true) ? null : symName.trim();
if (symName == null)
symName = name;
factory = new BundleBuilderFactory(jar, symName);
factory.setName(name);
factory.setIgnoreExistingManifest(ignoreExistingManifest);
} catch (Exception e) {
throw Caster.toPageException(e);
}
String activator = getString("bundleActivator", null);
if (activator == null)
activator = getString("activator", null);
if (!StringUtil.isEmpty(activator, true))
factory.setActivator(activator.trim());
String version = getString("version", null);
if (!StringUtil.isEmpty(version, true))
factory.setVersion(OSGiUtil.toVersion(version, null));
String description = getString("description", null);
if (!StringUtil.isEmpty(description, true))
factory.setDescription(description.trim());
String classPath = getString("classPath", null);
if (!StringUtil.isEmpty(classPath, true))
factory.addClassPath(classPath.trim());
// dynamic import packages
String dynamicImportPackage = getString("dynamicimportpackage", null);
if (!StringUtil.isEmpty(dynamicImportPackage, true))
factory.addDynamicImportPackage(dynamicImportPackage = dynamicImportPackage.trim());
Set<String> dynamicImportPackageSet = ListUtil.listToSet(dynamicImportPackage, ",", true);
/*
* String dynamicImportPackage=getString("dynamicimportpackage",null); if(doDyn) { if(relatedPackages.size()>0) { // add importPackage to set
* if(!StringUtil.isEmpty(dynamicImportPackage)) { String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(dynamicImportPackage, ',')); for(int
* i=0;i<arr.length;i++){ relatedPackages.add(arr[i]); } } dynamicImportPackage=ListUtil.toList(relatedPackages, ","); } relatedPackages.clear(); }
* if(!StringUtil.isEmpty(dynamicImportPackage,true))factory.addDynamicImportPackage(dynamicImportPackage.trim());
*/
// Import Package
// we remove all imports that are defined as dyn import
Iterator<String> it = dynamicImportPackageSet.iterator();
while (it.hasNext()) {
relatedPackages.remove(it.next());
}
String importPackage = getString("importpackage", null);
// add importPackage to set
if (!StringUtil.isEmpty(importPackage)) {
String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(importPackage, ','));
for (int i = 0; i < arr.length; i++) {
relatedPackages.add(arr[i]);
}
}
// remove all packages defined in dynamic imports
if (!StringUtil.isEmpty(dynamicImportPackage)) {
String[] arr = ListUtil.trimItems(ListUtil.listToStringArray(dynamicImportPackage, ','));
List<String> newDynImport = new ArrayList<String>();
for (int i = 0; i < arr.length; i++) {
if (!relatedPackages.contains(arr[i]))
newDynImport.add(arr[i]);
// relatedPackages.remove(arr[i]);
}
if (arr.length != newDynImport.size())
dynamicImportPackage = ListUtil.listToListEL(newDynImport, ",");
}
List sortedList = new ArrayList(relatedPackages);
Collections.sort(sortedList);
importPackage = ListUtil.toList(sortedList, ",");
if (!StringUtil.isEmpty(importPackage, true))
factory.addImportPackage(importPackage.trim());
String bundleActivationPolicy = getString("bundleActivationPolicy", null);
if (!StringUtil.isEmpty(bundleActivationPolicy, true))
factory.setBundleActivationPolicy(bundleActivationPolicy.trim());
String exportPackage = getString("exportpackage", null);
if (!StringUtil.isEmpty(exportPackage, true)) {
exportPackage = ListUtil.sort(exportPackage.trim(), "text", "asc", ",");
factory.addExportPackage(exportPackage);
}
String requireBundle = getString("requireBundle", null);
if (!StringUtil.isEmpty(requireBundle, true)) {
requireBundle = ListUtil.sort(requireBundle.trim(), "text", "asc", ",");
factory.addRequireBundle(requireBundle);
}
String requireBundleFragment = getString("requireBundleFragment", null);
if (!StringUtil.isEmpty(requireBundleFragment, true)) {
requireBundleFragment = ListUtil.sort(requireBundleFragment.trim(), "text", "asc", ",");
factory.addRequireBundleFragment(requireBundleFragment);
}
String fragmentHost = getString("fragmentHost", null);
if (!StringUtil.isEmpty(fragmentHost, true))
factory.addFragmentHost(fragmentHost.trim());
try {
factory.build(dest);
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class Admin method doGetCacheDefaultConnection.
private void doGetCacheDefaultConnection() throws PageException {
int type;
String strType = getString("admin", "GetCacheDefaultConnection", "cacheType");
strType = strType.toLowerCase().trim();
if (strType.equals("object"))
type = ConfigImpl.CACHE_TYPE_OBJECT;
else if (strType.equals("template"))
type = ConfigImpl.CACHE_TYPE_TEMPLATE;
else if (strType.equals("query"))
type = ConfigImpl.CACHE_TYPE_QUERY;
else if (strType.equals("resource"))
type = ConfigImpl.CACHE_TYPE_RESOURCE;
else if (strType.equals("function"))
type = ConfigImpl.CACHE_TYPE_FUNCTION;
else if (strType.equals("include"))
type = ConfigImpl.CACHE_TYPE_INCLUDE;
else if (strType.equals("http"))
type = ConfigImpl.CACHE_TYPE_HTTP;
else if (strType.equals("file"))
type = ConfigImpl.CACHE_TYPE_FILE;
else if (strType.equals("webservice"))
type = ConfigImpl.CACHE_TYPE_WEBSERVICE;
else
throw new ApplicationException("inv,query,resourcealid type defintion, valid values are [object,template,query,resource,function,include]");
CacheConnection cc = config.getCacheDefaultConnection(type);
if (cc != null) {
Struct sct = new StructImpl();
sct.setEL(KeyConstants._name, cc.getName());
sct.setEL(KeyConstants._class, cc.getClassDefinition().getClassName());
sct.setEL(KeyConstants._bundleName, cc.getClassDefinition().getName());
sct.setEL(KeyConstants._bundleVersion, cc.getClassDefinition().getVersionAsString());
sct.setEL(KeyConstants._custom, cc.getCustom());
sct.setEL(KeyConstants._default, Caster.toBoolean(true));
sct.setEL(KeyConstants._readonly, Caster.toBoolean(cc.isReadOnly()));
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
} else
throw new ApplicationException("there is no cache default connection");
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class Admin method doUpdateLogSettings.
private void doUpdateLogSettings() throws PageException {
String str = getString("admin", "UpdateLogSettings", "level", true);
Level l = Log4jUtil.toLevel(str, null);
if (l == null)
throw new ApplicationException("invalid log level name [" + str + "], valid log level names are [INFO,DEBUG,WARN,ERROR,FATAL,TRACE]");
ClassDefinition acd = new ClassDefinitionImpl(getString("admin", action, "appenderClass", true), getString("appenderBundleName", null), getString("appenderBundleVersion", null), config.getIdentification());
ClassDefinition lcd = new ClassDefinitionImpl(getString("admin", action, "layoutClass", true), getString("layoutBundleName", null), getString("layoutBundleVersion", null), config.getIdentification());
admin.updateLogSettings(getString("admin", "UpdateLogSettings", "name", true), l, acd, Caster.toStruct(getObject("admin", "UpdateLogSettings", "appenderArgs")), lcd, Caster.toStruct(getObject("admin", "UpdateLogSettings", "layoutArgs")));
store();
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class Admin method doCompileFile.
private void doCompileFile(Mapping mapping, Resource file, String path, Map<String, String> errors, Boolean explicitIgnoreScope) throws PageException {
if (ResourceUtil.exists(file)) {
if (file.isDirectory()) {
Resource[] files = file.listResources(FILTER_CFML_TEMPLATES);
if (files != null)
for (int i = 0; i < files.length; i++) {
String p = path + '/' + files[i].getName();
// print.ln(files[i]+" - "+p);
doCompileFile(mapping, files[i], p, errors, explicitIgnoreScope);
}
} else if (file.isFile()) {
PageSource ps = mapping.getPageSource(path);
PageContextImpl pci = (PageContextImpl) pageContext;
boolean envIgnoreScopes = pci.ignoreScopes();
try {
if (explicitIgnoreScope != null)
pci.setIgnoreScopes(explicitIgnoreScope);
((PageSourceImpl) ps).clear();
((PageSourceImpl) ps).loadPage(pageContext, explicitIgnoreScope != null);
// pageContext.compile(ps);
} catch (PageException pe) {
SystemOut.printDate(pe);
String template = ps.getDisplayPath();
StringBuilder msg = new StringBuilder(pe.getMessage());
msg.append(", Error Occurred in File [");
msg.append(template);
if (pe instanceof PageExceptionImpl) {
try {
PageExceptionImpl pei = (PageExceptionImpl) pe;
Array context = pei.getTagContext(config);
if (context.size() > 0) {
msg.append(":");
msg.append(Caster.toString(((Struct) context.getE(1)).get("line")));
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
msg.append("]");
if (errors != null)
errors.put(template, msg.toString());
else
throw new ApplicationException(msg.toString());
} finally {
pci.setIgnoreScopes(envIgnoreScopes);
}
}
}
}
Aggregations