001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.mail.resolver;
018
019import org.apache.commons.mail.DataSourceResolver;
020
021/**
022 * Base class for various resolvers.
023 *
024 * @since 1.3
025 */
026public abstract class DataSourceBaseResolver implements DataSourceResolver
027{
028    /** shall we ignore resources not found or complain with an exception */
029    private final boolean lenient;
030
031    /**
032     * Constructor.
033     */
034    public DataSourceBaseResolver()
035    {
036        this.lenient = false;
037    }
038
039    /**
040     * Constructor.
041     *
042     * @param lenient shall we ignore resources not found or throw an exception?
043     */
044    public DataSourceBaseResolver(final boolean lenient)
045    {
046        this.lenient = lenient;
047    }
048
049    /**
050     * Shall we ignore resources not found or throw an exception?
051     *
052     * @return the lenient flag
053     */
054    public boolean isLenient()
055    {
056        return lenient;
057    }
058
059    /**
060     * Is this a content id?
061     *
062     * @param resourceLocation the resource location
063     * @return true if it is a CID
064     */
065    protected boolean isCid(final String resourceLocation)
066    {
067        return resourceLocation.startsWith("cid:");
068    }
069
070    /**
071     * Is this a file URL?
072     *
073     * @param urlString the URL string
074     * @return true if it is a file URL
075     */
076    protected boolean isFileUrl(final String urlString)
077    {
078        return urlString.startsWith("file:/");
079    }
080
081    /**
082     * Is this a HTTP/HTTPS URL?
083     *
084     * @param urlString the URL string
085     * @return true if it is a HTTP/HTTPS URL
086     */
087    protected boolean isHttpUrl(final String urlString)
088    {
089        return urlString.startsWith("http://") || urlString.startsWith("https://");
090    }
091}