/**
* 解析上传文件路径
*
* @return
* @throws DocumentException
* @throws IllegalAccessException
*/
@SuppressWarnings("unchecked")
private void parseXml() throws DocumentException, IllegalAccessException {
SAXReader cgReader = new SAXReader();
Document doc;
try {
doc = cgReader.read(new File(webPath));
} catch (Exception e1) {
// e1.printStackTrace();
System.err.println("找不到文件,请确认文件是否存在!");
return;
}
Element root = doc.getRootElement();
// 得到上传文件路径
Element uploadElement = root.element("server-upload-path");
if (uploadElement == null) {
System.err.println("请确认文件格式是否被改变,不能解析上传文件路径!");
} else {
// 解析绝对路径和相对路径
Element realpathElement = uploadElement.element("realpath");
Element absolutepathElement = uploadElement.element("absolutepath");
if (realpathElement != null || absolutepathElement != null) {
if (realpathElement != null)
{
String rValue = realpathElement.elementText("value");
if (null != rValue && !"".equals(rValue)) {
if (rValue.charAt(rValue.length()-1) == '/') {
uploadPath = rValue;
}else {
uploadPath = rValue + "/";
}
}
}
if (absolutepathElement != null)
{
String aValue = absolutepathElement.elementText("value");
if (null != aValue && !"".equals(aValue)) {
uploadPath = PathUtil.getWebRoot() + aValue + "/";
}
}
} else {
System.err.println("不能解析上传文件路径!");
}
}
// 得到录音文件路径
Element tapElement = root.element("server-tap-path");
if (tapElement == null) {
System.err.println("请确认文件格式是否被改变,不能解析录音文件路径!");
} else {
// 解析绝对路径和相对路径
Element realpathElement = tapElement.element("realpath");
Element absolutepathElement = tapElement.element("absolutepath");
if (realpathElement != null || absolutepathElement != null) {
if (realpathElement != null)
{
String rValue = realpathElement.elementText("value");
tapPath = rValue ;
}
if (absolutepathElement != null)
{
String aValue = absolutepathElement.elementText("value");
tapWebPath = aValue;
}
// if (null != aValue && !"".equals(aValue)) {
// tapPath = PathUtil.getWebRoot() + aValue + "/";
//
// } else {
// if (null != rValue && !"".equals(rValue)) {
// tapPath = PathUtil.getWebRoot() + aValue + "/";
// } else {
// System.err.println("请确认文件格式是否被改变,不能解析录音文件路径!");
// }
// }
}
}
// 得到上传文件格式
Element faxTypeElement = root.element("server-fax-upload-file-type");
if (faxTypeElement == null) {
System.err.println("请确认文件格式是否被改变,不能解析可上传传真类型文件!");
}else {
Element allow = faxTypeElement.element("allow");
if (allow != null) {
List<Element> types = allow.elements("value");
for (Element type : types) {
if (!"".equals(type) && !list.contains(type.getText().toLowerCase()))
list.add(type.getText().toLowerCase());
}
}else {
System.err.println("请确认文件格式是否被改变,不能解析可上传传真类型文件!");
}
}
// 解析oxc配置
Element ocxElement = root.element("server-hw-ocx-config");
if (ocxElement == null) {
System.err.println("请确认文件格式是否被改变,不能解析server配置文件路径!");
} else {
List<Element> ocxConfig = ocxElement.elements();
for (Element e : ocxConfig) {
if (e.getName().equals("MainCcsIP")) {
MainCcsIP = e.elementText("value");
continue;
}
if (e.getName().equals("BackCcsIP")) {
BackCcsIP = e.elementText("value");
continue;
}
if (e.getName().equals("AgentType")) {
AgentType = e.elementText("value");
continue;
}
if (e.getName().equals("CardType")) {
CardType = e.elementText("value");
continue;
}
if (e.getName().equals("CcsID")) {
CcsID = e.elementText("value");
continue;
}
if (e.getName().equals("AutoAnswer")) {
AutoAnswer =e.elementText("value");
continue;
}
if (e.getName().equals("AutoRelease")) {
AutoRelease = e.elementText("value");
continue;
}
if (e.getName().equals("AutoReconnect")) {
AutoReconnect = e.elementText("value");
continue;
}
if (e.getName().equals("CalledIDForDial")) {
CalledIDForDial = e.elementText("value");
continue;
}
}
}
// 解析坐席统计参数配置
Element arElement = root.element("server-accountreport");
if (arElement == null) {
System.err.println("不能解析 server-accountreport 配置文件路径!");
} else {
List<Element> arConfig = arElement.elements();
for (Element e : arConfig) {
if (e.getName().equals("CallLong")) {
if (e.elementText("value")!=null && !"".equals(e.elementText("value")))
CallLong = Long.parseLong(e.elementText("value"));
continue;
}
}
}
}