Search in sources :

Example 91 with ApplicationException

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

the class Admin method doGetLocalExtension.

private void doGetLocalExtension() throws PageException {
    String id = getString("admin", action, "id");
    boolean asBinary = getBoolV("asBinary", false);
    if (asBinary) {
        Iterator<ExtensionDefintion> it = DeployHandler.getLocalExtensions(config).iterator();
        ExtensionDefintion ext;
        while (it.hasNext()) {
            ext = it.next();
            if (id.equalsIgnoreCase(ext.getId())) {
                try {
                    pageContext.setVariable(getString("admin", action, "returnVariable"), IOUtil.toBytes(ext.getSource()));
                    return;
                } catch (IOException e) {
                    throw Caster.toPageException(e);
                }
            }
        }
        throw new ApplicationException("there is no local extension with id " + id);
    } else {
        List<RHExtension> locals = RHExtension.toRHExtensions(DeployHandler.getLocalExtensions(config));
        Query qry = RHExtension.toQuery(config, locals.toArray(new RHExtension[locals.size()]));
        int rows = qry.getRecordcount();
        String _id;
        int row = 0;
        for (int r = 1; r <= rows; r++) {
            _id = Caster.toString(qry.getAt(KeyConstants._id, r), null);
            if (id.equalsIgnoreCase(_id)) {
                row = r;
                break;
            }
        }
        if (row == 0)
            throw new ApplicationException("there is no local extension with id " + id);
        pageContext.setVariable(getString("admin", action, "returnVariable"), Caster.toStruct(qry, row));
    }
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) ApplicationException(lucee.runtime.exp.ApplicationException) Query(lucee.runtime.type.Query) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) IOException(java.io.IOException)

Example 92 with ApplicationException

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

the class Admin method doStartTag.

