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 * @version $Id: DataSourceBaseResolver.java 1420381 2012-12-11 20:18:05Z tn $ 026 */ 027public abstract class DataSourceBaseResolver implements DataSourceResolver 028{ 029 /** shall we ignore resources not found or complain with an exception */ 030 private final boolean lenient; 031 032 /** 033 * Constructor. 034 */ 035 public DataSourceBaseResolver() 036 { 037 this.lenient = false; 038 } 039 040 /** 041 * Constructor. 042 * 043 * @param lenient shall we ignore resources not found or throw an exception? 044 */ 045 public DataSourceBaseResolver(final boolean lenient) 046 { 047 this.lenient = lenient; 048 } 049 050 /** 051 * Shall we ignore resources not found or throw an exception? 052 * 053 * @return the lenient flag 054 */ 055 public boolean isLenient() 056 { 057 return lenient; 058 } 059 060 /** 061 * Is this a content id? 062 * 063 * @param resourceLocation the resource location 064 * @return true if it is a CID 065 */ 066 protected boolean isCid(final String resourceLocation) 067 { 068 return resourceLocation.startsWith("cid:"); 069 } 070 071 /** 072 * Is this a file URL? 073 * 074 * @param urlString the URL string 075 * @return true if it is a file URL 076 */ 077 protected boolean isFileUrl(final String urlString) 078 { 079 return urlString.startsWith("file:/"); 080 } 081 082 /** 083 * Is this a HTTP/HTTPS URL? 084 * 085 * @param urlString the URL string 086 * @return true if it is a HTTP/HTTPS URL 087 */ 088 protected boolean isHttpUrl(final String urlString) 089 { 090 return urlString.startsWith("http://") || urlString.startsWith("https://"); 091 } 092}