Package org.shredzone.commons.view.util
Class PathUtils
- java.lang.Object
-
- org.shredzone.commons.view.util.PathUtils
-
@ParametersAreNonnullByDefault public final class PathUtils extends Object
Utility methods for view path management.- Author:
- Richard "Shred" Körber
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
decode(String string)
URL decodes a string.static String
encode(String string)
URL encodes a string.static String
simplify(String part)
Simplifies a path part.static String
suffix(String mime)
Suggests a file name suffix for the given content type.
-
-
-
Method Detail
-
simplify
@Nonnull public static String simplify(String part)
Simplifies a path part. The resulting string only contains numbers ([0-9]) and lowercase characters ([a-z]). One ore more consecutive whitespaces or a few non-ascii characters are converted into a single dash '-'. All other characters are either converted to ASCII characters, or removed.This method can be used to convert e.g. titles into URL parts, for search engine optimization.
On accented characters, the accent is removed. However, currently German umlauts are converted into their respective ASCII counterparts ('ä' -> 'ae'). Future implementations may also contain translations for other language's accented characters.
Consider this method as one-way encoding. Future releases may return different strings.
- Parameters:
part
- path part to simplify- Returns:
- simplified path part
-
suffix
@Nonnull public static String suffix(String mime)
Suggests a file name suffix for the given content type.The current implementation only detects the standard HTML image types.
- Parameters:
mime
- content type to find a suffix for- Returns:
- suggested suffix, or "bin" if there is no known suffix
-
encode
@Nonnull public static String encode(String string)
URL encodes a string. utf-8 charset is used for encoding.This is a convenience call of
URLEncoder.encode(String, String)
with exception handling.- Parameters:
string
- string to be URL encoded- Returns:
- encoded string
-
decode
@Nonnull public static String decode(String string)
URL decodes a string. utf-8 charset is used for decoding.This is a convenience call of
URLDecoder.decode(String, String)
with exception handling.- Parameters:
string
- the string to be URL decoded- Returns:
- decoded string
-
-