Top Description Fields Constructors Methods
org.apache.tomcat.util.buf

public final Class UriUtil

extends Object
Class Inheritance
Imports
java.io.File, java.net.MalformedURLException, .URI, .URISyntaxException, .URL, java.util.regex.Pattern

Utility class for working with URIs and URLs.

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static URL
public static URL
buildJarUrl(File jarFile)

public static URL
buildJarUrl(File jarFile, String entryPath)

public static URL
buildJarUrl(String fileUrlString)

public static URL
buildJarUrl(String fileUrlString, String entryPath)

public static String
public static boolean

Returns:

true if a scheme is present, otherwise {code @false}
hasScheme
(CharSequence
The URI to test
uri
)

Determine if a URI string has a scheme component.

public static boolean

Returns:

true if the supplied path starts with once of the recognised sequences.
isAbsoluteURI
(String
The path to test
path
)

Does the provided path start with file:/ or <protocol>://.

private static boolean

Returns:

true if a the character is allowed, otherwise false
isSchemeChar
(char
The character to test
c
)

Determine if the character is allowed in the scheme of a URI.

private static String
public static URI

Returns:

The resulting URI as per URI#resolve(String)
resolve
(URI
The base URI to resolve against
base
,
String
The path to resolve
target
)

Replicates the behaviour of URI#resolve(String) and adds support for URIs of the form jar:file:/...

public static URL

Returns:

The equivalent JAR URL
warToJar
(URL
The WAR URL to convert
warUrl
)

Convert a URL of the form war:file:...

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEXback to summary
private static final char[] HEX
PATTERN_ASTERISKback to summary
private static final Pattern PATTERN_ASTERISK
PATTERN_CARETback to summary
private static final Pattern PATTERN_CARET
PATTERN_CUSTOMback to summary
private static final Pattern PATTERN_CUSTOM
PATTERN_EXCLAMATION_MARKback to summary
private static final Pattern PATTERN_EXCLAMATION_MARK
REPLACE_CUSTOMback to summary
private static final String REPLACE_CUSTOM
WAR_SEPARATORback to summary
private static final String WAR_SEPARATOR

Constructor Detail

UriUtilback to summary
private UriUtil()

Method Detail

buildJarSafeUrlback to summary
public static URL buildJarSafeUrl(File file) throws MalformedURLException
buildJarUrlback to summary
public static URL buildJarUrl(File jarFile) throws MalformedURLException
buildJarUrlback to summary
public static URL buildJarUrl(File jarFile, String entryPath) throws MalformedURLException
buildJarUrlback to summary
public static URL buildJarUrl(String fileUrlString) throws MalformedURLException
buildJarUrlback to summary
public static URL buildJarUrl(String fileUrlString, String entryPath) throws MalformedURLException
getWarSeparatorback to summary
public static String getWarSeparator()
hasSchemeback to summary
public static boolean hasScheme(CharSequence uri)

Determine if a URI string has a scheme component.

Parameters
uri:CharSequence

The URI to test

Returns:boolean

true if a scheme is present, otherwise {code @false}

isAbsoluteURIback to summary
public static boolean isAbsoluteURI(String path)

Does the provided path start with file:/ or <protocol>://.

Parameters
path:String

The path to test

Returns:boolean

true if the supplied path starts with once of the recognised sequences.

isSchemeCharback to summary
private static boolean isSchemeChar(char c)

Determine if the character is allowed in the scheme of a URI. See RFC 2396, Section 3.1

Parameters
c:char

The character to test

Returns:boolean

true if a the character is allowed, otherwise false

makeSafeForJarUrlback to summary
private static String makeSafeForJarUrl(String input)
resolveback to summary
public static URI resolve(URI base, String target) throws MalformedURLException, URISyntaxException

Replicates the behaviour of URI#resolve(String) and adds support for URIs of the form jar:file:/... .

Parameters
base:URI

The base URI to resolve against

target:String

The path to resolve

Returns:URI

The resulting URI as per URI#resolve(String)

Exceptions
MalformedURLException:
If the base URI cannot be converted to a URL
URISyntaxException:
If the resulting URL cannot be converted to a URI
warToJarback to summary
public static URL warToJar(URL warUrl) throws MalformedURLException

Convert a URL of the form war:file:... to jar:file:....

Parameters
warUrl:URL

The WAR URL to convert

Returns:URL

The equivalent JAR URL

Exceptions
MalformedURLException:
If the conversion fails