/** 保存文件内容 */ @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; }
/** * 把模板保存至模板库 * * @return */ @SuppressWarnings("unchecked") @Transactional(rollbackFor = {RuntimeException.class, Exception.class}) public void saveAsTemplateLibDeal(Map paramMap) throws BusinessServiceException { PageTemplateInfo pageTemplateInfo = (PageTemplateInfo) paramMap.get("pageTemplateInfo"); String currentUser = (String) paramMap.get("currentUser"); Date date = new Date(); // 查询当前模板信息及参数信息 CmsSiteTpl cmsSiteTpl = findTplByTemplateId(pageTemplateInfo.getTemplateId()); PreparedTemplateManageBo preparedTemplateManageBo = SpringBeanUtil.getBean("preparedTemplateManageBo"); if (preparedTemplateManageBo.queryTemplateByKey(cmsSiteTpl.getTemplateKey()) == null) { List<CmsSiteTplDt> list = queryTemplateDatatags(cmsSiteTpl.getTemplateId()); // 复制模板库内容 CmsTemplateLib lib = new CmsTemplateLib(); lib.setCreatedBy(currentUser); lib.setCreatedDate(date); lib.setUpdateBy(currentUser); lib.setUpdateDate(date); lib.setLibDescription(cmsSiteTpl.getCmsSite().getSiteName()); lib.setLibName(cmsSiteTpl.getCmsSite().getSiteName()); // 复制模板内容 CmsTemplate template = new CmsTemplate(); template.setCmsTemplateLib(lib); template.setCreatedBy(currentUser); template.setCreatedDate(date); template.setUpdateBy(currentUser); template.setUpdateDate(date); template.setDescription(cmsSiteTpl.getDescription()); template.setPath(cmsSiteTpl.getPath()); template.setTargetFile(cmsSiteTpl.getTargetFile()); template.setTemplateFile(cmsSiteTpl.getTemplateFile()); template.setTemplateKey(cmsSiteTpl.getTemplateKey()); template.setTemplateName(cmsSiteTpl.getTemplateName()); // 模板文件保存到文件系统中 // url = systemConfigBo.getSysParam().getTemplatepath() + url; // template.setTemplateContent(FileOperationUtils.readFile(url)); // 复制模板参数 for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { CmsSiteTplDt cmsSiteTplDt = (CmsSiteTplDt) iterator.next(); // 新建模板对象 CmsTplDt cmsTplDt = new CmsTplDt(); cmsTplDt.setCreatedBy(currentUser); cmsTplDt.setCreatedDate(date); cmsTplDt.setUpdateBy(currentUser); cmsTplDt.setUpdateDate(date); cmsTplDt.setDatatagId(cmsSiteTplDt.getDatatagId()); cmsTplDt.setDatatagKey(cmsSiteTplDt.getDatatagKey()); // cmsTplDt.setTemplateKey(cmsSiteTpl.getTemplateKey()); // //2010-08-13 cmsTplDt.setCmsTemplate(template); for (Iterator iterator2 = cmsSiteTplDt.getCmsSiteTplDtparams().iterator(); iterator2.hasNext(); ) { CmsSiteTplDtparam cmsSiteTplDtparam = (CmsSiteTplDtparam) iterator2.next(); // 新建参数对象 CmsTplDtparam cmsTplDtparam = new CmsTplDtparam(); // cmsTplDtparam.setDatatagId(cmsSiteTplDt.getDatatagId()); // cmsTplDtparam.setTemplateKey(cmsSiteTpl.getTemplateKey()); // //2010-08-13 cmsTplDtparam.setCmsTplDt(cmsTplDt); cmsTplDtparam.setDefaultValue(cmsSiteTplDtparam.getValue()); cmsTplDtparam.setParamKey(cmsSiteTplDtparam.getParamKey()); cmsTplDtparam.setParamName(cmsSiteTplDtparam.getParamName()); // 添加到模板信息中 cmsTplDt.getCmsTplDtparams().add(cmsTplDtparam); } template.getCmsTplDts().add(cmsTplDt); } Map map = new HashMap(); map.put("cmsTemplateLib", lib); map.put("cmsTemplate", template); saveAsTemplateLib(map); } else { throw new BusinessServiceException("该模板已经存在模板库中!"); } }