xworker.manong.MaNongJavaScriptFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xworker_app Show documentation
Show all versions of xworker_app Show documentation
XWorker app model liberary.
The newest version!
package xworker.manong;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import org.xmeta.Thing;
import org.xmeta.World;
import xworker.lang.util.UtilTemplate;
import xworker.lang.util.XWorkerUtils;
public class MaNongJavaScriptFunction extends BrowserFunction{
public MaNongJavaScriptFunction(Browser browser, String name) {
super(browser, name);
}
@Override
public Object function(Object[] arguments) {
String action = arguments[0].toString();
String projectId = arguments[1].toString();
if("check".equals(action)){
String majorVersionStr = arguments[2].toString();
String minorVersionStr = arguments[3].toString();
int majorVersion = Integer.parseInt(majorVersionStr);
int minorVersion = Integer.parseInt(minorVersionStr);
Map context = new HashMap();
context.put("projectId", projectId);
context.put("majorVersion", String .valueOf(majorVersion));
context.put("minorVersion", String.valueOf(minorVersionStr));
context.put("arguments", arguments);
Thing project = World.getInstance().getThing(projectId);
if(project != null){
context.put("project", project);
project = project.getRoot();
putLinks(project, context);
//理论上服务器上的版本应该总是最新的
if(project.getInt("majorVersion") != majorVersion || project.getInt("minorVersion") != minorVersion){
context.put("command", "update");
}else{
context.put("command", "noupdate");
}
}else{
context.put("command", "download");
}
try {
String html = UtilTemplate.process(context, "/xworker/manong/web/project_link.ftl", "freemarker");
//System.out.println(html);
return html;
} catch (Throwable e) {
e.printStackTrace();
return "";
}
}else if("download".equals(action)){
//到根项目
int index = projectId.indexOf("/@");
if(index >= 0){
projectId = projectId.substring(0, index);
}
MaNongClient.download(projectId);
return "版本已是最新";
}else if("links".equals(action)){
Thing project = World.getInstance().getThing(projectId);
Map context = new HashMap();
context.put("projectId", projectId);
context.put("historygo", "true");
if(project != null){
context.put("majorVersion", project.getString("majorVersion"));
context.put("minorVersion", project.getString("minorVersionStr"));
context.put("arguments", arguments);
context.put("project", project);
project = project.getRoot();
putLinks(project, context);
context.put("command", "noupdate");
}else{
String args[] = new String[6];
args[4] = "functions";
args[5] = projectId;
context.put("arguments", args);
context.put("majorVersion", "0");
context.put("minorVersion", "0");
context.put("command", "download");
}
try {
String html = UtilTemplate.process(context, "/xworker/manong/web/project_link.ftl", "freemarker");
//System.out.println(html);
return html;
} catch (Throwable e) {
e.printStackTrace();
return "";
}
}else{
return "未知的命令";
}
}
public static void putLinks(Thing project, Map context){
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy