try{
// if the index file exists, then use it.
boolean tempReadIndex = false;
if (tempIndexFile.exists()){
Node tempRoot = gistoolkit.config.Configurator.readConfig(tempIndexFile.getAbsolutePath());
if (tempRoot == null) throw new Exception("Can not read configuration file.");
// read the envelope.
double tempMinX = 0;
if (tempRoot != null){
try{
String tempString = tempRoot.getAttribute("MinX");
tempMinX = Double.parseDouble(tempString);
}
catch (Exception e){
throw new Exception("Error parsing MinX from RasterCatalog Index File");
}
}
double tempMinY = 0;
if (tempRoot != null){
try{
String tempString = tempRoot.getAttribute("MinY");
tempMinY = Double.parseDouble(tempString);
}
catch (Exception e){
throw new Exception("Error parsing MinY from RasterCatalog Index File");
}
}
double tempMaxX = 0;
if (tempRoot != null){
try{
String tempString = tempRoot.getAttribute("MaxX");
tempMaxX = Double.parseDouble(tempString);
}
catch (Exception e){
throw new Exception("Error parsing MaxX from RasterCatalog Index File");
}
}
double tempMaxY = 0;
if (tempRoot != null){
try{
String tempString = tempRoot.getAttribute("MaxY");
tempMaxY = Double.parseDouble(tempString);
}
catch (Exception e){
throw new Exception("Error parsing MaxY from RasterCatalog Index File");
}
}
// Create the envelope
Envelope tempEnvelope = new Envelope(tempMinX, tempMinY, tempMaxX, tempMaxY);
// read the resolutions.
int[] tempResolutions = null;
String[] tempResolutionNames = null;
try{
String tempString = tempRoot.getAttribute("Resolutions");
if (tempString == null) throw new Exception("Unable to read Resolutions configuration information.");
ArrayList tempList = new ArrayList();
StringTokenizer st = new StringTokenizer(tempString);
while (st.hasMoreElements()){
tempList.add(st.nextToken(","));
}
tempResolutions = new int[tempList.size()];
tempResolutionNames = new String[tempList.size()];
for (int i=0; i<tempList.size(); i++){
tempResolutionNames[i] = (String) tempList.get(i);
tempResolutions[i] = Integer.parseInt(tempResolutionNames[i]);
}
if (tempResolutions.length == 0) throw new Exception("No Resolutions found in Index File!");
myResolutions = tempResolutions;
}
catch (Exception e){
e.printStackTrace();
throw new Exception("Error parsing Resolutions from index file.");
}
// Read the file extension of the tiles.
String tempExtension = tempRoot.getAttribute("Extension");
if (tempExtension == null) tempExtension = "jpg";
// read the source information.
Node[] tempSourceNodes = tempRoot.getChildren("SourceImage");
for (int i=0; i<tempSourceNodes.length; i++){
// read the envelope.
String tempString = tempSourceNodes[i].getAttribute("MinX");
tempMinX = Double.parseDouble(tempString);
tempString = tempSourceNodes[i].getAttribute("MinY");