DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(stream);
String name = fixToString(document.getElementsByTagName("name").item(0).getFirstChild().toString());
String description = fixToString(document.getElementsByTagName("description").item(0).getFirstChild().toString());
SampleScheme scheme = new SampleScheme();
NodeList samples = document.getElementsByTagName("sample");
for( int i = 0; i < samples.getLength(); i++ ) {
Node sample = samples.item(i);
int size = Integer.parseInt(sample.getAttributes().getNamedItem("size").getNodeValue());
String values = fixToString(sample.getFirstChild().toString());
int[] list = new int[size];
StringTokenizer tok = new StringTokenizer(values);
for( int j = 0; j < size; j++ ) {
list[j] = Integer.parseInt(tok.nextToken(","));
}
scheme.setSampleScheme(size, list);
}
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);
}
}
}
}
pal.setType(type);
if (scheme.getMaxCount() == -1) {
Color[] colors = pal.getColors();
int length = colors.length;
CustomSampleScheme scheme2 = new CustomSampleScheme(length);
for( int j = 2; j < length; j++ ) {