Design pattern to implement an iterative fallback mechanism
<p>I have written a word definition fetcher that parses web pages from a dictionary website.
Not all web pages have exactly the same HTML structure, so I had to implement several parsing methods to support the majority of cases.</p>

<p>Below is what I have done so far, which is pretty ugly code.</p>

<p><strong>What do you think would be the cleanest way of coding some kind of iterative fallback mechanism</strong> (there may be a more appropriate term), so that I can implement N ordered parsing methods (parsing failures must trigger the next parsing method, whereas exceptions such as IOException should break the process) ?</p>

<pre><code>    public String[] getDefinition(String word) {
    String[] returnValue = { "", "" };
    returnValue[0] = word;
    Document doc = null;
    try {
        String finalUrl = String.format(_baseUrl, word);
        Connection con = Jsoup.connect(finalUrl).userAgent("Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
        doc = con.get();
        // *** Case 1 (parsing method that works for 80% of the words) ***
        String basicFormOfWord = doc.select("DIV.luna-Ent H2.me").first().text().replace("·", "");
        String firstPartOfSpeech = doc.select("DIV.luna-Ent SPAN.pg").first().text();
        String firstDef = doc.select("DIV.luna-Ent DIV.luna-Ent").first().text();

        returnValue[1] = "&lt;b&gt;" + firstPartOfSpeech + "&lt;/b&gt;&lt;br/&gt;" + firstDef;
        returnValue[0] = basicFormOfWord;
    } catch (NullPointerException e) {
        try {
            // *** Case 2 (Alternate parsing method - for poorer results) ***
            String basicFormOfWord = doc.select("DIV.results_content p").first().text().replace("·", "");
            String firstDef = doc.select("DIV.results_content").first().text().replace(basicFormOfWord, "");

            returnValue[1] = firstDef;
            returnValue[0] = basicFormOfWord;
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnValue;
}
</code></pre>
