@@ -0,0 +1,2244 @@
+/**%0A * Copyright 2015 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage other;%0A%0Aimport java.math.BigInteger;%0Aimport java.net.URLEncoder;%0Aimport java.security.MessageDigest;%0Aimport java.security.NoSuchAlgorithmException;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0A/**%0A * @author Lorenzo Speranzoni%0A * @since 1 Nov 2015%0A */%0Apublic class WikipediaImageURLDecoderTest %7B%0A%0A  @Test%0A  public void shouldComputeWikipediaImageURL() %7B%0A%0A    try %7B%0A%0A      String imageName = %22Spelterini_Bl%C3%BCemlisalp.jpg%22;%0A      %0A      Assert.assertEquals(%22ae1a26d34d6a674d4400c8a1e6fe73f8%22, encodeAsMD5(imageName));%0A%0A      String actual = toWikipediaImageURL(imageName);%0A      %0A      String expected = %22http://upload.wikimedia.org/wikipedia/commons/a/ae/Spelterini_Bl%25C3%25BCemlisalp.jpg%22;%0A      %0A      Assert.assertEquals(expected, actual); %0A    %7D%0A    catch (Exception e) %7B%0A%0A      e.printStackTrace();%0A%0A      Assert.fail();%0A    %7D%0A  %7D%0A%0A  private String toWikipediaImageURL(String imageName) throws Exception %7B%0A    %0A    String encodedAsMD5 = encodeAsMD5(imageName);%0A    String encodeAsURL = URLEncoder.encode(imageName, %22UTF-8%22);%0A    %0A    return %22http://upload.wikimedia.org/wikipedia/commons/%22 + encodedAsMD5.charAt(0) + %22/%22 + encodedAsMD5.charAt(0) + encodedAsMD5.charAt(1) + %22/%22 + encodeAsURL;%0A  %7D%0A%0A  private String encodeAsMD5(String imageName) throws NoSuchAlgorithmException %7B%0A    %0A    MessageDigest messageDigest = MessageDigest.getInstance(%22MD5%22);%0A    byte%5B%5D digest = messageDigest.digest(imageName.getBytes());%0A    BigInteger bigInt = new BigInteger(1, digest);%0A    String hashtext = bigInt.toString(16);%0A    while (hashtext.length() %3C 32) %7B%0A      hashtext = %220%22 + hashtext;%0A    %7D%0A    return hashtext;%0A  %7D%0A%7D%0A

add wikipedia thumbnail url decoding