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.mail2.javax.resolver; 018 019import org.apache.commons.mail2.javax.DataSourceResolver; 020 021/** 022 * Abstract class for resolvers. 023 * 024 * @since 1.3 025 */ 026public abstract class DataSourceBaseResolver implements DataSourceResolver { 027 028 /** Whether to ignore resources not found or complain with an exception. */ 029 private final boolean lenient; 030 031 /** 032 * Constructs a new instance. 033 */ 034 public DataSourceBaseResolver() { 035 this.lenient = false; 036 } 037 038 /** 039 * Constructs a new instance. 040 * 041 * @param lenient shall we ignore resources not found or throw an exception? 042 */ 043 public DataSourceBaseResolver(final boolean lenient) { 044 this.lenient = lenient; 045 } 046 047 /** 048 * Tests whether the argument is a content id. 049 * 050 * @param resourceLocation the resource location to test. 051 * @return true if it is a CID. 052 */ 053 protected boolean isCid(final String resourceLocation) { 054 return resourceLocation.startsWith("cid:"); 055 } 056 057 /** 058 * Tests whether this a file URL. 059 * 060 * @param urlString the URL string. 061 * @return true if it is a file URL. 062 */ 063 protected boolean isFileUrl(final String urlString) { 064 return urlString.startsWith("file:/"); 065 } 066 067 /** 068 * Tests whether this a HTTP or HTTPS URL. 069 * 070 * @param urlString the URL string to test. 071 * @return true if it is a HTTP or HTTPS URL. 072 */ 073 protected boolean isHttpUrl(final String urlString) { 074 return urlString.startsWith("http://") || urlString.startsWith("https://"); 075 } 076 077 /** 078 * Tests whether to ignore resources not found or throw an exception. 079 * 080 * @return the lenient flag. 081 */ 082 public boolean isLenient() { 083 return lenient; 084 } 085}