commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/resolver/DataSourcePathResolver.java [35:111]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public final class DataSourcePathResolver extends DataSourceBaseResolver {

    /**
     * The base directory of the resource when resolving relative paths.
     */
    private final Path baseDir;

    /**
     * NIO options to open the data source.
     */
    private final OpenOption[] options;

    /**
     * Constructs a new instance.
     */
    public DataSourcePathResolver() {
        this(Paths.get("."));
    }

    /**
     * Constructs a new instance.
     *
     * @param baseDir the base directory of the resource when resolving relative paths
     */
    public DataSourcePathResolver(final Path baseDir) {
        this(baseDir, false);
    }

    /**
     * Constructs a new instance.
     *
     * @param baseDir the base directory of the resource when resolving relative paths
     * @param lenient shall we ignore resources not found or complain with an exception
     * @param options options for opening streams.
     */
    public DataSourcePathResolver(final Path baseDir, final boolean lenient, final OpenOption... options) {
        super(lenient);
        this.baseDir = baseDir;
        this.options = options;
    }

    /**
     * Gets the base directory used for resolving relative resource locations.
     *
     * @return the baseUrl
     */
    public Path getBaseDir() {
        return baseDir;
    }

    /** {@inheritDoc} */
    @Override
    public DataSource resolve(final String resourceLocation) throws IOException {
        return resolve(resourceLocation, isLenient());
    }

    /** {@inheritDoc} */
    @Override
    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException {
        Path file;
        DataSource result = null;

        if (!isCid(resourceLocation)) {
            file = Paths.get(resourceLocation);

            if (!file.isAbsolute()) {
                file = getBaseDir() != null ? getBaseDir().resolve(resourceLocation) : Paths.get(resourceLocation);
            }

            if (Files.exists(file)) {
                result = new PathDataSource(file, FileTypeMap.getDefaultFileTypeMap(), options);
            } else if (!isLenient) {
                throw new IOException("Cant resolve the following file resource :" + file.toAbsolutePath());
            }
        }

        return result;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



commons-email2-javax/src/main/java/org/apache/commons/mail2/javax/resolver/DataSourcePathResolver.java [35:111]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public final class DataSourcePathResolver extends DataSourceBaseResolver {

    /**
     * The base directory of the resource when resolving relative paths.
     */
    private final Path baseDir;

    /**
     * NIO options to open the data source.
     */
    private final OpenOption[] options;

    /**
     * Constructs a new instance.
     */
    public DataSourcePathResolver() {
        this(Paths.get("."));
    }

    /**
     * Constructs a new instance.
     *
     * @param baseDir the base directory of the resource when resolving relative paths
     */
    public DataSourcePathResolver(final Path baseDir) {
        this(baseDir, false);
    }

    /**
     * Constructs a new instance.
     *
     * @param baseDir the base directory of the resource when resolving relative paths
     * @param lenient shall we ignore resources not found or complain with an exception
     * @param options options for opening streams.
     */
    public DataSourcePathResolver(final Path baseDir, final boolean lenient, final OpenOption... options) {
        super(lenient);
        this.baseDir = baseDir;
        this.options = options;
    }

    /**
     * Gets the base directory used for resolving relative resource locations.
     *
     * @return the baseUrl
     */
    public Path getBaseDir() {
        return baseDir;
    }

    /** {@inheritDoc} */
    @Override
    public DataSource resolve(final String resourceLocation) throws IOException {
        return resolve(resourceLocation, isLenient());
    }

    /** {@inheritDoc} */
    @Override
    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException {
        Path file;
        DataSource result = null;

        if (!isCid(resourceLocation)) {
            file = Paths.get(resourceLocation);

            if (!file.isAbsolute()) {
                file = getBaseDir() != null ? getBaseDir().resolve(resourceLocation) : Paths.get(resourceLocation);
            }

            if (Files.exists(file)) {
                result = new PathDataSource(file, FileTypeMap.getDefaultFileTypeMap(), options);
            } else if (!isLenient) {
                throw new IOException("Cant resolve the following file resource :" + file.toAbsolutePath());
            }
        }

        return result;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



