AddXmlOperation.jsp
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%@ include file="/templetecheck/filecheck/CheckUserIsSysadmin.jsp" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.security.file.FileType" %>
<%@ page import="weaver.security.util.SecurityMethodUtil" %>
<%@ page import="java.util.*,org.dom4j.*,java.io.*,org.json.JSONObject" %>
<%@ page import="weaver.templetecheck.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
JSONObject object = new JSONObject();
String fpath = request.getParameter("path");
ArrayList<String> types  = new ArrayList<String>();
types.add(".xml");
if(!FileType.validateFileExt(fpath,types)) {
	object.put("message","2");//文件创建失败
	out.print(object.toString());
	return;
}
String content = request.getParameter("contentarea");
CheckConfigFile checkConfigFile = new CheckConfigFile();
FileUtil fileUtil = new FileUtil();
//判断path是存已存在,路径是否正确
File file = new File(fileUtil.getPath(fpath));
if(file.exists()) {
	//response.sendRedirect("AddXml.jsp?message=1");//文件已存在
	object.put("message","1");//文件已存在
	out.print(object.toString());
	return;
}
try {
	//System.out.println("==content:"+content);
/*	if(content.indexOf("Entity") > -1) {
		object.put("message","2");//禁止引用
		out.print(object.toString());
		return;
	}*/
	content = SecurityMethodUtil.clearEntity(content);
	Document doc = checkConfigFile.Str2Document(content);
	XMLUtil xmlUtil = new XMLUtil();
	String res = xmlUtil.addXml(file,doc);
	object.put("message",res);//文件已存在
	out.print(object.toString());
} catch(Exception e) {
	e.printStackTrace();
	//response.sendRedirect("AddXml.jsp?message=2");//文件创建失败
	object.put("message","2");//文件创建失败
	out.print(object.toString());
	return;
}
%>