@Override
public int doStartTag() throws PageException {
    config = (ConfigImpl) pageContext.getConfig();
    // Action
    Object objAction = attributes.get(KeyConstants._action);
    if (objAction == null)
        throw new ApplicationException("missing attrbute action for tag admin");
    action = StringUtil.toLowerCase(Caster.toString(objAction)).trim();
    // Generals
    if (action.equals("buildbundle")) {
        doBuildBundle();
        return SKIP_BODY;
    }
    if (action.equals("readbundle")) {
        doReadBundle();
        return SKIP_BODY;
    }
    if (action.equals("getlocales")) {
        doGetLocales();
        return SKIP_BODY;
    }
    if (action.equals("gettimezones")) {
        doGetTimeZones();
        return SKIP_BODY;
    }
    if (action.equals("printdebug")) {
        throw new DeprecatedException("action [printdebug] is no longer supported, use instead [getdebugdata]");
    }
    if (action.equals("getdebugdata")) {
        doGetDebugData();
        return SKIP_BODY;
    }
    if (action.equals("adddump")) {
        doAddDump();
        return SKIP_BODY;
    }
    if (action.equals("getloginsettings")) {
        doGetLoginSettings();
        return SKIP_BODY;
    }
    // Type
    type = toType(getString("type", "web"), true);
    // has Password
    if (action.equals("haspassword")) {
        boolean hasPassword = type == TYPE_WEB ? pageContext.getConfig().hasPassword() : pageContext.getConfig().hasServerPassword();
        pageContext.setVariable(getString("admin", action, "returnVariable", true), Caster.toBoolean(hasPassword));
        return SKIP_BODY;
    } else // update Password
    if (action.equals("updatepassword")) {
        try {
            ((ConfigWebImpl) pageContext.getConfig()).updatePassword(type != TYPE_WEB, getString("oldPassword", null), getString("admin", action, "newPassword", true));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
        return SKIP_BODY;
    }
    try {
        _doStartTag();
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return Tag.SKIP_BODY;
}
Also used : DeprecatedException(lucee.runtime.exp.DeprecatedException) ApplicationException(lucee.runtime.exp.ApplicationException) 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)

Example 93 with ApplicationException

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

the class Admin method doCreateArchive.

private void doCreateArchive(short mappingType) throws PageException {
    String virtual = getString("admin", action, "virtual").toLowerCase();
    String strFile = getString("admin", action, "file");
    Resource file = ResourceUtil.toResourceNotExisting(pageContext, strFile);
    boolean addCFMLFiles = getBoolV("addCFMLFiles", true);
    boolean addNonCFMLFiles = getBoolV("addNonCFMLFiles", true);
    Boolean ignoreScopes = getBool("ignoreScopes", null);
    // compile
    MappingImpl mapping = (MappingImpl) doCompileMapping(mappingType, virtual, true, ignoreScopes);
    // class files
    if (mapping == null)
        throw new ApplicationException("there is no mapping for [" + virtual + "]");
    if (!mapping.hasPhysical())
        throw new ApplicationException("mapping [" + virtual + "] has no physical directory");
    Resource classRoot = mapping.getClassRootDirectory();
    Resource temp = SystemUtil.getTempDirectory().getRealResource("mani-" + IDGenerator.stringId());
    Resource mani = temp.getRealResource("META-INF/MANIFEST.MF");
    try {
        if (file.exists())
            file.delete();
        if (!file.exists())
            file.createFile(true);
        ResourceFilter filter;
        // include everything, no filter needed
        if (addCFMLFiles && addNonCFMLFiles)
            filter = null;
        else // CFML Files but no other files
        if (addCFMLFiles) {
            if (mappingType == MAPPING_CFC)
                filter = new ExtensionResourceFilter(ArrayUtil.toArray(Constants.getComponentExtensions(), "class", "MF"), true, true);
            else
                filter = new ExtensionResourceFilter(ArrayUtil.toArray(Constants.getExtensions(), "class", "MF"), true, true);
        } else // No CFML Files, but all other files
        if (addNonCFMLFiles) {
            filter = new NotResourceFilter(new ExtensionResourceFilter(Constants.getExtensions(), false, true));
        } else // no files at all
        {
            filter = new ExtensionResourceFilter(new String[] { "class", "MF" }, true, true);
        }
        String id = HashUtil.create64BitHashAsString(mapping.getStrPhysical(), Character.MAX_RADIX);
        // String id = MD5.getDigestAsString(mapping.getStrPhysical());
        String type;
        if (mappingType == MAPPING_CFC)
            type = "cfc";
        else if (mappingType == MAPPING_CT)
            type = "ct";
        else
            type = "regular";
        String token = HashUtil.create64BitHashAsString(System.currentTimeMillis() + "", Character.MAX_RADIX);
        // create manifest
        Manifest mf = new Manifest();
        // StringBuilder manifest=new StringBuilder();
        // Write OSGi specific stuff
        Attributes attrs = mf.getMainAttributes();
        attrs.putValue("Bundle-ManifestVersion", Caster.toString(BundleBuilderFactory.MANIFEST_VERSION));
        attrs.putValue("Bundle-SymbolicName", id);
        attrs.putValue("Bundle-Name", ListUtil.trim(mapping.getVirtual().replace('/', '.'), "."));
        attrs.putValue("Bundle-Description", "this is a " + type + " mapping generated by " + Constants.NAME + ".");
        attrs.putValue("Bundle-Version", "1.0.0." + token);
        // attrs.putValue("Import-Package","lucee.*");
        attrs.putValue("Require-Bundle", "lucee.core");
        // Mapping
        attrs.putValue("mapping-id", id);
        attrs.putValue("mapping-type", type);
        attrs.putValue("mapping-virtual-path", mapping.getVirtual());
        attrs.putValue("mapping-hidden", Caster.toString(mapping.isHidden()));
        attrs.putValue("mapping-physical-first", Caster.toString(mapping.isPhysicalFirst()));
        attrs.putValue("mapping-readonly", Caster.toString(mapping.isReadonly()));
        attrs.putValue("mapping-top-level", Caster.toString(mapping.isTopLevel()));
        attrs.putValue("mapping-inspect", ConfigWebUtil.inspectTemplate(mapping.getInspectTemplateRaw(), ""));
        attrs.putValue("mapping-listener-type", ConfigWebUtil.toListenerType(mapping.getListenerType(), ""));
        attrs.putValue("mapping-listener-mode", ConfigWebUtil.toListenerMode(mapping.getListenerMode(), ""));
        mani.createFile(true);
        IOUtil.write(mani, ManifestUtil.toString(mf, 100, null, null), "UTF-8", false);
        // source files
        Resource[] sources;
        if (!addCFMLFiles && !addNonCFMLFiles)
            sources = new Resource[] { temp, classRoot };
        else
            sources = new Resource[] { temp, mapping.getPhysical(), classRoot };
        CompressUtil.compressZip(ResourceUtil.listResources(sources, filter), file, filter);
        if (getBoolV("append", false)) {
            if (mappingType == MAPPING_CFC) {
                admin.updateComponentMapping(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw());
            } else if (mappingType == MAPPING_CT) {
                admin.updateCustomTag(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw());
            } else
                admin.updateMapping(mapping.getVirtual(), mapping.getStrPhysical(), strFile, mapping.isPhysicalFirst() ? "physical" : "archive", mapping.getInspectTemplateRaw(), mapping.isTopLevel(), mapping.getListenerMode(), mapping.getListenerType(), mapping.isReadonly());
            store();
        }
    } catch (IOException e) {
        throw Caster.toPageException(e);
    } finally {
        ResourceUtil.removeEL(temp, true);
    }
    adminSync.broadcast(attributes, config);
}
Also used : Resource(lucee.commons.io.res.Resource) DynamicAttributes(lucee.runtime.ext.tag.DynamicAttributes) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) MappingImpl(lucee.runtime.MappingImpl) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) DirectoryResourceFilter(lucee.commons.io.res.filter.DirectoryResourceFilter) NotResourceFilter(lucee.commons.io.res.filter.NotResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) ApplicationException(lucee.runtime.exp.ApplicationException) NotResourceFilter(lucee.commons.io.res.filter.NotResourceFilter) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter)

Example 94 with ApplicationException

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

the class Admin method doUpdateCachedWithin.

private void doUpdateCachedWithin() throws PageException {
    String str = getString("admin", action, "cachedWithinType");
    int type = AppListenerUtil.toCachedWithinType(str, -1);
    if (type == -1)
        throw new ApplicationException("cached within type [" + str + "] is invalid, valid types are [function,include,query,resource]");
    admin.updateCachedWithin(type, getString("admin", action, "cachedWithin"));
    store();
    adminSync.broadcast(attributes, config);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException)

Example 95 with ApplicationException

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

the class Directory method actionDelete.

/**
 * delete directory
 * @param dir
 * @param forceDelete
 * @throws PageException
 */
public static void actionDelete(PageContext pc, Resource dir, boolean forceDelete, String serverPassword) throws PageException {
    SecurityManager securityManager = pc.getConfig().getSecurityManager();
    securityManager.checkFileLocation(pc.getConfig(), dir, serverPassword);
    // directory doesn't exist
    if (!dir.exists()) {
        if (dir.isDirectory())
            throw new ApplicationException("directory [" + dir.toString() + "] doesn't exist");
        else if (dir.isFile())
            throw new ApplicationException("file [" + dir.toString() + "] doesn't exist and isn't a directory");
    }
    // check if file
    if (dir.isFile())
        throw new ApplicationException("can't delete [" + dir.toString() + "], it isn't a directory it is a file");
    // delete directory
    try {
        dir.remove(forceDelete);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) SecurityManager(lucee.runtime.security.SecurityManager) IOException(java.io.IOException)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)173 IOException (java.io.IOException)41 Resource (lucee.commons.io.res.Resource)36 PageException (lucee.runtime.exp.PageException)30 Struct (lucee.runtime.type.Struct)25 SecurityException (lucee.runtime.exp.SecurityException)17 BundleException (org.osgi.framework.BundleException)16 StructImpl (lucee.runtime.type.StructImpl)15 MalformedURLException (java.net.MalformedURLException)13 Element (org.w3c.dom.Element)13 Array (lucee.runtime.type.Array)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 InputStream (java.io.InputStream)10 Query (lucee.runtime.type.Query)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ExpressionException (lucee.runtime.exp.ExpressionException)9 Entry (java.util.Map.Entry)8 PageContextImpl (lucee.runtime.PageContextImpl)8 ClassDefinition (lucee.runtime.db.ClassDefinition)8