Search in sources :

Example 1 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class StandaloneApplicationContext method createTempFile.

public File createTempFile(final IPentahoSession session, final String prefix, final String extn, final File parentDir, boolean trackFile) throws IOException {
    ITempFileDeleter fileDeleter = null;
    if (session == null) {
        return null;
    }
    if (trackFile) {
        fileDeleter = (ITempFileDeleter) session.getAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE);
    }
    String name = session.getName();
    final String newPrefix = new StringBuilder().append(prefix).append(name.substring(0, name.length() > 10 ? 10 : name.length())).append('-').toString();
    if (parentDir != null) {
        parentDir.mkdirs();
    }
    final File file = File.createTempFile(newPrefix, extn, parentDir);
    if (fileDeleter != null) {
        fileDeleter.trackTempFile(file);
    } else {
        // There is no deleter, so cleanup on VM exit. (old behavior)
        file.deleteOnExit();
    }
    return file;
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter) File(java.io.File)

Example 2 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class PentahoSessionFactory method getSession.

public static IPentahoSession getSession(final String userName, final HttpSession session, final HttpServletRequest request) {
    IPentahoSession userSession = (IPentahoSession) session.getAttribute(PentahoSystem.PENTAHO_SESSION_KEY);
    if (userSession != null) {
        return userSession;
    }
    userSession = new PentahoHttpSession(userName, session, request.getLocale(), userSession);
    ITempFileDeleter deleter = PentahoSystem.get(ITempFileDeleter.class, userSession);
    if (deleter != null) {
        userSession.setAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE, deleter);
    }
    return userSession;
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 3 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class HttpSessionPentahoSessionIntegrationFilter method generatePentahoSession.

protected IPentahoSession generatePentahoSession(final HttpServletRequest httpRequest) {
    HttpSession httpSession = httpRequest.getSession(false);
    IPentahoSession pentahoSession = null;
    if (httpSession != null) {
        pentahoSession = new PentahoHttpSession(null, httpSession, httpRequest.getLocale(), null);
    } else {
        pentahoSession = new NoDestroyStandaloneSession(null);
    }
    if (callSetAuthenticatedForAnonymousUsers) {
        pentahoSession.setAuthenticated(getAnonymousUser());
    }
    ITempFileDeleter deleter = PentahoSystem.get(ITempFileDeleter.class, pentahoSession);
    if (deleter != null) {
        pentahoSession.setAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE, deleter);
    }
    return pentahoSession;
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter) HttpSession(javax.servlet.http.HttpSession) PentahoHttpSession(org.pentaho.platform.web.http.session.PentahoHttpSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) PentahoHttpSession(org.pentaho.platform.web.http.session.PentahoHttpSession)

Example 4 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class UploadFileUtils method handleTarGZ.

protected String handleTarGZ(File file) throws IOException {
    // first extract the gz
    String filename = handleGZip(file, true);
    File tarFile = new File(filename);
    ITempFileDeleter fileDeleter;
    if ((session != null)) {
        fileDeleter = (ITempFileDeleter) session.getAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE);
        if (fileDeleter != null) {
            // make sure the deleter knows to clean this puppy up...
            fileDeleter.trackTempFile(tarFile);
        }
    }
    return handleTar(tarFile);
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 5 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class UploadFileUtils method handleUnzip.

protected boolean handleUnzip(File file) throws IOException {
    String fileNames = file.getName();
    // .zip/.tar/.gz/.tgz files are always considered temporary and deleted on session expire
    ITempFileDeleter fileDeleter = null;
    if ((session != null)) {
        fileDeleter = (ITempFileDeleter) session.getAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE);
        if (fileDeleter != null) {
            // make sure the deleter knows to clean this puppy up...
            fileDeleter.trackTempFile(file);
        }
    }
    if ((getUploadedFileItem().getName().toLowerCase().endsWith(".zip") || getUploadedFileItem().getContentType().equals("application/zip"))) {
        // handle a zip
        if (checkLimits(getUncompressedZipFileSize(file), true)) {
            fileNames = handleZip(file);
        } else {
            // delete immediately (see requirements on BISERVER-4321)
            file.delete();
            return false;
        }
    } else if ((// $NON-NLS-1$
    getUploadedFileItem().getName().toLowerCase().endsWith(".tgz") || // $NON-NLS-1$
    getUploadedFileItem().getName().toLowerCase().endsWith(".tar.gz") || getUploadedFileItem().getContentType().equals("application/x-compressed") || getUploadedFileItem().getContentType().equals("application/tgz"))) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        // handle a tgz
        long tarSize = getUncompressedGZipFileSize(file);
        if (checkLimits(tarSize, true)) {
            if (isTemporary() || checkLimits(tarSize * 2, true)) {
                fileNames = handleTarGZ(file);
            } else {
                return false;
            }
        } else {
            // delete immediately (see requirements on BISERVER-4321)
            file.delete();
            return false;
        }
    } else if ((getUploadedFileItem().getName().toLowerCase().endsWith(".gzip") || getUploadedFileItem().getName().toLowerCase().endsWith(".gz"))) {
        // handle a gzip
        if (checkLimits(getUncompressedGZipFileSize(file), true)) {
            fileNames = handleGZip(file, false);
        } else {
            // delete immediately (see requirements on BISERVER-4321)
            file.delete();
            return false;
        }
    } else if ((getUploadedFileItem().getName().toLowerCase().endsWith(".tar") || getUploadedFileItem().getContentType().equals("application/x-tar"))) {
        // Marc
        if (isTemporary() || checkLimits(getUploadedFileItem().getSize(), true)) {
            fileNames = handleTar(file);
        } else {
            // delete immediately (see requirements on BISERVER-4321)
            file.delete();
            return false;
        }
    }
    // else - just outputs the file name.
    writer.write(fileNames);
    return true;
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter)

Aggregations

ITempFileDeleter (org.pentaho.platform.api.util.ITempFileDeleter)6 File (java.io.File)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 RandomAccessFile (java.io.RandomAccessFile)1 ZipFile (java.util.zip.ZipFile)1 HttpSession (javax.servlet.http.HttpSession)1 PentahoHttpSession (org.pentaho.platform.web.http.session.PentahoHttpSession)1