Search in sources :

Example 1 with TranslatableIllegalArgumentException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException in project ma-core-public by infiniteautomation.

the class FileStoreService method getPathWithinFileStore.

private FileStorePath getPathWithinFileStore(FileStore fileStore, String path) {
    Path root = getFileStoreRoot(fileStore);
    Path filePath = root.resolve(path).toAbsolutePath().normalize();
    if (!filePath.startsWith(root)) {
        throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
    }
    return new FileStorePath(fileStore, filePath);
}
Also used : Path(java.nio.file.Path) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 2 with TranslatableIllegalArgumentException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException in project ma-core-public by infiniteautomation.

the class FileStoreService method resolveFileStore.

private FileStorePath resolveFileStore(Path path) {
    Path absolutePath = path.toAbsolutePath().normalize();
    if (!absolutePath.startsWith(fileStoreRoot)) {
        throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
    }
    Path relative = fileStoreRoot.relativize(absolutePath);
    if (relative.getNameCount() == 0) {
        throw new TranslatableIllegalArgumentException(new TranslatableMessage("filestore.invalidPath"));
    }
    String fileStoreName = relative.getName(0).toString();
    FileStore fileStore = getWithoutPermissionCheck(fileStoreName);
    return new FileStorePath(fileStore, absolutePath);
}
Also used : Path(java.nio.file.Path) FileStore(com.serotonin.m2m2.vo.FileStore) TranslatableIllegalArgumentException(com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

TranslatableIllegalArgumentException (com.infiniteautomation.mango.util.exception.TranslatableIllegalArgumentException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 Path (java.nio.file.Path)2 FileStore (com.serotonin.m2m2.vo.FileStore)1