MECAction.jsp
4.36 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<%@page import="net.sf.json.JSONArray"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="com.weaver.formmodel.mobile.plugin.Resource"%>
<%@page import="com.weaver.formmodel.mobile.plugin.Plugin"%>
<%@page import="com.weaver.formmodel.mobile.plugin.PluginCenter"%>
<%@page import="java.lang.reflect.Method"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="weaver.general.Util"%>
<%@page import="java.util.*"%>
<%@page import="java.net.*"%>
<%@page import="weaver.file.FileUpload"%>
<%@page import="com.weaver.formmodel.util.StringHelper"%>
<%@page import="com.weaver.formmodel.mobile.MobileFileUpload"%>
<%@page import="com.weaver.formmodel.mobile.mec.MECManager"%>
<%@page import="com.weaver.formmodel.mobile.mec.handler.AbstractMECHandler"%>
<%@ include file="/mobilemode/mobile/base.jsp"%>
<%
FileUpload fileUpload = new MobileFileUpload(request,"UTF-8",false);
String action = Util.null2String(fileUpload.getParameter("action"));
if(action.equals("getMecHtml")){
String mec_id = Util.null2String(fileUpload.getParameter("mec_id"));
String _DataSet = Util.null2String(fileUpload.getParameter("_DataSet"));
if(StringHelper.isNotEmpty(_DataSet)){
try{
_DataSet = URLDecoder.decode(_DataSet, "utf-8");
}catch(Exception e){
e.printStackTrace();
}
String key = "_DataSet";
Map<String, Object> dataMap = (Map<String, Object>)request.getAttribute(key);
if(dataMap == null){
dataMap = new HashMap<String, Object>();
}
JSONArray dataArray = JSONArray.fromObject(_DataSet);
for(int i=0;i<dataArray.size();i++){
JSONObject jsontemp = dataArray.getJSONObject(i);
Iterator it = jsontemp.keys();
while(it.hasNext()){
String name = it.next().toString();
JSONObject data = jsontemp.getJSONObject(name);
dataMap.put(name, data);
}
}
request.setAttribute(key, dataMap);
}
AbstractMECHandler mecHandler = MECManager.getMecHandler(mec_id, request, response);
if(mecHandler == null){
return;
}
mecHandler.setLoadType("1");
String viewHtml = mecHandler.getViewHtml();
String jsScript = mecHandler.getJSScript();
String result = viewHtml + "\n" + jsScript;
out.print(result);
}else if(action.equals("getMecData")){
String mec_id = Util.null2String(fileUpload.getParameter("mec_id"));
AbstractMECHandler mecHandler = MECManager.getMecHandler(mec_id, request, response);
if(mecHandler == null){
return;
}
Object data = mecHandler.getData();
out.print(data.toString());
}else if(action.startsWith("method:")){
String methodName = action.substring("method:".length()).trim();
if(methodName.equals("")){
return;
}
String mec_id = Util.null2String(fileUpload.getParameter("mec_id"));
AbstractMECHandler mecHandler = MECManager.getMecHandler(mec_id, request, response);
if(mecHandler == null){
return;
}
try{
Class cl = mecHandler.getClass();
Method method = cl.getDeclaredMethod(methodName);
Object result = method.invoke(mecHandler);
out.print(result.toString());
}catch(Exception ex){
ex.printStackTrace();
return;
}
}else if(action.equals("getDesignJS")){
response.setContentType("application/x-javascript");
//long a = System.currentTimeMillis();
String content = PluginCenter.getInstance().getDesignJSContent();
//System.out.println("1:" + (System.currentTimeMillis()-a));
out.print(content);
}else if(action.equals("getDesignCss")){
response.setContentType("text/css");
//long a = System.currentTimeMillis();
String content = PluginCenter.getInstance().getDesignCssContent();
//System.out.println("2:" + (System.currentTimeMillis()-a));
out.print(content);
}else if(action.equals("getDesignResource")){
String mec_type = Util.null2String(fileUpload.getParameter("mec_type"));
JSONArray jsonArray = new JSONArray();
Plugin plugin = PluginCenter.getInstance().getPluginById(mec_type);
List<Resource> resources = plugin.getDesignReourrces();
for(Resource resource : resources){
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", resource.getType());
jsonObject.put("path", resource.getPath());
jsonObject.put("content", resource.getContent());
jsonArray.add(jsonObject);
}
Collections.sort(jsonArray, new Comparator<JSONObject>(){
public int compare(JSONObject o1, JSONObject o2) {
String type = Util.null2String(o1.get("type"));
String type2 = Util.null2String(o2.get("type"));
return type.compareTo(type2);
}
});
out.print(jsonArray.toString());
}
out.flush();
%>