| | */ |
| | public class ProtocolResolver { |
| | - public static final String SCHEME_HTTP = "http"; |
| | + private static final String SCHEME_HTTP = "http"; |
| | + private static final String SCHEME_FILE = "file"; |
| | |
| | /** |
| | * Answers {@code true} if the given protocol is either HTTP or HTTPS. |
| | * |
| | - * @param protocol The protocol to compare against the web protocol. |
| | + * @param protocol The protocol to compare against the web URI scheme. |
| | * @return {@code true} the protocol is either HTTP or HTTPS. |
| | */ |
| | - public static boolean isHttp( String protocol ) { |
| | - protocol = protocol == null ? "" : protocol; |
| | - return protocol.toLowerCase().startsWith( SCHEME_HTTP ); |
| | + public static boolean isHttp( final String protocol ) { |
| | + return sanitize( protocol ).startsWith( SCHEME_HTTP ); |
| | + } |
| | + |
| | + /** |
| | + * Answers {@code true} if the given protocol is for a local file. |
| | + * |
| | + * @param protocol The protocol to compare against the file URI scheme. |
| | + * @return {@code true} the protocol is for a local file reference. |
| | + */ |
| | + public static boolean isFile( String protocol ) { |
| | + return sanitize( protocol ).startsWith( SCHEME_FILE ); |
| | } |
| | |
| | /** |
| | * Returns the protocol for a given URI or filename. |
| | * |
| | * @param resource Determine the protocol for this URI or filename. |
| | - * @return The protocol for the given source. |
| | + * @return The protocol for the given resource. |
| | */ |
| | public static String getProtocol( final String resource ) { |
 |
| | |
| | return result; |
| | + } |
| | + |
| | + /** |
| | + * Returns an empty string if the given string to sanitize is {@code null}, |
| | + * otherwise the given string in lowercase. |
| | + * |
| | + * @param s The string to sanitize, may be {@code null}. |
| | + * @return A non-{@code null} string. |
| | + */ |
| | + private static String sanitize( final String s ) { |
| | + return s == null ? "" : s.toLowerCase(); |
| | } |
| | } |