private void updateJoramAdminXml(String hostName,
String port)
throws Exception {
File file = new File(confDir, JORAMADMIN_XML);
FileReader fileReader = new FileReader(file);
BufferedReader reader = new BufferedReader(fileReader);
boolean end = false;
String line;
StringBuffer buff = new StringBuffer();
int i = -1;
while (! end) {
line = reader.readLine();
if (line == null)
end = true;
else {
if (line.trim().startsWith("<connect")) {
while (true) {
i = line.indexOf("host");
if (i > 0) {
buff.append(line.substring(0,i+10));
buff.append(hostName);
int j = line.indexOf("\"",i+11);
buff.append(line.substring(j,line.length()) + "\n");
if (line.trim().endsWith("/>")) {
line = reader.readLine();
break;
}
line = reader.readLine();
continue;
}
i = line.indexOf("port");
if (i > 0) {
buff.append(line.substring(0,i+6));
buff.append(port);
int j = line.indexOf("\"",i+7);
buff.append(line.substring(j,line.length()) + "\n");
if (line.trim().endsWith("/>")) {
line = reader.readLine();
break;
}
line = reader.readLine();
continue;
}
buff.append(line + "\n");
if (line.trim().endsWith("/>")) {
line = reader.readLine();
break;
}
line = reader.readLine();
}
} else if (line.trim().startsWith("<tcp")) {
while (true) {
i = line.indexOf("host");
if (i > 0) {
buff.append(line.substring(0,i+6));
buff.append(hostName);
int j = line.indexOf("\"",i+7);
buff.append(line.substring(j,line.length()) + "\n");
if (line.trim().endsWith("/>")) {
line = reader.readLine();
break;
}
line = reader.readLine();
continue;
}
i = line.indexOf("port");
if (i > 0) {
buff.append(line.substring(0,i+6));
buff.append(port);
int j = line.indexOf("\"",i+7);
buff.append(line.substring(j,line.length()) + "\n");
if (line.trim().endsWith("/>")) {
line = reader.readLine();
break;
}
line = reader.readLine();
continue;
}
buff.append(line + "\n");
if (line.trim().endsWith("/>"))
break;
line = reader.readLine();
}
}
buff.append(line + "\n");
}
}