Search in sources :

Example 41 with ApplicationException

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

the class Ftp method doEndTag.

@Override
public int doEndTag() throws PageException {
    pool = ((PageContextImpl) pageContext).getFTPPool();
    AFTPClient client = null;
    // retries
    do {
        try {
            if (action.equals("open"))
                client = actionOpen();
            else if (action.equals("close"))
                client = actionClose();
            else if (action.equals("changedir"))
                client = actionChangeDir();
            else if (action.equals("createdir"))
                client = actionCreateDir();
            else if (action.equals("listdir"))
                client = actionListDir();
            else if (action.equals("removedir"))
                client = actionRemoveDir();
            else if (action.equals("getfile"))
                client = actionGetFile();
            else if (action.equals("putfile"))
                client = actionPutFile();
            else if (action.equals("rename"))
                client = actionRename();
            else if (action.equals("remove"))
                client = actionRemove();
            else if (action.equals("getcurrentdir"))
                client = actionGetCurrentDir();
            else if (action.equals("getcurrenturl"))
                client = actionGetCurrentURL();
            else if (action.equals("existsdir"))
                client = actionExistsDir();
            else if (action.equals("existsfile"))
                client = actionExistsFile();
            else if (action.equals("exists"))
                client = actionExists();
            else
                throw new ApplicationException("attribute action has an invalid value [" + action + "]", "valid values are [open,close,listDir,createDir,removeDir,changeDir,getCurrentDir," + "getCurrentURL,existsFile,existsDir,exists,getFile,putFile,rename,remove]");
        } catch (IOException ioe) {
            if (count++ < retrycount)
                continue;
            throw Caster.toPageException(ioe);
        }
        if (client == null || !checkCompletion(client))
            break;
    } while (true);
    return EVAL_PAGE;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) AFTPClient(lucee.runtime.net.ftp.AFTPClient) IOException(java.io.IOException)

Example 42 with ApplicationException

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

the class ThreadTag method register.

public void register(Page currentPage, int threadIndex) throws PageException {
    if (ACTION_RUN != action)
        return;
    Key name = name(true);
    try {
        // pc.getThreadScope(name);
        Threads ts = ThreadTag.getThreadScope(pc, name, ThreadTag.LEVEL_ALL);
        if (type == TYPE_DAEMON) {
            if (ts != null)
                throw new ApplicationException("could not create a thread with the name [" + name.getString() + "]. name must be unique within a request");
            ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, false);
            pc.setThreadScope(name, new ThreadsImpl(ct));
            ct.setPriority(priority);
            ct.setDaemon(false);
            ct.start();
        } else {
            ChildThreadImpl ct = new ChildThreadImpl((PageContextImpl) pc, currentPage, name.getString(), threadIndex, attrs, true);
            ct.setPriority(priority);
            ((ConfigImpl) pc.getConfig()).getSpoolerEngine().add(new ChildSpoolerTask(ct, plans));
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        // this method is not called from template when type is run, a call from template is to early,
        ((PageContextImpl) pc).reuse(this);
    }
}
Also used : Threads(lucee.runtime.type.scope.Threads) ThreadsImpl(lucee.runtime.thread.ThreadsImpl) ChildThreadImpl(lucee.runtime.thread.ChildThreadImpl) ApplicationException(lucee.runtime.exp.ApplicationException) ChildSpoolerTask(lucee.runtime.thread.ChildSpoolerTask) PageContextImpl(lucee.runtime.PageContextImpl) Key(lucee.runtime.type.Collection.Key)

Example 43 with ApplicationException

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

the class VideoPlayerParamBean method setFlash.

/**
 * @param flash the flash to set
 * @throws PageException
 */
public void setFlash(Resource flash, String pathFlash) throws PageException {
    if (!"swf".equalsIgnoreCase(getExtension(flash)))
        throw new ApplicationException("only swf movies are supported");
    this.flash = flash;
    this.pathFlash = pathFlash;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException)

Example 44 with ApplicationException

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

the class Zip method actionRead.

private void actionRead(boolean binary) throws ZipException, IOException, PageException {
    required("file", file, true);
    required("variable", variable);
    required("entrypath", entryPaths);
    ZipFile zip = getZip(file);
    if (entryPaths.length > 1)
        throw new ApplicationException("you can only read one entry!");
    try {
        ZipEntry ze = getZipEntry(zip, entryPaths[0]);
        if (ze == null) {
            String msg = ExceptionUtil.similarKeyMessage(names(zip), entryPaths[0], "entry", "zip file", "in the zip file [" + file + "]", true);
            throw new ApplicationException(msg);
        // throw new ApplicationException("zip file ["+file+"] has no entry with name ["+entryPath+"]");
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream is = zip.getInputStream(ze);
        IOUtil.copy(is, baos, true, false);
        zip.close();
        if (binary)
            pageContext.setVariable(variable, baos.toByteArray());
        else {
            if (charset == null)
                charset = ((PageContextImpl) pageContext).getResourceCharset().name();
            pageContext.setVariable(variable, new String(baos.toByteArray(), charset));
        }
    } finally {
        IOUtil.closeEL(zip);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ZipFile(java.util.zip.ZipFile) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 45 with ApplicationException

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

the class Zip method actionDelete.

private void actionDelete() throws ApplicationException, IOException {
    required("file", file, true);
    Resource existing = pageContext.getConfig().getTempDirectory().getRealResource(getTempName());
    IOUtil.copy(file, existing);
    ZipInputStream zis = null;
    ZipOutputStream zos = null;
    try {
        zis = new ZipInputStream(IOUtil.toBufferedInputStream(existing.getInputStream()));
        zos = new ZipOutputStream(IOUtil.toBufferedOutputStream(file.getOutputStream()));
        ZipEntry entry;
        String path, name;
        int index;
        boolean accept;
        if (filter == null && recurse && (entryPaths == null || entryPaths.length == 0))
            throw new ApplicationException("define at least one restriction, can't delete all the entries from a zip file");
        while ((entry = zis.getNextEntry()) != null) {
            accept = false;
            path = entry.getName().replace('\\', '/');
            index = path.lastIndexOf('/');
            if (!recurse && index > 0)
                accept = true;
            // dir=index==-1?"":path.substring(0,index);
            name = path.substring(index + 1);
            if (filter != null && !filter.accept(file.getRealResource(name)))
                accept = true;
            if (!entryPathMatch(path))
                accept = true;
            if (!accept)
                continue;
            add(zos, entry, zis, false);
            zis.closeEntry();
        }
    } finally {
        IOUtil.closeEL(zis);
        IOUtil.closeEL(zos);
        existing.delete();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ApplicationException(lucee.runtime.exp.ApplicationException) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource)

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