package com.wb.interact;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;
import org.json.JSONArray;
import org.json.JSONObject;
import com.wb.common.Base;
import com.wb.common.UrlBuffer;
import com.wb.common.Var;
import com.wb.tool.Console;
import com.wb.tool.QueueWriter;
import com.wb.tool.ScriptCompressor;
import com.wb.util.DateUtil;
import com.wb.util.FileUtil;
import com.wb.util.JsonUtil;
import com.wb.util.SortUtil;
import com.wb.util.StringUtil;
import com.wb.util.SysUtil;
import com.wb.util.WebUtil;
/**
* 集成开发环境后台部分应用。
*/
public class IDE {
/** 常用的图片文件类型 */
private static final String imageTypes[] = { "gif", "jpg", "png", "bmp" };
/**
* 获取模块或文件的列表。
*
* @param request 请求对象。
* @param response 响应对象。
* @throws Exception 获取过程中发生异常。
*/
public static void getList(HttpServletRequest request,
HttpServletResponse response) throws Exception {
if ("root".equals(request.getParameter("node")))
getBaseList(request, response);
else {
if ("module".equals(request.getParameter("type")))
getModuleList(request, response);
else
getFileList(request, response);
}
}
/**
* 获取文件树的文件节点列表。
*
* @param request 请求对象。
* @param response 响应对象。
* @throws Exception 获取过程中发生异常。
*/
private static void getFileList(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String path = request.getParameter("path"), type = request
.getParameter("type"), fileDir;
JSONArray fileArray = new JSONArray();
JSONObject fileObject;
File base, files[];
if (StringUtil.isEmpty(path)) {
checkFilePerm(null);
base = null;
files = File.listRoots();
} else {
base = new File(path);
checkFilePerm(base);
files = base.listFiles();
}
SortUtil.sort(files);
for (File file : files) {
fileDir = FileUtil.getPath(file);
if ("app".equals(type) && file.equals(Base.modulePath)
|| "file".equals(type) && file.equals(Base.path))
continue;
fileObject = new JSONObject();
fileObject.put("text", StringUtil.select(file.getName(), fileDir));
if (file.isDirectory()) {
if (FileUtil.isEmpty(file))
fileObject.put("children", new JSONArray());
} else {
fileObject.put("leaf", true);
fileObject.put("icon", "m?xwl=dev/ide/get-file-icon&file="
+ WebUtil.encode(fileDir));
}
fileObject.put("size", file.length());
fileArray.put(fileObject);
}
WebUtil.send(response, new JSONObject().put("children", fileArray));
}
/**
* 获取文件树的模块节点列表。
*
* @throws Exception 获取过程中发生异常。
*/
private static void getModuleList(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String path = request.getParameter("path"), icon, iconCls, fileName;
File file, base;
ArrayList<Entry<String, Integer>> fileNames;
JSONObject content, fileObject;
JSONArray fileArray;
boolean isFolder, hidden;
base = new File(path);
if (!FileUtil.isAncestor(Base.path, base))
SysUtil.accessDenied();
fileNames = getSortedFile(base);
fileArray = new JSONArray();
for (Entry<String, Integer> entry : fileNames) {
fileName = entry.getKey();
if ("folder.json".equalsIgnoreCase(fileName))
continue;
file = new File(base, fileName);
if (!file.exists())
continue;
isFolder = file.isDirectory();
content = null;
if (isFolder) {
File configFile = new File(file, "folder.json");
if (configFile.exists())
content = JsonUtil.readObject(configFile);
} else if (fileName.endsWith(".xwl"))
content = JsonUtil.readObject(file);
if (content == null) {
content = new JSONObject();
if (!isFolder) {
// 其他类型的文件
content.put("icon", "m?xwl=dev/ide/get-file-icon&file="
+ WebUtil.encode(FileUtil.getPath(file)));
}
}
fileObject = new JSONObject();
fileObject.put("text", fileName);
fileObject.put("title", content.optString("title"));
hidden = Boolean.TRUE.equals(content.opt("hidden"));
fileObject.put("hidden", hidden);
if (hidden)
fileObject.put("cls", "x-highlight");// 隐藏的节点高亮显示
fileObject.put("inframe", Boolean.TRUE.equals(content
.opt("inframe")));
fileObject.put("pageLink", content.optString("pageLink"));
iconCls = content.optString("iconCls");
if (!StringUtil.isEmpty(iconCls))
fileObject.put("iconCls", iconCls);
// icon用于非xwl文件
icon = content.optString("icon");
if (!StringUtil.isEmpty(icon))
fileObject.put("icon", icon);
if (isFolder) {
if (!hasChildren(file))
fileObject.put("children", new JSONArray());
} else {
fileObject.put("leaf", true);
}
fileArray.put(fileObject);
}
WebUtil.send(response, new JSONObject().put("children", fileArray));
}
/**
* 获取文件树的根节点列表。
*
* @param request 请求对象。
* @param response 响应对象。
* @throws Exception 获取过程中发生异常。
*/
private static void getBaseList(HttpServletRequest request,
HttpServletResponse response) throws Exception {
JSONArray list = new JSONArray();
JSONObject node = new JSONObject();
String sysFolderBase = Var.getString("sys.ide.sysFolderBase");
node.put("text", "模块");
node.put("iconCls", "module_icon");
node.put("expanded", true);
node.put("base", FileUtil.getPath(Base.modulePath) + '/');
node.put("type", "module");
list.put(node);
node = new JSONObject();
node.put("text", "应用");
node.put("iconCls", "application_icon");
node.put("base", FileUtil.getPath(Base.path) + '/');
node.put("type", "app");
list.put(node);
if (!sysFolderBase.equals("app")) {
node = new JSONObject();
node.put("text", "系统");
node.put("iconCls", "system_icon");
if (sysFolderBase.equals("server"))
sysFolderBase = FileUtil.getPath(Base.path.getParentFile()
.getParent()) + '/';
else
sysFolderBase = ""; // root
node.put("base", sysFolderBase);
node.put("type", "file");
list.put(node);
}
WebUtil.send(response, list);
}
/**
* 设置文件或模块的属性。
*
* @param request 请求对象。
* @param response 响应对象。
* @throws Exception 设置过程中发生异常。
*/
public static void setProperty(HttpServletRequest request,
HttpServletResponse response) throws Exception {
JSONObject map = WebUtil.fetch(request), result;
File indexFile, configFile = null, newFile, oldFile = new File(map
.getString("path"));
String url = map.optString("url"), oldName = oldFile.getName(), newName = map
.getString("text");
boolean nameModified = !oldName.equals(newName), indexFileExists;
boolean isModule, isDir, needConfig, urlValid = map
.optBoolean("urlValid");
JSONObject indexContent = null, content;
isDir = oldFile.isDirectory();
if (urlValid && !UrlBuffer.exists(url, oldFile))
throw new IllegalArgumentException("URL捷径 \"" + url + "\" 已经存在。");
if (nameModified)
newFile = new File(oldFile.getParent(), newName);
else
newFile = oldFile;
if (nameModified)
FileUtil.syncRename(oldFile, newFile);
indexFile = new File(
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
WebBuilder是一款开源的可视化Web应用开发和运行平台。基于浏览器的集成开发环境,可视化和智能化的设计,能轻松完成常规应用和面向手机的移动应用开发;高效、稳定和可扩展的特点,适合复杂企业级应用的运行;跨平台、数据库和浏览器的架构,适应复杂的服务器和客户端环境;包含多项先进技术,使应用系统的开发更快捷和简单。
资源推荐
资源详情
资源评论
收起资源包目录
Java Web快速开发平台 WebBuilder 7 (2294个子文件)
ext-theme-neptune-all-rtl-debug.css 780KB
ext-theme-neptune-all-debug.css 724KB
tizen-debug.css 722KB
ext-theme-classic-all-rtl-debug.css 698KB
ext-theme-gray-all-rtl-debug.css 689KB
ext-theme-classic-all-debug.css 642KB
ext-theme-gray-all-debug.css 634KB
tizen.css 566KB
bb103-debug.css 452KB
sencha-touch-debug.css 425KB
bb10-debug.css 382KB
ext-theme-neptune-all-rtl.css 350KB
wp-debug.css 346KB
cupertino-classic-debug.css 345KB
bb103.css 326KB
base-debug.css 321KB
cupertino-debug.css 318KB
ext-theme-neptune-all.css 318KB
ext-theme-classic-all-rtl.css 306KB
ext-theme-gray-all-rtl.css 296KB
mountainview-debug.css 291KB
apple-debug.css 282KB
ext-theme-classic-all.css 273KB
ext-theme-gray-all.css 264KB
sencha-touch.css 252KB
bb10.css 247KB
base.css 234KB
cupertino-classic.css 209KB
wp.css 201KB
cupertino.css 187KB
apple.css 182KB
mountainview.css 171KB
bootstrap-debug.css 144KB
bootstrap.css 120KB
style-debug.css 27KB
font-awesome-debug.css 26KB
bootstrap-theme-debug.css 26KB
style.css 24KB
bootstrap-theme.css 23KB
font-awesome.css 21KB
cmirror-debug.css 19KB
cmirror.css 15KB
GroupTabPanel.css 4KB
statusbar.css 3KB
ide-debug.css 2KB
ide.css 2KB
ItemSelector.css 629B
TabScrollerMenu.css 408B
RangeMenu.css 382B
GridFilters.css 189B
LiveSearchGridPanel.css 77B
DragSelector.css 76B
fontawesome-webfont.eot 55KB
glyphicons-halflings-regular.eot 20KB
ide.gif 44KB
focus.gif 15KB
login.gif 8KB
tool-sprites.gif 6KB
tool-sprites.gif 5KB
btn.gif 4KB
error-tip-corners.gif 4KB
error-tip-corners.gif 4KB
html5.gif 4KB
wb.gif 4KB
java.gif 3KB
btn.gif 3KB
blue-loading.gif 3KB
large-loading.gif 3KB
large-loading.gif 3KB
loading.gif 3KB
blue-loading.gif 3KB
tools-sprites-trans.gif 3KB
sort-hd.gif 3KB
group-cs.gif 2KB
group-cs.gif 2KB
saving.gif 2KB
search-trigger-rtl.gif 2KB
search-trigger.gif 2KB
search-trigger-rtl.gif 2KB
search-trigger.gif 2KB
loading-balls.gif 2KB
loading-balls.gif 2KB
file_ppt.gif 2KB
file_doc.gif 2KB
file_xls.gif 2KB
love.gif 2KB
star.gif 2KB
tb-sprite.gif 2KB
tb-sprite.gif 2KB
checkbox.gif 2KB
checkbox.gif 2KB
series.gif 2KB
clear-trigger.gif 2KB
tools-sprites-trans.gif 2KB
spinner-rtl.gif 2KB
spinner.gif 2KB
spinner.gif 2KB
spinner-rtl.gif 2KB
ellipsis-trigger-rtl.gif 2KB
ellipsis-trigger-rtl.gif 2KB
共 2294 条
- 1
- 2
- 3
- 4
- 5
- 6
- 23
资源评论
快速开发平台
- 粉丝: 30
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功