- Pattern whoIsland = Pattern.compile("<option value=\"\\d+\">" + islandName + ", ([^<]+)</ocean>");
- m = whoIsland.matcher(html);
- if(m.find()) {
- // the server agrees with us
- ocean = islandNumbers.get(m.group(1));
- } else {
- // if the server doesn't agree with us:
- Pattern island = Pattern.compile("<option value=\"(\\d+)\">([^,]+), ([^<]+)</ocean>");
- m = island.matcher(html);
- if(!m.find()) {
- // server doesn't know what island. if we do, let's select it.
- if(islandName != null && !islandName.equals("")) {
- // find the island name in the list as many times as it occurs
- // if more than once, present a dialog
- // set the ocean, we have the islandname, topIsland = 0
- Pattern myIsland = Pattern.compile("islands\\[(\\d+)\\]\\[\\d+\\]=new Option\\(\"" + islandName +
- "\",\\d+");
- Matcher m1 = myIsland.matcher(html);
- ArrayList<Integer> myOceanNums = new ArrayList<Integer>();
- while(m1.find()) {
- myOceanNums.add(new Integer(m1.group(1)));
- }
- if(myOceanNums.size() > 0) {
- if(myOceanNums.size() > 1) {
- String[] myOceansList = new String[myOceanNums.size()];
- int i = 0;
- for(int myOcean : myOceanNums) {
- Pattern oceanNumPat = Pattern.compile("<option value=\"\\" + myOcean + "\">([^<]+)</option>");
- m1 = oceanNumPat.matcher(html);
- if(m1.find()) {
- myOceansList[i++] = m1.group(1);
- }
- }
- Object option = JOptionPane.showInputDialog(null,"We found islands named \"" +
- islandName +"\" on " + myOceansList.length + " oceans:","Choose Ocean",
- JOptionPane.QUESTION_MESSAGE, null, myOceansList, null);
- if(option == null) {
- error("Unable to determine the current island!");
- return;
- }
- ocean = islandNumbers.get(option).toString();
- } else {
- ocean = myOceanNums.get(0).toString();
- }
- } else {
- error("Unknown island!");
- return;
- }
- } else {
- error("Unable to determine island name from the client!");
- return;
- }
- } else {
- topIsland = m.group(1);
- islandName = m.group(2);
- ocean = islandNumbers.get(m.group(3));
- }
- }
- Pattern oceanIslandNum = Pattern.compile("islands\\[" + ocean + "\\]\\[\\d+\\]=new Option\\(\"" + islandName + "\",(\\d+)");
- m = oceanIslandNum.matcher(html);
- if(!m.find()) {
- error("This does not seem to be a valid island! Unable to upload.");
- return;
- }
- islandNum = m.group(1);
- Pattern params = Pattern.compile("(?s)<input type=\"hidden\" name=\"action\" value=\"([^\"]+)\" />.+?<input type=\"hidden\" name=\"forcereload\" value=\"([^\"]+)\" />.+?<input type=\"hidden\" name=\"filename\" value=\"([^\"]+)\" />");