correctEmbeddedSpacesInUrl
protected String correctEmbeddedSpacesInUrl(String sourceImageUrl)
URLs are not allowed to contain spaces character. This method replaces space
characters (that would otherwise be invalid) with their "%20" URL encoded form.
This helps our customers as they won't need to double encode space characters in image
transformation URLs.
Background
----------
Basic Image
-----------
If you have a source image called "my image1.jpg", the URL would have to look like
http://localhost:9090/img/my%20image1.jpg
i.e. the space character would need to be replaced with a %20 character
Transformed Image
-----------------
To trim an image you need a URL like
http://localhost:9090/t/trim/100/<.. the source URL ..>
However, URLs also have to encode "%" characters (as "%25"), so to transform the
basic image (the "http://localhost:9090/img/my%20image1.jpg" URL) you would get
http://localhost:9090/t/trim/100/localhost:9090/img/my%2520image1.jpg
Where "%" has been replaced with "%25"
Problem
--------
This is a little cumbersome for our customers, to make it easier we will automatically
"fix" any source image URLs which contain invalid space characters. So if the
following URL is specified
http://localhost:9090/t/trim/100/localhost:9090/img/my%20image1.jpg
The web server will decode this into
http://localhost:9090/t/trim/100/localhost:9090/img/my image1.jpg
We will then identify the source image URL as "http://localhost:9090/img/my image1.jpg"
and correct it to "localhost:9090/img/my%20image1.jpg" using this method.
Note
----
Browsers will automatically encode spaces which are entered in
the address bar, so if you were to type in
http://localhost:9090/t/trim/100/localhost:9090/img/my image1.jpg
The browser would automatically convert the space character into a
%20 for you and you would see the correctly transformed image.
- Parameters:
sourceImageUrl
- the Url to correct e.g. "http://localhost:9090/t/trim/100/localhost:9090/img/my image1.jpg"
- Returns:
- the corrected URL e.g. "http://localhost:9090/t/trim/100/localhost:9090/img/my%20image1.jpg"