📄 devsfiletodom.java
字号:
fillInServers(marshalNode, MARSHAL_DIR);
// get the list of redirect servers
Document redirectDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_REDIRECT_SERVERS_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_REDIRECT_SERVERS_FILE));
try
{
redirectDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_REDIRECT_SERVERS_FILE);
StringReader reader = new StringReader(LIST_OF_REDIRECT_SERVERS_XML);
redirectDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(redirectDoc.getDocumentElement(),
REDIRECT_SERVERS, SYSTEM_DIR, LIST_OF_REDIRECT_SERVERS_FILE);
}
Element redirectNode =
(Element) (baseDocument.importNode(redirectDoc.getDocumentElement(),
true));
redirectNode.setAttribute("fileDir", SYSTEM_DIR);
redirectNode.setAttribute("fileName", LIST_OF_REDIRECT_SERVERS_FILE);
redirectNode.setAttribute("fileType",
Integer.toString(REDIRECT_SERVERS));
serversElement.appendChild(redirectNode);
// fill in the redirect hosts
fillInServers(redirectNode, REDIRECT_DIR);
// get the list of cdr servers
Document cdrDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_CDR_SERVERS_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_CDR_SERVERS_FILE));
try
{
cdrDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_CDR_SERVERS_FILE);
StringReader reader = new StringReader(LIST_OF_CDR_SERVERS_XML);
cdrDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(cdrDoc.getDocumentElement(), CDR_SERVERS,
SYSTEM_DIR, LIST_OF_CDR_SERVERS_FILE);
}
Element cdrNode =
(Element) (baseDocument.importNode(cdrDoc.getDocumentElement(),
true));
cdrNode.setAttribute("fileDir", SYSTEM_DIR);
cdrNode.setAttribute("fileName", LIST_OF_CDR_SERVERS_FILE);
cdrNode.setAttribute("fileType", Integer.toString(CDR_SERVERS));
serversElement.appendChild(cdrNode);
// fill in the cdr hosts
fillInServers(cdrNode, CDR_DIR);
// get the list of pdp servers
Document pdpDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_PDP_SERVERS_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_PDP_SERVERS_FILE));
try
{
pdpDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_PDP_SERVERS_FILE);
StringReader reader = new StringReader(LIST_OF_PDP_SERVERS_XML);
pdpDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(pdpDoc.getDocumentElement(), PDP_SERVERS,
SYSTEM_DIR, LIST_OF_PDP_SERVERS_FILE);
}
Element pdpNode =
(Element) (baseDocument.importNode(pdpDoc.getDocumentElement(),
true));
pdpNode.setAttribute("fileDir", SYSTEM_DIR);
pdpNode.setAttribute("fileName", LIST_OF_PDP_SERVERS_FILE);
pdpNode.setAttribute("fileType", Integer.toString(PDP_SERVERS));
serversElement.appendChild(pdpNode);
// fill in the pdp hosts
fillInServers(pdpNode, PDP_DIR);
// get the list of dvr client
Document dvrDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_DVR_CLIENT_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_DVR_CLIENT_FILE));
try
{
dvrDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_DVR_CLIENT_FILE);
StringReader reader = new StringReader(LIST_OF_DVR_CLIENT_FILE);
dvrDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(dvrDoc.getDocumentElement(), DVR_CLIENT,
SYSTEM_DIR, LIST_OF_DVR_CLIENT_FILE);
}
Element dvrNode =
(Element) (baseDocument.importNode(dvrDoc.getDocumentElement(),
true));
dvrNode.setAttribute("fileDir", SYSTEM_DIR);
dvrNode.setAttribute("fileName", LIST_OF_DVR_CLIENT_FILE);
dvrNode.setAttribute("fileType", Integer.toString(DVR_CLIENT));
uaclientElement.appendChild(dvrNode);
// fill in the dvr hosts
fillInClient(dvrNode, DVR_DIR);
// get the list of dvr client
Document envDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_ENV_CLIENT_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_ENV_CLIENT_FILE));
try
{
envDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_ENV_CLIENT_FILE);
StringReader reader = new StringReader(LIST_OF_ENV_CLIENT_FILE);
envDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(dvrDoc.getDocumentElement(), ENV_CLIENT,
SYSTEM_DIR, LIST_OF_ENV_CLIENT_FILE);
}
Element envNode =
(Element) (baseDocument.importNode(envDoc.getDocumentElement(),
true));
dvrNode.setAttribute("fileDir", SYSTEM_DIR);
dvrNode.setAttribute("fileName", LIST_OF_ENV_CLIENT_FILE);
dvrNode.setAttribute("fileType", Integer.toString(ENV_CLIENT));
uaclientElement.appendChild(envNode);
// fill in the dvr hosts
fillInClient(envNode, ENV_DIR);
// get the list of heartbeat servers
Document heartbeatDoc = null;
try
{
System.out.println("looking for " + SYSTEM_DIR
+ LIST_OF_HEARTBEAT_SERVERS_FILE);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(SYSTEM_DIR,
LIST_OF_HEARTBEAT_SERVERS_FILE));
try
{
heartbeatDoc = parser.parse(new InputSource(reader));
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
catch (VPPNoSuchFileException e)
{
System.out.println("Creating new " + LIST_OF_HEARTBEAT_SERVERS_FILE);
StringReader reader = new StringReader(LIST_OF_HEARTBEAT_SERVERS_XML);
heartbeatDoc = parser.parse(new InputSource(reader));
DOMToFile.writeFileFromNode(heartbeatDoc.getDocumentElement(),
HEARTBEAT_SERVERS, SYSTEM_DIR,
LIST_OF_HEARTBEAT_SERVERS_FILE);
}
Element heartbeatNode =
(Element) (baseDocument.importNode(heartbeatDoc.getDocumentElement(),
true));
heartbeatNode.setAttribute("fileDir", SYSTEM_DIR);
heartbeatNode.setAttribute("fileName", LIST_OF_HEARTBEAT_SERVERS_FILE);
heartbeatNode.setAttribute("fileType",
Integer.toString(HEARTBEAT_SERVERS));
serversElement.appendChild(heartbeatNode);
// fill in the heartbeat hosts
fillInServers(heartbeatNode, HEARTBEAT_DIR);
}
catch (FailedToWriteFileException ftwfex)
{
// not much we can do about it.
}
return baseDocument;
}
/**
*
* @param serversElement
* @param dirName
*
* @throws IOException
*/
private static void fillInClient(Element uaclientElement,
String dirName) throws IOException, VPPException
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = null;
try
{
parser = dbf.newDocumentBuilder();
}
catch(ParserConfigurationException e1)
{
e1.printStackTrace();
return;
}
NodeList nodes = uaclientElement.getElementsByTagName("client");
Vector vector = new Vector(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++)
{
vector.addElement(nodes.item(i));
}
for (int i = 0; i < vector.size(); i++)
{
Element clientElement = (Element) vector.elementAt(i);
Node clientParent = clientElement.getParentNode();
String clientFileName = (clientElement.getAttribute("host") + ":"
+ clientElement.getAttribute("port"));
System.out.println("looking for " + clientFileName);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(dirName,
clientFileName));
try
{
Document clientDocument = parser.parse(new InputSource(reader));
Element clientNode = (Element) (baseDocument.importNode
(clientDocument.getDocumentElement(), true));
clientNode.setAttribute("fileDir", dirName);
clientNode.setAttribute("fileName", clientFileName);
clientNode.setAttribute("fileType", Integer.toString(DVR));
clientParent.replaceChild(clientNode, uaclientElement);
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
}
/**
*
* @param serversElement
* @param dirName
*
* @throws IOException
*/
private static void fillInServers(Element serversElement,
String dirName) throws IOException, VPPException
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = null;
try
{
parser = dbf.newDocumentBuilder();
}
catch(ParserConfigurationException e1)
{
e1.printStackTrace();
return;
}
NodeList nodes = serversElement.getElementsByTagName("server");
Vector vector = new Vector(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++)
{
vector.addElement(nodes.item(i));
}
for (int i = 0; i < vector.size(); i++)
{
Element serverElement = (Element) vector.elementAt(i);
Node serverParent = serverElement.getParentNode();
String serverFileName = (serverElement.getAttribute("host") + ":"
+ serverElement.getAttribute("port"));
System.out.println("looking for " + serverFileName);
StringReader reader =
new StringReader(AdministrativeLogin.getConnection().doGet(dirName,
serverFileName));
try
{
Document serverDocument = parser.parse(new InputSource(reader));
Element serverNode = (Element) (baseDocument.importNode
(serverDocument.getDocumentElement(), true));
serverNode.setAttribute("fileDir", dirName);
serverNode.setAttribute("fileName", serverFileName);
serverNode.setAttribute("fileType", Integer.toString(FEATURE_SERVER));
serverParent.replaceChild(serverNode, serverElement);
}
catch (SAXException e)
{
System.out.println("bad XML: " + reader.toString());
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -