//有edit权限 查出来 却为false1
2
3Login login = ActionFunc.getLogin(req);
PmChecker pChecker = login.getPmChecker();
Boolean edit = pChecker.check(ztj_id, ResOper.EDIT.getOperId());
Boolean view = pChecker.check(ztj_id, ResOper.VIEW.getOperId());
Boolean viewchild = pChecker.check(ztj_id, ResOper.VIEWCHILD.getOperId());
Boolean mana=pChecker.check(ztj_id, ResOper.MANAGE.getOperId());
Boolean authorize=pChecker.check(ztj_id, ResOper.AUTHORIZE.getOperId());
Boolean denyauthorize=pChecker.check(ztj_id, ResOper.AUTHORIZE.getOperId());
Boolean edit = pChecker.check(ztj_id, ResOper.EDIT.getOperId());
Boolean add = pChecker.check(ztj_id, ResOper.ADD.getOperId());
Boolean del = pChecker.check(ztj_id, ResOper.DELETE.getOperId());
应用1:完全控制 应用2.查看 编辑 应用3.查看
{“id”:”EBI$7$CYKR67IYIOPZK2ZYYYWM99YRL3YOFZY1”,”name”:”应用1”,”view”:true,”viewchild”:true,”mana”:true,”authorize”:true,”denyauthorize”:true,”del”:true,”add”:true,”edit”:true}
{“id”:”EBI$7$I6KIN7LRVSA7MU76AUZYIU9UEL69RC5M”,”name”:”应用2”,”view”:true,”viewchild”:true,”mana”:false,”authorize”:false,”denyauthorize”:false,”del”:false,”add”:false,”edit”:false}
{“id”:”EBI$7$3FCTFME0ELSPQFPFQQULWIIOLXFLATIY”,”name”:”应用3”,”view”:true,”viewchild”:true,”mana”:false,”authorize”:false,”denyauthorize”:false,”del”:false,”add”:false,”edit”:false}
package com.esen.bi.jsp.action.user.rptcooldsn;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.esen.bi.dw.meta.DWMgr;
import com.esen.bi.dw.meta.DWSubjectSet;
import com.esen.bi.jsp.action.user.fact.ActionTaskMgr;
import com.esen.bi.jsp.util.ActionFunc4BI;
import com.esen.bi.reportcool.base.CWidgetUtil;
import com.esen.bi.reportcool.base.cwidget.CWHtmlContentMgr;
import com.esen.bi.reportcool.syshtml.CWidgetHtmlConfCache;
import com.esen.bi.reportcool.syshtml.CoolSysWidgetMgr;
import com.esen.bi.server.ClusterMgrBI;
import com.esen.exception.Exception4I18N;
import com.esen.irpt.login.Login4BI;
import com.esen.irpt.security3.PermissionChecker;
import com.esen.irpt.server.ResourceId4BI;
import com.esen.irpt.server.ResourceIdTypes;
import com.esen.irpt.server.Server;
import com.esen.platform.action.util.ActionFunc;
import com.esen.platform.login.Login;
import com.esen.platform.resource.ReleasableObj;
import com.esen.platform.resource.ResOper;
import com.esen.platform.resource.ResourceId;
import com.esen.platform.security.PmChecker;
import com.esen.platform.security.PmCheckerFactory;
import com.esen.platform.server.EsenServer;
import com.esen.util.ArrayFunc;
import com.esen.util.ExceptionHandler;
import com.esen.util.FileFunc;
import com.esen.util.StrFunc;
import com.esen.util.XmlFunc;
import com.esen.util.cluster.ClusterMessage;
import com.esen.util.cluster.ClusterMessageFactory;
import com.esen.util.i18n.I18N;
import com.esen.util.tmpfile.DefaultTempFileFactory;
import com.esen.vfs2.Vfs2;
import com.esen.vfs2.VfsException;
import com.esen.vfs2.VfsFile2;
import com.esen.weblib.ClientResult;
import com.esen.weblib.action.Action_Js;
import com.esen.weblib.download.HttpDownloadCacher;
import com.esen.weblib.upload.HttpServletRequestEx;
import com.esen.weblib.util.ServletFunc;
import com.esen.zip.ZipEntry;
import com.esen.zip.ZipOutputStream;
import com.google.gson.JsonObject;
/**
- 此类负责,HTML组件的管理,增删改查等操作
* - 接口说明: 调用方式如:edithtmlwidget.do?action=xxx
* - @author zqj
@date 2017.12.13
*/
@Controller
@RequestMapping(“/edithtmlwidget”)
public class ActionEditHtmlWidget extends Action_Js {/**
html组件的编辑界面
*/
private static final String HTMLEDITOR = “/ebi/user/coolrptdsn/htmlwidgeteditor/chtmleditor”;/**
- html组件的预览界面
*/
private static final String HTMLSHOW = “/ebi/user/coolrptdsn/htmlwidgeteditor/htmlwidgetshow/chtmlshow”;
private static final String HTMLSHOWFORSAVE = “/ebi/user/coolrptdsn/htmlwidgeteditor/htmlwidgetshow/chtmlshowforsave”;
/** 编辑界面工具栏存放的位置
*/
private static final String UICONFIG_PATH_PRE = “ebi/user/coolrptdsn/htmlwidgeteditor/“;private static final String SYSWIDGETDIR = CWidgetUtil.SYSWIDGETDIR;
private static final String USERWIDGETDIR = CWidgetUtil.USERWIDGETDIR;
private static final String PREVIEWPAGE = “coolwidgetimg”;private static final String CONF_PROP_ID = CWidgetUtil.CONF_PROP_ID;
private static final String CONF_PROP_CAP = “caption”;
private static final String CONF_PROP_IMG = “img”;
/**- 存属性列表的标签名
*/
private static final String CONF_PROP_COMMATTR = “comattr”;
/** 属性中的默认值标签名
*/
private static final String CONF_PROP_NAME = “name”;
private static final String CONF_PROP_DEFATTR = “defattr”;@Override
public String jsexecute(HttpServletRequest req, HttpServletResponse res,ClientResult result) throws Exception {
// 检查是否登录
Login4BI login = ActionFunc4BI.getLogin(req);
login.checkLogined();// 参数
String action = req.getParameter(“action”);
try {if (StrFunc.isNull(action) || "showeditpage".equalsIgnoreCase(action)) { // 跳转到组件编辑界面的ftl return showEditPage(req, res); } else if ("showpreviewpage".equalsIgnoreCase(action)) { // 跳转到组件预览界面的ftl return showPreviewPage(req, res); } else if ("getwidgetjson".equalsIgnoreCase(action)) { // 获得组件的json格式 getWidgetJson(req, result); } else if ("savewidget".equalsIgnoreCase(action)) { // 保存组件 saveWidget(req, result); } else if ("deletewidget".equalsIgnoreCase(action)) { // 删除组件 deleteWidget(req, result); } else if ("clonewidget".equalsIgnoreCase(action)) { // 克隆组件 cloneWidget(req, result); } else if ("exportwidget".equalsIgnoreCase(action)) { export(req, res, result); } else if ("refreshsys".equalsIgnoreCase(action)) { refreshSysHtml(req, result); } else if ("import".equalsIgnoreCase(action)) { HttpServletRequestEx hsr = new HttpServletRequestEx(req); importZip(res, req, result, hsr); } else if ("newfolder".equalsIgnoreCase(action)) { // 新建分组 newFolder(req, result); } else if ("delfolder".equalsIgnoreCase(action)) { // 删除分组 deleteFolder(req, result); } else if ("renamefolder".equalsIgnoreCase(action)) { // 重命名分组 renameFolder(req, result); } else if ("renamewidget".equalsIgnoreCase(action)) { // 重命名组件 renameWidget(req, result); } else if ("list".equalsIgnoreCase(action)) { // 罗列分组下的分组和组件列表 doList(req, result); } else if ("showpreviewpageForSave".equalsIgnoreCase(action)) { // 跳转到组件预览界面的ftl return showPreviewPageForSave(req, res); } else if ("reload".equalsIgnoreCase(action)) { // 重新加载酷屏HTML组件缓存(移除额外的分组配置缓存、移除HTML组件JSON缓存) this.reload(req); } else if ("delSeletes".equalsIgnoreCase(action)) { // 删除选中的组件和分组 delSeletes(req, result); } else if ("moveTo".equalsIgnoreCase(action)) { // 移动选中的组件和分组 moveTo(req, result); } else if ("getRoles".equalsIgnoreCase(action)){ getRoles(req, res, result); }
} catch (Exception ex) {
ExceptionHandler.rethrowRuntimeException(ex);
}
return null;
}/**
- 移动到指定分组
* - @param req
- @param result
- @throws Exception4I18N
@throws DOMException
*/
private void moveTo(HttpServletRequest req, ClientResult result)throws DOMException, Exception4I18N {
String basepath = req.getParameter(“basepath”);
String floderName = req.getParameter(“aimdir”);
String ids = req.getParameter(“ids”);
String items[] = ids.split(“,”);
ListwidgetList = filterRepetition(items, false); // 对路径做处理
String groups[] = floderName.split(“/“);
ListnewGroups = new ArrayList ();
for (int i = 0, len = groups.length; i < len; i++) {if (!StrFunc.isNull(groups[i])) newGroups.add(groups[i]);
}
if (newGroups.size() != 0) {floderName = StrFunc.ensureStartWith( ArrayFunc.list2Str(newGroups, "/"), "/");
} else {
floderName = "/";
}
// CWidgetUtil.getWidgetConfCache(basepath.substring(0,basepath.lastIndexOf(“/“))).moveTo(floderName,
// widgetList);
CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))).moveTo( floderName, widgetList, basepath);
result.getWriter().write(“ok”);
}/**
- 删除选中的组件和分组
* - @param req
- @param result
@throws Exception
*/
private void delSeletes(HttpServletRequest req, ClientResult result)throws Exception {
// 用户自定义分组,删除自己和下面所有的分组和文件
String path = req.getParameter(“path”);
String basepath = req.getParameter(“basepath”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
String paths[] = path.split(“,”);
ListwidgetAndFloderPaths = filterRepetition(paths, false);
// 存放删除组件的信息的JSONArray对象,用于修改xml
JSONArray array = new JSONArray();
JSONObject json;
boolean isGroup = false;
String delPath;
for (int i = 0, len = widgetAndFloderPaths.size(); i < len; i++) {String name = FileFunc.extractFileName(widgetAndFloderPaths.get(i)); // 单个组件直接删除 if (widgetAndFloderPaths.get(i).endsWith(".json")) { name = FileFunc.excludeFileExt(name); // 删除缓存和vfs文件 delPath = widgetAndFloderPaths.get(i); } else { isGroup = true; // 分组的话要拿到所有组件和分组节点删除,返回所有组件的id delPath = widgetAndFloderPaths.get(i).substring(0, widgetAndFloderPaths.get(i).lastIndexOf("/")); } json = new JSONObject(); json.put("isGroup", isGroup); json.put("name", name); json.put("path", delPath); array.put(json); isGroup = false;
}
// 删除缓存,然后拿到返回的id,删除vfs上的资源
ListallWidgets = CWidgetUtil.getWidgetConfCache( basepath.substring(0, basepath.lastIndexOf("/"))).delSelets( array);
if (allWidgets != null && allWidgets.size() != 0) {
for (int j = 0; j < allWidgets.size(); j++) { CWHtmlContentMgr.getInstance().delete(basepath, allWidgets.get(j)); }
}
if (allWidgets.size() != 0) {
deletePreviewImg(basepath, allWidgets.toArray(new String[0])); // 把删除的组件id串传给前台 result.getWriter().write(ArrayFunc.list2Str(allWidgets, ","));
} else {
result.getWriter().write("ok");
}
}/*
重新加载
*/
private void reload(HttpServletRequest req) {
// 移除酷屏HTML组件JSON缓存
CWHtmlContentMgr.getInstance().clear();
// 移除酷屏HTML组件自定义分组配置缓存
String basePath = req.getParameter(“basepath”);
basePath = StrFunc.ensureNotEndWith(basePath, “/“);
if (!StrFunc.isNull(basePath)) {CWidgetHtmlConfCache widgetConfCache = CWidgetUtil .getWidgetConfCache(basePath); if (widgetConfCache != null) { widgetConfCache.reload(); }
}
this.doCluster_sync_reload(basePath);
}/*
集群下发送清除全部HTML组件缓存-重新加载(刷新)消息
*/
private void doCluster_sync_reload(String basePath) {
if (!EsenServer.isCluster()) {return;
}
String vfsFilePath = basePath;
String resourceId = ResourceId4BI.BI_MODULEID+ ResourceId4BI.DEFAULT_DELIMETER + ResourceIdTypes.RES_VFS_FILE + ResourceId4BI.DEFAULT_DELIMETER + vfsFilePath;
ClusterMessageFactory clusterMessageFactory = ClusterMgrBI
.getBiMessageFactory();
ClusterMessage csMsg = clusterMessageFactory.createClusterSyncMessage(
ReleasableObj.RES_OPER_EDIT, resourceId, vfsFilePath, "COOLWIDGETHTML_CACHE_RELOAD", basePath);
ClusterMgrBI.getBiMessageSender().sendMessage(csMsg);
}private String showPreviewPageForSave(HttpServletRequest req,
HttpServletResponse res) throws UnsupportedEncodingException {
String path = req.getParameter(“path”);
/*- String content = null; VfsFile2 file = EsenServer.getVfsFile(path);
- if (file.exists()) { content = file.getAsString().trim(); }
*/
Object obj = HttpDownloadCacher.getInstance().getObj(path);
HttpDownloadCacher.getInstance().removeCacheObj(path);
req.setAttribute(“json”, obj.toString());
req.setCharacterEncoding(“utf-8”);
return HTMLSHOWFORSAVE;
}
/**
- 获取conf.xml文件的内容返回给前台
* - @param req
- @param result
@throws Exception
*/
private void doList(HttpServletRequest req, ClientResult result)throws Exception {
String path = req.getParameter(“path”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
Document doc = null;
if (path.endsWith(USERWIDGETDIR)) {CWidgetHtmlConfCache cache = CWidgetUtil.getWidgetConfCache(path .substring(0, path.lastIndexOf("/"))); doc = cache.getConfDocument();
} else {
VfsFile2 vfs = EsenServer.getVfsFile(path + "/conf.xml"); if (vfs.exists()) { doc = vfs.getAsXml(); }
}
if (doc == null) {throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.lackdoc", "配置文件被删除!");
}
result.setContentType(“text/xml; charset=UTF-8”);
XmlFunc.saveDocument(doc, result.getOutputStream(), StrFunc.UTF8);
}/**
- 新建分组
* - @param req
- @param result
@throws Exception
*/
private void newFolder(HttpServletRequest req, ClientResult result)throws Exception {
String folderPath = req.getParameter(“path”);
String name = req.getParameter(“name”);
if (!CWidgetUtil.getWidgetConfCache(folderPath.substring(0, folderPath.lastIndexOf(USERWIDGETDIR) - 1)).checkName( folderPath, name)) { throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.exists", "分组已经存在!");
}
CWidgetUtil.getWidgetConfCache(folderPath.substring(0, folderPath.lastIndexOf(USERWIDGETDIR) - 1)).newFolder( folderPath, name);
result.getWriter().write(“ok”);
}/**
- 删除分组
* - @param req
- @param result
@throws Exception
*/
private void deleteFolder(HttpServletRequest req, ClientResult result)throws Exception {
// 用户自定义分组,删除自己和下面所有的分组和文件
String path = req.getParameter(“path”);
String basepath = req.getParameter(“basepath”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
String name = path.substring(path.lastIndexOf(“/“) + 1, path.length());
String parentPath = path.substring(0, path.lastIndexOf(“/“));
Listwidgets = CWidgetUtil.getWidgetConfCache( basepath.substring(0, basepath.lastIndexOf("/"))).deleteFolder( name, parentPath);
if (widgets != null && widgets.size() != 0) {
for (int i = 0; i < widgets.size(); i++) { String widget = basepath + "/" + widgets.get(i) + ".json"; VfsFile2 file = EsenServer.getVfsFile(widget); file.remove(); } // 如果该分组下有组件,就删除组件的预览图 if (!widgets.isEmpty()) { deletePreviewImg(basepath, widgets.toArray(new String[0])); } // 把删除的组件id串传给前台 result.getWriter().write(ArrayFunc.list2Str(widgets, ","));
} else {
result.getWriter().write("ok");
}
}/**
- 重命名分组
* - @param req
- @param result
@throws Exception
*/
private void renameFolder(HttpServletRequest req, ClientResult result)throws Exception {
// 用户自定义分组,重命名分组需要vfs修改文件名字
String path = req.getParameter(“path”);
String srcName = path.substring(path.lastIndexOf(“/“) + 1);
String parPath = path.substring(0, path.lastIndexOf(“/“));
String newname = req.getParameter(“name”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
if (!CWidgetUtil.getWidgetConfCache(
path.substring(0, path.lastIndexOf(USERWIDGETDIR) - 1)) .checkName(parPath, newname)) { throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.exists", "分组已经存在!");
}
CWidgetUtil.getWidgetConfCache(path.substring(0, path.lastIndexOf(USERWIDGETDIR) - 1)) .renameFolder(srcName, newname, parPath);
result.getWriter().write(“ok”);
}/**
- 重命名组件 name=新的名字
- path=/root/products/ebi/sys/coolrpt/cooluserwidget/其他组件123
- /CHtmlWidgetSLZJBT.json
* - @param req
- @param result
@throws Exception
*/
private void renameWidget(HttpServletRequest req, ClientResult result)throws Exception {
// 自定义组件重命名
String path = req.getParameter(“path”);
String newname = req.getParameter(“name”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
String basepath = path.substring(0, path.lastIndexOf(USERWIDGETDIR))+ USERWIDGETDIR;
// 组件cap判断
if (CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))) .checkWidgetByCap(newname, null)) { throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.widgetexists", "组件名已经存在,请重新命名!");
}
VfsFile2 file = EsenServer.getVfsFile(basepath
+ path.substring(path.lastIndexOf("/")));
if (!file.exists()) {
throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.noexists", "选中的组件已经被删除!");
}
JSONObject obj = new JSONObject(file.getAsString().trim());
alterOnCaptionChange(obj, newname);
file.saveAsString(obj.toString(4), StrFunc.UTF8);
CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))) .renameWidget( path, newname, path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")));
result.getWriter().write(“ok”);
}/**
- 当组件重命名或克隆后,需要更新json文件中的caption属性,和标题属性的默认值
* - @param fileobj
- @param newCaptoin
@throws JSONException
*/
private void alterOnCaptionChange(JSONObject fileobj, String newCaptoin)throws JSONException {
fileobj.put(CONF_PROP_CAP, newCaptoin);
// 当更新了组件的标题时,
JSONArray attrs = fileobj.optJSONArray(CONF_PROP_COMMATTR);
// 组件的第2个属性是标题属性
JSONObject capCfg = attrs.getJSONObject(1);
if (CONF_PROP_CAP.equalsIgnoreCase(capCfg.optString(CONF_PROP_NAME))) {capCfg.put(CONF_PROP_DEFATTR, newCaptoin);
}
}/**
- 导入zip文件 zip文件中可能存在多个html组件
* - @param hsr
- @param result
- @param req
- @param res
@throws Exception
/
private void importZip(HttpServletResponse res, HttpServletRequest req,ClientResult result, HttpServletRequestEx hsr) throws Exception {
String path = req.getParameter(“path”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackbasepath", "参数basepath没有指定");
}
path = StrFunc.decoding2UTF8(path);
FileItem item = hsr.getFiles()[0];
String tempfile = null;
InputStream in = item.getInputStream();
try {tempfile = FileFunc.stm2Tempfile(in, null);
} finally {
in.close(); // 导入后删除 item.delete();
}
Map<String, String> map = getWidgetOrFloder(req, tempfile, path);
if (map.size() != 0) {JSONObject obj = new JSONObject(map); res.getWriter().print(obj);
} else {
result.getWriter().write("ok");
}
}/**
- 导入html组件
* - @param req
- @param files
- @param path
- @param map
- @param previewMap
- @param importMap
@throws Exception
*/
private void importWidget(HttpServletRequest req, File file, String path,Map<String, String> map, Map<String, File> previewMap, Map<String, JSONObject> importMap) throws Exception {
String filePath = file.getAbsolutePath();
String fileName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
String widgetId = FileFunc.excludeFileExt(fileName);
String basePath = path.substring(0, path.lastIndexOf(USERWIDGETDIR))+ USERWIDGETDIR;
VfsFile2 vfsfile = EsenServer.getVfsFile(basePath);
JSONObject jsonfile;
InputStream in = new FileInputStream(file);// 获取路径中的有效路径
String effectivePath = getWidgetDir(filePath);
// 记录json内容
String content;
try {// 如果存在且覆盖,那么直接覆盖文件即可 boolean isCover = checkName(req, fileName); if (isCover) { vfsfile.importStm(in, fileName); content = EsenServer.getVfsFile(basePath + "/" + fileName) .getAsString().trim(); jsonfile = new JSONObject(content); importPreview(widgetId, null, previewMap, basePath); } else { // id不唯一时,证明对应的.json文件已经存在 String oldId = widgetId; if (!isUniqueId(basePath, widgetId)) { widgetId = getNewHtmlId(basePath); fileName = widgetId + ".json"; } vfsfile.importStm(in, fileName); // 获取该html组件的caption content = EsenServer.getVfsFile(basePath + "/" + fileName) .getAsString().trim(); jsonfile = new JSONObject(content); jsonfile.put(CONF_PROP_ID, widgetId); importPreview(oldId, widgetId, previewMap, basePath); } path = path + "/" + effectivePath; String caption = jsonfile.getString("caption"); // 判断是否存在同分组重名组件,存在就重命名改组件 if (!isCover) { CWidgetHtmlConfCache confCache = CWidgetUtil .getWidgetConfCache(basePath.substring(0, basePath.lastIndexOf("/"))); while (confCache.checkWidgetByCap(caption, null)) { caption = caption + (int) (Math.random() * 1000); } jsonfile.put(CONF_PROP_CAP, caption); content = jsonfile.toString(); } map.put(widgetId, content); importMap.put(path, jsonfile); // 更新组件缓存 CWHtmlContentMgr.getInstance().put(basePath, widgetId, jsonfile);
} finally {
in.close();
}
}/**
- 导出预览图
* - @param basePath
- @param list
- @param zipout
- @throws IOException
@throws VfsException
*/
private void exportPreview(ZipOutputStream zipout, Listlist, String basePath) throws VfsException, IOException {
if (list.size() == 0)
return;
String widgetName; // 组件id
String imgPath; // 预览图在vfs中的路径
VfsFile2 imgFile; // 预览图的vfs文件
String fileName; // 导出的文件名for (int i = 0; i < list.size(); i++) {
widgetName = FileFunc.excludeFileExt(list.get(i)); if (widgetName.contains("/")) { widgetName = FileFunc.extractFileName(widgetName); } imgPath = basePath.substring(0, basePath.lastIndexOf("/") + 1) + PREVIEWPAGE + "/" + widgetName + ".png"; imgFile = EsenServer.getVfsFile(imgPath); fileName = PREVIEWPAGE + "/" + widgetName + ".png"; if (imgFile.exists()) { zipout.putNextEntry(new ZipEntry(fileName)); zipout.write(imgFile.getAsBytes()); }
}
}/**
- 导入预览图
* - @param previewMap
- @param newId
- @param oldId
- @param basePath
@throws IOException
*/
private void importPreview(String oldId, String newId,Map<String, File> previewMap, String basePath) throws IOException {
if (previewMap.size() == 0)
return;
String id = oldId;
if (!StrFunc.isNull(newId)) {id = newId;
}
File file = previewMap.get(oldId);
if (file == null)return;
InputStream in = new FileInputStream(file);
String path = basePath.substring(0, basePath.lastIndexOf(“/“) + 1)+ PREVIEWPAGE;
VfsFile2 vfsfile = EsenServer.getVfsFile(path);
String name = id + “.png”;
try {vfsfile.importStm(in, name);
} finally {
in.close();
}
}/**
- 跟临时文件路径获取有效路径
* - @param filePath
@return
*/
private String getWidgetDir(String filePath) {
String pathArray[] = filePath.split(“importHtmlWidget_”);
String dirPath = pathArray[1].substring(pathArray[1].indexOf(File.separator) + 1);
dirPath = dirPath.replaceAll(“\\“, “/“);
return dirPath;
}/**
- 获取解压后的分组和组件,并导入文件
* - @param req
- @param tempfile
- @param path
- @return
@throws Exception
*/
private Map<String, String> getWidgetOrFloder(HttpServletRequest req,String tempfile, String path) throws Exception {
// 解压文件
File file = new File(tempfile);
String absolutePath = file.getAbsolutePath();
FileInputStream in = new FileInputStream(absolutePath);
try {String tempDir = DefaultTempFileFactory.getInstance() .createTempDir("importHtmlWidget").getAbsolutePath(); try { FileFunc.unzip(in, tempDir); // 用来存放组件的集合 List<File> widgetFiles = new ArrayList<File>(); // 用来存放预览图文件的map集合 Map<String, File> previewMap = new HashMap<String, File>(); getHtmlList(widgetFiles, previewMap, new File(tempDir)); // 用来存放组件id和组件内容的map集合 Map<String, String> map = new HashMap<String, String>(); // 用来存放所有path和json的map Map<String, JSONObject> importMap = new HashMap<String, JSONObject>(); for (int i = 0; i < widgetFiles.size(); i++) { importWidget(req, widgetFiles.get(i), path, map, previewMap, importMap); } String basePath = path.substring(0, path.lastIndexOf(USERWIDGETDIR)) + USERWIDGETDIR; // 写目录结构和组件到xml.conf文件 CWidgetUtil.getWidgetConfCache( basePath.substring(0, basePath.lastIndexOf("/"))) .importAllWidget(importMap); return map; } finally { FileFunc.remove(tempDir); }
} finally {
in.close(); FileFunc.remove(file);
}
}/**
- 遍历临时目录,获取导入的分组和组件
* - @param previewMap
- @param list
@param tempDir
*/
private void getHtmlList(Listwidgets, Map<String, File> previewMap, File file) {
if (file.isDirectory()) {
File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { getHtmlList(widgets, previewMap, files[i]); }
} else if (file.getName().endsWith(“.json”)) {
widgets.add(file);
} else if (file.getName().endsWith(“.png”)) {
String id = FileFunc.excludeFileExt(file.getName()); previewMap.put(id, file);
}
}/**
- 检查文件名字是否存在于自定义组件中,判断是否为存在且直接覆盖
* - @param req
- @param widgetId
@return
*/
private boolean checkName(HttpServletRequest req, String name) {
String path = req.getParameter(“path”);
String isCover = req.getParameter(“isCover”);
VfsFile2 vfsfile = EsenServer.getVfsFile(path.substring(0,path.lastIndexOf(USERWIDGETDIR) - 1) + "/" + USERWIDGETDIR + "/" + name);
if (vfsfile.exists() && “true”.equalsIgnoreCase(isCover)) {
return true;
}
return false;
}/**
- 导出html组件的json
* - @param req
- @param res
- @param result
- @throws Exception4I18N
@throws IOException
*/
private void export(HttpServletRequest req, HttpServletResponse res,ClientResult result) throws Exception4I18N, IOException {
String basepath = req.getParameter(“basepath”);
String items = req.getParameter(“items”);
String isMutliSelets = req.getParameter(“ismutliselets”);
String filename;
if (StrFunc.compareStrIgnoreCase(isMutliSelets, “true”) || isDir(items)) {filename = I18N .getString( "com.esen.platform.action.portal.actionportalmgr.htmlwidget", "HTML组件") + "(" + StrFunc.formatDate("yyyyMMdd_HHmmss") + ").zip";
} else {
filename = FileFunc.excludeFileExt(items) + ".zip";
}
Listids = getExportWidget(items, basepath, isMutliSelets);
if (ids.isEmpty()) {result.getWriter() .write(I18N .getString( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.noexists", "选中的组件已经被删除!"));
} else {
ServletFunc.setDownloadHeader(result.getHttpServletResponse(), null, StrFunc.UTF8, null, filename); OutputStream osm = res.getOutputStream(); ZipOutputStream zipout = new ZipOutputStream(osm); zipout.setEncoding(StrFunc.GBK); try { addToStream(zipout, ids, basepath, isMutliSelets); zipout.finish(); } finally { zipout.close(); }
}
}/**
- 将选中的组件和分组遍历出来,依次写入到压缩流中
* - @param zipout
- @param ids
- @param basePath
- @param isMutliSelets2
- @throws IOException
@throws Exception4I18N
*/
private void addToStream(ZipOutputStream zipout, Listids, String basePath, String isMutliSelets) throws IOException, Exception4I18N {
for (int i = 0, len = ids.size(); i < len; i++) {
String id = ids.get(i); zipout.putNextEntry(new ZipEntry(id)); if (id.contains("/")) { zipout.write(EsenServer.getVfsFile( basePath + id.substring(id.lastIndexOf("/"))) .getAsBytes()); } else { zipout.write(EsenServer.getVfsFile(basePath + "/" + id) .getAsBytes()); }
}
exportPreview(zipout, ids, basePath);
}/**
- 过滤掉重复的内容和单容器等不需要导出的容器
* - @param items
- @param needExtractFileName
@return
*/
private ListfilterRepetition(String[] items, boolean needExtractFileName) {
// 排序,将分组放到组件的前面
Comparator comparator = new Comparator() { public int compare(String o1, String o2) { if (isDir(o1) && !isDir(o2)) { return -1; } else if (!isDir(o1) && isDir(o2)) { return 1; } else { return 0; } }
};
Arrays.sort(items, comparator);
// 遍历是否存在包含关系的组件或分组
Listlist = Arrays.asList(items);
ListitemsList = new ArrayList (list);
for (int i = 0, len = items.length; i < len; i++) {for (int j = 0, length = items.length; j < length; j++) { if (items[i].contains(items[j]) && !StrFunc.compareStrIgnoreCase(items[i], items[j])) { itemsList.remove(items[i]); break; } }
}
if (needExtractFileName) {
// 去掉组件前面的路径,方便与目录中的组件进行比较 for (int i = 0, len = itemsList.size(); i < len; i++) { String item = itemsList.get(i); if (item.endsWith(".json") && (FileFunc.excludeFileExt(item).length() == 32 || item .startsWith("CHtmlWidget"))) { itemsList.set(i, item.substring(item.lastIndexOf("/") + 1)); } ; }
}
return itemsList;
}/**
- 获取导出的所有存在的组件的id
* - @param isMutliSelets
- @param items
@throws Exception4I18N
*/
private ListgetExportWidget(String widgets, String basePath, String isMutliSelets) throws Exception4I18N {
// 用来存放存在的组件的id
Listids = new ArrayList ();
// 判断是否是多选
if (isMutliSelets.equalsIgnoreCase(“true”)) {String items[] = widgets.split(","); // 用来存放过滤后的path List<String> widgetList = filterRepetition(items, true); String path; String fileName; for (int i = 0; i < widgetList.size(); i++) { path = widgetList.get(i); if (isDir(path) && !FileFunc.extractFileName(path).startsWith("elem_")) { ids.addAll(getExistWigByGroup(basePath, path)); } else { fileName = FileFunc.extractFileName(path); if (EsenServer.getVfsFile(basePath + "/" + fileName) .exists()) { ids.add(fileName); } } }
} else {
if (isDir(widgets)) { ids.addAll(getExistWigByGroup(basePath, widgets)); } else { if (EsenServer.getVfsFile(basePath + "/" + widgets).exists()) { ids.add(widgets); } }
}
return ids;
}/**
- 根据分组路径获取旗下存在的组件的文件名
* - @param basePath
- @param id
- @return
@throws Exception4I18N
*/
private ListgetExistWigByGroup(String basePath, String id) throws Exception4I18N {
List
list = new ArrayList ();
Listids = new ArrayList ();
if (basePath.contains(“cooluserwidget”)) {list = CWidgetUtil.getWidgetConfCache( basePath.substring(0, basePath.lastIndexOf("/"))) .listChildren(id);
} else {
list = listWidgetsBySysGroup(id, basePath);
}
String fileName;
for (int j = 0; j < list.size(); j++) {String widget = list.get(j); fileName = FileFunc.extractFileName(widget); if (EsenServer.getVfsFile(basePath + "/" + fileName).exists()) { ids.add(widget); }
}
return ids;
}/**
- 根据系统内置组件分组列出所有字节点
* - @param path
- @param basePath
@return
*/
private ListlistWidgetsBySysGroup(String path, String basePath) {
VfsFile2 vfs = EsenServer.getVfsFile(basePath + “/conf.xml”);
if (vfs.exists()) {Document doc = vfs.getAsXml(); Element parentEle = getParentEle(path, doc); List<String> list = new ArrayList<String>(); return listChildren(parentEle, parentEle.getAttribute("caption"), list);
}
return null;
}/**
- 列出给定路径的系统内置组件的文件和分组列表
* - @param parentEle
- @param caption
@param list
*/
private ListlistChildren(Element parentEle, String caption, List<String> list) {
NodeList allChild = parentEle.getChildNodes();
for (int i = 0, len = allChild.getLength(); i < len; i++) {Node node = allChild.item(i); if (node.getNodeName().equalsIgnoreCase("group")) { Element ele = (Element) node; listChildren(ele, caption + "/" + ele.getAttribute("caption"), list); } else if (node.getNodeName().equalsIgnoreCase("widget")) { Element ele = (Element) node; list.add(caption + "/" + ele.getAttribute("id") + ".json"); }
}
return list;}
/**
- 根据路径,获得父节点
* - @param path
- 路径,用于获取组件的父节点
- @param doc
@return
*/
public Element getParentEle(String path, Document doc) {
path = path.substring(path.indexOf(“coolsyswidget”));
if (path.endsWith(“.json”)) {path = path.substring(0, path.lastIndexOf("/"));
}
Element parentele = (Element) doc.getElementsByTagName(“coolsyswidget”).item(0);
String[] groups = path.split(“/“);
for (int i = 0, len = groups.length - 1; i < len; i++) {
parentele = getGroupNodeByCaption(parentele, groups[i + 1]); if (parentele == null) return null;
}
return parentele;}
/**
- 得到指定子节点
* - @param parentEle
- 父节点
- @param caption
- 目标节点的caption属性值
@return
*/
private Element getGroupNodeByCaption(Element parentEle, String caption) {
Listlist = XmlFunc.getChildElements(parentEle);
for (int i = 0, len = list.size(); i < len; i++) {Element ele = list.get(i); if (ele.getNodeName().equalsIgnoreCase("group") && ele.getAttribute("caption").equalsIgnoreCase(caption)) { return ele; }
}
return null;
}/**
- 判断是否是目录
* - @param widgetId
@return
*/
private boolean isDir(String widgetId) {
if (!widgetId.endsWith(“.json”)) {return true;
}
return false;
}/**
- 重置内置html组件
* - @param req
- @param result
@throws Exception
*/
private void refreshSysHtml(HttpServletRequest req, ClientResult result)throws Exception {
String basepath = req.getParameter(“basepath”);
if (StrFunc.isNull(basepath)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
// 移除酷屏HTML组件JSON缓存
CWHtmlContentMgr.getInstance().clear();
this.doCluster_sync_reload(basepath.substring(0,basepath.lastIndexOf("/")));
CoolSysWidgetMgr mgr = new CoolSysWidgetMgr();
Document content = null;
if (basepath.startsWith(mgr.VFS_COOL_PATH)) {// 酷屏 content = mgr.initSysHtmlForRpt(true);
} else {
// 酷屏门户 content = mgr.initSysHtmlForPortal(true);
}
result.setContentType(“text/xml; charset=UTF-8”);
XmlFunc.saveDocument(content, result.getOutputStream(), StrFunc.UTF8);
CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))).reload();
}
/**
- 编辑界面
* - @param req
- @param res
@return
*/
private String showEditPage(HttpServletRequest req, HttpServletResponse res) {// 工具栏的xml配置的路径
req.setAttribute("uiconfig", UICONFIG_PATH_PRE + I18N.getString("chtmleditor.xml", "chtmleditor_zh_CN.xml"));
// 编辑的组件的路径,新建的为空
String basepath = req.getParameter(“basepath”);
req.setAttribute(“basepath”, basepath);
// 新建的需要分组名,编辑为空
String widgetId = req.getParameter(“widgetId”);
req.setAttribute(“widgetId”, widgetId);
// if(path != null){
// VfsFile2 file = EsenServer.getVfsFile(path);
// if (file.exists()) {
// String content = file.getAsString().trim();
// req.setAttribute(“widgetjson”, content);
// }
// }
try {String path = basepath + "/" + widgetId + ".json"; String content = null; VfsFile2 file = EsenServer.getVfsFile(path); if (file.exists()) { content = file.getAsString().trim(); } req.setAttribute("widgetjson", content);
} catch (Exception e) {
ExceptionHandler .rethrowRuntimeException( e, "com.esen.bi.jsp.action.user.rptcooldsn.actionedithtmlwidget.getresultjson", "获取结果表HTML组件{0}的JSON时出现异常:{1}。", new String[] { widgetId, e.getMessage() });
}
// 是否是查看,true-查看(内置的组件);false-编辑(自定义的组件)
req.setAttribute(“isshow”, req.getParameter(“isshow”));return HTMLEDITOR;
}/**
- 预览界面
* - @param req
- @param res
@return
*/
private String showPreviewPage(HttpServletRequest req,HttpServletResponse res) {
return HTMLSHOW;
}/**
- 获得组件json格式
* - @param req
- @param result
@throws JSONException
*/
private void getWidgetJson(HttpServletRequest req, ClientResult result)throws JSONException {
String basepath = req.getParameter(“basepath”);
String widgetId = req.getParameter(“widgetId”);
String path = CWidgetUtil.findWidgetPathById(basepath, widgetId);
try {JSONObject jsonContent = CWHtmlContentMgr.getInstance().get( basepath, widgetId); if (jsonContent != null) { String content = jsonContent.toString(4); if (!StrFunc.isNull(content)) { result.getWriter().write(content); } }
} catch (Exception e) {
ExceptionHandler .rethrowRuntimeException( e, "com.esen.bi.jsp.action.user.rptcooldsn.actionedithtmlwidget.getresultjson", "获取HTML组件{0}的JSON时出现异常:{1}。", new String[] { path, e.getMessage() });
}
}/**
- 保存组件
* - @param req
- @param result
@throws Exception
*/
private void saveWidget(HttpServletRequest req, ClientResult result)throws Exception {
// 参数两种情况1:basepath与widgetId(编辑组件保存) 2.foldpath:在分组下新建或另存为
String widgetId = req.getParameter(“widgetId”);
String widgetpath = req.getParameter(“widgetpath”);
String basepath = req.getParameter(“basepath”);
String foldpath = req.getParameter(“foldpath”);
String json = req.getParameter(“definejson”);
if (StrFunc.isNull(basepath) && StrFunc.isNull(foldpath)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
JSONObject defineJson = new JSONObject(json);
if (!StrFunc.isNull(foldpath)) {
// 组件cap判断 if (CWidgetUtil .getWidgetConfCache( basepath.substring(0, basepath.lastIndexOf("/"))) .checkWidgetByCap(defineJson.getString(CONF_PROP_CAP), null)) { throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.widgetexists", "组件名已经存在,请重新命名!"); } // 是新建或另存为的组件,后台生成维一组件id // widgetId = getNewHtmlId(basepath, // defineJson.getString(CONF_PROP_CAP)); widgetId = getNewHtmlId(basepath); defineJson.put(CONF_PROP_ID, widgetId); widgetpath = foldpath + "/" + widgetId + ".json";
}
// 更新缓存,并保存组件
CWHtmlContentMgr.getInstance().put(basepath, widgetId, defineJson);
if (!StrFunc.isNull(foldpath)) {// 处理xml文件,放在保存组件后做,以防保存时出现异常,但是xml中却生成节点 CWidgetUtil.getWidgetConfCache( basepath.substring(0, basepath.lastIndexOf("/"))) .saveWidget(widgetId, defineJson.getString("caption"), "", widgetpath);
}
result.getWriter().write(widgetId);
}/**
- 组件id:CHtmlWidget+cap拼音 + 加随机数
* - @param basepath
- : basepath即组件json的保存路径
- @param cap
- @return
@throws JSONException
*/
private String getNewHtmlId(String basepath) throws JSONException {
String id = UUID.randomUUID().toString().replace(“-“, “”);
while (!isUniqueId(basepath, id)) {id = UUID.randomUUID().toString().replace("-", "");
}
return id;
}/**
- 判断id是否唯一
* - @param basepath
- @param id
- @return
@throws JSONException
*/
private boolean isUniqueId(String basepath, String id) throws JSONException {
boolean user = CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))).checkId(id);
if (!user)
return false;
VfsFile2 vfs = EsenServer.getVfsFile(basepath.substring(0,
basepath.lastIndexOf("/") + 1) + SYSWIDGETDIR + "/conf.xml");
if (vfs.exists()) {
Document doc = vfs.getAsXml(); NodeList list = doc.getElementsByTagName("widget"); for (int i = 0; i < list.getLength(); i++) { Element ele = (Element) list.item(i); if (ele.getAttribute("id").equalsIgnoreCase(id)) { return false; } }
}
return true;
}/**
- 删除组件
* - @param req
- @param result
- @throws JSONException
@throws VfsException
*/
private void deleteWidget(HttpServletRequest req, ClientResult result)throws Exception {
String id = req.getParameter(“widgetId”);
String path = req.getParameter(“path”);
String basepath = req.getParameter(“basepath”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
// 删除缓存和vfs文件
CWHtmlContentMgr.getInstance().delete(basepath, id);
CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))).deleteWidget( id, path);
// 删除预览图
deletePreviewImg(basepath, new String[] { id });
result.getWriter().write(“ok”);
}/**
- 删除组件的预览图,存在就删除
* - @param basepath
@param ids
*/
private void deletePreviewImg(String basepath, String[] ids) {
String imgPath;
VfsFile2 img;
for (int i = 0; i < ids.length; i++) {imgPath = basepath.substring(0, basepath.lastIndexOf("/") + 1) + PREVIEWPAGE + "/" + ids[i] + ".png"; img = EsenServer.getVfsFile(imgPath); if (img.exists()) { img.remove(); }
}
}/**
- 克隆组件,暂时把克隆的组件放在最下边
* - @param req
- path:被克隆组件的路径;包括分组信息的
- basepath:被克隆组件所在的位置:eg/root/products/../cooluserwidget
- caption:克隆组件的名称
- @param result
@throws Exception
*/
private void cloneWidget(HttpServletRequest req, ClientResult result)throws Exception {
String path = req.getParameter(“path”);
String basepath = req.getParameter(“basepath”);
if (StrFunc.isNull(path)) {throw new Exception4I18N( "com.esen.platform.action.portal.actionportalmgr.lackpath", "参数path没有指定.");
}
String oldId = path.substring(path.lastIndexOf(“/“) + 1,path.lastIndexOf("."));
// 读取被克隆组件
int lastSlash = path.lastIndexOf(“/“);
String parentPath = path.substring(0, lastSlash);
String name = path.substring(lastSlash + 1, path.length());
VfsFile2 file = EsenServer.getVfsFile(basepath + “/“ + name);
if (!file.exists()) {throw new Exception4I18N( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.java.noexists", "选中的组件已经被删除!");
}
JSONObject clonedObj = new JSONObject(file.getAsString());
// 生成克隆内容
String origcap = req.getParameter(“caption”);
String id = getNewHtmlId(basepath);
clonedObj.put(CONF_PROP_ID, id);// 保存:自定义组件克隆放在统一文件夹下;内置组件克隆放在自定义组件根目录下
boolean isSys = basepath.endsWith(SYSWIDGETDIR);
if (isSys) {basepath = basepath.replaceFirst(SYSWIDGETDIR, USERWIDGETDIR); parentPath = basepath;
}
path = basepath + “/“ + id + “.json”;
String cap = getCloneWidgetCaption(basepath, parentPath, origcap);
alterOnCaptionChange(clonedObj, cap);
String img = clonedObj.optString(CONF_PROP_IMG, “”);
// 更新缓存,并保存组件
CWHtmlContentMgr.getInstance().put(basepath, id, clonedObj);
// 修改配置
CWidgetUtil.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/"))).saveWidget( id, cap, img, parentPath);
// 克隆预览图,如果存在,才克隆
String previewImgPath = basepath.substring(0,basepath.lastIndexOf("/") + 1) + "coolwidgetimg" + "/" + oldId + ".png";
VfsFile2 previewImg = EsenServer.getVfsFile(previewImgPath);
if (previewImg.exists()) {String dirPath = basepath.substring(0, basepath.lastIndexOf("/") + 1) + "coolwidgetimg"; previewImg .copyTo(EsenServer.getVfsFile(dirPath), id + ".png", true);
}
// 克隆组件的id和cap传回前台
JSONObject newInfo = new JSONObject();
newInfo.put(“id”, id);
newInfo.put(“cap”, cap);
result.getWriter().write(newInfo.toString());
}/**
- 克隆时生成的名字 保证在同一个分组下不存在重名
* - @param basepath
- @param parentPath
- @param origcap
- 被克隆组件的名称
- @return
- @throws Exception4I18N
*/
private String getCloneWidgetCaption(String basepath, String parentPath,
String newCap = origcapString origcap) throws Exception4I18N {
String resultCap = newCap;+ I18N.getString( "com.esen.bi.jsp.action.user.rptcooldsn.ActionEditHtmlWidget.copy", "_副本");
int n = 0;
CWidgetHtmlConfCache widgetConfCache = CWidgetUtil
// while(widgetConfCache.checkIdByGroup(resultCap, parentPath)){.getWidgetConfCache(basepath.substring(0, basepath.lastIndexOf("/")));
while (widgetConfCache.checkWidgetByCap(resultCap, null)) {
}resultCap = newCap + "_" + n; n++;
return resultCap;
}
/**
* 从文件读取 并转换成 主题集(及其控件)的角色 的json对象 数组
* @param req
* @param res
* @param result
* @return
* @throws IOException
*/
public String getRoles(HttpServletRequest req,HttpServletResponse res, ClientResult result) throws IOException {
// 1.获取存储在vfs的主题集的文件名
// 1.1从VFS读数据文件
Server svr = Server.getInstance();
Vfs2 vfs = svr.getVfs();
// 1.2获取文件InputStream对象 VfsFile2InputStream
// 自定义组件 配置文件路径 /root/products/ebi/sys/coolrpt/colluserwidget/conf.xml
VfsFile2 file = vfs.getVfsFile(
"/root/products/ebi/sys/coolrpt/cooluserwidget/conf.xml",
ActionFunc.getLogin(req));
InputStream in = file.getInputStream();
// 1.3将文件解析得到有用信息并存入list数组
// 主题集名称+控件id
List<List> pmlist = ActionEditHtmlWidget.file2list(in);
// 1.4 获得主题集名称
List<String> ztjList = pmlist.get(0);
// 主题集权限json对象(包括操作json对象)集合,根据文件名获取id 最终得到ztjLimitObjects
// 需要根据req获取login对象
PermissionChecker pChecker = ActionFunc4BI.getPermissionChecker(req);
List<JsonObject> ztjLimitObjects = new ArrayList<JsonObject>();
//2.获得前端的itemid 并查出8中权限 有哪几种
for (String ztj : ztjList) {
DWSubjectSet dwSubjectSet = DWMgr.getInstance()
.getDWSubjectSetByCaption(ztj);
String ztj_id ="EBI$7$"+ dwSubjectSet.getServerId();
//CYKR67IYIOPZK2ZYYYWM99YRL3YOFZY1
Boolean view = pChecker.check(ztj_id, ResOper.VIEW.getOperId());
//Boolean viewchild = pChecker.check(ztj_id, ResOper.VIEWCHILD.getOperId());
//完全控制权限
Boolean mana=pChecker.check(ztj_id, ResOper.MANAGE.getOperId());
//Boolean authorize=pChecker.check(ztj_id, ResOper.AUTHORIZE.getOperId());
//Boolean denyauthorize=pChecker.check(ztj_id, ResOper.AUTHORIZE.getOperId());
Boolean edit = pChecker.check(dwSubjectSet, ResOper.EDIT.getOperId());
//Boolean add = pChecker.check(ztj_id, ResOper.ADD.getOperId());
//Boolean del = pChecker.check(ztj_id, ResOper.DELETE.getOperId());
JsonObject zjLimit = new JsonObject();
zjLimit.addProperty("id", ztj_id);
zjLimit.addProperty("name", ztj);
zjLimit.addProperty("view", view);
//zjLimit.addProperty("viewchild", viewchild);
zjLimit.addProperty("mana", mana);
//zjLimit.addProperty("authorize", authorize);
//zjLimit.addProperty("denyauthorize", denyauthorize);
//zjLimit.addProperty("del", del);
//zjLimit.addProperty("add", add);
zjLimit.addProperty("edit", edit);
//根据zjLimit 获取权限
JsonObject role=new JsonObject();
//存入主题集名称(即id) 和对应角色
//System.out.println(zjLimit.toString());
role.addProperty("itemId", ztj);
role.addProperty("role", getRole(zjLimit));
ztjLimitObjects.add(role);
}
result.getWriter().print(ztjLimitObjects.toString());
return null;
}
/**
* 将文件的inputStream对象的有用信息(ztj主题集名称)存到2个list数组中 并存在一个json对象中
*
* @param in
* @return
* @throws IOException
*/
public static List<List> file2list(InputStream in) throws IOException {
JsonObject data = new JsonObject();
List<String> ztjlist = new ArrayList<String>();
List<String> widgetlist = new ArrayList<String>();
if (in != null) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
in, "UTF-8"));
try {
String line = br.readLine();
while (line != null) {
if (line.contains("<group caption")) {
String[] fileds = line.split("\"");
ztjlist.add(fileds[1]);
}
if (line.contains("widget caption")) {
String[] fileds = line.split("\"");
widgetlist.add(fileds[3]);
}
line = br.readLine();
// System.out.println(line);
}
} finally {
br.close();
}
} finally {
in.close();
}
}
List<List> ztj_widgetlist = new ArrayList<List>();
ztj_widgetlist.add(ztjlist);
ztj_widgetlist.add(widgetlist);
return ztj_widgetlist;
}
/**
* 传入一个list权限集合 返回四种类型的一种
* 1.通过判断是否拥有“完全控制”权限,来判断是否是拥有者,如果不是
* 2.通过判断是否拥有“编辑”权限,来判断是否是管理者,如果不是
* 3.通过判断是否拥有“查看”权限,来判断是否是只读者,如果不是
* 4.没有对应权限
*/
public static String getRole(JsonObject limits) {
if(limits.get("mana").getAsBoolean()) {
return "owner";
}else if(limits.get("edit").getAsBoolean()){
return "manager";
}else if(limits.get("view").getAsBoolean()){
return "reader";
}else{
return "nopm";
}
}
}
if (role == “owner”) {
// 0.新建html组件,1.新建分组,2..删除、3重命名、4.导入5.导出 6.刷新 7 移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
if (role == "manager") {
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
if (role == "reader") {
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(false);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
if (role == "nopm") {
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(false);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
if (role == "owner") {
// 0.查看 1.删除、2.重命名、3.克隆4.导出 5移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
if (role == "manager") {
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
if (role == "reader") {
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
if (role == "nopm") {
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}