diff --git a/ccm-core/src/main/java/org/libreccm/files/CcmFiles.java b/ccm-core/src/main/java/org/libreccm/files/CcmFiles.java new file mode 100644 index 000000000..3928660ba --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/CcmFiles.java @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.util.List; +import javax.faces.bean.RequestScoped; + +/** + * This class provides access to the file (local) system. If available an + * implementation of the {@link FileSystemAdapter} interface is used. The + * implementations of {@link FileSystemAdapter} provide a (transaction) safe way + * to access the local file system. If no implementation of + * {@link FileSystemAdapter} is available this class will use + * {@link java.nio.file.Path} etc. as fallback. Depending on your application + * server access to the local file system using these classes may fail. For + * information about how to deploy and configure a specific implementation of + * {@link FileSystemAdapter} please refer the the documentation of the + * implementation. + * + * The method in this class encapsulate the details of the access to the local + * file system. Therefore the paths to the files to read are usually provided as + * strings. + * + * @author Jens Pelzetter + */ +@RequestScoped +public class CcmFiles { + + /** + * Creates a {@link Reader} for the provided {@code path}. + * + * @param path + * @return + * @throws org.libreccm.files.FileDoesNotExistException + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public Reader createReader(final String path) + throws FileDoesNotExistException, + FileAccessException, + InsufficientPermissionsException { + + throw new UnsupportedOperationException(); + } + + /** + * Creates a {@link Writer} for the provided {@code path}. + * + * @param path + * @return + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public Writer createWriter(final String path) + throws FileAccessException, InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * Creates a {@link InputStream} for the provided {@code path}. + * + * @param path + * @return + * @throws org.libreccm.files.FileDoesNotExistException + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public InputStream createInputStream(final String path) + throws FileDoesNotExistException, + FileAccessException, + InsufficientPermissionsException { + + throw new UnsupportedOperationException(); + } + + /** + * Creates a {@link OutputStream} for the provided {@code path}. + * + * @param path + * @return + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public OutputStream createOutputStream(final String path) + throws FileAccessException, InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * Checks if a file exists. + * + * @param path + * @return {@code true} if a file with the provided {@code path} exists, + * {@code false} otherwise. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public boolean existsFile(final String path) + throws FileAccessException, InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * checks if the provided path points to a directory. + * + * @param path + * @return {@code true} if the the file to which the provided path points + * exists and is a directory, {@code false} otherwise. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.InsufficientPermissionsException + * @throws org.libreccm.files.FileDoesNotExistException + */ + public boolean isDirectory(final String path) + throws FileAccessException, + FileDoesNotExistException, + InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * Create a directory at the provided path. + * + * @param path The path of the new directory. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.FileAlreadyExistsException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public void createDirectory(final String path) + throws FileAccessException, + FileAlreadyExistsException, + InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * List the files in a directory. + * + * @param path The {@code path} of the directory. + * @return A list of the names of the files in the directory. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.FileDoesNotExistException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public List listFiles(final String path) + throws FileAccessException, + FileDoesNotExistException, + InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * Delete a file or directory. If the file is a directory the directory must + * be empty. + * + * @param path The path of the file to delete. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.FileDoesNotExistException + * @throws org.libreccm.files.DirectoryNotEmptyException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public void deleteFile(final String path) + throws FileAccessException, + FileDoesNotExistException, + DirectoryNotEmptyException, + InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } + + /** + * Delete a file or directory. + * + * @param path + * @param recursively Delete directories recursively. + * @throws org.libreccm.files.FileAccessException + * @throws org.libreccm.files.FileDoesNotExistException + * @throws org.libreccm.files.InsufficientPermissionsException + */ + public void deleteFile(final String path, final boolean recursively) + throws FileAccessException, + FileDoesNotExistException, + InsufficientPermissionsException { + throw new UnsupportedOperationException(); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/DirectoryNotEmptyException.java b/ccm-core/src/main/java/org/libreccm/files/DirectoryNotEmptyException.java new file mode 100644 index 000000000..bc50ff7dd --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/DirectoryNotEmptyException.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Thrown if a non empty directory is not deleted recursively. + * + * @author Jens Pelzetter + */ +public class DirectoryNotEmptyException extends Exception { + + private static final long serialVersionUID = -8515711805034123260L; + + /** + * Creates a new instance of DirectoryNotEmptyException without + * detail message. + */ + DirectoryNotEmptyException() { + super(); + } + + /** + * Constructs an instance of DirectoryNotEmptyException with + * the specified detail message. + * + * @param msg the detail message. + */ + DirectoryNotEmptyException(final String msg) { + super(msg); + } + + DirectoryNotEmptyException(final Exception ex) { + super(ex); + } + + DirectoryNotEmptyException(final String msg, final Exception ex) { + super(msg, ex); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/FileAccessException.java b/ccm-core/src/main/java/org/libreccm/files/FileAccessException.java new file mode 100644 index 000000000..b255b7f08 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/FileAccessException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Generic exception thrown if an error occurs while accessing the local file + * system which is not covered by other exceptions. + * + * @author Jens Pelzetter + */ +public class FileAccessException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance of FileAccessException without detail + * message. + */ + FileAccessException() { + super(); + } + + /** + * Constructs an instance of FileAccessException with the + * specified detail message. + * + * @param msg the detail message. + */ + FileAccessException(final String msg) { + super(msg); + } + + FileAccessException(final Exception ex) { + super(ex); + } + + FileAccessException(final String msg, final Exception ex) { + super(msg, ex); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/FileAlreadyExistsException.java b/ccm-core/src/main/java/org/libreccm/files/FileAlreadyExistsException.java new file mode 100644 index 000000000..6bc5fc2ab --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/FileAlreadyExistsException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Thrown if a method requires that a file does not exist already but the file + * exists. + * + * @author Jens Pelzetter + */ +public class FileAlreadyExistsException extends Exception { + + private static final long serialVersionUID = 2237027823060973043L; + + /** + * Creates a new instance of FileAlreadyExistsException without + * detail message. + */ + FileAlreadyExistsException() { + super(); + } + + /** + * Constructs an instance of FileAlreadyExistsException with + * the specified detail message. + * + * @param msg the detail message. + */ + FileAlreadyExistsException(final String msg) { + super(msg); + } + + FileAlreadyExistsException(final Exception ex) { + super(ex); + } + + FileAlreadyExistsException(final String msg, final Exception ex) { + super(msg, ex); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/FileDoesNotExistException.java b/ccm-core/src/main/java/org/libreccm/files/FileDoesNotExistException.java new file mode 100644 index 000000000..3be582ec0 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/FileDoesNotExistException.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Thrown if by methods that require that the file accessed exists if the + * requested file does not exist. + * + * @author Jens Pelzetter + */ +public class FileDoesNotExistException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance of FileDoesNotExistException without + * detail message. + */ + FileDoesNotExistException() { + } + + /** + * Constructs an instance of FileDoesNotExistException with the + * specified detail message. + * + * @param msg the detail message. + */ + FileDoesNotExistException(String msg) { + super(msg); + } + + FileDoesNotExistException(final Exception ex) { + super(ex); + } + + FileDoesNotExistException(final String msg, final Exception ex) { + super(msg, ex); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/InsufficientPermissionsException.java b/ccm-core/src/main/java/org/libreccm/files/InsufficientPermissionsException.java new file mode 100644 index 000000000..c259a0bf6 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/InsufficientPermissionsException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Thrown if the user which is used to run the application server has not the + * necessary permissions to access the requested file. + * + * @author Jens Pelzetter + */ +public class InsufficientPermissionsException extends Exception { + + private static final long serialVersionUID = -7496839503615573013L; + + /** + * Creates a new instance of InsufficientPermissionsException + * without detail message. + */ + InsufficientPermissionsException() { + super(); + } + + /** + * Constructs an instance of InsufficientPermissionsException + * with the specified detail message. + * + * @param msg the detail message. + */ + InsufficientPermissionsException(final String msg) { + super(msg); + } + + InsufficientPermissionsException(final Exception ex) { + super(ex); + } + + InsufficientPermissionsException(final String msg, final Exception ex) { + super(msg, ex); + } +} diff --git a/ccm-core/src/main/java/org/libreccm/files/NoDirectoryException.java b/ccm-core/src/main/java/org/libreccm/files/NoDirectoryException.java new file mode 100644 index 000000000..8d3f8087d --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/files/NoDirectoryException.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.files; + +/** + * Thrown if the a method expects that the requested file is a directory but is + * not. + * + * @author Jens Pelzetter + */ +public class NoDirectoryException extends Exception { + + private static final long serialVersionUID = -5811387600385322767L; + + /** + * Creates a new instance of NoDirectoryException without + * detail message. + */ + NoDirectoryException() { + super(); + } + + /** + * Constructs an instance of NoDirectoryException with the + * specified detail message. + * + * @param msg the detail message. + */ + NoDirectoryException(final String msg) { + super(msg); + } + + NoDirectoryException(final Exception ex) { + super(ex); + } + + NoDirectoryException(final String msg, final Exception ex) { + super(msg, ex); + } +}