Search in sources :

Example 11 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class DatabaseFileSystem method getInputStream.

/**
     * {@inheritDoc}
     */
public InputStream getInputStream(String filePath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    FileSystemPathUtil.checkFormat(filePath);
    String parentDir = FileSystemPathUtil.getParentDir(filePath);
    String name = FileSystemPathUtil.getName(filePath);
    synchronized (selectDataSQL) {
        try {
            final ResultSet rs = conHelper.exec(selectDataSQL, new Object[] { parentDir, name }, false, 0);
            if (!rs.next()) {
                throw new FileSystemException("no such file: " + filePath);
            }
            InputStream in = rs.getBinaryStream(1);
            /**
                 * return an InputStream wrapper in order to
                 * close the ResultSet when the stream is closed
                 */
            return new FilterInputStream(in) {

                public void close() throws IOException {
                    super.close();
                    // close ResultSet
                    DbUtility.close(rs);
                }
            };
        } catch (SQLException e) {
            String msg = "failed to retrieve data of file: " + filePath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FilterInputStream(java.io.FilterInputStream) SQLException(java.sql.SQLException) FileInputStream(java.io.FileInputStream) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet)

Example 12 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class DatabaseFileSystem method listFiles.

/**
     * {@inheritDoc}
     */
public String[] listFiles(String folderPath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    FileSystemPathUtil.checkFormat(folderPath);
    if (!isFolder(folderPath)) {
        throw new FileSystemException("no such folder: " + folderPath);
    }
    synchronized (selectFileNamesSQL) {
        ResultSet rs = null;
        try {
            rs = conHelper.exec(selectFileNamesSQL, new Object[] { folderPath }, false, 0);
            ArrayList<String> names = new ArrayList<String>();
            while (rs.next()) {
                names.add(rs.getString(1));
            }
            return names.toArray(new String[names.size()]);
        } catch (SQLException e) {
            String msg = "failed to list file entries of folder: " + folderPath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            DbUtility.close(rs);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 13 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class DatabaseFileSystem method length.

/**
     * {@inheritDoc}
     */
public long length(String filePath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    FileSystemPathUtil.checkFormat(filePath);
    String parentDir = FileSystemPathUtil.getParentDir(filePath);
    String name = FileSystemPathUtil.getName(filePath);
    synchronized (selectLengthSQL) {
        ResultSet rs = null;
        try {
            rs = conHelper.exec(selectLengthSQL, new Object[] { parentDir, name }, false, 0);
            if (!rs.next()) {
                throw new FileSystemException("no such file: " + filePath);
            }
            return rs.getLong(1);
        } catch (SQLException e) {
            String msg = "failed to determine length of file: " + filePath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            DbUtility.close(rs);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 14 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class DatabaseFileSystem method deleteFolder.

/**
     * {@inheritDoc}
     */
public void deleteFolder(String folderPath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    FileSystemPathUtil.checkFormat(folderPath);
    if (folderPath.equals(FileSystem.SEPARATOR)) {
        throw new FileSystemException("cannot delete root");
    }
    String parentDir = FileSystemPathUtil.getParentDir(folderPath);
    String name = FileSystemPathUtil.getName(folderPath);
    int count = 0;
    synchronized (deleteFolderSQL) {
        try {
            count = conHelper.update(deleteFolderSQL, new Object[] { parentDir, name, folderPath, folderPath + FileSystem.SEPARATOR + "%" });
        } catch (SQLException e) {
            String msg = "failed to delete folder: " + folderPath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        }
    }
    if (count == 0) {
        throw new FileSystemException("no such folder: " + folderPath);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException)

Example 15 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class DatabaseFileSystem method isFile.

/**
     * {@inheritDoc}
     */
public boolean isFile(String path) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    FileSystemPathUtil.checkFormat(path);
    String parentDir = FileSystemPathUtil.getParentDir(path);
    String name = FileSystemPathUtil.getName(path);
    synchronized (selectFileExistSQL) {
        ResultSet rs = null;
        try {
            rs = conHelper.exec(selectFileExistSQL, new Object[] { parentDir, name }, false, 0);
            // a file exists if the result set has at least one entry
            return rs.next();
        } catch (SQLException e) {
            String msg = "failed to check existence of file: " + path;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            DbUtility.close(rs);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Aggregations

FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)54 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)18 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)16 IOException (java.io.IOException)15 SQLException (java.sql.SQLException)15 File (java.io.File)11 ResultSet (java.sql.ResultSet)10 InputStream (java.io.InputStream)7 RepositoryException (javax.jcr.RepositoryException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 OutputStreamWriter (java.io.OutputStreamWriter)4 ArrayList (java.util.ArrayList)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 BufferedInputStream (java.io.BufferedInputStream)3 BufferedWriter (java.io.BufferedWriter)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Properties (java.util.Properties)3 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2