1 package net.mlw.util;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /***
7 *
8 * @author Matthew L. Wilson
9 * @version $Revision: 1.4 $ $Date: 2004/03/17 14:20:21 $
10 */
11 public final class ParsingUtils
12 {
13 /*** protecte singleton. **/
14 private ParsingUtils()
15 {
16
17 }
18
19 /*** Returns a String array derived from the contents of the <td>s.
20 *
21 * @param html The text to parse
22 * @return String array derived from the contents of the <td>s.
23 */
24 public static String[] getTdContentsAsArray(String html)
25 {
26 List contents = new ArrayList();
27 int startIndex = 0, endIndex = 0;
28
29 while ((endIndex = html.indexOf("</td>", endIndex + 4)) >= 0 && (startIndex = html.lastIndexOf(">", endIndex) + 1) >= 0)
30 {
31 String value = html.substring(startIndex, endIndex);
32 value = value.replaceAll(" ", "");
33 contents.add(value);
34 }
35
36 return (String[]) contents.toArray(new String[] {
37 });
38 }
39
40 /*** Returns a String array derived from the contents of the <td>s.
41 *
42 * @param html The text to parse
43 * @param defaultValue If the TD is empty then use this value.
44 * @return String array derived from the contents of the <td>s.
45 */
46 public static String getTdContents(String html, String defaultValue)
47 {
48 return getTdContents(html, defaultValue, 0);
49 }
50
51 /*** Returns a String array derived from the contents of the <td>s.
52 *
53 * @param html The text to parse
54 * @param defaultValue If the TD is empty then use this value.
55 * @param offset the number of TDs to skip.
56 * @return The value of the td.
57 */
58 public static String getTdContents(String html, String defaultValue, int offset)
59 {
60 int startIndex = 0, endIndex = 0;
61
62 for (int i = 0; i < offset; i++)
63 {
64 startIndex = html.indexOf(">", startIndex) + 1;
65 }
66
67 if ((startIndex > 0) && ((endIndex = html.indexOf("<", startIndex)) > 0))
68 {
69 String value = html.substring(startIndex, endIndex);
70 value = value.replaceAll(" ", "");
71 return (value.length() > 0) ? value : defaultValue;
72 }
73 else
74 {
75 return defaultValue;
76 }
77 }
78
79 }
This page was automatically generated by Maven