NodeList palettes = document.getElementsByTagName("palette");
for( int i = 0; i < palettes.getLength(); i++ ) {
BrewerPalette pal = new BrewerPalette();
PaletteSuitability suitability = new PaletteSuitability();
NodeList paletteInfo = palettes.item(i).getChildNodes();
for( int j = 0; j < paletteInfo.getLength(); j++ ) {
Node item = paletteInfo.item(j);
if (item.getNodeName().equals("name")) {
pal.setName(fixToString(item.getFirstChild().toString()));
}
if (item.getNodeName().equals("description")) {
pal.setDescription(fixToString(item.getFirstChild().toString()));
}
if (item.getNodeName().equals("colors")) {
StringTokenizer oTok = new StringTokenizer(fixToString(item.getFirstChild().toString()));
List<Color> colors = new ArrayList<Color>();
while( oTok.hasMoreTokens() ) {
String entry = oTok.nextToken(":");
StringTokenizer iTok = new StringTokenizer(entry);
int r = Integer.parseInt(iTok.nextToken(",").trim());
int g = Integer.parseInt(iTok.nextToken(",").trim());
int b = Integer.parseInt(iTok.nextToken(",").trim());
colors.add(new Color(r, g, b));
}
pal.setColors((Color[]) colors.toArray(new Color[colors.size()]));
}
if (item.getNodeName().equals("suitability")) {
NodeList schemeSuitability = item.getChildNodes();
for( int k = 0; k < schemeSuitability.getLength(); k++ ) {
Node palScheme = schemeSuitability.item(k);
if (palScheme.getNodeName().equals("scheme")) {
int paletteSize = Integer.parseInt(palScheme.getAttributes().getNamedItem("size").getNodeValue());
String values = fixToString(palScheme.getFirstChild().toString());
String[] list = new String[6];
StringTokenizer tok = new StringTokenizer(values);
// obtain all 6 values, which should each be
// G=GOOD, D=DOUBTFUL, B=BAD, or ?=UNKNOWN.
for( int m = 0; m < 6; m++ ) {
list[m] = tok.nextToken(",");
}
suitability.setSuitability(paletteSize, list);
}
}
}
}