Search in sources :

Example 6 with PageException

use of lucee.runtime.exp.PageException 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);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException) BundleBuilderFactory(lucee.runtime.osgi.BundleBuilderFactory) ApplicationException(lucee.runtime.exp.ApplicationException) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 7 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class Admin method doGetError.

private void doGetError() throws PageException {
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    // sct.set("errorTemplate",config.getErrorTemplate());
    Struct templates = new StructImpl();
    Struct str = new StructImpl();
    sct.set(TEMPLATES, templates);
    sct.set(STR, str);
    sct.set(DO_STATUS_CODE, Caster.toBoolean(config.getErrorStatusCode()));
    // 500
    String template = config.getErrorTemplate(500);
    try {
        PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
        if (ps != null)
            templates.set("500", ps.getDisplayPath());
        else
            templates.set("500", "");
    } catch (PageException e) {
        templates.set("500", "");
    }
    str.set("500", template);
    // 404
    template = config.getErrorTemplate(404);
    try {
        PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
        if (ps != null)
            templates.set("404", ps.getDisplayPath());
        else
            templates.set("404", "");
    } catch (PageException e) {
        templates.set("404", "");
    }
    str.set("404", template);
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource)

Example 8 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class Admin method _doVerifyDatasource.

private void _doVerifyDatasource(DataSource ds, String username, String password) throws PageException {
    try {
        DataSourceManager manager = pageContext.getDataSourceManager();
        DatasourceConnectionImpl dc = new DatasourceConnectionImpl(ds.getConnection(config, username, password), ds, username, password);
        manager.releaseConnection(pageContext, dc);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : DatasourceConnectionImpl(lucee.runtime.db.DatasourceConnectionImpl) DataSourceManager(lucee.runtime.db.DataSourceManager) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 9 with PageException

use of lucee.runtime.exp.PageException 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);
            }
        }
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 10 with PageException

use of lucee.runtime.exp.PageException in project Lucee by lucee.

the class Admin method doRemoveRHExtension.

private void doRemoveRHExtension() throws PageException {
    String id = getString("admin", "removeRHExtensions", "id");
    if (!Decision.isUUId(id))
        throw new ApplicationException("invalid id [" + id + "], id must be a UUID");
    try {
        admin.removeRHExtension(id);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    store();
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

PageException (lucee.runtime.exp.PageException)200 ApplicationException (lucee.runtime.exp.ApplicationException)56 IOException (java.io.IOException)54 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)37 ExpressionException (lucee.runtime.exp.ExpressionException)32 Resource (lucee.commons.io.res.Resource)30 SecurityException (lucee.runtime.exp.SecurityException)26 BundleException (org.osgi.framework.BundleException)26 MalformedURLException (java.net.MalformedURLException)25 Array (lucee.runtime.type.Array)21 Key (lucee.runtime.type.Collection.Key)17 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)15 SAXException (org.xml.sax.SAXException)15 Entry (java.util.Map.Entry)14 ClassException (lucee.commons.lang.ClassException)14 DeprecatedException (lucee.runtime.exp.DeprecatedException)14 SMTPException (lucee.runtime.net.mail.SMTPException)13 ArrayImpl (lucee.runtime.type.ArrayImpl)13 Query (lucee.runtime.type.Query)13