/** * 获取数据库中文件列表并进行页面数据整合 * * @param path * @return * @throws BusinessServiceException */ @SuppressWarnings("unchecked") public Map querySiteTemplates(Map paramMap) throws BusinessServiceException { String path = (String) paramMap.get("path"); String siteId = (String) paramMap.get("siteId"); String businessCode = (String) paramMap.get("businessCode"); // 获取数据库中文件列表 List<CmsSiteTpl> list = (List<CmsSiteTpl>) querySiteTemplates(siteId, businessCode, path); List<PageTemplateInfo> fileInfoList = new ArrayList<PageTemplateInfo>(); Iterator<CmsSiteTpl> it = list.iterator(); Map model = new HashMap(); String tempDirectoryName = ""; while (it.hasNext()) { CmsSiteTpl cmsSiteTpl = it.next(); PageTemplateInfo pageTemplateInfo = new PageTemplateInfo(); String filePath = cmsSiteTpl.getPath(); // 如果为文件 if (filePath != null && filePath.equals(path)) { pageTemplateInfo.setDirectory(false); pageTemplateInfo.setFileName(cmsSiteTpl.getTemplateFile()); pageTemplateInfo.setImagePath( FileOperationUtils.getFileImagePath( pageTemplateInfo.isDirectory(), pageTemplateInfo.getFileName())); pageTemplateInfo.setFilePath(path); pageTemplateInfo.setTemplateKey(cmsSiteTpl.getTemplateKey()); pageTemplateInfo.setTemplateName(cmsSiteTpl.getTemplateName()); pageTemplateInfo.setTemplateId(cmsSiteTpl.getTemplateId()); fileInfoList.add(pageTemplateInfo); } else { // 如果为文件夹 // 获取子目录名称 String directoryName = filePath.substring(path.length()); int index = directoryName.indexOf("/"); if (index > 0) { directoryName = directoryName.substring(0, index); } if (!tempDirectoryName.equals(directoryName)) { tempDirectoryName = directoryName; pageTemplateInfo.setDirectory(true); pageTemplateInfo.setFileName(directoryName); pageTemplateInfo.setImagePath( FileOperationUtils.getFileImagePath( pageTemplateInfo.isDirectory(), pageTemplateInfo.getFileName())); pageTemplateInfo.setFilePath(path); pageTemplateInfo.setTemplateKey(null); // 文件夹没有对应的模板Key fileInfoList.add(pageTemplateInfo); } } } model.put("path", path); model.put("fileInfoList", fileInfoList); return model; }
/** 保存文件内容 */ @SuppressWarnings("unchecked") public void saveSiteTemplateContent(Map paramMap) throws BusinessServiceException { List<CmsSiteTplDt> list = (List) paramMap.get("cmsSiteTplDtList"); saveSiteTemplateContent(list); String url = (String) paramMap.get("url"); String fileName = (String) paramMap.get("fileName"); String content = (String) paramMap.get("content"); SystemConfigBo systemConfigBo = SpringBeanUtil.getBean("systemConfigBo"); url = systemConfigBo.getTemplatepath() + url; if (!FileOperationUtils.saveFile(content, url, fileName)) { log.error("保存文件内容失败,请联系管理员!"); throw new BusinessServiceException("保存文件内容失败,请联系管理员!"); } }
/** * 删除模板 * * @return */ @SuppressWarnings("unchecked") public String removeSiteTemplate(Map paramMap) throws BusinessServiceException { PageTemplateInfo pageTemplateInfo = (PageTemplateInfo) paramMap.get("pageTemplateInfo"); String url = (String) paramMap.get("url"); String msg = "删除模板失败"; if (pageTemplateInfo != null) { CmsSiteTpl cmsSiteTpl = new CmsSiteTpl(); cmsSiteTpl.setTemplateId(pageTemplateInfo.getTemplateId()); removeSiteTemplate(cmsSiteTpl); // 删除模板文件 SystemConfigBo systemConfigBo = SpringBeanUtil.getBean("systemConfigBo"); url = systemConfigBo.getTemplatepath() + url; if (FileOperationUtils.deleteFile(url)) { msg = "删除文件成功!"; } } return msg; }