package com.gallatinsystems.image;


public class ImageUtils {
	/*
	 * Utility method to return the parts of an image path for S3 
	 * Position 0 = web domain with bucket ends with / 
	 * Position 1 = middle path elements ends with / 
	 * Position 2 = file name
	 */
	public static String[] parseImageParts(String url) {
		String[] parts = new String[3];
		url = url.replace("http://", "");
		String[] items = url.split("/");
		if (items.length == 3) {
			// no country in path
			parts[0]=("http://:" + items[0] + "/");
			parts[1]=(items[1] + "/");
			parts[2]=(items[2]);
		} else if (items.length > 3) {
			parts[0]=("http://:" + items[0] + "/");
			String middlePath = "";
			int i = 0;
			for (i = 1; i < items.length - 1; i++)
				middlePath += items[i] + "/";
			parts[1]=(middlePath);
			parts[2]=(items[i]);
		}

		return parts;
	}

	public static void main(String[] args) {
		String test1 = "http://waterforpeople.s3.amazonaws.com/images/wfpPhoto10062903227521.jpg";
		String test2 = "http://waterforpeople.s3.amazonaws.com/images/hn/ch003[1].jpg";
		System.out.println(test1);
		for (String item : parseImageParts(test1))
			System.out.println("   " + item);
		System.out.println(test2);
		for (String item : parseImageParts(test2))
			System.out.println("   " + item);
	}
}

@@ -384,16 +384,60 @@
 %22, %22%22);%0A
+%09%09url = url.substring(0, url.indexOf(%22?%22));%0A
 %09%09String
@@ -1008,24 +1008,35 @@
 03227521.jpg
+?random=123
 %22;%0A%09%09String 
@@ -1105,16 +1105,21 @@
 3%5B1%5D.jpg
+?test
 %22;%0A%09%09Sys

parse out any other values after jpg